lib/client.js
function addSubscription (client, topic, messageType,
                          callback, subscribeToTopic) {
  if (typeof (subscribeToTopic) === 'undefined') { subscribeToTopic = true }

  if (callback !== explicitSubscriptionCallback) {
    client._callbackManager.addCallback(messageType, topic, callback)
  }

  if (subscribeToTopic && topic) {
    var topicMessageTypes = client._subscriptionsByMessageType[topic]
    // Only subscribe for the topic with the broker if no prior
    // subscription has been established
    if (!topicMessageTypes) {
      if (client._mqttClient) {
        client._mqttClient.subscribe(topic)
      }
      topicMessageTypes = {}
      client._subscriptionsByMessageType[topic] = topicMessageTypes
    }

    var messageTypeCallbacks = topicMessageTypes[messageType]
    if (messageTypeCallbacks) {
      if (messageTypeCallbacks.indexOf(callback) < 0) {
        messageTypeCallbacks.push(callback)
      }
    } else {
      topicMessageTypes[messageType] = [callback]
    }
  }
}
function addSubscription (client, topic, messageType,
                          callback, subscribeToTopic) {
  if (typeof (subscribeToTopic) === 'undefined') { subscribeToTopic = true }

  if (callback !== explicitSubscriptionCallback) {
    client._callbackManager.addCallback(messageType, topic, callback)
  }

  if (subscribeToTopic && topic) {
    var topicMessageTypes = client._subscriptionsByMessageType[topic]
    // Only subscribe for the topic with the broker if no prior
    // subscription has been established
    if (!topicMessageTypes) {
      if (client._mqttClient) {
        client._mqttClient.subscribe(topic)
      }
      topicMessageTypes = {}
      client._subscriptionsByMessageType[topic] = topicMessageTypes
    }

    var messageTypeCallbacks = topicMessageTypes[messageType]
    if (messageTypeCallbacks) {
      if (messageTypeCallbacks.indexOf(callback) < 0) {
        messageTypeCallbacks.push(callback)
      }
    } else {
      topicMessageTypes[messageType] = [callback]
    }
  }
}
function addSubscription ( client , topic , messageType , callback , subscribeToTopic ) { if ( typeof ( subscribeToTopic ) === 'undefined' ) { subscribeToTopic = true } if ( callback !== explicitSubscriptionCallback ) { client . _callbackManager . addCallback ( messageType , topic , callback ) } if ( subscribeToTopic && topic ) { var topicMessageTypes = client . _subscriptionsByMessageType [ topic ] // Only subscribe for the topic with the broker if no prior // subscription has been established if ( ! topicMessageTypes ) { if ( client . _mqttClient ) { client . _mqttClient . subscribe ( topic ) } topicMessageTypes = { } client . _subscriptionsByMessageType [ topic ] = topicMessageTypes } var messageTypeCallbacks = topicMessageTypes [ messageType ] if ( messageTypeCallbacks ) { if ( messageTypeCallbacks . indexOf ( callback ) < 0 ) { messageTypeCallbacks . push ( callback ) } } else { topicMessageTypes [ messageType ] = [ callback ] } } }
Add a topic subscription.
@private
@param {Client} client - The {@link Client} instance to which the topic
subscription should be added.
@param {String} topic - Topic to subscribe to. An empty string or null value
indicates that the callback should receive messages for all topics
(no filtering).
@param {(Number|String)} messageType - Type of DXL messages for which the
callback should be invoked. Corresponds to one of the message type
constants in the {@link Message} class - for example,
{@link Message.MESSAGE_TYPE_RESPONSE}.
@param {Function} callback - Callback function which should be invoked
for a matching message. The first argument passed to the callback
function is the DXL Message object.
@param {Boolean} [subscribeToTopic=true] - Whether or not to subscribe for
the topic with the broker.
Add a topic subscription .