From 6ec5284dfe4d10a2506508bbd909e9ae91342f25 Mon Sep 17 00:00:00 2001 From: ITZVGcGPmO <42504016+ITZVGcGPmO@users.noreply.github.com> Date: Tue, 21 May 2019 11:58:16 -0700 Subject: [PATCH] bg gamechat notifications --- WebContent/js/cah.js | 21 +++++++++++++++++++++ WebContent/js/cah.log.js | 1 + 2 files changed, 22 insertions(+) diff --git a/WebContent/js/cah.js b/WebContent/js/cah.js index a373e40..3be1bde 100644 --- a/WebContent/js/cah.js +++ b/WebContent/js/cah.js @@ -135,3 +135,24 @@ cah.updateHash = function(hash) { window.location.replace(window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/#$/g, '') + '#' + hash); }; + + + +/** + * Sends notifications, when the window is not in focus + * + * @notifcont {String} + * string A string to notify to the user + */ +cah.notifyBg = function(notifcont) { + if ("Notification" in window) { // if browser supports notifications + // If it's okay let's create a notification + if (Notification.permission === "granted" && !(document.hasFocus())) { + var notification = new Notification(notifcont); + } + // Otherwise, we need to ask the user for permission + else if (Notification.permission !== "denied") { + Notification.requestPermission(); + } + } +} \ No newline at end of file diff --git a/WebContent/js/cah.log.js b/WebContent/js/cah.log.js index 5628002..98b9f74 100644 --- a/WebContent/js/cah.log.js +++ b/WebContent/js/cah.log.js @@ -83,6 +83,7 @@ cah.log.status_with_game = function(game_or_id, text, opt_class, opt_allow_html, if (game_or_id === null || game_or_id === undefined) { logElement = cah.log.log; } else { + cah.notifyBg(text); // send notifications of game chat, when in bg var game; if (game_or_id instanceof cah.Game) { game = game_or_id;