focus handling

This commit is contained in:
Jonas Weinz 2019-03-21 17:17:42 +01:00
parent 5e19473e53
commit 93bec941f2
2 changed files with 17 additions and 8 deletions

20
main.js
View File

@ -199,6 +199,7 @@ logout = function()
// delete session: // delete session:
session_id = get_cookie("sessionid"); session_id = get_cookie("sessionid");
set_cookie("sessionid", session_id, -100); set_cookie("sessionid", session_id, -100);
session_id = null;
} }
} }
@ -278,16 +279,19 @@ b_match_invite.addEventListener("click", invite_player);
reconnect(); reconnect();
/*
var websocket_connection = new WebsocketConnection('127.0.0.1', 5556);
websocket_connection.connect();
*/
// register resize event: // register resize event:
window.addEventListener("resize", function() { window.addEventListener("resize", function() {
var tilesize = getComputedStyle(document.body).getPropertyValue("--tile-size"); var tilesize = getComputedStyle(document.body).getPropertyValue("--tile-size");
grid.on_screen_orientation_change(tilesize, tilesize); grid.on_screen_orientation_change(tilesize, tilesize);
}) });
window.onload = function() {
window.onfocus = function() {
if (session_id != null && connection == null)
{
reconnect();
}
};
};

View File

@ -345,6 +345,11 @@ class WebsocketConnection
} }
notify(text) { notify(text) {
if (document.hasFocus())
{
return;
}
Notification.requestPermission(function(result) { Notification.requestPermission(function(result) {
if (result === 'granted') { if (result === 'granted') {