Skip to content

Commit

Permalink
Inform player when they've lost connection
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Jun 30, 2019
1 parent ec2a80f commit a804f23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/scripts/components/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class DashboardComponent {
'Requesting new game...' :
this.session.status === 'roomNotFound' ?
'This room does not exist.' :
this.session.disconnected ?
'Sorry, you\'ve lost connection.' :

// If the current player needs to enter a name
this.session.status === 'newPlayer' ?
Expand Down Expand Up @@ -149,7 +151,7 @@ class DashboardComponent {
),

// If game is in progress, allow user to end game at any time
this.game.inProgress && this.session.status !== 'watchingGame' ? [
this.game.inProgress && this.session.status !== 'watchingGame' && !this.session.disconnected ? [
m('button', { onclick: () => this.endGame(roomCode) }, 'End Game')
] :

Expand Down
5 changes: 5 additions & 0 deletions app/scripts/components/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class GameComponent {
this.game.restoreFromServer({ game, localUser });
m.redraw();
});
this.session.on('disconnect', () => {
// At this point, the session object's `disconnected` flag is
// automatically set to true
m.redraw();
});
}

view({ attrs: { roomCode } }) {
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class Session {
this.executeCallQueue();
}

get connected() {
return this.socket ? this.socket.connected : false;
}

get disconnected() {
return this.socket ? this.socket.disconnected : false;
}

executeCallQueue() {
this.callQueue.forEach(({ method, args }) => {
this[method](...args);
Expand Down

0 comments on commit a804f23

Please sign in to comment.