if a user is inactive for 12 hours disconect them.

This commit is contained in:
Henry Oswald 2015-10-14 14:15:33 +01:00
parent 28e507b007
commit f5162d424f
3 changed files with 27 additions and 5 deletions

View file

@ -30,8 +30,11 @@ block content
.alert.alert-warning.small(ng-if="connection.reconnecting")
strong #{translate("reconnecting")}...
.alert.alert-warning.small(ng-if="connection.inactive_disconnect")
strong #{translate("editor_disconected_click_to_reconnect")}
.div(ng-controller="SavingNotificationController")
.alert.alert-warning.small( ng-repeat="(doc_id, state) in docSavingStatus" ng-if="state.unsavedSeconds > 8") #{translate("saving_notification_with_seconds", {docname:"{{ state.doc.name }}", seconds:"{{ state.unsavedSeconds }}"})}
.alert.alert-warning.small(ng-repeat="(doc_id, state) in docSavingStatus" ng-if="state.unsavedSeconds > 8") #{translate("saving_notification_with_seconds", {docname:"{{ state.doc.name }}", seconds:"{{ state.unsavedSeconds }}"})}
include ./editor/left-menu

View file

@ -48,7 +48,7 @@
"session.socket.io": "0.1.4",
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0",
"socket.io": "0.9.16",
"translations-sharelatex": "git+https://github.com/sharelatex/translations-sharelatex.git#v0.2.0",
"translations-sharelatex": "git+https://github.com/sharelatex/translations-sharelatex.git#master",
"underscore": "1.6.0",
"underscore.string": "^3.0.2",
"v8-profiler": "^5.2.3",

View file

@ -1,5 +1,9 @@
define [], () ->
ONEHOUR = 1000 * 60 * 60
class ConnectionManager
lastUserAction : new Date()
constructor: (@ide, @$scope) ->
if !io?
console.error "Socket.io javascript not loaded. Please check that the real-time service is running and accessible."
@ -8,18 +12,25 @@ define [], () ->
$scope.$apply () =>
@$scope.state.error = "Could not connect to websocket server :("
return
@connected = false
setInterval(() =>
@disconnectIfInactive()
, ONEHOUR)
@connected = false
@userIsInactive = false
@$scope.connection =
reconnecting: false
# If we need to force everyone to reload the editor
forced_disconnect: false
inactive_disconnect: false
@$scope.tryReconnectNow = () =>
@tryReconnect()
@$scope.$on 'cursor:editor:update', () =>
@lastUserAction = new Date()
if !@connected
@tryReconnect()
@ -38,6 +49,7 @@ define [], () ->
@$scope.$apply () =>
@$scope.connection.reconnecting = false
@$scope.connection.inactive_disconnect = false
if @$scope.state.loading
@$scope.state.load_progress = 70
@ -63,7 +75,7 @@ define [], () ->
ga('send', 'event', 'editor-interaction', 'disconnect')
, 2000)
if !$scope.connection.forced_disconnect
if !$scope.connection.forced_disconnect and !@userIsInactive
@startAutoReconnectCountdown()
@ide.socket.on 'forceDisconnect', (message) =>
@ -141,3 +153,10 @@ define [], () ->
@ide.socket.socket.reconnect()
setTimeout (=> @startAutoReconnectCountdown() if !@connected), 2000
disconnectIfInactive: ()->
@userIsInactive = (new Date() - @lastUserAction) > ONEHOUR * 12
if @userIsInactive and @connected
@disconnect()
@$scope.$apply () =>
@$scope.connection.inactive_disconnect = true