|
|
@@ -10,7 +10,8 @@ const TWO_MINUTES_IN_MS = 2 * 60 * 1000
|
|
|
const DISCONNECT_AFTER_MS = ONE_HOUR_IN_MS * 24
|
|
|
|
|
|
const CONNECTION_ERROR_RECONNECT_DELAY = 1000
|
|
|
-const USER_ACTIVITY_RECONNECT_DELAY = 1000
|
|
|
+const USER_ACTIVITY_RECONNECT_NOW_DELAY = 1000
|
|
|
+const USER_ACTIVITY_RECONNECT_DELAY = 5000
|
|
|
const JOIN_PROJECT_RATE_LIMITED_DELAY = 15 * 1000
|
|
|
|
|
|
const RECONNECT_GRACEFULLY_RETRY_INTERVAL_MS = 5000
|
|
|
@@ -95,7 +96,7 @@ export class ConnectionManager extends Emitter<Events> {
|
|
|
}
|
|
|
|
|
|
tryReconnectNow() {
|
|
|
- this.tryReconnectWithBackoff(USER_ACTIVITY_RECONNECT_DELAY)
|
|
|
+ this.tryReconnectWithBackoff(USER_ACTIVITY_RECONNECT_NOW_DELAY)
|
|
|
}
|
|
|
|
|
|
// Called when document is clicked or the editor cursor changes
|
|
|
@@ -329,9 +330,27 @@ export class ConnectionManager extends Emitter<Events> {
|
|
|
inactiveDisconnect: false,
|
|
|
lastConnectionAttempt: performance.now(),
|
|
|
})
|
|
|
+
|
|
|
+ this.addReconnectListeners()
|
|
|
this.socket.socket.connect()
|
|
|
}
|
|
|
|
|
|
+ private addReconnectListeners() {
|
|
|
+ const handleFailure = () => {
|
|
|
+ removeSocketListeners()
|
|
|
+ this.startAutoReconnectCountdown(0)
|
|
|
+ }
|
|
|
+ const handleSuccess = () => {
|
|
|
+ removeSocketListeners()
|
|
|
+ }
|
|
|
+ const removeSocketListeners = () => {
|
|
|
+ this.socket.removeListener('error', handleFailure)
|
|
|
+ this.socket.removeListener('connect', handleSuccess)
|
|
|
+ }
|
|
|
+ this.socket.on('error', handleFailure)
|
|
|
+ this.socket.on('connect', handleSuccess)
|
|
|
+ }
|
|
|
+
|
|
|
private tryReconnectGracefully() {
|
|
|
if (
|
|
|
this.state.readyState === WebSocket.CLOSED ||
|