 
     if @sock?
       try
+        @initiatedClose = true
         @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()

_ = require 'lodash'
FS = require 'fs'
Q = require 'q'
moment = require 'moment'
request = require 'request'
WebSocket = require 'ws'

            @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
