ipfs-shipyard/ipfs-service-worker-demos

Instructions to demonstrate this?

mitra42 opened this issue · 5 comments

Are there a set of instructions to get this working ?

What I figured so far ...

  • Clone the repo from here
  • cd to ipfs-service-worker
  • npm install
  • cd examples
  • npm run build
  • cp -r public+sw/* dist/public+sw

Then copy all of dist/public+sw to a http server
Access for example /public+sw/index.html

It reports ...

-> Registered the service worker successfuly
bundle.js:1:807398
install step
service-worker-bundle.js:1:1582000
activate step

so it looks like the SW is activated.

But ...clicking on window.ipfs.id gets:

 TypeError: asm.js type error: expecting argument type declaration for 'e' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
TypeError: e(...) is undefined

and putting a IPFS hash in the input box results in e.g.

Handling fetch event for http://localhost:8080/ipfs/zb2rhfUz7JSdBBb39AHrhtiMLFa5XV2h8Ni1mGz8D67NNKsZg

So it looks like service worker is getting the request, but it never returns.

I'm not sure if I'm doing something wrong (e.g. I didn't change config from the repo default) or if its still early days for this?

Some more info ... in case its useful
First time I run this in the browser I see the "activate step" in the console, but not the events after IPFS successfully loads.
Close the browser, restart, and this "activate step" doesn't occur. I don't know if part of FF or Chrome remains in memory, but if not then it suggests that on subsequent runs its not trying to connect to IPFS.
Attempts to retrieve a IPFS hash after a browser restart report service-worker-bundle.js:1 Uncaught (in promise) TypeError: Cannot read property 'files' of undefined
at service-worker-bundle.js:1
at self.addEventListener.e (service-worker-bundle.js:1)
which suggests that "node" is undefined, i.e. confirming that its lost whatever connection to IPFS its had.

Hope that's helpful ...

I created a pull request to fix the problems above and upgrade to newer webpack and ipfs

Hello @mitra42, I tried the current version in master as you described, as well as your PR implementation.

The master version worked perfectly for me using the steps as you described:

  • Clone the repo from here
  • cd to ipfs-service-worker
  • npm install
  • cd examples/use-from-another-page
  • npm install
  • npm run build
  • run using http-server

However, with your version, I couldn't manage to use get window.ipfs.id nor fetch working.

Note: The use-from-another-page example should have its usage explained, as you did in the PR.

Hi Vasco - I'm not sure what the problem was with the PR, I did quite a bit of work on it post this PR to get a service worker version of our archive.app page going. In the end I skipped using the ipfs proxy because it was too hard to follow what the code did, and we needed to make some changes, and instead rewrote message passing to the Service Worker.

I'm just in the process of posting it to its own repo which I'll share in a few days, it probably won't get much more attention because we have to use webtorrent for the videos (because of some other IPFS issues) and webtorrent won't currently work in a SW because of the lack of WebRTC in ServiceWorkers.

One thing that was definitely clear was that we had to start IPFS at the activate stage, not at the install stage. The install is not getting run on second accesses etc, so as I reported above its trying to access a undefined "node".

@mitra42 you are right regarding the second access. Master version has problems on a page refresh 🤔

I will appreciate that you share that when available, thanks