switch (obj.code) {
// Start new game:
case "gamestart": {
- if (!$.hasFocus()) notifyMe("game");
+ if (document.hidden) notifyMe("game");
gid = obj.gid;
initializeGame(obj);
break;
break;
// Receive opponent's move:
case "newmove":
- if (!$.hasFocus()) notifyMe("move");
+ if (document.hidden) notifyMe("move");
vr.playReceivedMove(obj.moves, () => {
if (vr.getCurrentScore(obj.moves[obj.moves.length-1]) != "*") {
localStorage.removeItem("gid");
}
if (Notification.permission === 'granted') doNotify();
else if (Notification.permission !== 'denied') {
- Notification.requestPermission().then((permission) => {
+ Notification.requestPermission().then(permission => {
if (permission === 'granted') doNotify();
});
}
else launchAnimation(); //focused user!
};
let boardContainer = document.getElementById("boardContainer");
- if (!document.hasFocus()) {
- window.onfocus = () => {
- window.onfocus = undefined;
+ if (document.hidden) {
+ document.onvisibilitychange = () => {
+ document.onvisibilitychange = undefined;
checkDisplayThenAnimate();
};
}