From 76dd162d54af39adcef18bd0bebc4dc524b99147 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 2 Jun 2013 23:55:11 +0200 Subject: [PATCH] Keep web socket connections down after session got disabled. --- .../javascripts/app/controllers/task_widget.js.coffee | 1 + .../javascripts/app/lib/app_post/websocket.js.coffee | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/controllers/task_widget.js.coffee b/app/assets/javascripts/app/controllers/task_widget.js.coffee index cf3edafd9..6bbd529ce 100644 --- a/app/assets/javascripts/app/controllers/task_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/task_widget.js.coffee @@ -42,6 +42,7 @@ class App.TaskWidget extends App.Controller # disable all delay's and interval's App.Delay.reset() App.Interval.reset() + App.WebSocket.close( force: true ) render: -> diff --git a/app/assets/javascripts/app/lib/app_post/websocket.js.coffee b/app/assets/javascripts/app/lib/app_post/websocket.js.coffee index 61ecb50ff..e3b64e0ed 100644 --- a/app/assets/javascripts/app/lib/app_post/websocket.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/websocket.js.coffee @@ -37,6 +37,7 @@ class _Singleton extends App.Controller queue: [] supported: true lastSpoolMessage: undefined + connectionKeepDown: false connectionEstablished: false connectionWasEstablished: false tryToConnect: false @@ -67,7 +68,7 @@ class _Singleton extends App.Controller else # console.log 'ws:send trying', data, @ws, @ws.readyState - + # A value of 0 indicates that the connection has not yet been established. # A value of 1 indicates that the connection is established and communication is possible. # A value of 2 indicates that the connection is going through the closing handshake. @@ -106,7 +107,10 @@ class _Singleton extends App.Controller # set timestamp to get spool messages later @lastSpoolMessage = Math.round( +new Date()/1000 ) - close: => + close: ( params = {} ) => + if params['force'] + @connectionKeepDown = true + return if @backend is 'ajax' @ws.close() @@ -179,6 +183,9 @@ class _Singleton extends App.Controller @ws.onclose = (e) => @log 'Websocket', 'debug', "ws:onclose", e + # take connection down and keep it down + return if @connectionKeepDown + # set timestamp to get spool messages later if @connectionEstablished @lastSpoolMessage = Math.round( +new Date()/1000 )