-
Notifications
You must be signed in to change notification settings - Fork 9
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
Document interaction with (shared) service workers #26
Comments
cc @Gozala |
@dokterbob creating an example demonstrating how to use IPFS in the shared worker from the service worker is on my TODO list. Unfortunately that is a non-trivial task because
There's some research to be done to see if a better alternatives like the one below is viable: const [client] = await self.clients.matchAll({ includeUncontrolled: true, type: "sharedworker" })
const ipfs = client && IPFSClient.from(client) As things stand today that does not work because shared worker isn't getting messages send using But from what I can tell there is not way for shared worker to receive message from |
Thanks for the feedback @Gozala! I'm not sure whether I fully understand - but it does seem there are two distinct things: Right now, it does seem that scenario a) is 'good enough for now'. It might imply that users have multiple JS IPFS nodes running in the background (which, I do think should kill themselves within a given timeout, e.g. 2 or 5 minutes or so). Would implementing this be somehow simpler? Then, for b), I've read something somewhere (sorry, no reference...) about using an iframe in an iframe. Although, once a web worker is running for Lastly, I consider this only a bridge, I think we should try and get more enthusiastic users to either run JS IPFS in an extension or to run a native IPFS daemon. It's more about offloading the dependency on a single gateway, and also to prevent potential censorship of said gateway. Curious what your thoughts are. |
Submitted a pull request that demonstrates use of the shared ipfs node from service worker |
Implementation of ipfs-message-port-server and client are designed to abstract between those two use cases. I'll try to explain how:
This enables a) because you can load server in the SharedWorker and create clients to it in tabs. This also enables b) because origin A can operate server and pass Now that said there are some challenges we need to address before we can have good story for b). Namely we need to ensure that B cant abuse A by enforcing origin separation, otherwise we may enable user tracking and other ill behaviors.
I'm not sure I fully understand this question. Implementing a) now should be possible as demonstrated by If you use js-ipfs as is (without message-port-server / client) you'll likely end up with n nodes for n tabs and there are some problems one would have to overcome e.g. all nodes will end up with same peerID and only one would be really connected because peers on the other devices will end up talking to one of those tabs and not others.
Are you by chance referring to https://hackmd.io/QYzm5P3bRQ6f85MJ4qsGWg or a https://github.com/gozala/lunet ? If so those are explorations that lead to message-port-server / client work. And yes once we address origin separation challenges (described above) I hope we will be able to get something along the lines what you are describing. More specifically if you look at ipfs/js-ipfs#3374 you can see it does something very similar. On fetch event service worker obtains message port for the shared worker from the iframe parent, and uses message-port client to get IPFS content. Thing that will have to change (once we have all the pieces) is parent page will obtain port for message port from other origin like mentioned I wish it was more simple or obvious, but many web APIs have server client architecture so ingrained in the design that doing anything different requires orchestration of all the moving pieces to make it work. If you have more questions or need clarification please don't hesitate to follow up. |
It would be great to know whether and how (shared) service workers would be supported.
Shared service workers: https://github.com/ipfs/js-ipfs/tree/master/examples/browser-sharing-node-across-tabs
The text was updated successfully, but these errors were encountered: