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

Documentation/Recipe around integrating/interfacing ember-service-worker with an Ember Service. #78

Open
hronik1 opened this issue May 3, 2017 · 3 comments

Comments

@hronik1
Copy link

hronik1 commented May 3, 2017

For context, I'm looking to use ember-service-worker to facilitate push notifications using the PushSubscription API.

My app has a service which is responsible for maintaining user session information, and I would like to expose that session service to the service worker, so that it can map push subscriptions to a specific user. I imagine this is a fairly common pattern for folks who are looking to use service workers for the purpose of push subscriptions, however the documentation seems geared solely towards using service workers for the purpose of making apps offline first.

@jlami
Copy link

jlami commented Mar 23, 2018

Have you ever found anything on this subject? I found this resource: https://developers.google.com/web/fundamentals/push-notifications/common-notification-patterns

It seems like you would need messages for this. Something like this on the service side?

navigator.serviceWorker.addEventListener('message', function(event) {
  referenceToService.handle(event);
}

I'm not really sure when to add this listener. In an initialiser? Or on the init of the service? init could probably work.

And we need this on the service worker side:

windowClient.postMessage(event);

To get a client the service worker needs to inspect self.clients https://developer.mozilla.org/en-US/docs/Web/API/Clients

@ghost
Copy link

ghost commented Mar 23, 2018

Instead of relying on postMessage, I would either store it in Local Storage or IndexedDB if it's not sensitive data, or fetch it from the server if it is. The SW has free access to IDB and LS.

@jlami
Copy link

jlami commented Mar 23, 2018

Why would you not use postMessage? Browser support?

Using the server does not really make sense to me for push notifications, since you would then need a push notification from the server that it has a message ;)

But LocalStorage (or SessionStorage) seems like a good alternative with the window.addEventListener('storage', function(event) {}) option.

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

2 participants