Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't you send string using p2pcf.send #22

Open
silenceofthewans opened this issue Mar 5, 2023 · 2 comments
Open

Why can't you send string using p2pcf.send #22

silenceofthewans opened this issue Mar 5, 2023 · 2 comments

Comments

@silenceofthewans
Copy link

Just trying to learn, Is there a reason the send method only supports ArrayBuffer. I know I can convert string to ArrayBuffer with TextEncoder and vice versa but it's additional steps since I only need to send simple two characters messages. Is it more performant than sending strings directly? My use case is sending simple two character string with lowest latency possible.

@jonathanhawleypeters
Copy link

jonathanhawleypeters commented Mar 26, 2023

Hi @silenceofthewans,

The choice to use ArrayBuffer is at the WebRTC specification level, @gfodor will not be able to change that for you. You can see a draft of the WebRTC specification here https://w3c.github.io/webrtc-charter/webrtc-charter.html, and join the W3C here to discuss it.

If you choose to work with the constraint, you can compare the performance of converting the messages to ArrayBuffer ahead of time to encoding them as messages are sent (I'm assuming that all possible values are known to you). I suspect you will not see much of a difference, but you can't know without testing.

Hope that helps.

Edit: I was mistaken, see the following comment.

@evan-brass
Copy link

Perhaps this comment needs an update?

I don't know the details of P2Pcf, or simple-peer, but WebRTC DataChannels can send strings, typed arrays, or blobs.

WebRTC has two (actually 4) data message types: string or binary. Receiving a string message results in a js string as the data property, while receiving a binary message will produce either an ArrayBuffer or Blob based on the binaryType property set by the receiver.

If there's a constraint to only ArrayBuffers, I think it's higher in the stack than the WebRTC API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants