lib/client.js
function removeSubscription (client, topic, messageType, callback) {
  if (callback !== explicitSubscriptionCallback) {
    client._callbackManager.removeCallback(messageType, topic, callback)
  }

  if (topic) {
    var subscriptionsByMessageType = client._subscriptionsByMessageType
    var topicMessageTypes = subscriptionsByMessageType[topic]
    if (topicMessageTypes) {
      // If a call to the client's unsubscribe() function for the topic
      // was made, unsubscribe regardless of any other active
      // callback-based subscriptions
      if (callback === explicitSubscriptionCallback) {
        delete subscriptionsByMessageType[topic]
      } else {
        var messageTypeCallbacks = topicMessageTypes[messageType]
        if (messageTypeCallbacks) {
          var callbackPosition = messageTypeCallbacks.indexOf(callback)
          if (callbackPosition > -1) {
            if (messageTypeCallbacks.length > 1) {
              // Remove the callback from the list of subscribers
              // for the topic and associated message type
              messageTypeCallbacks.splice(callbackPosition, 1)
            } else {
              if (Object.keys(topicMessageTypes).length > 1) {
                // Remove the message type entry since no more callbacks
                // are registered for the topic
                delete topicMessageTypes[messageType]
              } else {
                // Remove the topic entry since no more message types are
                // registered for it
                delete subscriptionsByMessageType[topic]
              }
            }
          }
        }
      }
      if (client._mqttClient && !subscriptionsByMessageType[topic]) {
        client._mqttClient.unsubscribe(topic)
      }
    }
  }
}
function removeSubscription (client, topic, messageType, callback) {
  if (callback !== explicitSubscriptionCallback) {
    client._callbackManager.removeCallback(messageType, topic, callback)
  }

  if (topic) {
    var subscriptionsByMessageType = client._subscriptionsByMessageType
    var topicMessageTypes = subscriptionsByMessageType[topic]
    if (topicMessageTypes) {
      // If a call to the client's unsubscribe() function for the topic
      // was made, unsubscribe regardless of any other active
      // callback-based subscriptions
      if (callback === explicitSubscriptionCallback) {
        delete subscriptionsByMessageType[topic]
      } else {
        var messageTypeCallbacks = topicMessageTypes[messageType]
        if (messageTypeCallbacks) {
          var callbackPosition = messageTypeCallbacks.indexOf(callback)
          if (callbackPosition > -1) {
            if (messageTypeCallbacks.length > 1) {
              // Remove the callback from the list of subscribers
              // for the topic and associated message type
              messageTypeCallbacks.splice(callbackPosition, 1)
            } else {
              if (Object.keys(topicMessageTypes).length > 1) {
                // Remove the message type entry since no more callbacks
                // are registered for the topic
                delete topicMessageTypes[messageType]
              } else {
                // Remove the topic entry since no more message types are
                // registered for it
                delete subscriptionsByMessageType[topic]
              }
            }
          }
        }
      }
      if (client._mqttClient && !subscriptionsByMessageType[topic]) {
        client._mqttClient.unsubscribe(topic)
      }
    }
  }
}
function removeSubscription ( client , topic , messageType , callback ) { if ( callback !== explicitSubscriptionCallback ) { client . _callbackManager . removeCallback ( messageType , topic , callback ) } if ( topic ) { var subscriptionsByMessageType = client . _subscriptionsByMessageType var topicMessageTypes = subscriptionsByMessageType [ topic ] if ( topicMessageTypes ) { // If a call to the client's unsubscribe() function for the topic // was made, unsubscribe regardless of any other active // callback-based subscriptions if ( callback === explicitSubscriptionCallback ) { delete subscriptionsByMessageType [ topic ] } else { var messageTypeCallbacks = topicMessageTypes [ messageType ] if ( messageTypeCallbacks ) { var callbackPosition = messageTypeCallbacks . indexOf ( callback ) if ( callbackPosition > - 1 ) { if ( messageTypeCallbacks . length > 1 ) { // Remove the callback from the list of subscribers // for the topic and associated message type messageTypeCallbacks . splice ( callbackPosition , 1 ) } else { if ( Object . keys ( topicMessageTypes ) . length > 1 ) { // Remove the message type entry since no more callbacks // are registered for the topic delete topicMessageTypes [ messageType ] } else { // Remove the topic entry since no more message types are // registered for it delete subscriptionsByMessageType [ topic ] } } } } } if ( client . _mqttClient && ! subscriptionsByMessageType [ topic ] ) { client . _mqttClient . unsubscribe ( topic ) } } } }
Removes a topic subscription.
@private
@param {Client} client - The {@link Client} instance from which the topic
subscription should be removed.
@param {String} topic - Topic to unsubscribe from.
@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.
Removes a topic subscription .