Closed guest271314 closed 2 years ago
The WebRTC API is not exposed to Service Workers in browsers so sadly datachannel-wasm won't work in a Service Worker.
Ah, I was thinking you defined WebRTC in WASM, thus exposed WebRTC in any context. This https://rustwasm.github.io/wasm-bindgen/examples/webrtc_datachannel.html must not do that either.
Ah, I was thinking you defined WebRTC in WASM, thus exposed WebRTC in any context. This https://rustwasm.github.io/wasm-bindgen/examples/webrtc_datachannel.html must not do that either.
In browser contexts you can't implement a custom WebRTC stack as there are no lower-level network API, so you actually need to wrap the existing JS API. That's indeed what Rust bindings also do.
Can this library create a WASM datachannel in a
ServiceWorker
and communicate withwindow
?In the source code
window
is referenced.ServiceWorker
does not have awindow
.globalThis
can be substituted forwindow
below if in fact datachannel-wasm can be created in aServiceWorker
(or Worker).https://github.com/paullouisageneau/datachannel-wasm/blob/bb1da1b7b1f9d4555aaf097d606bcad20eed7245/wasm/js/webrtc.js#L152