From 3767060632db6bc3963d24f034735c75aec099de Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 31 Mar 2021 16:34:37 +0200 Subject: [PATCH 1/2] fix reloading or opening wrong page when clicking notif --- src/platform/web/service-worker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/web/service-worker.js b/src/platform/web/service-worker.js index 7001600a..335930bb 100644 --- a/src/platform/web/service-worker.js +++ b/src/platform/web/service-worker.js @@ -196,12 +196,13 @@ async function openClientFromNotif(event) { const {sessionId, roomId} = event.notification.data; const sessionHash = `#/session/${sessionId}`; const roomHash = `${sessionHash}/room/${roomId}`; - const roomURL = `/${roomHash}`; const clientWithSession = await findClient(async client => { return await sendAndWaitForReply(client, "hasSessionOpen", {sessionId}); }); if (clientWithSession) { console.log("notificationclick: client has session open, showing room there"); + // just change the hash, so the page doesn't refresh on / vs /index.html + const roomURL = new URL(roomHash, clientWithSession.url).href; clientWithSession.navigate(roomURL); if ('focus' in clientWithSession) { try { @@ -210,6 +211,7 @@ async function openClientFromNotif(event) { } } else if (self.clients.openWindow) { console.log("notificationclick: no client found with session open, opening new window"); + const roomURL = new URL(`./${roomHash}`, baseURL).href; await self.clients.openWindow(roomURL); } } From 8894329fa3598342605e861117fff323466786c0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 31 Mar 2021 16:51:25 +0200 Subject: [PATCH 2/2] don't use url to open room as it still refreshes the page on chrome even though only the hash is different --- src/platform/web/dom/ServiceWorkerHandler.js | 2 ++ src/platform/web/service-worker.js | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/platform/web/dom/ServiceWorkerHandler.js b/src/platform/web/dom/ServiceWorkerHandler.js index d2dacc6b..dd2c755f 100644 --- a/src/platform/web/dom/ServiceWorkerHandler.js +++ b/src/platform/web/dom/ServiceWorkerHandler.js @@ -76,6 +76,8 @@ export class ServiceWorkerHandler { // this flag is read in fetch.js this.haltRequests = true; event.source.postMessage({replyTo: data.id}); + } else if (data.type === "openRoom") { + this._navigation.push("room", data.payload.roomId); } } diff --git a/src/platform/web/service-worker.js b/src/platform/web/service-worker.js index 335930bb..29b124d9 100644 --- a/src/platform/web/service-worker.js +++ b/src/platform/web/service-worker.js @@ -201,9 +201,8 @@ async function openClientFromNotif(event) { }); if (clientWithSession) { console.log("notificationclick: client has session open, showing room there"); - // just change the hash, so the page doesn't refresh on / vs /index.html - const roomURL = new URL(roomHash, clientWithSession.url).href; - clientWithSession.navigate(roomURL); + // use a message rather than clientWithSession.navigate here as this refreshes the page on chrome + clientWithSession.postMessage({type: "openRoom", payload: {roomId}}); if ('focus' in clientWithSession) { try { await clientWithSession.focus();