Communication between asp.net app and a serviceworker, via signalR?
Asked Answered
R

1

8

I'm new to serviceworkers and I wonder how could I connect my serviceworker to my asp.net application. My js client already is communicated with a service worker and it's able to show notifications. However, I've seen that some webs (e.g facebook) send notifications even the browser's tab ins't opened (not inactive, not opened). I use signalR to communicate my app with the server. Would it be possible to communicate the serviceworker with the server? It would require to add signalR code to the serviceworker if I'm not wrong, but I don't think it's possible. I've seen that google has another way of communication, Google Cloud Communication

I can't use that, so any ideas of how could I solve this problem?

Reiko answered 17/2, 2016 at 16:51 Comment(2)
I don't think signalR can work on a worker... It certainly struggles with webworkers. It's a new future due this year in SignalR v3Ahders
correct, sockets do not pass through the service worker. Service workers only 'catch' https requests, not socket or other protocols. You really want a push service to trigger notifications like this. The user has to opt into those BTW.Cadal
V
10

To make use of offline notifications (i.e., your browser is open but your page isn't), the browser itself needs to know about a messaging service that it can respond to, and which would let it know to wake up your service worker and give it a notification. These services are hard-coded into the browser. In Chrome's case, the service is GCM. And I believe Firefox is rolling out something of its own. You cannot wake up your service worker yourself from your server without going through one of these messaging services.

Remember that generally your service worker is asleep. The browser only wakes it up in response to specific events, and, if your pages are closed, there is no way to trigger a service worker event from your server, unless the browser provides a messaging service such as GCM.

Vitriolize answered 17/2, 2016 at 17:11 Comment(1)
This is the push service used in Firefox: github.com/mozilla-services/autopushBarring

© 2022 - 2024 — McMap. All rights reserved.