Skip to content

Commit

Permalink
Reconnect on lost websocket connection
Browse files Browse the repository at this point in the history
When the websocket connection failed after having been established before,
the complete rtc session is tried to reinitialize.
  • Loading branch information
farao committed May 21, 2020
1 parent 474e28b commit d561e19
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/views/Room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
peers: [],
localPeer: null,
infoPage: null,
signalingConnectedBefore = false,
}
},
created() {
Expand Down Expand Up @@ -84,12 +85,12 @@ export default {
rtc.on("signaling_not_reachable", () => {
logger.error("signaling server not reachable")
this.uiState = [RoomError, { error: "connection_error" }]
reconnectRtc()
})
rtc.on("signaling_error", (error) => {
logger.error("signaling error", error)
this.uiState = [RoomError, { error: "connection_error" }]
reconnectRtc()
})
rtc.on("signaling_shutdown", (seconds) => {
Expand Down Expand Up @@ -202,6 +203,18 @@ export default {
},
})
},
reconnectRtc() {
if (this.signalingConnectedBefore) {
// TODO: show "Palava server not reachable" or "Network not reachable" overlay
if (navigator.online) {
rtc.reconnect()
} else {
window.addEventListener('online', function() {rtc.reconnect()});
}
} else {
this.uiState = [RoomError, { error: "connection_error" }]
}
},
closeInfoScreen() {
this.infoPage = null
},
Expand Down

0 comments on commit d561e19

Please sign in to comment.