MatthieuLemoine / electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
191 stars 62 forks source link

Where does one get the end point? #31

Closed riatzukiza closed 5 years ago

riatzukiza commented 5 years ago

I get a log in my browser that I have successfully subscribed to a push api, but I get nothing. I am migrating an existing push api service from a website to an electron client.

  navigator.serviceWorker.register('/serviceworker.js')
    .then(function(registration) {

        return registration.pushManager.subscribe({ userVisibleOnly: true })
        .then(function(subscription) {
             subscription.endpoint // something like "https://android.google.com/gcm/send/....."
        });
  }).catch(function(error) {
  });

How do I generate the endpoint url from the token data I'm provided from this library?

MatthieuLemoine commented 5 years ago

Electron doesn't implement the PushManager API so you can't use a serviceWorker registration to receive push notifications. It's the reason why I created push-receiver in the first place.

Using electron-push-receiver, you'll receive a TOKEN_UPDATED event with the token you can use to send a push notification. To setup this library, you just need to follow the README.

riatzukiza commented 5 years ago

I understand that, I don't want the service worker. I want to get the endpoint url with out invoking all that browser stuff. is there a way to generate it from the token?

MatthieuLemoine commented 5 years ago

The endpoint to use to send notifications is the FCM one. You can find an example here https://github.com/MatthieuLemoine/push-receiver/blob/master/scripts/send/index.js#L21

riatzukiza commented 5 years ago

I saw that, the issue I'm having is I'm working on an electron client to a backend I don't have much control over, and they are sending the exact url that the browser would usually give them, and doing push notifications with that url. The url the browser gives looks like https://android.google.com/gcm/send/oig9h238h49fsf7....

The fact that it was gcm that the chromium browser gave back was a little funny to me.

I've been hunting all around to see if I can get a url similar to that, that wouldn't require that back end to be changed.

If I could also know for sure that I couldn't do it with the token I get back from this library, that'd be fine and I just need to wait on the backend to be modified to accept a token.

MatthieuLemoine commented 5 years ago

I guess you could try https://fcm.googleapis.com/fcm/send/${token}, it's what we use to register to FCM https://github.com/MatthieuLemoine/push-receiver/blob/817c843c0689d0b73b823485012897d7b02a168e/src/fcm/index.js#L20