bg gamechat notifications
This commit is contained in:
parent
8e1c5e805b
commit
6ec5284dfe
|
@ -135,3 +135,24 @@ cah.updateHash = function(hash) {
|
||||||
window.location.replace(window.location.protocol + '//' + window.location.host
|
window.location.replace(window.location.protocol + '//' + window.location.host
|
||||||
+ window.location.pathname.replace(/#$/g, '') + '#' + hash);
|
+ 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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) {
|
if (game_or_id === null || game_or_id === undefined) {
|
||||||
logElement = cah.log.log;
|
logElement = cah.log.log;
|
||||||
} else {
|
} else {
|
||||||
|
cah.notifyBg(text); // send notifications of game chat, when in bg
|
||||||
var game;
|
var game;
|
||||||
if (game_or_id instanceof cah.Game) {
|
if (game_or_id instanceof cah.Game) {
|
||||||
game = game_or_id;
|
game = game_or_id;
|
||||||
|
|
Loading…
Reference in New Issue