1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

ActionCable.log

This commit is contained in:
Javan Makhmali 2016-02-19 10:48:50 -05:00 committed by Pratik Naik
parent 1a90ff9a4d
commit dde833816a
3 changed files with 25 additions and 14 deletions

View file

@ -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...)

View file

@ -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: ->

View file

@ -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