Phoenix channels and service worker

Right now I’m investigating how to work with service workers and phoenix channels, I would like to know if someone has experience with these topics, it would be really helpful to know the correct way to use. What I want is to push notifications when the browser is closed using phoenix channels.

2 Likes

@boriscy did you figure out a way to do this in the end?
I’m exploring maintaining channels connection in a service worker as well.

I recently looked at this as an option and can only say that we went with a shared worker connecting to channels instead. The reliability of service workers in terms of when they run and for how long isn’t something to be circumvented, IMO. There are push alternatives to notifying a service worker and I think just accepting that is recommended.

With that said, using channels from a shared worker is good. If you’re not doing cache management and other more service worker specific stuff you could argue the worker route is the correct one regardless.

@gon782 your approach seems the most reasonable for me as well, I’ll try implementing it the same way.

Good thing this came up so I won’t be wasting time baking channels connection into a service worker.