src/simple-mqtt-client/client.js
function connectNode (subscriptions, host, clientId) {
    // Create client
    var url = "tcp://" + host + ":1883";
    var client = mqtt_lib.connect(url, {clientId : clientId});
    // Register incoming message callback
    client.on('message', function(channel, message) {
        // Execute all the appropriate callbacks:
        // the ones specific to this channel with a single parameter (message)
        // the ones associated to a wildcard channel, with two parameters (message and channel)
        var cbs = findCallbacks(subscriptions, channel);
        if (cbs!==undefined) {
            cbs.forEach(function(cb) {
                if (Object.keys(subscriptions).indexOf(channel)!==-1) {
                    cb(message.toString());
                } else {
                    cb(message.toString(), channel);
                }
            });
        }
    });
    return client;
}
function connectNode (subscriptions, host, clientId) {
    // Create client
    var url = "tcp://" + host + ":1883";
    var client = mqtt_lib.connect(url, {clientId : clientId});
    // Register incoming message callback
    client.on('message', function(channel, message) {
        // Execute all the appropriate callbacks:
        // the ones specific to this channel with a single parameter (message)
        // the ones associated to a wildcard channel, with two parameters (message and channel)
        var cbs = findCallbacks(subscriptions, channel);
        if (cbs!==undefined) {
            cbs.forEach(function(cb) {
                if (Object.keys(subscriptions).indexOf(channel)!==-1) {
                    cb(message.toString());
                } else {
                    cb(message.toString(), channel);
                }
            });
        }
    });
    return client;
}
function connectNode ( subscriptions , host , clientId ) { // Create client var url = "tcp://" + host + ":1883" ; var client = mqtt_lib . connect ( url , { clientId : clientId } ) ; // Register incoming message callback client . on ( 'message' , function ( channel , message ) { // Execute all the appropriate callbacks: // the ones specific to this channel with a single parameter (message) // the ones associated to a wildcard channel, with two parameters (message and channel) var cbs = findCallbacks ( subscriptions , channel ) ; if ( cbs !== undefined ) { cbs . forEach ( function ( cb ) { if ( Object . keys ( subscriptions ) . indexOf ( channel ) !== - 1 ) { cb ( message . toString ( ) ) ; } else { cb ( message . toString ( ) , channel ) ; } } ) ; } } ) ; return client ; }
Helper function that connects the MQTT client in node
Helper function that connects the MQTT client in node