Nickersoft / push-fcm-plugin

Official Firebase Cloud Messaging plugin for Push.js v1.0 :fire:
https://pushjs.org
42 stars 13 forks source link

Closing notifications on mobile #18

Open hb0nes opened 5 years ago

hb0nes commented 5 years ago

Editing the .sw file to listen for clicks to close them does not work. Is there a way to make the notification redirect/close on click with this plugin? This is what my sw looks like now;

importScripts('https://www.gstatic.com/firebasejs/4.1.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.1.2/firebase-messaging.js');

if (firebase.apps.length > 0)
    firebase.messaging();

self.addEventListener('message', function (event) {
    if (firebase.apps.length === 0) {
        firebase.initializeApp(event.data);
        firebase.messaging();
    }
    event.ports[0].postMessage(event.data);
});
self.addEventListener('notificationclick', function (event) {
    console.log('Clicked');
    const clickedNotification = event.notification;
    clickedNotification.close();
});