Skip to content

Commit cf504e3

Browse files
author
shellus
committed
fix scope data binding can not update and fix mqtt topic regexp
1 parent 7841c53 commit cf504e3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/angular-MQTT.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ angular.module('ngMQTT', [])
1919
}])
2020

2121
.service('MQTTService',
22-
['$q', 'MQTT', function($q, MQTT) {
22+
['$q', '$rootScope', 'MQTT', function($q, $rootScope, MQTT) {
2323
var Service = {};
2424
var callbacks = {};
2525

@@ -32,8 +32,17 @@ angular.module('ngMQTT', [])
3232
throw new Error("received data can not parse for JSON !");
3333
}
3434
angular.forEach(callbacks,function(callback, name){
35-
if(name === topic){
36-
callback(data);
35+
var regexpStr = name.replace(new RegExp('(#)|(\\*)'),function(str){
36+
if(str=="#"){
37+
return ".*?"
38+
}else if(str=="*"){
39+
return ".*?"
40+
}
41+
});
42+
if(topic.match(regexpStr)){
43+
$rootScope.$apply(function() {
44+
callback(data);
45+
});
3746
}
3847
})
3948
});

0 commit comments

Comments
 (0)