Skip to content

Commit c3ade44

Browse files
authored
Merge pull request #238 from zxcpoiu/support_options
ios: support additional options pass from js
2 parents 3bcd5ea + a0eb87a commit c3ade44

File tree

5 files changed

+104
-42
lines changed

5 files changed

+104
-42
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
186186
- `hasVideo`: boolean (optional, iOS only)
187187
- `false` (default)
188188
- `true` (you know... when not false)
189+
- `options`: object (optional)
190+
- `ios`: object
191+
- `supportsHolding`: boolean (optional, default true)
192+
- `supportsDTMF`: boolean (optional, default true)
193+
- `supportsGrouping`: boolean (optional, default true)
194+
- `supportsUngrouping`: boolean (optional, default true)
195+
- `android`: object (currently no-op)
189196

190197
### answerIncomingCall
191198
_This feature is available only on Android._
@@ -241,6 +248,14 @@ RNCallKeep.updateDisplay(uuid, displayName, handle)
241248
- Name of the caller to be displayed on the native UI
242249
- `handle`: string
243250
- Phone number of the caller
251+
- `options`: object (optional)
252+
- `ios`: object
253+
- `hasVideo`: boolean (optional)
254+
- `supportsHolding`: boolean (optional)
255+
- `supportsDTMF`: boolean (optional)
256+
- `supportsGrouping`: boolean (optional)
257+
- `supportsUngrouping`: boolean (optional)
258+
- `android`: object (currently no-op)
244259

245260
### endCall
246261

@@ -775,7 +790,18 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
775790
// NSString *handle = @"caller number here";
776791
// NSDictionary *extra = [payload.dictionaryPayload valueForKeyPath:@"custom.path.to.data"]; /* use this to pass any special data (ie. from your notification) down to RN. Can also be `nil` */
777792

