diff options
author | Javan Makhmali <javan@javan.us> | 2016-02-19 10:48:50 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2016-02-23 09:37:50 -0600 |
commit | dde833816a46c2738fa40af179751e9162a468eb (patch) | |
tree | 875fd6d706544da34b9e29b2d5fbc66d426ef225 /actioncable/app | |
parent | 1a90ff9a4d43b118448fcad72d547074c1efb2fb (diff) | |
download | rails-dde833816a46c2738fa40af179751e9162a468eb.tar.gz rails-dde833816a46c2738fa40af179751e9162a468eb.tar.bz2 rails-dde833816a46c2738fa40af179751e9162a468eb.zip |
ActionCable.log
Diffstat (limited to 'actioncable/app')
3 files changed, 25 insertions, 14 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable.coffee.erb b/actioncable/app/assets/javascripts/action_cable.coffee.erb index 18a48c0610..d95fe78ac5 100644 --- a/actioncable/app/assets/javascripts/action_cable.coffee.erb +++ b/actioncable/app/assets/javascripts/action_cable.coffee.erb @@ -21,3 +21,14 @@ a.href else url + + startDebugging: -> + @debugging = true + + stopDebugging: -> + @debugging = null + + log: (messages...) -> + if @debugging + messages.push(Date.now()) + console.log("[ActionCable]", messages...) diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index a67ad6e915..39277255f7 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -17,10 +17,10 @@ class ActionCable.Connection open: => if @isAlive() - console.log("[cable] Attemped to open WebSocket, but existing socket is #{@getState()}", Date.now()) + ActionCable.log("Attemped to open WebSocket, but existing socket is #{@getState()}") throw new Error("Existing connection must be closed before opening") else - console.log("[cable] Opening WebSocket, current state is #{@getState()}", Date.now()) + ActionCable.log("Opening WebSocket, current state is #{@getState()}") @uninstallEventHandlers() if @webSocket? @webSocket = new WebSocket(@consumer.url) @installEventHandlers() @@ -30,14 +30,14 @@ class ActionCable.Connection @webSocket?.close() reopen: -> - console.log("[cable] Reopening WebSocket, current state is #{@getState()}", Date.now()) + ActionCable.log("Reopening WebSocket, current state is #{@getState()}") if @isClosed() @open() else try @close() finally - console.log("[cable] Failed to reopen WebSocket, retrying in #{@constructor.reopenDelay}ms", Date.now()) + ActionCable.log("Failed to reopen WebSocket, retrying in #{@constructor.reopenDelay}ms") setTimeout(@open, @constructor.reopenDelay) isOpen: -> @@ -79,16 +79,16 @@ class ActionCable.Connection @consumer.subscriptions.notify(identifier, "received", message) open: -> - console.log("[cable] WebSocket onopen event", Date.now()) + ActionCable.log("WebSocket onopen event") @disconnected = false @consumer.subscriptions.reload() close: -> - console.log("[cable] WebSocket onclose event", Date.now()) + ActionCable.log("WebSocket onclose event") @disconnect() error: -> - console.log("[cable] WebSocket onerror event", Date.now()) + ActionCable.log("WebSocket onerror event") @disconnect() disconnect: -> diff --git a/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee b/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee index 3216408430..75a6f1fb07 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection_monitor.coffee @@ -17,7 +17,7 @@ class ActionCable.ConnectionMonitor @reset() @pingedAt = now() delete @disconnectedAt - console.log("[cable] ConnectionMonitor connected", Date.now()) + ActionCable.log("ConnectionMonitor connected") disconnected: -> @disconnectedAt = now() @@ -34,12 +34,12 @@ class ActionCable.ConnectionMonitor @startedAt = now() @poll() document.addEventListener("visibilitychange", @visibilityDidChange) - console.log("[cable] ConnectionMonitor started, pollInterval is #{@getInterval()}ms", Date.now()) + ActionCable.log("ConnectionMonitor started, pollInterval is #{@getInterval()}ms") stop: -> @stoppedAt = now() document.removeEventListener("visibilitychange", @visibilityDidChange) - console.log("[cable] ConnectionMonitor stopped", Date.now()) + ActionCable.log("ConnectionMonitor stopped") poll: -> setTimeout => @@ -55,12 +55,12 @@ class ActionCable.ConnectionMonitor reconnectIfStale: -> if @connectionIsStale() - console.log("[cable] ConnectionMonitor detected stale connection, reconnectAttempts = #{@reconnectAttempts}", Date.now()) + ActionCable.log("ConnectionMonitor detected stale connection, reconnectAttempts = #{@reconnectAttempts}") @reconnectAttempts++ if @disconnectedRecently() - console.log("[cable] ConnectionMonitor skipping repopen because recently disconnected at #{@disconnectedAt}", Date.now()) + ActionCable.log("ConnectionMonitor skipping reopen because recently disconnected at #{@disconnectedAt}") else - console.log("[cable] ConnectionMonitor reopening", Date.now()) + ActionCable.log("ConnectionMonitor reopening") @consumer.connection.reopen() connectionIsStale: -> @@ -73,7 +73,7 @@ class ActionCable.ConnectionMonitor if document.visibilityState is "visible" setTimeout => if @connectionIsStale() or not @consumer.connection.isOpen() - console.log("[cable] ConnectionMonitor reopening stale connection after visibilitychange", Date.now()) + ActionCable.log("ConnectionMonitor reopening stale connection after visibilitychange to #{document.visibilityState}") @consumer.connection.reopen() , 200 |