Skip to content

Commit 4b9242d

Browse files
author
fzicaro
committed
add unsubscribe function
1 parent f94c15c commit 4b9242d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/angular-MQTT.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ angular.module('ngMQTT', [])
2929
try {
3030
var data = JSON.parse(payload.toString());
3131
}catch (e){
32-
var data = payload.toString();
32+
throw new Error("received data can not parse for JSON !");
3333
}
3434
angular.forEach(callbacks,function(callback, name){
3535
var regexpStr = name.replace(new RegExp('(#)|(\\*)'),function(str){
@@ -41,7 +41,7 @@ angular.module('ngMQTT', [])
4141
});
4242
if(topic.match(regexpStr)){
4343
$rootScope.$apply(function() {
44-
callback(data, topic);
44+
callback(data);
4545
});
4646
}
4747
})
@@ -56,5 +56,9 @@ angular.module('ngMQTT', [])
5656
Service.send = function(name, data){
5757
client.publish(name, JSON.stringify(data));
5858
};
59+
Service.drop = function(name, callback){
60+
callbacks[name] = callback;
61+
client.unsubscribe(name);
62+
};
5963
return Service;
6064
}]);

0 commit comments

Comments
 (0)