 jsonify = (obj) -> JSON.stringify obj, null, 2
 
 isNode = -> window == undefined
+defaultReconnectDelay = 5000
+maxReconnectDelay = 120000
 
 class PubSubWebSocket extends EventEmitter
   constructor: (@keys, @options) ->
     super()
 
+    @autoReconnectDelay = defaultReconnectDelay
     @sessionUuid = @options.sessionUuid
     @baseWsUrl = @options.baseWsUrl ? 'wss://api.cogswell.io'
     @connectTimeout = @options.connectTimeout ? 5000
     @autoReconnect = @options.autoReconnect ? true
     @pingInterval = @options.pingInterval ? 15000
     @logLevel = @options.logLevel ? 'error'
+    @hasConnected = false
 
     logger.setLogLevel @logLevel
     logger.info "Set logger level to '#{@logLevel}'"

              
              logger.info "Connection closed. Reconnecting in 5 seconds."

              setTimeout reconnect, 5000

            else
              setImmediate => @emit 'close'

              if hasConnected
                logger.info "Pub/Sub WebSocket closed."
              else
                message = "Websocket closed before the connection was established"

  # Close the underlying socket. If this is called directly,
  # and auto-reconnect is enabled, the underlying socket will
  # be replaced.
  dropConnection: (options = undefined) ->
    if _.isNumber(options?.autoReconnectDelay)
      @autoReconnectDelay = options.autoReconnectDelay

    @clearPinger()

    if @sock?
