webrtc
webrtc copied to clipboard
Limited Web (Wasm through js_sys) layer for code reuse ?
Hi,
I was wondering if there was a way to reuse code written with this lib in a frontend wasm project, obviously not all features, but maybe a subset.
I've been using a fork of this project compiled to WASM and running it inside Deno for a couple weeks now: [https://github.com/evan-brass/webrtc-deno]. Specifically I'm using the SCTP crate (which depends on Util), and I've tried using the DataChannel crate. Some of the other crates compile, but I don't really know which of them actually work.
I made some ugly patches to get it to work for my use case:
- Removing Send and Sync from all the async stuff
- Switching all the tokio::spawn() to be wasm_bindgen_futures::spawn()
- Adding a mock SystemTime that uses js_sys instead of tokio::SystemTime
- Mock UDPSocket that wraps around Deno's tcp/udp sockets
- Eventually I intend to use Mbedtls to replace RusTLS: https://github.com/evan-brass/Mbedtls.js-sys/tree/please-rust-please
- More stuff that I forgot..
Which pieces were you wanting to use?
If you have any questions about mixing webrtc-rs and wasm, I might be able to help.
You can't open sockets like you want inside a browser, you are forced to use the Webrtc API through JS, so it requires two codebases for the client and the server. i was wondering if there is a project that allows writing for both at the same time. Essentially the server behaves like an additional peer, with a few extra features so having the same codebase would be advantageous.
I'm not aware of a crate that provides a common interface and wraps over webrtc-rs and web_sys::RtcPeerConnection, but I also haven't looked. Maybe one of the maintainers knows of one?
There's been previous discussions to this effect in Discord. As you identify we cannot run via WASM in the browser since direct socket access is not possible, but Pion implements a WASM shim that allows using Pion and the browser WebRTC API transparently(What @evan-brass suggests). We should be able to port this over from Pion.
The various files named *_js.go in pion/webrtc are worth reviewing for inspiration
Not sure how related to this issue it is, but how do-able would it be to have at least the types be supported under wasm32 without having to shadow them? The specific types needed would be RTCSessionDescription, RTCIceCandidateInit and RTCIceServer