       callbacks['onConnect']?()
 
   reconnect: =>
+    @clearPingWaitTimeout()
     @resetPingTime()
     @disconnected()
 

      @connection.send JSON.stringify { action: 'unsubscribe', identifier: identifier }

  pingReceived: (timestamp) =>
    if @lastPingTime? and (timestamp - @lastPingTime) > @MAX_PING_INTERVAL
      console.log "Websocket connection is stale. Reconnecting.."
      @connection.close()
    else
      @lastPingTime = timestamp

class @Cable
  MAX_CONNECTION_ATTEMPTS: 10
  MAX_CONNECTION_INTERVAL: 5 * 1000
  PING_STALE_INTERVAL: 6

  constructor: (@cableUrl) ->
    @subscribers = {}
