From 9a2ac1c43277f898c81c4eae07b9968d65f968ae Mon Sep 17 00:00:00 2001 From: maia arson crimew Date: Wed, 30 Mar 2022 13:44:11 +0200 Subject: [PATCH] make pings send browser notifications --- frontend/lib/chat.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index 26825f6..37f8bff 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -416,6 +416,23 @@ export const logEventToChat = async (event) => { printChatMessage("ping", event.user, event.colour, messageContent); beep(); + if ("Notification" in window) { + const title = "watch party :)"; + const options = { + body: event.data + ? `${event.user} pinged saying: ${event.data}` + : `${event.user} pinged`, + }; + if (Notification.permission === "granted") { + new Notification(title, options); + } else if (Notification.permission !== "denied") { + Notification.requestPermission().then(function (permission) { + if (permission === "granted") { + new Notification(title, options); + } + }); + } + } break; } }