 
         # 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()


        # An error occurred
        @sock.on 'error', (error) =>
          @notify 'error', error

          console.error "WebSocket error for namespace '#{data.record.namespace}' topic [#{_(data.record.attributes).join(",")}] : #{error}\n#{error.stack}"

        # Received a message
        @sock.on 'message', (msg) =>
          @notify 'message', msg

          try
            @messageCount += 1


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

  connect: ->
    d = Q.defer()
