Problem/Motivation

We want to add Google Firebase notifications to the app. So I am creating this issue to make the code available for anyone to fiddle around with. It's work in progress, so don't be harsh please ;-)

Background

We are creating a pwa. I tried both this module (pwa), combined with the pf_notifications module and the advanced_pwa module.
For both modules I did not really like the notifications part. I could not get it to work steadyly (off course this is my lack of expertise).

So then I decided to go for this module because I can use it without notification stuff, but just use it for the manifest and service handler. I added an (undocumented, but there are more of them in the module ;-) ) hook to modify the service worker and add the notification stuff.

The sending of notifications I am not shure I want that in this module. I have the Firebase_php module running and that works quite well. But that's for another day.

Update

Because the submodule was getting too specific, I removed it. The basic features are available in de demo module in the zip file. The only thing that is changed in de base module is the added hook to alter the service worker, which I think is a good addition.

Status

  • Add new submodule for the notifications
  • Add hook to expand the service worker
  • The firebase service worker has to come from a specific url: /firebase-messaging-sw.js. The url is altered with a route to serve the service worker from this location.
  • Added cspell words and eslint ignore file
  • When a user accepts the push messages, the token is saved to the database.
CommentFileSizeAuthor
#8 pwa_firebase_notifications.zip30.24 KBjoshahubbers

Issue fork pwa-3481782

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joshahubbers created an issue. See original summary.

joshahubbers’s picture

Issue summary: View changes
joshahubbers’s picture

Issue summary: View changes
joshahubbers’s picture

joshahubbers’s picture

Back to working on this... please mind this is work in progress. F.e. in the current patch we show the token of the browser in the frontend to allow us to easily send test messages. ;-) Just so you know the current status.

joshahubbers’s picture

Issue summary: View changes
joshahubbers’s picture

Issue summary: View changes
StatusFileSize
new30.24 KB

I removed the module from this commit, as I think you mostly want to customize what exactly happens there, and not everything is generic enough.

I add the module as zip for reference.
Example module

So what this patch does:

  • Add hook to expand the service worker

What it does not do (see how to do it in the example module):

  • Add new submodule for the notifications (see zip file for an example)
  • The firebase service worker has to come from a specific url: /firebase-messaging-sw.js. The url is altered with a route to serve the service worker from this location.
  • When a user accepts the push messages, the token is saved to the database.
joshahubbers’s picture

Title: Firebase notifications » Add hook to modify service worker (was: Firebase notifications)
Status: Active » Needs review
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Great wor @joshahubbers thank you!!

  • anybody committed e1c514c2 on 2.x authored by joshahubbers
    Issue #3481782 by joshahubbers: Add hook to modify service worker (was:...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.