codedge-llc / pigeon

iOS and Android push notifications for Elixir
https://hex.pm/packages/pigeon
MIT License
645 stars 145 forks source link

Web Push Payload Encryption #229

Open shahryarjb opened 2 years ago

shahryarjb commented 2 years ago

Request for feature. 🌹

Hi, I created a post in elixir forum https://elixirforum.com/t/how-to-send-push-notification-with-pigeon-when-we-have-subscriptions/50934

So I asked about Web Push Payload Encryption

When we have a subscription like

{
  "endpoint": "https://fcm.googleapis.com/fcm/send/USER_STUFF",
  "keys": {
    "auth": "AUTH_CODE",
    "p256dh": "P256DH_CODE"
  }
}

which is created by this code in service worker (sw.js) file:

var vapidPublicKey = 'MY_PUBLIC_KEY';
var convertedVapidPublicKey = urlBase64ToUint8Array(vapidPublicKey);
return reg.pushManager.subscribe({
  userVisibleOnly: true,
  applicationServerKey: convertedVapidPublicKey,
});

I think your library does not support it, I could not be able to find any document. I work with https://www.npmjs.com/package/web-push in JavaScript and recently found a library https://github.com/danhper/elixir-web-push-encryption in elixir to support it.

If it is possible, support this Feature

Thank you in advance for all your efforts.

petermm commented 2 years ago

the elixir library (https://github.com/danhper/elixir-web-push-encryption) works great - and present day webpush is a totally different from the classic app push services that pigeon support.

namely you do individual POST per browser push subscription:

    ...
    msg = %{
      title: "Chat: #{user.first_name} #{user.sur_name}",
      body: "#{message_text}",
      openUrl: "/chat?topic=#{message.room_id}"
    }

    browsers
    |> Enum.each(fn browser ->
      subscription = %{
        keys: %{
          p256dh: browser.p256dh,
          auth: browser.auth
        },
        endpoint: browser.endpoint
      }

      {:ok, response} = WebPushEncryption.send_web_push(Jason.encode!(msg), subscription)
      ...

which is totally different from what Pigeon does (maintain a http2 connection/stream to the push servers)..

so with all respect I see little reason for Pigeon to support webpush - especially as there already is a well functioning elixir library..