diff --git a/shine-UI/firebase-messaging-sw.js b/shine-UI/firebase-messaging-sw.js index cf68f0a..ccec2c2 100644 --- a/shine-UI/firebase-messaging-sw.js +++ b/shine-UI/firebase-messaging-sw.js @@ -1,20 +1,39 @@ self.addEventListener('install', () => self.skipWaiting()); self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim())); +async function broadcastToClients(payload) { + const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true }); + clients.forEach((client) => { + client.postMessage({ + type: 'SHINE_WEB_PUSH_EVENT', + payload, + }); + }); +} + self.addEventListener('push', (event) => { let body = 'Новое сообщение SHiNE'; + let rawText = ''; try { if (event.data) { const text = event.data.text(); - body = text || body; + rawText = text || ''; + body = rawText || body; } } catch { // ignore } - event.waitUntil(self.registration.showNotification('SHiNE: входящее сообщение', { - body, - tag: 'shine-direct-message', - renotify: true, - })); + event.waitUntil(Promise.all([ + self.registration.showNotification('SHiNE: входящее сообщение', { + body, + tag: 'shine-direct-message', + renotify: true, + }), + broadcastToClients({ + body, + rawText, + receivedAt: Date.now(), + }), + ])); }); diff --git a/shine-UI/index.html b/shine-UI/index.html index e452966..84840d8 100644 --- a/shine-UI/index.html +++ b/shine-UI/index.html @@ -29,7 +29,7 @@