Skip to content

Commit 73b8bdf

Browse files
committed
Add disconnection/reconnection alerts
1 parent 4a3c61c commit 73b8bdf

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

package-lock.json

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"socket.io-client": "^3.1.1",
3434
"vue": "^2.6.12",
3535
"vue-loader": "^15.9.5",
36-
"vue-template-compiler": "^2.6.12"
36+
"vue-template-compiler": "^2.6.12",
37+
"vue-toasted": "^1.1.28"
3738
}
3839
}

src/app.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from 'vue';
2+
import VueToasted from 'vue-toasted';
23
import * as Sentry from '@sentry/vue';
34
import { Integrations as SentryIntegrations } from '@sentry/tracing';
45

@@ -12,6 +13,8 @@ Sentry.init({
1213
release: process.env.MIX_COMMIT_HASH,
1314
});
1415

16+
Vue.use(VueToasted);
17+
1518
// Extend Vue
1619
const App = Vue.extend({ render: renderer => renderer(Main) });
1720

src/components/Game.vue

+15
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ export default {
177177
timer: null,
178178
timerFrame: null,
179179
180+
disconnectedToast: null,
181+
180182
mobile: false,
181183
};
182184
},
@@ -189,6 +191,19 @@ export default {
189191
this.teamId = matches.groups.team || null;
190192
this.socket = io({ transports: ['websocket', 'polling'], query: { game: this.gameId, team: this.teamId } });
191193
194+
this.socket.on('connect', () => {
195+
if(this.disconnectedToast !== null) {
196+
this.disconnectedToast.goAway();
197+
198+
this.$toasted.success('Reconnected!', { duration: 3000 }).goAway();
199+
}
200+
});
201+
this.socket.on('disconnect', () => {
202+
this.disconnectedToast?.goAway();
203+
204+
this.disconnectedToast = this.$toasted.error('Attempting to reconnect...');
205+
});
206+
192207
this.socket.on('game-state', state => {
193208
this.state = state;
194209

0 commit comments

Comments
 (0)