     @isState("open")
 
   # Private
+
+  isClosed: ->
+    @isState("closing", "closed")
 
   isState: (states...) ->
     @getState() in states

      false

  open: =>
    if @webSocket and not @isState("closed")
      console.log("[cable] Attemped to open WebSocket, but existing socket is #{@getState()}", Date.now())
      throw new Error("Existing connection must be closed before opening")
    else
      console.log("[cable] Opening WebSocket", Date.now())
      @webSocket = new WebSocket(@consumer.url)
      @installEventHandlers()
      true


  reopen: ->
    console.log("[cable] Reopening WebSocket, current state is #{@getState()}", Date.now())
    if @isClosed()
      @open()
    else
      try
