fixing #80 in service-worker
This commit is contained in:
+6
-3
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user