diff --git a/src/config.js b/src/config.js index 6065976..4f7b8e7 100644 --- a/src/config.js +++ b/src/config.js @@ -6,6 +6,7 @@ export default { defaultRtcUrl: 'ws://localhost:4233', defaultStunUrl: 'stun:stun.palava.tv', defaultJoinTimeout: 1500, + reconnectTimeout: 1000, maximumPeers: 6, defaultLocale: 'en', supportedLocales: ['en', 'de'], diff --git a/src/views/Room.vue b/src/views/Room.vue index db4aea1..8313885 100644 --- a/src/views/Room.vue +++ b/src/views/Room.vue @@ -48,6 +48,8 @@ export default { peers: [], localPeer: null, infoPage: null, + signalingConnectedBefore: false, + repeatedReconnect: false, } }, created() { @@ -84,12 +86,12 @@ export default { rtc.on("signaling_not_reachable", () => { logger.error("signaling server not reachable") - this.uiState = [RoomError, { error: "connection_error" }] + this.reconnectRtc() }) rtc.on("signaling_error", (error) => { logger.error("signaling error", error) - this.uiState = [RoomError, { error: "connection_error" }] + this.reconnectRtc() }) rtc.on("signaling_shutdown", (seconds) => { @@ -124,6 +126,9 @@ export default { logger.log(`room joined with ${room.getRemotePeers().length} other peers`) const peers = this.rtc.room.getAllPeers() + this.signalingConnectedBefore = true + this.repeatedReconnect = false + if (peers.length > config.maximumPeers) { this.uiState = [RoomError, { error: "room_full" }] this.waiting = false @@ -202,6 +207,24 @@ export default { }, }) }, + reconnectRtc() { + if (this.signalingConnectedBefore) { + // TODO: show "Palava server not reachable" or "Network not reachable" overlay + window.addEventListener('online', this.onlineEventListener) + if (navigator.onLine) window.dispatchEvent(new Event('online')) + } else { + this.uiState = [RoomError, { error: "connection_error" }] + } + }, + onlineEventListener() { + if (this.repeatedReconnect) { + setTimeout(this.rtc.reconnect, config.reconnectTimeout) + } else { + this.repeatedReconnect = true + this.rtc.reconnect() + } + window.removeEventListener('online', this.onlineEventListener) + }, closeInfoScreen() { this.infoPage = null },