OneRoute Embed also supports push notifications and requires some dependencies from your Web App.
/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */
importScripts(
"https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js"
);
importScripts(
"https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js"
);
const firebaseConfig = {
apiKey: "<-- Check dashboard -->",
authDomain: "<-- Check dashboard -->",
projectId: "<-- Check dashboard -->",
storageBucket: "<-- Check dashboard -->",
messagingSenderId: "<-- Check dashboard -->",
appId: "<-- Check dashboard -->",
};
firebase.initializeApp(firebaseConfig);
// Retrieve firebase messaging
const messaging = firebase.messaging();
messaging.onBackgroundMessage(function (payload) {
const message = JSON.parse(payload.data.message);
console.log("NBMA");
const notificationTitle = `New message from ${message.sender.name}`;
const notificationOptions = {
body: message.content,
icon: "/favicon.ico", // Your WebApp's favicon.
};
self.registration.showNotification(notificationTitle, notificationOptions);
self.addEventListener("notificationclick", function (event) {
event.notification.close();
});
});