             @emit 'error', error
 
         @ws.on 'open', =>
+            @connected = true
+            @emit 'connected'
             @_connAttempts = 0
             @_lastPong = Date.now()
             @_pongTimeout = setInterval =>
                 if not @connected then return
 
                 @logger.debug 'ping'
-                @_send {"type": "ping"}
-                if @_lastPong? and Date.now() - @_lastPong > 10000
+                @_send {"action": "ping"}
+                if @_lastPong? and Date.now() - @_lastPong > (2*pingInterval)
                     @logger.error "Last pong is too old: %d", (Date.now() - @_lastPong) / 1000
                     @authenticated = false
                     @connected = false
                     @reconnect()
-            , 5000
+            , pingInterval
 
         @ws.on 'message', (data, flags) =>
             @onMessage JSON.parse(data)

        @channels = {}
        @users = {}

        @socketUrl = 'wss://' + @host + (if @options.wssPort? then ':'+ @options.wssPort else ':443') + '/api/v1/websocket'

        @ws = null
        @_messageID = 0

                @authenticated = true
                # Continue happy flow here
                @token = headers.token
                @socketUrl = 'wss://' + @host + (if @options.wssPort? then ':'+ @options.wssPort else ':443') + '/api/v1/websocket'
                @logger.info 'Websocket URL: ' + @socketUrl
                @self = new User @, data
                @emit 'loggedIn', @self
