 
         # The WebSocket was closed
         @sock.on 'close', =>
-          @notify 'close'
-
-          console.log "Push WebSocket closed for namespace '#{data.record.namespace}' topic [#{_(data.record.attributes).join(",")}]"
+          if @autoReconnect == true and @initiatedClose != true
+            @sock = null
+            @connect().then ->
+              console.log "Push WebSocket replaced for namespace '#{data.record.namespace}' topic [#{_(data.record.attributes).join(",")}]"
+
+            @emit 'reconnect'
+          else
+            @emit 'close'
+            console.log "Push WebSocket closed for namespace '#{data.record.namespace}' topic [#{_(data.record.attributes).join(",")}]"
 
         # The WebSocket connection has been established
         @sock.on 'open', =>
-          @notify 'open'
+          @emit 'open'
 
           pinger = =>
             @sock.ping()


    if @sock?
      try
        @sock.close()
      catch error
        console.log "Error while closing WebSocket: #{error}\n#{error.stack}"
      finally
        @sock = null

  # Notify of this event via the optional @eventHandler function
  notify: (event, data = undefined) ->
    try
      if @eventHandler?
        @eventHandler event, data
    catch error
      console.error "Error in user-supplied event handler: #{error}\n#{error.stack}"

  connect: ->
    d = Q.defer()

            @sock.send JSON.stringify(acknowledgement), (error) ->
              if error?
                console.error "Error sending acknowledgement for message '#{message.message_id}': #{error}\n#{error.stack}"
              else
                @emit 'acked', message.message_id
          catch error
            console.error "Invalid push message received: #{error}\n#{error.stack}"

        # WebSocket connection was rejected by the API
        @sock.on 'unexpected-response', (req, res) =>
          @emit 'unexpected-response', [req, res]

          res.on 'data', (raw) ->
            try
