fix reloading or opening wrong page when clicking notif

This commit is contained in:
Bruno Windels 2021-03-31 16:34:37 +02:00
parent f4bb95f459
commit 3767060632

View file

@ -196,12 +196,13 @@ async function openClientFromNotif(event) {
const {sessionId, roomId} = event.notification.data; const {sessionId, roomId} = event.notification.data;
const sessionHash = `#/session/${sessionId}`; const sessionHash = `#/session/${sessionId}`;
const roomHash = `${sessionHash}/room/${roomId}`; const roomHash = `${sessionHash}/room/${roomId}`;
const roomURL = `/${roomHash}`;
const clientWithSession = await findClient(async client => { const clientWithSession = await findClient(async client => {
return await sendAndWaitForReply(client, "hasSessionOpen", {sessionId}); return await sendAndWaitForReply(client, "hasSessionOpen", {sessionId});
}); });
if (clientWithSession) { if (clientWithSession) {
console.log("notificationclick: client has session open, showing room there"); 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); clientWithSession.navigate(roomURL);
if ('focus' in clientWithSession) { if ('focus' in clientWithSession) {
try { try {
@ -210,6 +211,7 @@ async function openClientFromNotif(event) {
} }
} else if (self.clients.openWindow) { } else if (self.clients.openWindow) {
console.log("notificationclick: no client found with session open, opening new window"); console.log("notificationclick: no client found with session open, opening new window");
const roomURL = new URL(`./${roomHash}`, baseURL).href;
await self.clients.openWindow(roomURL); await self.clients.openWindow(roomURL);
} }
} }