|
|
@@ -27,6 +27,8 @@
|
|
27
|
27
|
#import <React/RCTEventEmitter.h>
|
|
28
|
28
|
#import <React/RCTUtils.h>
|
|
29
|
29
|
|
|
|
30
|
+#import <JitsiMeet/JitsiMeet-Swift.h>
|
|
|
31
|
+
|
|
30
|
32
|
// The events emitted/supported by RNCallKit:
|
|
31
|
33
|
static NSString * const RNCallKitPerformAnswerCallAction
|
|
32
|
34
|
= @"performAnswerCallAction";
|
|
|
@@ -37,14 +39,10 @@ static NSString * const RNCallKitPerformSetMutedCallAction
|
|
37
|
39
|
static NSString * const RNCallKitProviderDidReset
|
|
38
|
40
|
= @"providerDidReset";
|
|
39
|
41
|
|
|
40
|
|
-@interface RNCallKit : RCTEventEmitter <CXProviderDelegate>
|
|
|
42
|
+@interface RNCallKit : RCTEventEmitter <JMCallKitEventListener>
|
|
41
|
43
|
@end
|
|
42
|
44
|
|
|
43
|
45
|
@implementation RNCallKit
|
|
44
|
|
-{
|
|
45
|
|
- CXCallController *_callController;
|
|
46
|
|
- CXProvider *_provider;
|
|
47
|
|
-}
|
|
48
|
46
|
|
|
49
|
47
|
RCT_EXTERN void RCTRegisterModule(Class);
|
|
50
|
48
|
|
|
|
@@ -70,35 +68,8 @@ RCT_EXTERN void RCTRegisterModule(Class);
|
|
70
|
68
|
];
|
|
71
|
69
|
}
|
|
72
|
70
|
|
|
73
|
|
-// Display the incoming call to the user
|
|
74
|
|
-RCT_EXPORT_METHOD(displayIncomingCall:(NSString *)callUUID
|
|
75
|
|
- handle:(NSString *)handle
|
|
76
|
|
- hasVideo:(BOOL)hasVideo
|
|
77
|
|
- resolve:(RCTPromiseResolveBlock)resolve
|
|
78
|
|
- reject:(RCTPromiseRejectBlock)reject) {
|
|
79
|
|
-#ifdef DEBUG
|
|
80
|
|
- NSLog(@"[RNCallKit][displayIncomingCall] callUUID = %@", callUUID);
|
|
81
|
|
-#endif
|
|
82
|
|
-
|
|
83
|
|
- NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
84
|
|
- CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
85
|
|
- callUpdate.remoteHandle
|
|
86
|
|
- = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
|
|
87
|
|
- callUpdate.supportsDTMF = NO;
|
|
88
|
|
- callUpdate.supportsHolding = NO;
|
|
89
|
|
- callUpdate.supportsGrouping = NO;
|
|
90
|
|
- callUpdate.supportsUngrouping = NO;
|
|
91
|
|
- callUpdate.hasVideo = hasVideo;
|
|
92
|
|
-
|
|
93
|
|
- [self.provider reportNewIncomingCallWithUUID:callUUID_
|
|
94
|
|
- update:callUpdate
|
|
95
|
|
- completion:^(NSError * _Nullable error) {
|
|
96
|
|
- if (error) {
|
|
97
|
|
- reject(nil, @"Error reporting new incoming call", error);
|
|
98
|
|
- } else {
|
|
99
|
|
- resolve(nil);
|
|
100
|
|
- }
|
|
101
|
|
- }];
|
|
|
71
|
+- (void)dealloc {
|
|
|
72
|
+ [JMCallKitProxy removeListener:self];
|
|
102
|
73
|
}
|
|
103
|
74
|
|
|
104
|
75
|
// End call
|
|
|
@@ -141,14 +112,12 @@ RCT_EXPORT_METHOD(setProviderConfiguration:(NSDictionary *)dictionary) {
|
|
141
|
112
|
dictionary);
|
|
142
|
113
|
#endif
|
|
143
|
114
|
|
|
144
|
|
- CXProviderConfiguration *configuration
|
|
145
|
|
- = [self providerConfigurationFromDictionary:dictionary];
|
|
146
|
|
- if (_provider) {
|
|
147
|
|
- _provider.configuration = configuration;
|
|
148
|
|
- } else {
|
|
149
|
|
- _provider = [[CXProvider alloc] initWithConfiguration:configuration];
|
|
150
|
|
- [_provider setDelegate:self queue:nil];
|
|
|
115
|
+ if (![JMCallKitProxy hasProviderBeenConfigurated]) {
|
|
|
116
|
+ [self configureProviderFromDictionary:dictionary];
|
|
151
|
117
|
}
|
|
|
118
|
+
|
|
|
119
|
+ // register to receive CallKit proxy events
|
|
|
120
|
+ [JMCallKitProxy addListener: self];
|
|
152
|
121
|
}
|
|
153
|
122
|
|
|
154
|
123
|
// Start outgoing call
|
|
|
@@ -162,6 +131,15 @@ RCT_EXPORT_METHOD(startCall:(NSString *)callUUID
|
|
162
|
131
|
#endif
|
|
163
|
132
|
|
|
164
|
133
|
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
134
|
+
|
|
|
135
|
+ // Don't start a call action if there's
|
|
|
136
|
+ // an active call for this UUID
|
|
|
137
|
+ // (i.e. JitsiMeetView was configured from an incoming call
|
|
|
138
|
+ if ([JMCallKitProxy hasActiveCallForUUID:callUUID]) {
|
|
|
139
|
+ resolve(nil);
|
|
|
140
|
+ return;
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
165
|
143
|
CXHandle *handle_
|
|
166
|
144
|
= [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
|
|
167
|
145
|
CXStartCallAction *action
|
|
|
@@ -177,9 +155,9 @@ RCT_EXPORT_METHOD(reportCallFailed:(NSString *)callUUID
|
|
177
|
155
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
178
|
156
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
179
|
157
|
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
180
|
|
- [self.provider reportCallWithUUID:callUUID_
|
|
181
|
|
- endedAtDate:[NSDate date]
|
|
182
|
|
- reason:CXCallEndedReasonFailed];
|
|
|
158
|
+ [JMCallKitProxy reportCallWith:callUUID_
|
|
|
159
|
+ endedAt:nil
|
|
|
160
|
+ reason:CXCallEndedReasonFailed];
|
|
183
|
161
|
resolve(nil);
|
|
184
|
162
|
}
|
|
185
|
163
|
|
|
|
@@ -188,8 +166,8 @@ RCT_EXPORT_METHOD(reportConnectedOutgoingCall:(NSString *)callUUID
|
|
188
|
166
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
189
|
167
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
190
|
168
|
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
191
|
|
- [self.provider reportOutgoingCallWithUUID:callUUID_
|
|
192
|
|
- connectedAtDate:[NSDate date]];
|
|
|
169
|
+ [JMCallKitProxy reportOutgoingCallWith:callUUID_
|
|
|
170
|
+ connectedAt:nil];
|
|
193
|
171
|
resolve(nil);
|
|
194
|
172
|
}
|
|
195
|
173
|
|
|
|
@@ -206,36 +184,20 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
206
|
184
|
#endif
|
|
207
|
185
|
|
|
208
|
186
|
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
209
|
|
- CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
210
|
|
- if (options[@"displayName"]) {
|
|
211
|
|
- callUpdate.localizedCallerName = options[@"displayName"];
|
|
212
|
|
- }
|
|
213
|
|
- if (options[@"hasVideo"]) {
|
|
214
|
|
- callUpdate.hasVideo = [(NSNumber*)options[@"hasVideo"] boolValue];
|
|
215
|
|
- }
|
|
216
|
|
- [self.provider reportCallWithUUID:callUUID_ updated:callUpdate];
|
|
|
187
|
+ NSString *displayName = options[@"displayName"];
|
|
|
188
|
+ BOOL hasVideo = [(NSNumber*)options[@"hasVideo"] boolValue];
|
|
|
189
|
+
|
|
|
190
|
+ [JMCallKitProxy reportCallUpdateWith:callUUID_
|
|
|
191
|
+ handle:nil
|
|
|
192
|
+ displayName:displayName
|
|
|
193
|
+ hasVideo:hasVideo];
|
|
|
194
|
+
|
|
217
|
195
|
resolve(nil);
|
|
218
|
196
|
}
|
|
219
|
197
|
|
|
220
|
198
|
#pragma mark - Helper methods
|
|
221
|
199
|
|
|
222
|
|
-- (CXCallController *)callController {
|
|
223
|
|
- if (!_callController) {
|
|
224
|
|
- _callController = [[CXCallController alloc] init];
|
|
225
|
|
- }
|
|
226
|
|
-
|
|
227
|
|
- return _callController;
|
|
228
|
|
-}
|
|
229
|
|
-
|
|
230
|
|
-- (CXProvider *)provider {
|
|
231
|
|
- if (!_provider) {
|
|
232
|
|
- [self setProviderConfiguration:nil];
|
|
233
|
|
- }
|
|
234
|
|
-
|
|
235
|
|
- return _provider;
|
|
236
|
|
-}
|
|
237
|
|
-
|
|
238
|
|
-- (CXProviderConfiguration *)providerConfigurationFromDictionary:(NSDictionary* )dictionary {
|
|
|
200
|
+- (void)configureProviderFromDictionary:(NSDictionary* )dictionary {
|
|
239
|
201
|
#ifdef DEBUG
|
|
240
|
202
|
NSLog(@"[RNCallKit][providerConfigurationFromDictionary:]");
|
|
241
|
203
|
#endif
|
|
|
@@ -251,30 +213,25 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
251
|
213
|
= [[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"];
|
|
252
|
214
|
}
|
|
253
|
215
|
|
|
254
|
|
- CXProviderConfiguration *providerConfiguration
|
|
255
|
|
- = [[CXProviderConfiguration alloc] initWithLocalizedName:localizedName];
|
|
256
|
|
-
|
|
257
|
216
|
// iconTemplateImageData
|
|
258
|
217
|
NSString *iconTemplateImageName = dictionary[@"iconTemplateImageName"];
|
|
|
218
|
+ NSData *iconTemplateImageData;
|
|
259
|
219
|
if (iconTemplateImageName) {
|
|
260
|
220
|
UIImage *iconTemplateImage
|
|
261
|
221
|
= [UIImage imageNamed:iconTemplateImageName
|
|
262
|
222
|
inBundle:[NSBundle bundleForClass:self.class]
|
|
263
|
223
|
compatibleWithTraitCollection:nil];
|
|
264
|
224
|
if (iconTemplateImage) {
|
|
265
|
|
- providerConfiguration.iconTemplateImageData
|
|
|
225
|
+ iconTemplateImageData
|
|
266
|
226
|
= UIImagePNGRepresentation(iconTemplateImage);
|
|
267
|
227
|
}
|
|
268
|
228
|
}
|
|
269
|
229
|
|
|
270
|
|
- providerConfiguration.maximumCallGroups = 1;
|
|
271
|
|
- providerConfiguration.maximumCallsPerCallGroup = 1;
|
|
272
|
|
- providerConfiguration.ringtoneSound = dictionary[@"ringtoneSound"];
|
|
273
|
|
- providerConfiguration.supportedHandleTypes
|
|
274
|
|
- = [NSSet setWithObjects:@(CXHandleTypeGeneric), nil];
|
|
275
|
|
- providerConfiguration.supportsVideo = YES;
|
|
276
|
|
-
|
|
277
|
|
- return providerConfiguration;
|
|
|
230
|
+ NSString *ringtoneSound = dictionary[@"ringtoneSound"];
|
|
|
231
|
+
|
|
|
232
|
+ [JMCallKitProxy configureCallKitProviderWithLocalizedName:localizedName
|
|
|
233
|
+ ringtoneSound:ringtoneSound
|
|
|
234
|
+ iconTemplateImageData:iconTemplateImageData];
|
|
278
|
235
|
}
|
|
279
|
236
|
|
|
280
|
237
|
- (void)requestTransaction:(CXTransaction *)transaction
|
|
|
@@ -284,8 +241,8 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
284
|
241
|
NSLog(@"[RNCallKit][requestTransaction] transaction = %@", transaction);
|
|
285
|
242
|
#endif
|
|
286
|
243
|
|
|
287
|
|
- [self.callController requestTransaction:transaction
|
|
288
|
|
- completion:^(NSError * _Nullable error) {
|
|
|
244
|
+ [JMCallKitProxy request:transaction
|
|
|
245
|
+ completion:^(NSError * _Nullable error) {
|
|
289
|
246
|
if (error) {
|
|
290
|
247
|
NSLog(
|
|
291
|
248
|
@"[RNCallKit][requestTransaction] Error requesting transaction (%@): (%@)",
|
|
|
@@ -298,10 +255,10 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
298
|
255
|
}];
|
|
299
|
256
|
}
|
|
300
|
257
|
|
|
301
|
|
-#pragma mark - CXProviderDelegate
|
|
|
258
|
+#pragma mark - JitsiMeetCallKitListener
|
|
302
|
259
|
|
|
303
|
260
|
// Called when the provider has been reset. We should terminate all calls.
|
|
304
|
|
-- (void)providerDidReset:(CXProvider *)provider {
|
|
|
261
|
+- (void)providerDidReset {
|
|
305
|
262
|
#ifdef DEBUG
|
|
306
|
263
|
NSLog(@"[RNCallKit][CXProviderDelegate][providerDidReset:]");
|
|
307
|
264
|
#endif
|
|
|
@@ -310,84 +267,61 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
310
|
267
|
}
|
|
311
|
268
|
|
|
312
|
269
|
// Answering incoming call
|
|
313
|
|
-- (void) provider:(CXProvider *)provider
|
|
314
|
|
- performAnswerCallAction:(CXAnswerCallAction *)action {
|
|
|
270
|
+- (void) performAnswerCallWithUUID:(NSUUID *)UUID {
|
|
315
|
271
|
#ifdef DEBUG
|
|
316
|
272
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performAnswerCallAction:]");
|
|
317
|
273
|
#endif
|
|
318
|
274
|
|
|
319
|
275
|
[self sendEventWithName:RNCallKitPerformAnswerCallAction
|
|
320
|
|
- body:@{ @"callUUID": action.callUUID.UUIDString }];
|
|
321
|
|
- [action fulfill];
|
|
|
276
|
+ body:@{ @"callUUID": UUID.UUIDString }];
|
|
322
|
277
|
}
|
|
323
|
278
|
|
|
324
|
279
|
// Call ended, user request
|
|
325
|
|
-- (void) provider:(CXProvider *)provider
|
|
326
|
|
- performEndCallAction:(CXEndCallAction *)action {
|
|
|
280
|
+- (void) performEndCallWithUUID:(NSUUID *)UUID {
|
|
327
|
281
|
#ifdef DEBUG
|
|
328
|
282
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performEndCallAction:]");
|
|
329
|
283
|
#endif
|
|
330
|
284
|
|
|
331
|
285
|
[self sendEventWithName:RNCallKitPerformEndCallAction
|
|
332
|
|
- body:@{ @"callUUID": action.callUUID.UUIDString }];
|
|
333
|
|
- [action fulfill];
|
|
|
286
|
+ body:@{ @"callUUID": UUID.UUIDString }];
|
|
334
|
287
|
}
|
|
335
|
288
|
|
|
336
|
289
|
// Handle audio mute from CallKit view
|
|
337
|
|
-- (void) provider:(CXProvider *)provider
|
|
338
|
|
- performSetMutedCallAction:(CXSetMutedCallAction *)action {
|
|
|
290
|
+- (void) performSetMutedCallWithUUID:(NSUUID *)UUID
|
|
|
291
|
+ isMuted:(BOOL)isMuted {
|
|
339
|
292
|
#ifdef DEBUG
|
|
340
|
293
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction:]");
|
|
341
|
294
|
#endif
|
|
342
|
295
|
|
|
343
|
296
|
[self sendEventWithName:RNCallKitPerformSetMutedCallAction
|
|
344
|
297
|
body:@{
|
|
345
|
|
- @"callUUID": action.callUUID.UUIDString,
|
|
346
|
|
- @"muted": @(action.muted)
|
|
|
298
|
+ @"callUUID": UUID.UUIDString,
|
|
|
299
|
+ @"muted": @(isMuted)
|
|
347
|
300
|
}];
|
|
348
|
|
- [action fulfill];
|
|
349
|
301
|
}
|
|
350
|
302
|
|
|
351
|
303
|
// Starting outgoing call
|
|
352
|
|
-- (void) provider:(CXProvider *)provider
|
|
353
|
|
- performStartCallAction:(CXStartCallAction *)action {
|
|
|
304
|
+- (void) performStartCallWithUUID:(NSUUID *)UUID
|
|
|
305
|
+ isVideo:(BOOL)isVideo {
|
|
354
|
306
|
#ifdef DEBUG
|
|
355
|
307
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performStartCallAction:]");
|
|
356
|
308
|
#endif
|
|
357
|
|
-
|
|
358
|
|
- [action fulfill];
|
|
359
|
|
-
|
|
360
|
|
- // Update call info.
|
|
361
|
|
- NSUUID *callUUID = action.callUUID;
|
|
362
|
|
- CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
363
|
|
- callUpdate.remoteHandle = action.handle;
|
|
364
|
|
- callUpdate.supportsDTMF = NO;
|
|
365
|
|
- callUpdate.supportsHolding = NO;
|
|
366
|
|
- callUpdate.supportsGrouping = NO;
|
|
367
|
|
- callUpdate.supportsUngrouping = NO;
|
|
368
|
|
- callUpdate.hasVideo = action.isVideo;
|
|
369
|
|
- [provider reportCallWithUUID:callUUID updated:callUpdate];
|
|
370
|
|
-
|
|
371
|
|
- // Notify the system about the outgoing call.
|
|
372
|
|
- [provider reportOutgoingCallWithUUID:callUUID
|
|
373
|
|
- startedConnectingAtDate:[NSDate date]];
|
|
|
309
|
+ [JMCallKitProxy reportOutgoingCallWith:UUID
|
|
|
310
|
+ startedConnectingAt:nil];
|
|
374
|
311
|
}
|
|
375
|
312
|
|
|
376
|
313
|
// The following just help with debugging:
|
|
377
|
314
|
#ifdef DEBUG
|
|
378
|
315
|
|
|
379
|
|
-- (void) provider:(CXProvider *)provider
|
|
380
|
|
- didActivateAudioSession:(AVAudioSession *)audioSession {
|
|
|
316
|
+- (void) providerDidActivateAudioSessionWithSession:(AVAudioSession *)session {
|
|
381
|
317
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:didActivateAudioSession:]");
|
|
382
|
318
|
}
|
|
383
|
319
|
|
|
384
|
|
-- (void) provider:(CXProvider *)provider
|
|
385
|
|
- didDeactivateAudioSession:(AVAudioSession *)audioSession {
|
|
|
320
|
+- (void) providerDidDeactivateAudioSessionWithSession:(AVAudioSession *)session {
|
|
386
|
321
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:didDeactivateAudioSession:]");
|
|
387
|
322
|
}
|
|
388
|
323
|
|
|
389
|
|
-- (void) provider:(CXProvider *)provider
|
|
390
|
|
- timedOutPerformingAction:(CXAction *)action {
|
|
|
324
|
+- (void) providerTimedOutPerformingActionWithAction:(CXAction *)action {
|
|
391
|
325
|
NSLog(@"[RNCallKit][CXProviderDelegate][provider:timedOutPerformingAction:]");
|
|
392
|
326
|
}
|
|
393
|
327
|
|