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

Using WebRTC peer-to-peer networks to back Service Workers #60

Open
interfect opened this issue Jul 8, 2020 · 2 comments
Open

Using WebRTC peer-to-peer networks to back Service Workers #60

interfect opened this issue Jul 8, 2020 · 2 comments

Comments

@interfect
Copy link

interfect commented Jul 8, 2020

Currently all the use case document says about WebRTC-NV and workers is:

<tr id="N13">
<td>N13</td>
<td>It must be possible to support data exchange
in a worker.</td>
</tr>

<tr id="N21">
<td>N21</td>
<td>It must be possible to efficiently share media
between the main thread and worker threads.</td>
</tr>
<tr id="N22">
<td>N22</td>
<td>It must be possible to do efficient media
manipulation in worker threads by utilizing the GPU.</td>
</tr>

A lot of people over at w3c/webrtc-pc#230 and related PRs have been asking for the machinery needed to effectively use WebRTC to build peer-to-peer networks in Service Workers specifically. The point of this is being able to fulfill requests for URLs by pulling them from a peer to peer network instead of going over HTTP. This would involve revising WebRTC so that the API is usable in Service Workers, and also revising Service Workers to clarify what the expected worker lifetime semantics should be for Service Workers that are maintaining WebRTC connections, so requests don't generally have to try and reconnect to the peer-to-peer network from scratch.

I opened an issue over on the current WebRTC spec recommending that the API be exposed to all forms of worker (w3c/webrtc-pc#2553), but it seems like people are reluctant to revise 1.0 to have this feature, and sent it over here.

Making WebRTC work in Service Workers kind of fits into the "File Sharing" use case, especially this line:

It is also possible for a participant to send a large file to a user who is not currently online.

But I think the part of N13 about supporting data exchange in "a worker" might need to change to list the types of workers that need access to the API explicitly, and include Service Workers.

There might also be room for an entire new use case focusing on peer-to-peer content distribution used to back a page or web application, instead of just on file sharing within the context of a video/voice conference between a few users (where an ordinary Web Worker would do).

Is it clear that N13 would require WebRTC to be available in Service Workers already? If not, should it be added there? Or should backing Service Worker fetches with a peer-to-peer network become an entire new use case section?

@ivelin
Copy link

ivelin commented Dec 28, 2020

Thanks for opening this issue, @interfect .

Another use case that can benefit from allowing webrtc access in service workers is enabling frontend frameworks like Vue/Vuetify to access remote IoT edge devices via standard html fetch() without worrying about all the mechanics of p2p connectivity.

https://webrtchacks.com/private-home-surveillance-with-the-webrtc-datachannel/

Additional benefit would be enabling service worker background sync over webrtc/http layer (as illustrated in the blog above). A PWA can asynchronously pull edge device data and make it available to users on demand. That would be better UX than the user having to wait for a remote edge device data pull when they open the app page.

@jimmywarting
Copy link

new semantic to the service worker allows for website to extend the lifetime of a service worker with a promise to live indefinitely (as long as there is any owning tab open to that service workers scope)
it's similar to waitUntil i suppose...

anyhow, the (new?) waitUntil will therefor be respectful of the developers decision so folks don't have to abuse the lifetime with pinging a service worker with postMessages all the time. the hard (30s - 5m) time-to-live timer will kick in when all the tabs are closed

this makes it potentially very useful for us to have a WebRTC + DataChannel inside of a Service Worker that isn't terminated after a hard timeout

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

4 participants