   monitorPresence:(callbacks)-> @send 'monitorPresence', callbacks
 
   subscribe:(name, options={}, callback)->
-    console.log "bongo/subscribe", name, options
+    trace "bongo/subscribe", name, options
     return callback? new Error "not supported anymore"
 
     throw new Error "no broker client"  unless @mq?


  bindAutoreconnect: ->

    console.log "bongo/bindAutoreconnect"

    @mq.on 'disconnected', =>
      console.log "bongo/bindAutoreconnect/disconnected"
      @mq.once 'connected', @bound 'reconnectHelper'


  disconnect:(shouldReconnect, callback)->
    console.log "bongo/disconnect"

    # @channel.close().off()  if @channel?

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

    if 'function' is typeof shouldReconnect
      console.log "bongo/disconnect", shouldReconnect
      callback = shouldReconnect
      shouldReconnect = no

    return "already disconnected"  if @readyState is NOTCONNECTED or @readyState is DISCONNECTED

    console.log "bongo/disconnect $"

    @mq.once 'disconnected', callback.bind this  if callback?
    @mq.disconnect shouldReconnect
    @readyState = DISCONNECTED

  messageFailed:(message)->
    console.log 'MESSAGE FAILED', message

  getTimeout:(message, clientTimeout=5000)->
    setTimeout @messageFailed.bind(this, message), clientTimeout

  ping:(callback)->
    console.log "bongo/ping $"
    @send 'ping', callback  if @readyState is CONNECTED and @useWebsockets

  send:(method, args)->
    console.log "bongo/send $"
    args = [args] unless Array.isArray args

    scrubber = new Scrubber @localStore
    scrubber.scrub args, =>
      console.log "bongo/scrubber.scrub $"
      message = scrubber.toDnodeProtocol()
      message.method = method
      @sendHelper message

  sendHelper: (message) ->
    console.log "bongo/sendHelper $"
    if @useWebsockets
      console.log "bongo/sendHelper/@useWebsockets $"

      if @mq? and not @channel
        throw new Error 'No channel!'

      messageString = JSON.stringify message
      if @channel.isOpen
        console.log "bongo/sendHelper/isOpen $"
        @channel.publish messageString
      else
        console.log "bongo/sendHelper/isOpen else"
        @lastMessage = messageString
        @connect()
    else if @apiEndpoint
      console.log "bongo/sendHelper/@apiEndpoint"

      konstructor = @api[message.method.constructorName]
      if @batchRequests and not konstructor?.attributes.bypassBatch

    return channel

  xhrHandshake: ->
    trace "bongo/xhrHandshake"
    return @handshakeDone()

    @send 'xhrHandshake', (api) =>
