|
@@ -27,6 +27,7 @@ define [], () ->
|
|
|
|
|
|
|
|
@connected = false
|
|
@connected = false
|
|
|
@userIsInactive = false
|
|
@userIsInactive = false
|
|
|
|
|
+ @gracefullyReconnecting = false
|
|
|
|
|
|
|
|
@$scope.connection =
|
|
@$scope.connection =
|
|
|
reconnecting: false
|
|
reconnecting: false
|
|
@@ -54,6 +55,7 @@ define [], () ->
|
|
|
@ide.socket.on "connect", () =>
|
|
@ide.socket.on "connect", () =>
|
|
|
sl_console.log "[socket.io connect] Connected"
|
|
sl_console.log "[socket.io connect] Connected"
|
|
|
@connected = true
|
|
@connected = true
|
|
|
|
|
+ @gracefullyReconnecting = false
|
|
|
@ide.pushEvent("connected")
|
|
@ide.pushEvent("connected")
|
|
|
|
|
|
|
|
@$scope.$apply () =>
|
|
@$scope.$apply () =>
|
|
@@ -81,7 +83,7 @@ define [], () ->
|
|
|
@$scope.$apply () =>
|
|
@$scope.$apply () =>
|
|
|
@$scope.connection.reconnecting = false
|
|
@$scope.connection.reconnecting = false
|
|
|
|
|
|
|
|
- if !$scope.connection.forced_disconnect and !@userIsInactive
|
|
|
|
|
|
|
+ if !$scope.connection.forced_disconnect and !@userIsInactive and !@gracefullyReconnecting
|
|
|
@startAutoReconnectCountdown()
|
|
@startAutoReconnectCountdown()
|
|
|
|
|
|
|
|
@ide.socket.on 'forceDisconnect', (message) =>
|
|
@ide.socket.on 'forceDisconnect', (message) =>
|
|
@@ -97,7 +99,11 @@ define [], () ->
|
|
|
setTimeout () ->
|
|
setTimeout () ->
|
|
|
location.reload()
|
|
location.reload()
|
|
|
, 10 * 1000
|
|
, 10 * 1000
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @ide.socket.on "reconnectGracefully", () =>
|
|
|
|
|
+ sl_console.log "Reconnect gracefully"
|
|
|
|
|
+ @reconnectGracefully()
|
|
|
|
|
+
|
|
|
joinProject: () ->
|
|
joinProject: () ->
|
|
|
sl_console.log "[joinProject] joining..."
|
|
sl_console.log "[joinProject] joining..."
|
|
|
@ide.socket.emit 'joinProject', {
|
|
@ide.socket.emit 'joinProject', {
|
|
@@ -180,3 +186,24 @@ define [], () ->
|
|
|
@$scope.$apply () =>
|
|
@$scope.$apply () =>
|
|
|
@$scope.connection.inactive_disconnect = true
|
|
@$scope.connection.inactive_disconnect = true
|
|
|
|
|
|
|
|
|
|
+ RECONNECT_GRACEFULLY_RETRY_INTERVAL: 5000 # ms
|
|
|
|
|
+ MAX_RECONNECT_GRACEFULLY_INTERVAL: 60 * 5 * 1000 # 5 minutes
|
|
|
|
|
+ reconnectGracefully: () ->
|
|
|
|
|
+ @reconnectGracefullyStarted ?= new Date()
|
|
|
|
|
+ userIsInactive = (new Date() - @lastUserAction) > @RECONNECT_GRACEFULLY_RETRY_INTERVAL
|
|
|
|
|
+ maxIntervalReached = (new Date() - @reconnectGracefullyStarted) > @MAX_RECONNECT_GRACEFULLY_INTERVAL
|
|
|
|
|
+ if userIsInactive or maxIntervalReached
|
|
|
|
|
+ sl_console.log "[reconnectGracefully] User didn't do anything for last 5 seconds, reconnecting"
|
|
|
|
|
+ @_reconnectGracefullyNow()
|
|
|
|
|
+ else
|
|
|
|
|
+ sl_console.log "[reconnectGracefully] User is working, will try again in 5 seconds"
|
|
|
|
|
+ setTimeout () =>
|
|
|
|
|
+ @reconnectGracefully()
|
|
|
|
|
+ , @RECONNECT_GRACEFULLY_RETRY_INTERVAL
|
|
|
|
|
+
|
|
|
|
|
+ _reconnectGracefullyNow: () ->
|
|
|
|
|
+ @gracefullyReconnecting = true
|
|
|
|
|
+ @reconnectGracefullyStarted = null
|
|
|
|
|
+ # Clear cookie so we don't go to the same backend server
|
|
|
|
|
+ $.cookie("SERVERID", "", { expires: -1, path: "/" })
|
|
|
|
|
+ @reconnectImmediately()
|