Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
515 stars 197 forks source link

Browser push notifications? #220

Open Neobii opened 8 years ago

Neobii commented 8 years ago

Do you think you'll ever add browser push notifications to this package?

Neobii commented 8 years ago

Okay, @raix I see some of the comments you've made in the past. It seems like we need to be able to generate the service worker and manifest.json.

I see these two places in the code

webServiceUrl: Match.Optional(String),
      websitePushId: Match.Optional(String),

Is the webservice url the service worker? Where's it getting the manifest from?

Neobii commented 8 years ago

I added this file to it: https://github.com/Neobii/push/blob/v3.x/lib/client/browserPush.js and it's based off of https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en .

So now, when you call Push.enable(true) and you are in the browser, it will prompt you to "allow or deny" push notifications. Do you have any guidance on where to take it from here?

Neobii commented 8 years ago

I'm getting a little bit closer: https://github.com/Neobii/push , on push configure I'm adding the manifest and service worker which are in the package folder now.

raix commented 8 years ago

I think the server part adding certificates generating manifests etc. is not implemented - the client browser code might have to be aligned with the latests cordova api

Neobii commented 8 years ago

What do you think I should use to generate the manifest and web service worker? I see cfs:http-methods and WebApp.connectHandlers. The manifest needs to have gcm_sender_id and we have that from the config already.

It doesn't look like browser push notifications are implemented in the cordova plugin you're using.

raix commented 8 years ago

It's best to use connect directly via WebApp - Right the corodva plugin is only for android+iOS - but I've started on the browser client code a long time ago, it's in https://github.com/raix/push/blob/fix-device-dependency-deprecate-json-format/lib/client/browser.js (it needs a clean up or maybe use https://www.npmjs.com/package/push.js for the client-side)

Neobii commented 8 years ago

Hmm, are you loading in the service worker in an iframe there? I don't see where you define the service worker like navigator.serviceWorker.register('/packages/raix_push/browser/service-worker.js'). Are you doing it a different way?

raix commented 8 years ago

the iframe is a legacy thing - before meteor had cordova support - so that could go

Neobii commented 8 years ago

Okay, I'm going to work on generating the manifest.json file from the config, check out this other package that seems to work: https://github.com/taromero/meteor-chrome-push-notifications/ I need a hint on tying the service worker back to the general push stuff.

Neobii commented 8 years ago

What do you think about moving the json file to the private folder and loading them in through Assets? It looks like I can't load assets outside of the package, how do you suggest I load the json file if not with the assets?

Neobii commented 8 years ago

Okay! I got the browser manifest generating from the push configuration using the push.configuration.js plugin. https://github.com/Neobii/push/blob/v3.x/lib/server/push.api.js#L50

To add it to the body I simply did $("body").append('<link rel="manifest" href="/push-manifest.json">');, only if they are not running in cordova.

I need to send the subscription id to the server, if someone from chrome connects would an android (gcm) show a connection on the push debug?

Neobii commented 8 years ago

The more I think about it, it seems like we should split this into a couple different packages.

eskan commented 8 years ago

hi, this is how i handle "chrome" notification with service worker https://gist.github.com/eskan/133451a13ecb670d253322e1dcdfb033

oskareke commented 7 years ago

I can't seem to get this working - may I ask what does your service worker look like?

eskan commented 7 years ago

hum .. i don't remember this gist :D ... the idea is to update raix:push data with the meteor method when a subscription is received. The service worker should be simple as

self.addEventListener('push', function(event) {
  event.waitUntil(self.registration.showNotification('New Message', {
    body: 'new message',
    icon: '/img/icon.png',
    vibrate: [500]
  }));
});

You can test it in Dev tools -> Application -> Service worker -> (push)

jamauro commented 6 years ago

Was anyone able to get browser push notifications working with this package?