-
Notifications
You must be signed in to change notification settings - Fork 19
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
Investigate the possibility to interact with data channel in workers #64
Comments
This is possibly related to some things I've been thinking about lately: in particular, I'd like to be able to transfer various webrtc-related objects between iframes in a page using postMessage() -- it seems like making RTCDataChannel Transferrable would solve this for workers as well. (For my own use case I'm also interested in doing this with media streams and other objects) |
@zenhack, could you share more of your use case? As of transferring MediaStreamTrack objects, this might best be tracked in a separate issue in https://github.com/w3c/mediacapture-extensions. |
Sure! This is in the context of Sandstorm. Basically, it's a platform for self-hosting web apps, and we don't want apps to be able to "phone home" to app developers without the consent of the user -- so on the server side apps are containerized and not given network access, and in the browser we use Content-Security-Policy to block most ways an app could contact the outside world (there's currently no way to do this for webrtc, which I'm trying to help solve in w3c/webappsec-csp#457). We also run the app's page itself from a separate origin than the Sandstorm UI, inside of an iframe, with the Sandstorm UI around it. You can get a feel for it at https://demo.sandstorm.io. The iframe has the unfortunate consequence that apps can't request access to mic & camera directly. So, I'd like to provide a way through which apps could request this access (and also controlled use of the networking portions of webrtc) from Sandstorm itself via a postMessage() API; we already use this mechanism for requesting access to server-provided resources, so it would be a natural extension: https://docs.sandstorm.io/en/latest/developing/powerbox/ With that in place, Sandstorm can request access to resources from the browser itself, and then mediate apps' access to them. Note that if/when the CSP change is implemented, Sandstorm itself can still create webrtc connections, since it is served from a different origin than the apps, with a different (more relaxed) CSP. |
I proposed this quite a few years ago in the WG - making datachannels transferrable so that apps could process and respond to network input without waiting on the mainthread. A good example is a game with a datachannel connection to a server and/or to each other player. Game state maintenance could occur in a worker, while mainthread is frequently busy with user input and rendering. Similarly, we discussed possibly transferring mediastreams, and possibly already-connected connections |
I wish to be able to construct a WebRTC datachannel in (service) workers rather then having to get them from some main page as transfered |
I'll provide my use case here in case this presentation hasn't been given yet. I'm working on a browser-based MMORPG. To make the game as efficient as possible, I'm working to move everything except for rendering off of the UI thread and into workers. My current work is centered around moving network communications into their own worker. My Worker has been processing messages from WebSockets, then using a |
I did a prototype implementation in WebKit and have the following implementation feedback:
|
Cool!
That should only really affect service worker use cases, right?
Since setting the |
That might also affect cases where you transfer a channel to another window, though WebKit prototype does not yet support out-of-process channels.
Right, ditto for datachannel event. |
Great news! |
You can transfer any data channel, either ones you get from createDataChannel or ondatachannel events, provided they are in connecting state. |
But how would one catch an inbound channel that was still connecting ? What event could you wait for? By the time you know the label it is already open I think. |
Hum, you are right. The idea is that it would be fine to at least transfer the datachannel in the datachannel event handler. |
In a lot of cases it won't matter, you mostly want to transfer channels where you control the lifecycle, but it would make some P2P usages inconveniently asymmetric. |
OOB negotiated data channels would work fine, just IB negotiated data channels would not. Perhaps an alternative would be to only allow transfer of data channels where no event handler has been attached and
Or that. IIRC the channel is marked |
Right, we have a few options:
WebKit prototype is doing 1. |
We could try to allow processing of data channel messages in workers, without trying to solve the bigger issue of creating a data channel in a worker.
That would solve some known use cases like Zoom or streaming
The text was updated successfully, but these errors were encountered: