   {slice}           = []
 
   constructor:(options)->
+    console.log "bongo/constructor", options
+
     EventEmitter this
     { @mq, @getSessionToken, @getUserArea, @fetchName, @resourceName,
       @apiEndpoint, @useWebsockets, @batchRequests, @apiDescriptor } = options

        # console.log method

  reconnectHelper:->
    @mq.ready =>
      @readyState = CONNECTED
      @emit 'ready'
      @authenticateUser()


  connectHelper: (callback) ->

    @mq.once 'connected', callback  if callback


    @reconnectHelper()

    @channel.once 'broker.subscribed', =>
      console.log "bongo/connectHelper/broker.subscribed/once"

      # apply the middleware
      @stack.forEach (fn)=> fn.call @

    @channel.on 'broker.subscribed', =>
      console.log "bongo/connectHelper/broker.subscribed/on"
      @emit 'connected'

      if @disconnectedAt
        console.log "bongo/connectHelper/@disconnectedAt"
        @emit 'reconnected', disconnectedFor: Date.now() - @disconnectedAt
        @disconnectedAt = null

      if @lastMessage
        console.log "bongo/connectHelper/@lastMessage"
        @channel.publish @lastMessage
        @lastMessage = null


  connect:(callback)->
    console.log "bongo/connect"
    @emit 'ready'
    @readyState = CONNECTED
    return callback? new Error "not supported anymore"

    throw new Error "no broker client"  unless @mq?

    switch @readyState
