let simul hosts leave the game page

This commit is contained in:
Thibault Duplessis 2017-08-18 07:59:24 -05:00
parent ca527c5961
commit 5f3f67b212

View file

@ -151,6 +151,10 @@ export default class RoundController {
this.redraw();
};
private isSimulHost = () => {
return this.data.simul && this.data.simul.hostId === this.opts.userId;
};
makeCgHooks = () => ({
onUserMove: this.onUserMove,
onUserNewPiece: this.onUserNewPiece,
@ -642,12 +646,17 @@ export default class RoundController {
this.setTitle();
window.addEventListener('beforeunload', e => {
if (li.hasToReload || this.data.blind || !game.playable(this.data) || !this.data.clock || this.data.opponent.ai) return;
document.body.classList.remove('fpmenu');
this.socket.send('bye2');
const msg = 'There is a game in progress!';
(e || window.event).returnValue = msg;
return msg;
if (li.hasToReload ||
this.data.blind ||
!game.playable(this.data) ||
!this.data.clock ||
this.data.opponent.ai ||
this.isSimulHost()) return;
document.body.classList.remove('fpmenu');
this.socket.send('bye2');
const msg = 'There is a game in progress!';
(e || window.event).returnValue = msg;
return msg;
});
window.Mousetrap.bind(['esc'], () => this.chessground.cancelMove());