diff options
Diffstat (limited to 'lib/assets')
-rw-r--r-- | lib/assets/javascripts/cable/connection_monitor.js.coffee | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/assets/javascripts/cable/connection_monitor.js.coffee b/lib/assets/javascripts/cable/connection_monitor.js.coffee index cac65d9043..5573ea5a77 100644 --- a/lib/assets/javascripts/cable/connection_monitor.js.coffee +++ b/lib/assets/javascripts/cable/connection_monitor.js.coffee @@ -30,9 +30,11 @@ class Cable.ConnectionMonitor delete @stoppedAt @startedAt = now() @poll() + document.addEventListener("visibilitychange", @visibilityDidChange) stop: -> @stoppedAt = now() + document.removeEventListener("visibilitychange", @visibilityDidChange) poll: -> setTimeout => @@ -57,6 +59,13 @@ class Cable.ConnectionMonitor else secondsSince(@startedAt) > @staleThreshold.startedAt + visibilityDidChange: => + if document.visibilityState is "visible" + setTimeout => + if @connectionIsStale() or not @consumer.connection.isOpen() + @consumer.connection.reopen() + , 200 + toJSON: -> interval = @getInterval() connectionIsStale = @connectionIsStale() |