-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconnect on lost websocket connection #39
Conversation
Two things to discuss:
|
src/views/Room.vue
Outdated
@@ -48,6 +48,7 @@ export default { | |||
peers: [], | |||
localPeer: null, | |||
infoPage: null, | |||
signalingConnectedBefore = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntax error :/
signalingConnectedBefore = false, | |
signalingConnectedBefore: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not that familiar with javascript. But could we apply some sanitizer/compiler to our javascript files. Such that these kind of syntax errors could be detected in CI? I could setup github actions for this repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erikzenker It already happens and it would be super duper to have such a github action. The command is $ yarn lint
@@ -202,6 +203,18 @@ export default { | |||
}, | |||
}) | |||
}, | |||
reconnectRtc() { | |||
if (this.signalingConnectedBefore) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag is never flipped
src/views/Room.vue
Outdated
reconnectRtc() { | ||
if (this.signalingConnectedBefore) { | ||
// TODO: show "Palava server not reachable" or "Network not reachable" overlay | ||
if (navigator.online) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't known about navigator.online
before - good idea!
src/views/Room.vue
Outdated
if (this.signalingConnectedBefore) { | ||
// TODO: show "Palava server not reachable" or "Network not reachable" overlay | ||
if (navigator.online) { | ||
rtc.reconnect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although we are guarding against being offline, the network can be bad (or the server could be down), so there should probably be a timeout functionality here. Maybe also a retry count (or an "endless" interval with larger timeout)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what happens after the retry count? The person gets kicked out? I think as long as somebody wants to participate in the discussion, it should be continously tried to reconnect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. One way would be to then show a network error page with a "reconnect" button. But the endless-interval with reasonable timeout in between tries sounds fine too me too.
Can you please provide an example of the race condition, it's not yet clear to me |
The Chrome devtools have an "offline" flag in the network tab - this should trigger this event (maybe not, but I think it does) |
src/views/Room.vue
Outdated
if (navigator.online) { | ||
rtc.reconnect() | ||
} else { | ||
window.addEventListener('online', function() {rtc.reconnect()}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event listener needs to be unregistered, when fired, or they will "stack up" with every new error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole online/offline state thing could also be considered an extra feature (and treated separately from connection errors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On some point we could think of introducing some kind of state machine. Otherwise it will get hard to keep the overview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as long as the websocket connection stands, everything is ok - and when it fails, this is only a safeguard not to try it again until it could actually work :-) I don't see a need to treat this separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of having a state-machine (probably even the client library) - which brings together signaling, peer connection, and network/online status
Not quite sure, if javascript prevents this to happen, but what I imagine could happen:
How about this as a solution?:
|
Rebased + pushed to staging! |
I think we are safe here |
Unfortunately no:
|
Is it possible to emit the online event on window manually? |
Fixed it :-) |
Ok to merge or shall we do something about my original concern nr. 2 (local testing)? |
I think going forward we should invest some energy into automatic testing. Javascript should have
What about creating a new issue and doing it in a followup? By that you keep the focus in this PR on the reconnect feature. |
@farao I would say we always put the latest version of this PR on staging for simpler real-worold testing.
|
Absolutely, especially end-to-end (browser) tests (opened an issue for that #45). Also, there is already some boilerplate test setup in the project here: https://github.com/palavatv/palava-web/blob/master/tests/e2e/specs/test.js |
Ok, so we just leave it this way I guess!
👌
Super strange that the browsers implement this so differently, but apparently they at least have in common that offline always means offline. So I would think this is good enough, in chrome we will then simply keep on trying to reestablish the websocket connection.
Yes, this makes sense! |
Looks good! Some smallish things before we can finally merge:
|
When the websocket connection failed after having been established before, the complete rtc session is tried to reinitialize.
🎉 --> staging |
When the websocket connection failed after having been established before,
the complete rtc session is tried to reinitialize.
This needs an update on the palava client first: palavatv/palava-client#16