99#import " OrtcPushPlugin.h"
1010
1111@implementation OrtcPushPlugin
12-
13- - (void )connect : (CDVInvokedUrlCommand*)command
14- {
12+
13+ - (void )connect : (CDVInvokedUrlCommand*)command {
1514 _connectCommand = [[NSMutableDictionary alloc ] init ];
1615 [_connectCommand setObject: command forKey: @" connect" ];
1716 NSDictionary * args = [command.arguments objectAtIndex: 0 ];
@@ -33,80 +32,74 @@ - (void)connect:(CDVInvokedUrlCommand*)command
3332 // Connect
3433 [_ortc connect: appKey authenticationToken: token];
3534}
36-
37- - (void )disconnect : (CDVInvokedUrlCommand*)command
38- {
35+
36+ - (void )disconnect : (CDVInvokedUrlCommand*)command {
3937 [self trowException: @" ORTC not connected" forCommand: command code: ^(CDVInvokedUrlCommand *cmd) {
4038 [_connectCommand setObject: cmd forKey: @" disconnect" ];
4139 [_ortc disconnect ];
4240 }];
4341
4442
4543}
46-
47- - (void )getIsConnected : (CDVInvokedUrlCommand*)command
48- {
44+
45+ - (void )getIsConnected : (CDVInvokedUrlCommand*)command {
46+ if (_connectCommand == nil ){
47+ _connectCommand = [[NSMutableDictionary alloc ] init ];
48+ }
49+
4950 [_connectCommand setObject: command forKey: @" getIsConnected" ];
5051 CDVPluginResult* pluginResult = nil ;
51- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsInt: [_ortc isConnected ]];
52+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsInt: (_ortc != nil ? [_ortc isConnected ]: 0 ) ];
5253 [self .commandDelegate sendPluginResult: pluginResult callbackId: [[_connectCommand objectForKey: @" getIsConnected" ] callbackId ]];
5354}
54-
55-
55+
56+
5657- (void )trowException : (NSString *)exception forCommand : (CDVInvokedUrlCommand*)command code : (void (^)(CDVInvokedUrlCommand*))code {
5758 if (!_ortc) {
5859 [[NSNotificationCenter defaultCenter ] postNotificationName: @" onException" object: nil userInfo: @{@" exception" :exception}];
5960 return ;
6061 }
6162 code (command);
6263}
63-
64- - (void )onConnected : (OrtcClient *)ortc
65- {
64+
65+ - (void )onConnected : (OrtcClient *)ortc {
6666 CDVPluginResult* pluginResult = nil ;
6767 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
6868 [self .commandDelegate sendPluginResult: pluginResult callbackId: [[_connectCommand objectForKey: @" connect" ] callbackId ]];
6969}
70-
71- - (void )onDisconnected : (OrtcClient *)ortc
72- {
70+
71+ - (void )onDisconnected : (OrtcClient *)ortc {
7372 CDVPluginResult* pluginResult = nil ;
7473 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
7574 [self .commandDelegate sendPluginResult: pluginResult callbackId: [[_connectCommand objectForKey: @" disconnect" ] callbackId ]];
7675}
77-
78- - (void )onException : (OrtcClient *)ortc error : (NSError *)error
79- {
76+
77+ - (void )onException : (OrtcClient *)ortc error : (NSError *)error {
8078 [[NSNotificationCenter defaultCenter ] postNotificationName: @" onException" object: nil userInfo: @{@" exception" :error.localizedDescription }];
8179}
82-
83- - (void )onReconnected : (OrtcClient *)ortc
84- {
80+
81+ - (void )onReconnected : (OrtcClient *)ortc {
8582
8683}
87-
88- - (void )onReconnecting : (OrtcClient *)ortc
89- {
84+
85+ - (void )onReconnecting : (OrtcClient *)ortc {
9086
9187}
92-
93- - (void )onSubscribed : (OrtcClient *)ortc channel : (NSString *)channel
94- {
88+
89+ - (void )onSubscribed : (OrtcClient *)ortc channel : (NSString *)channel {
9590 CDVPluginResult* pluginResult = nil ;
9691 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
9792 [self .commandDelegate sendPluginResult: pluginResult callbackId: [[_connectCommand objectForKey: [NSString stringWithFormat: @" sub:%@ " ,channel]] callbackId ]];
9893}
99-
100- - (void )onUnsubscribed : (OrtcClient *)ortc channel : (NSString *)channel
101- {
94+
95+ - (void )onUnsubscribed : (OrtcClient *)ortc channel : (NSString *)channel {
10296 CDVPluginResult* pluginResult = nil ;
10397 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
10498 [self .commandDelegate sendPluginResult: pluginResult callbackId: [[_connectCommand objectForKey: [NSString stringWithFormat: @" unsub:%@ " ,channel]] callbackId ]];
10599}
106-
107-
108- - (void )subscribe : (CDVInvokedUrlCommand*)command
109- {
100+
101+
102+ - (void )subscribe : (CDVInvokedUrlCommand*)command {
110103 [self trowException: @" ORTC not connected" forCommand: command code: ^(CDVInvokedUrlCommand *cmd) {
111104 NSString * channel = [[cmd.arguments objectAtIndex: 0 ] objectForKey: @" channel" ];
112105 [_connectCommand setObject: cmd forKey: [NSString stringWithFormat: @" sub:%@ " ,channel]];
@@ -117,16 +110,15 @@ - (void)subscribe:(CDVInvokedUrlCommand*)command
117110 }];
118111 }];
119112}
120-
121- - (void )unsubscribe : (CDVInvokedUrlCommand*)command
122- {
113+
114+ - (void )unsubscribe : (CDVInvokedUrlCommand*)command {
123115 [self trowException: @" ORTC not connected" forCommand: command code: ^(CDVInvokedUrlCommand *cmd) {
124116 NSString * channel = [[cmd.arguments objectAtIndex: 0 ] objectForKey: @" channel" ];
125117 [_connectCommand setObject: cmd forKey: [NSString stringWithFormat: @" unsub:%@ " ,channel]];
126118 [_ortc unsubscribe: channel];
127119 }];
128120}
129-
121+
130122- (void )setApplicationIconBadgeNumber : (CDVInvokedUrlCommand*)command {
131123
132124 NSInteger badge = [[command.arguments objectAtIndex: 0 ] integerValue ];
@@ -135,9 +127,8 @@ - (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command{
135127 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
136128 [self .commandDelegate sendPluginResult: pluginResult callbackId: [command callbackId ]];
137129}
138-
139- - (void )send : (CDVInvokedUrlCommand*)command
140- {
130+
131+ - (void )send : (CDVInvokedUrlCommand*)command {
141132 [self trowException: @" ORTC not connected" forCommand: command code: ^(CDVInvokedUrlCommand *cmd) {
142133 NSDictionary * args = [cmd.arguments objectAtIndex: 0 ];
143134
@@ -147,46 +138,44 @@ - (void)send:(CDVInvokedUrlCommand*)command
147138 [_ortc send: channel message: channelMsg];
148139 }];
149140}
150-
141+
151142- (void )cancelAllLocalNotifications : (CDVInvokedUrlCommand*)command {
152143 [[UIApplication sharedApplication ] setApplicationIconBadgeNumber: 0 ];
153144 [[UIApplication sharedApplication ] cancelAllLocalNotifications ];
154145 CDVPluginResult* pluginResult = nil ;
155146 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
156147 [self .commandDelegate sendPluginResult: pluginResult callbackId: [command callbackId ]];
157148}
158-
159-
160- - (void )checkForNotifications : (CDVInvokedUrlCommand*)command
161- {
149+
150+
151+ - (void )checkForNotifications : (CDVInvokedUrlCommand*)command {
162152 [[NSNotificationCenter defaultCenter ] postNotificationName: @" checkForNotifications" object: @" OrtcPushPlugin" ];
163153 CDVPluginResult* pluginResult = nil ;
164154 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
165155 [self .commandDelegate sendPluginResult: pluginResult callbackId: [command callbackId ]];
166156}
167-
157+
168158- (void )removeNotifications : (CDVInvokedUrlCommand*)command
169- {
170- [[NSNotificationCenter defaultCenter ] postNotificationName: @" removeNotifications" object: @" OrtcPushPlugin" ];
171- CDVPluginResult* pluginResult = nil ;
172- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
173- [self .commandDelegate sendPluginResult: pluginResult callbackId: [command callbackId ]];
174- }
175-
176- - (void )log : (CDVInvokedUrlCommand*)command
177- {
159+ {
160+ [[NSNotificationCenter defaultCenter ] postNotificationName: @" removeNotifications" object: @" OrtcPushPlugin" ];
161+ CDVPluginResult* pluginResult = nil ;
162+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
163+ [self .commandDelegate sendPluginResult: pluginResult callbackId: [command callbackId ]];
164+ }
165+
166+ - (void )log : (CDVInvokedUrlCommand*)command {
178167 NSLog (@" OrtcPushPlugin: %@ " ,[command.arguments objectAtIndex: 0 ]);
179168}
180-
169+
181170- (void )enableHeadsUpNotifications : (CDVInvokedUrlCommand*)command {
182-
171+
183172}
184-
173+
185174- (void )disableHeadsUpNotifications : (CDVInvokedUrlCommand*)command {
186175
187176}
188-
189- @end
177+
178+ @end
190179
191180
192181
0 commit comments