From 93bec941f204d063e528bffca0332a89d0e2565d Mon Sep 17 00:00:00 2001 From: Jonas Weinz Date: Thu, 21 Mar 2019 17:17:42 +0100 Subject: [PATCH] focus handling --- main.js | 20 ++++++++++++-------- websocket_connection.js | 5 +++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index a303110..c69c32f 100644 --- a/main.js +++ b/main.js @@ -199,6 +199,7 @@ logout = function() // delete session: session_id = get_cookie("sessionid"); set_cookie("sessionid", session_id, -100); + session_id = null; } } @@ -278,16 +279,19 @@ b_match_invite.addEventListener("click", invite_player); reconnect(); - -/* -var websocket_connection = new WebsocketConnection('127.0.0.1', 5556); -websocket_connection.connect(); -*/ - - // register resize event: window.addEventListener("resize", function() { var tilesize = getComputedStyle(document.body).getPropertyValue("--tile-size"); grid.on_screen_orientation_change(tilesize, tilesize); -}) +}); + +window.onload = function() { + window.onfocus = function() { + if (session_id != null && connection == null) + { + reconnect(); + } + }; +}; + diff --git a/websocket_connection.js b/websocket_connection.js index 0333062..f67f6db 100644 --- a/websocket_connection.js +++ b/websocket_connection.js @@ -345,6 +345,11 @@ class WebsocketConnection } notify(text) { + + if (document.hasFocus()) + { + return; + } Notification.requestPermission(function(result) { if (result === 'granted') {