lib/harmonyclient.js
function HarmonyClient (xmppClient) {
  debug('create new harmony client')

  var self = this

  self._xmppClient = xmppClient
  self._responseHandlerQueue = []
  self._availableCommandsCache = null

  function handleStanza (stanza) {
    debug('handleStanza(' + stanza.toString() + ')')

    // Check for state digest:
    var event = stanza.getChild('event')
    if (event && event.attr('type') === 'connect.stateDigest?notify') {
      onStateDigest.call(self, JSON.parse(event.getText()))
    }

    // Check for queued response handlers:
    self._responseHandlerQueue.forEach(function (responseHandler, index, array) {
      if (responseHandler.canHandleStanza(stanza)) {
        debug('received response stanza for queued response handler')

        var response = stanza.getChildText('oa')
        var decodedResponse

        if (responseHandler.responseType === 'json') {
          decodedResponse = JSON.parse(response)
        } else {
          decodedResponse = xmppUtil.decodeColonSeparatedResponse(response)
        }

        responseHandler.deferred.resolve(decodedResponse)
        array.splice(index, 1)
      }
    })
  }

  xmppClient.on('stanza', handleStanza.bind(self))
  xmppClient.on('error', function (error) {
    debug('XMPP Error: ' + error.message)
  })
  EventEmitter.call(this)
}
function HarmonyClient (xmppClient) {
  debug('create new harmony client')

  var self = this

  self._xmppClient = xmppClient
  self._responseHandlerQueue = []
  self._availableCommandsCache = null

  function handleStanza (stanza) {
    debug('handleStanza(' + stanza.toString() + ')')

    // Check for state digest:
    var event = stanza.getChild('event')
    if (event && event.attr('type') === 'connect.stateDigest?notify') {
      onStateDigest.call(self, JSON.parse(event.getText()))
    }

    // Check for queued response handlers:
    self._responseHandlerQueue.forEach(function (responseHandler, index, array) {
      if (responseHandler.canHandleStanza(stanza)) {
        debug('received response stanza for queued response handler')

        var response = stanza.getChildText('oa')
        var decodedResponse

        if (responseHandler.responseType === 'json') {
          decodedResponse = JSON.parse(response)
        } else {
          decodedResponse = xmppUtil.decodeColonSeparatedResponse(response)
        }

        responseHandler.deferred.resolve(decodedResponse)
        array.splice(index, 1)
      }
    })
  }

  xmppClient.on('stanza', handleStanza.bind(self))
  xmppClient.on('error', function (error) {
    debug('XMPP Error: ' + error.message)
  })
  EventEmitter.call(this)
}
function HarmonyClient ( xmppClient ) { debug ( 'create new harmony client' ) var self = this self . _xmppClient = xmppClient self . _responseHandlerQueue = [ ] self . _availableCommandsCache = null function handleStanza ( stanza ) { debug ( 'handleStanza(' + stanza . toString ( ) + ')' ) // Check for state digest: var event = stanza . getChild ( 'event' ) if ( event && event . attr ( 'type' ) === 'connect.stateDigest?notify' ) { onStateDigest . call ( self , JSON . parse ( event . getText ( ) ) ) } // Check for queued response handlers: self . _responseHandlerQueue . forEach ( function ( responseHandler , index , array ) { if ( responseHandler . canHandleStanza ( stanza ) ) { debug ( 'received response stanza for queued response handler' ) var response = stanza . getChildText ( 'oa' ) var decodedResponse if ( responseHandler . responseType === 'json' ) { decodedResponse = JSON . parse ( response ) } else { decodedResponse = xmppUtil . decodeColonSeparatedResponse ( response ) } responseHandler . deferred . resolve ( decodedResponse ) array . splice ( index , 1 ) } } ) } xmppClient . on ( 'stanza' , handleStanza . bind ( self ) ) xmppClient . on ( 'error' , function ( error ) { debug ( 'XMPP Error: ' + error . message ) } ) EventEmitter . call ( this ) }
Creates a new HarmonyClient using the given xmppClient to communication.

@param xmppClient
@constructor
Creates a new HarmonyClient using the given xmppClient to communication .