paullouisageneau / datachannel-wasm

C++ WebRTC Data Channels and WebSockets for WebAssembly in browsers
MIT License
148 stars 25 forks source link

send Bytes over DataChannel #48

Closed tbuchs closed 6 months ago

tbuchs commented 6 months ago

I try to establish a communication over WebRTC using the library. The connection works fine and also sending strings over the connection works. However, when trying to send bytes instead of strings, I always get the following error in the browser: RTCDataChannel.send: Argument 1 can't be a SharedArrayBuffer or an ArrayBufferView backed by a SharedArrayBuffer

This also happens if I only try to send a very simple byte like: std::byte b{42}; dc->send(&b, 1);

paullouisageneau commented 6 months ago

It looks like your WASM heap is a SharedArrayBuffer, I guess because you are using WASM threads, and for some reason the browser does not like that the shared buffer is passed to RTCDataChannel.send. A simple copy should fix this. Does it work with https://github.com/paullouisageneau/datachannel-wasm/pull/49 ?

tbuchs commented 6 months ago

It looks like your WASM heap is a SharedArrayBuffer, I guess because you are using WASM threads

that's right

A simple copy should fix this. Does it work with https://github.com/paullouisageneau/datachannel-wasm/pull/49 ?

Yes, that works perfectly, thanks!

paullouisageneau commented 6 months ago

Great, I'm merging it!