778-
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:extra withCompletionHandler:completion];
793+
[RNCallKeep reportNewIncomingCall: uuid
794+
handle: handle
795+
handleType: @"generic"
796+
hasVideo: NO
797+
localizedCallerName: callerName
798+
supportsHolding: YES
799+
supportsDTMF: YES
800+
supportsGrouping: YES
801+
supportsUngrouping: YES
802+
fromPushKit: YES
803+
payload: extra
804+
withCompletionHandler: completion];
779805
}
780806
```
781807

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ declare module 'react-native-callkeep' {
6161
localizedCallerName?: string,
6262
handleType?: HandleType,
6363
hasVideo?: boolean,
64+
options?: object,
6465
): void
6566

6667
static startCall(
@@ -75,6 +76,7 @@ declare module 'react-native-callkeep' {
7576
uuid: string,
7677
displayName: string,
7778
handle: string,
79+
options?: object,
7880
): void
7981

8082
static checkPhoneAccountEnabled(): Promise<boolean>;

index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ class RNCallKeep {
7777
return;
7878
};
7979

80-
displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false) => {
80+
displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null) => {
8181
if (!isIOS) {
8282
RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);
8383
return;
8484
}
8585

86-
RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName);
86+
// should be boolean type value
87+
let supportsHolding = !!(options?.ios?.supportsHolding ?? true);
88+
let supportsDTMF = !!(options?.ios?.supportsDTMF ?? true);
89+
let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true);
90+
let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true);
91+
92+
RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, supportsHolding, supportsDTMF, supportsGrouping, supportsUngrouping);
8793
};
8894

8995
answerIncomingCall = (uuid) => {
@@ -200,7 +206,20 @@ class RNCallKeep {
200206
RNCallKeepModule.setCurrentCallActive(callUUID);
201207
};
202208

203-
updateDisplay = (uuid, displayName, handle) => RNCallKeepModule.updateDisplay(uuid, displayName, handle);
209+
updateDisplay = (uuid, displayName, handle, options = null) => {
210+
if (!isIOS) {
211+
RNCallKeepModule.updateDisplay(uuid, displayName, handle);
212+
return;
213+
}
214+
215+
let iosOptions = {};
216+
if (options && options.ios) {
217+
iosOptions = {
218+
...options.ios,
219+
}
220+
}
221+
RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions);
222+
};
204223

205224
setOnHold = (uuid, shouldHold) => RNCallKeepModule.setOnHold(uuid, shouldHold);
206225

ios/RNCallKeep/RNCallKeep.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ continueUserActivity:(NSUserActivity *)userActivity
3232
handleType:(NSString *)handleType
3333
hasVideo:(BOOL)hasVideo
3434
localizedCallerName:(NSString * _Nullable)localizedCallerName
35-
fromPushKit:(BOOL)fromPushKit
36-
payload:(NSDictionary * _Nullable)payload;
37-
38-
+ (void)reportNewIncomingCall:(NSString *)uuidString
39-
handle:(NSString *)handle
40-
handleType:(NSString *)handleType
41-
hasVideo:(BOOL)hasVideo
42-
localizedCallerName:(NSString * _Nullable)localizedCallerName
35+
supportsHolding:(BOOL)supportsHolding
36+
supportsDTMF:(BOOL)supportsDTMF
37+
supportsGrouping:(BOOL)supportsGrouping
38+
supportsUngrouping:(BOOL)supportsUngrouping
4339
fromPushKit:(BOOL)fromPushKit
4440
payload:(NSDictionary * _Nullable)payload
4541
withCompletionHandler:(void (^_Nullable)(void))completion;
@@ -49,4 +45,4 @@ continueUserActivity:(NSUserActivity *)userActivity
4945

5046
+ (BOOL)isCallActive:(NSString *)uuidString;
5147

52-
@end
48+
@end

ios/RNCallKeep/RNCallKeep.m

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,24 @@ + (void)initCallKitProvider {
179179
handle:(NSString *)handle
180180
handleType:(NSString *)handleType
181181
hasVideo:(BOOL)hasVideo
182-
localizedCallerName:(NSString * _Nullable)localizedCallerName)
183-
{
184-
[RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil withCompletionHandler:nil];
182+
localizedCallerName:(NSString * _Nullable)localizedCallerName
183+
supportsHolding:(BOOL)supportsHolding
184+
supportsDTMF:(BOOL)supportsDTMF
185+
supportsGrouping:(BOOL)supportsGrouping
186+
supportsUngrouping:(BOOL)supportsUngrouping)
187+
{
188+
[RNCallKeep reportNewIncomingCall: uuidString
189+
handle: handle
190+
handleType: handleType
191+
hasVideo: hasVideo
192+
localizedCallerName: localizedCallerName
193+
supportsHolding: supportsHolding
194+
supportsDTMF: supportsDTMF
195+
supportsGrouping: supportsGrouping
196+
supportsUngrouping: supportsUngrouping
197+
fromPushKit: NO
198+
payload: nil
199+
withCompletionHandler: nil];
185200
}
186201

187202
RCT_EXPORT_METHOD(startCall:(NSString *)uuidString
@@ -264,7 +279,7 @@ + (void)initCallKitProvider {
264279
[RNCallKeep endCallWithUUID: uuidString reason:reason];
265280
}
266281

267-
RCT_EXPORT_METHOD(updateDisplay:(NSString *)uuidString :(NSString *)displayName :(NSString *)uri)
282+
RCT_EXPORT_METHOD(updateDisplay:(NSString *)uuidString :(NSString *)displayName :(NSString *)uri :(NSDictionary *)options)
268283
{
269284
#ifdef DEBUG
270285
NSLog(@"[RNCallKeep][updateDisplay] uuidString = %@ displayName = %@ uri = %@", uuidString, displayName, uri);
@@ -274,6 +289,23 @@ + (void)initCallKitProvider {
274289
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
275290
callUpdate.localizedCallerName = displayName;
276291
callUpdate.remoteHandle = callHandle;
292+
293+
if ([options valueForKey:@"hasVideo"] != nil) {
294+
callUpdate.hasVideo = [RCTConvert BOOL:options[@"hasVideo"]];
295+
}
296+
if ([options valueForKey:@"supportsHolding"] != nil) {
297+
callUpdate.supportsHolding = [RCTConvert BOOL:options[@"supportsHolding"]];
298+
}
299+
if ([options valueForKey:@"supportsDTMF"] != nil) {
300+
callUpdate.supportsDTMF = [RCTConvert BOOL:options[@"supportsDTMF"]];
301+
}
302+
if ([options valueForKey:@"supportsGrouping"] != nil) {
303+
callUpdate.supportsGrouping = [RCTConvert BOOL:options[@"supportsGrouping"]];
304+
}
305+
if ([options valueForKey:@"supportsUngrouping"] != nil) {
306+
callUpdate.supportsUngrouping = [RCTConvert BOOL:options[@"supportsUngrouping"]];
307+
}
308+
277309
[self.callKeepProvider reportCallWithUUID:uuid updated:callUpdate];
278310
}
279311

@@ -390,17 +422,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
390422
handleType:(NSString *)handleType
391423
hasVideo:(BOOL)hasVideo
392424
localizedCallerName:(NSString * _Nullable)localizedCallerName
393-
fromPushKit:(BOOL)fromPushKit
394-
payload:(NSDictionary * _Nullable)payload
395-
{
396-
[RNCallKeep reportNewIncomingCall:uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit:fromPushKit payload:payload withCompletionHandler:nil];
397-
}
398-
399-
+ (void)reportNewIncomingCall:(NSString *)uuidString
400-
handle:(NSString *)handle
401-
handleType:(NSString *)handleType
402-
hasVideo:(BOOL)hasVideo
403-
localizedCallerName:(NSString * _Nullable)localizedCallerName
425+
supportsHolding:(BOOL)supportsHolding
426+
supportsDTMF:(BOOL)supportsDTMF
427+
supportsGrouping:(BOOL)supportsGrouping
428+
supportsUngrouping:(BOOL)supportsUngrouping
404429
fromPushKit:(BOOL)fromPushKit
405430
payload:(NSDictionary * _Nullable)payload
406431
withCompletionHandler:(void (^_Nullable)(void))completion
@@ -412,10 +437,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
412437
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
413438
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
414439
callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle];
415-
callUpdate.supportsDTMF = YES;
416-
callUpdate.supportsHolding = YES;
417-
callUpdate.supportsGrouping = YES;
418-
callUpdate.supportsUngrouping = YES;
440+
callUpdate.supportsHolding = supportsHolding;
441+
callUpdate.supportsDTMF = supportsDTMF;
442+
callUpdate.supportsGrouping = supportsGrouping;
443+
callUpdate.supportsUngrouping = supportsUngrouping;
419444
callUpdate.hasVideo = hasVideo;
420445
callUpdate.localizedCallerName = localizedCallerName;
421446

@@ -428,6 +453,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
428453
@"handle": handle,
429454
@"localizedCallerName": localizedCallerName ? localizedCallerName : @"",
430455
@"hasVideo": hasVideo ? @"1" : @"0",
456+
@"supportsHolding": supportsHolding ? @"1" : @"0",
457+
@"supportsDTMF": supportsDTMF ? @"1" : @"0",
458+
@"supportsGrouping": supportsGrouping ? @"1" : @"0",
459+
@"supportsUngrouping": supportsUngrouping ? @"1" : @"0",
431460
@"fromPushKit": fromPushKit ? @"1" : @"0",
432461
@"payload": payload ? payload : @"",
433462
}];
@@ -443,16 +472,6 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
443472
}];
444473
}
445474

446-
+ (void)reportNewIncomingCall:(NSString *)uuidString
447-
handle:(NSString *)handle
448-
handleType:(NSString *)handleType
449-
hasVideo:(BOOL)hasVideo
450-
localizedCallerName:(NSString * _Nullable)localizedCallerName
451-
fromPushKit:(BOOL)fromPushKit
452-
{
453-
[RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: fromPushKit payload:nil withCompletionHandler:nil];
454-
}
455-
456475
- (BOOL)lessThanIos10_2
457476
{
458477
if (_version.majorVersion < 10) {

0 commit comments

Comments
 (0)