made sc-mqtt module's client object fluent

This commit is contained in:
walterhiggins 2014-01-23 23:09:41 +00:00
parent a098963f90
commit f71d1a4e78

View file

@ -97,6 +97,7 @@ function Client(brokerUrl, clientId){
}else{ }else{
client.connect(options); client.connect(options);
} }
return client;
}, },
publish: function(topic, message, qos, retained){ publish: function(topic, message, qos, retained){
if (typeof message == 'string'){ if (typeof message == 'string'){
@ -109,21 +110,27 @@ function Client(brokerUrl, clientId){
retained = false; retained = false;
} }
client.publish(topic, message,qos, retained); client.publish(topic, message,qos, retained);
return client;
}, },
subscribe: function(topic){ subscribe: function(topic){
client.subscribe(topic); client.subscribe(topic);
return client;
}, },
unsubscribe: function(topic){ unsubscribe: function(topic){
client.unsubscribe(topic); client.unsubscribe(topic);
return client;
}, },
onMessageArrived: function(fn){ onMessageArrived: function(fn){
callback.setMesgArrived(fn); callback.setMesgArrived(fn);
return client;
}, },
onDeliveryComplete: function(fn){ onDeliveryComplete: function(fn){
callback.setDeliveryComplete(fn); callback.setDeliveryComplete(fn);
return client;
}, },
onConnectionLost: function(fn){ onConnectionLost: function(fn){
callback.setConnLost(fn); callback.setConnLost(fn);
return client;
} }
}; };
}; };