fixing #80 in service-worker

This commit is contained in:
or-else
2021-07-30 09:37:25 -07:00
parent febc75da17
commit 122fd018d0
+6 -3
View File
@@ -4,8 +4,9 @@ importScripts('https://cdn.jsdelivr.net/npm/firebase@8.7.1/firebase-messaging.js
importScripts('firebase-init.js');
importScripts('version.js');
// Channel to notify the webapp.
const webAppChannel = new BroadcastChannel('tinode-sw');
// Channel to notify the webapp. There is no BroadcastChannel in Safari.
const webAppChannel = (typeof BroadcastChannel == 'function') ?
new BroadcastChannel('tinode-sw') : null;
// Basic internationalization.
const i18n = {
@@ -56,7 +57,9 @@ fbMessaging.onBackgroundMessage((payload) => {
}
// Notify webapp that a message was received.
webAppChannel.postMessage(payload.data);
if (webAppChannel) {
webAppChannel.postMessage(payload.data);
}
const pushType = payload.data.what || 'msg';
const title = payload.data.title || self.i18nMessage(pushType == 'msg' ? 'new_message' : 'new_chat');