File tree 1 file changed +19
-7
lines changed
1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -32,13 +32,21 @@ angular.module('ngMQTT', [])
32
32
var data = payload . toString ( ) ;
33
33
}
34
34
angular . forEach ( callbacks , function ( callback , name ) {
35
- var regexpStr = name . replace ( new RegExp ( '(#)|(\\*)' ) , function ( str ) {
36
- if ( str == "#" ) {
37
- return ".*?"
38
- } else if ( str == "*" ) {
39
- return ".*?"
40
- }
41
- } ) ;
35
+ var regexpStr = name . replace ( new RegExp ( '(#)|(\\*)|(\\+)' ) , function ( str ) {
36
+ switch ( str ) {
37
+ case "#" :
38
+ return ".*?"
39
+ break ;
40
+ case "*" :
41
+ return ".*?"
42
+ break ;
43
+ case "+" :
44
+ return ".*"
45
+ break ;
46
+ default :
47
+ break ;
48
+ }
49
+ } ) ;
42
50
if ( topic . match ( regexpStr ) ) {
43
51
$rootScope . $apply ( function ( ) {
44
52
callback ( data , topic ) ;
@@ -56,5 +64,9 @@ angular.module('ngMQTT', [])
56
64
Service . send = function ( name , data ) {
57
65
client . publish ( name , JSON . stringify ( data ) ) ;
58
66
} ;
67
+ Service . drop = function ( name , callback ) {
68
+ callbacks [ name ] = callback ;
69
+ client . unsubscribe ( name ) ;
70
+ } ;
59
71
return Service ;
60
72
} ] ) ;
You can’t perform that action at this time.
0 commit comments