Skip to content

Commit

Permalink
Merge pull request #9 from frazzaglia/feature/management-plus-charact…
Browse files Browse the repository at this point in the history
…er-in-topic

Feature/management plus character in topic
  • Loading branch information
娃娃脾气 authored Jun 7, 2017
2 parents f94c15c + d0fd893 commit 7990046
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/angular-MQTT.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ angular.module('ngMQTT', [])
var data = payload.toString();
}
angular.forEach(callbacks,function(callback, name){
var regexpStr = name.replace(new RegExp('(#)|(\\*)'),function(str){
if(str=="#"){
return ".*?"
}else if(str=="*"){
return ".*?"
}
});
var regexpStr = name.replace(new RegExp('(#)|(\\*)|(\\+)'),function(str){
switch (str) {
case "#":
return ".*?"
break;
case "*":
return ".*?"
break;
case "+":
return ".*"
break;
default:
break;
}
});
if(topic.match(regexpStr)){
$rootScope.$apply(function() {
callback(data, topic);
Expand All @@ -56,5 +64,9 @@ angular.module('ngMQTT', [])
Service.send = function(name, data){
client.publish(name, JSON.stringify(data));
};
Service.drop = function(name, callback){
callbacks[name] = callback;
client.unsubscribe(name);
};
return Service;
}]);

0 comments on commit 7990046

Please # to comment.