From ae3830dae0d99496adab7316ec250d365df6a0c4 Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Sat, 28 Mar 2020 20:04:42 +0800 Subject: [PATCH 1/6] ios: implement support options for disaply incoming call --- index.d.ts | 1 + index.js | 16 ++++++++++-- ios/RNCallKeep/RNCallKeep.h | 6 ++++- ios/RNCallKeep/RNCallKeep.m | 51 +++++++++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 025593ab..97c0f810 100644 --- a/index.d.ts +++ b/index.d.ts @@ -61,6 +61,7 @@ declare module 'react-native-callkeep' { localizedCallerName?: string, handleType?: HandleType, hasVideo?: boolean, + options?: object, ): void static startCall( diff --git a/index.js b/index.js index 0ef37db0..fe8235c4 100644 --- a/index.js +++ b/index.js @@ -77,13 +77,25 @@ class RNCallKeep { return; }; - displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false) => { + displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false, options = null) => { if (!isIOS) { RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName); return; } - RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName); + let supportsHolding = true, + supportsDTMF = true, + supportsGrouping = true, + supportsUngrouping = true; + + if (options) { + if (typeof options.supportsHolding === 'boolean') supportsHolding = options.supportsHolding; + if (typeof options.supportsDTMF === 'boolean') supportsDTMF = options.supportsDTMF; + if (typeof options.supportsGrouping === 'boolean') supportsGrouping = options.supportsGrouping; + if (typeof options.supportsUngrouping === 'boolean') supportsUngrouping = options.supportsUngrouping; + } + + RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, supportsHolding, supportsDTMF, supportsGrouping, supportsUngrouping); }; answerIncomingCall = (uuid) => { diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index a91dfacd..c7b4ef09 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -32,6 +32,10 @@ continueUserActivity:(NSUserActivity *)userActivity handleType:(NSString *)handleType hasVideo:(BOOL)hasVideo localizedCallerName:(NSString * _Nullable)localizedCallerName + supportsHolding:(BOOL)supportsHolding + supportsDTMF:(BOOL)supportsDTMF + supportsGrouping:(BOOL)supportsGrouping + supportsUngrouping:(BOOL)supportsUngrouping fromPushKit:(BOOL)fromPushKit payload:(NSDictionary * _Nullable)payload; @@ -49,4 +53,4 @@ continueUserActivity:(NSUserActivity *)userActivity + (BOOL)isCallActive:(NSString *)uuidString; -@end \ No newline at end of file +@end diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 8179e168..162f102a 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -179,9 +179,24 @@ + (void)initCallKitProvider { handle:(NSString *)handle handleType:(NSString *)handleType hasVideo:(BOOL)hasVideo - localizedCallerName:(NSString * _Nullable)localizedCallerName) -{ - [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil withCompletionHandler:nil]; + localizedCallerName:(NSString * _Nullable)localizedCallerName + supportsHolding:(BOOL)supportsHolding + supportsDTMF:(BOOL)supportsDTMF + supportsGrouping:(BOOL)supportsGrouping + supportsUngrouping:(BOOL)supportsUngrouping) +{ + [RNCallKeep reportNewIncomingCall: uuidString + handle: handle + handleType: handleType + hasVideo: hasVideo + localizedCallerName: localizedCallerName + supportsHolding: supportsHolding + supportsDTMF: supportsDTMF + supportsGrouping: supportsGrouping + supportsUngrouping: supportsUngrouping + fromPushKit: NO + payload: nil + withCompletionHandler: nil]; } RCT_EXPORT_METHOD(startCall:(NSString *)uuidString @@ -390,6 +405,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString handleType:(NSString *)handleType hasVideo:(BOOL)hasVideo localizedCallerName:(NSString * _Nullable)localizedCallerName + supportsHolding:(BOOL)supportsHolding + supportsDTMF:(BOOL)supportsDTMF + supportsGrouping:(BOOL)supportsGrouping + supportsUngrouping:(BOOL)supportsUngrouping fromPushKit:(BOOL)fromPushKit payload:(NSDictionary * _Nullable)payload { @@ -412,10 +431,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; - callUpdate.supportsDTMF = YES; - callUpdate.supportsHolding = YES; - callUpdate.supportsGrouping = YES; - callUpdate.supportsUngrouping = YES; + callUpdate.supportsHolding = supportsHolding; + callUpdate.supportsDTMF = supportsDTMF; + callUpdate.supportsGrouping = supportsGrouping; + callUpdate.supportsUngrouping = supportsUngrouping; callUpdate.hasVideo = hasVideo; callUpdate.localizedCallerName = localizedCallerName; @@ -428,6 +447,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString @"handle": handle, @"localizedCallerName": localizedCallerName ? localizedCallerName : @"", @"hasVideo": hasVideo ? @"1" : @"0", + @"supportsHolding": supportsHolding ? @"1" : @"0", + @"supportsDTMF": supportsDTMF ? @"1" : @"0", + @"supportsGrouping": supportsGrouping ? @"1" : @"0", + @"supportsUngrouping": supportsUngrouping ? @"1" : @"0", @"fromPushKit": fromPushKit ? @"1" : @"0", @"payload": payload ? payload : @"", }]; @@ -443,6 +466,7 @@ + (void)reportNewIncomingCall:(NSString *)uuidString }]; } +// --- overloading functions for backward compatibility and simple api + (void)reportNewIncomingCall:(NSString *)uuidString handle:(NSString *)handle handleType:(NSString *)handleType @@ -450,7 +474,18 @@ + (void)reportNewIncomingCall:(NSString *)uuidString localizedCallerName:(NSString * _Nullable)localizedCallerName fromPushKit:(BOOL)fromPushKit { - [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: fromPushKit payload:nil withCompletionHandler:nil]; + [RNCallKeep reportNewIncomingCall: uuidString + handle: handle + handleType: handleType + hasVideo: hasVideo + localizedCallerName: localizedCallerName + supportsHolding: YES + supportsDTMF: YES + supportsGrouping: YES + supportsUngrouping: YES + fromPushKit: fromPushKit + payload: nil + withCompletionHandler: nil]; } - (BOOL)lessThanIos10_2 From 07afe9598e8af5b62e9d437e08a4a09ad7d8eb3d Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Sat, 28 Mar 2020 20:41:59 +0800 Subject: [PATCH 2/6] ios: implemet support options for updateDisplay --- index.d.ts | 1 + index.js | 12 +++++++++++- ios/RNCallKeep/RNCallKeep.m | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 97c0f810..2090fe29 100644 --- a/index.d.ts +++ b/index.d.ts @@ -76,6 +76,7 @@ declare module 'react-native-callkeep' { uuid: string, displayName: string, handle: string, + options?: object, ): void static checkPhoneAccountEnabled(): Promise; diff --git a/index.js b/index.js index fe8235c4..7a48d174 100644 --- a/index.js +++ b/index.js @@ -212,7 +212,17 @@ class RNCallKeep { RNCallKeepModule.setCurrentCallActive(callUUID); }; - updateDisplay = (uuid, displayName, handle) => RNCallKeepModule.updateDisplay(uuid, displayName, handle); + updateDisplay = (uuid, displayName, handle, options = null) => { + if (!isIOS) { + RNCallKeepModule.updateDisplay(uuid, displayName, handle); + return; + } + + if (!options) { + options = {}; + } + RNCallKeepModule.updateDisplay(uuid, displayName, handle, options); + }; setOnHold = (uuid, shouldHold) => RNCallKeepModule.setOnHold(uuid, shouldHold); diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 162f102a..c1b042a6 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -279,7 +279,7 @@ + (void)initCallKitProvider { [RNCallKeep endCallWithUUID: uuidString reason:reason]; } -RCT_EXPORT_METHOD(updateDisplay:(NSString *)uuidString :(NSString *)displayName :(NSString *)uri) +RCT_EXPORT_METHOD(updateDisplay:(NSString *)uuidString :(NSString *)displayName :(NSString *)uri :(NSDictionary *)options) { #ifdef DEBUG NSLog(@"[RNCallKeep][updateDisplay] uuidString = %@ displayName = %@ uri = %@", uuidString, displayName, uri); @@ -289,6 +289,23 @@ + (void)initCallKitProvider { CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; callUpdate.localizedCallerName = displayName; callUpdate.remoteHandle = callHandle; + + if ([options valueForKey:@"hasVideo"] != nil) { + callUpdate.hasVideo = [RCTConvert BOOL:options[@"hasVideo"]]; + } + if ([options valueForKey:@"supportsHolding"] != nil) { + callUpdate.supportsHolding = [RCTConvert BOOL:options[@"supportsHolding"]]; + } + if ([options valueForKey:@"supportsDTMF"] != nil) { + callUpdate.supportsDTMF = [RCTConvert BOOL:options[@"supportsDTMF"]]; + } + if ([options valueForKey:@"supportsGrouping"] != nil) { + callUpdate.supportsGrouping = [RCTConvert BOOL:options[@"supportsGrouping"]]; + } + if ([options valueForKey:@"supportsUngrouping"] != nil) { + callUpdate.supportsUngrouping = [RCTConvert BOOL:options[@"supportsUngrouping"]]; + } + [self.callKeepProvider reportCallWithUUID:uuid updated:callUpdate]; } From f3e014667000327a2af6b31f51528091a00b4886 Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Thu, 30 Apr 2020 16:18:02 +0800 Subject: [PATCH 3/6] ios: platform specific options for displayIncomingCall and updateDisplay --- index.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 7a48d174..88a9d37c 100644 --- a/index.js +++ b/index.js @@ -83,17 +83,11 @@ class RNCallKeep { return; } - let supportsHolding = true, - supportsDTMF = true, - supportsGrouping = true, - supportsUngrouping = true; - - if (options) { - if (typeof options.supportsHolding === 'boolean') supportsHolding = options.supportsHolding; - if (typeof options.supportsDTMF === 'boolean') supportsDTMF = options.supportsDTMF; - if (typeof options.supportsGrouping === 'boolean') supportsGrouping = options.supportsGrouping; - if (typeof options.supportsUngrouping === 'boolean') supportsUngrouping = options.supportsUngrouping; - } + // should be boolean type value + let supportsHolding = !!(options?.ios?.supportsHolding ?? true); + let supportsDTMF = !!(options?.ios?.supportsDTMF ?? true); + let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true); + let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true); RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, supportsHolding, supportsDTMF, supportsGrouping, supportsUngrouping); }; @@ -218,10 +212,13 @@ class RNCallKeep { return; } - if (!options) { - options = {}; + let iosOptions = {}; + if (options && options.ios) { + iosOptions = { + ...options.ios, + } } - RNCallKeepModule.updateDisplay(uuid, displayName, handle, options); + RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions); }; setOnHold = (uuid, shouldHold) => RNCallKeepModule.setOnHold(uuid, shouldHold); From 130fac17d4dcb06dff33d90a2638657117b1bfc7 Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Thu, 30 Apr 2020 16:29:19 +0800 Subject: [PATCH 4/6] readme: add options arg for displayIncomingCall and updateDisplay --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 90bcb20c..d486374a 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,13 @@ RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName); - `hasVideo`: boolean (optional, iOS only) - `false` (default) - `true` (you know... when not false) +- `options`: object (optional) + - `ios`: object + - `supportsHolding`: boolean (optional, default true) + - `supportsDTMF`: boolean (optional, default true) + - `supportsGrouping`: boolean (optional, default true) + - `supportsUngrouping`: boolean (optional, default true) + - `android`: object (currently no-op) ### answerIncomingCall _This feature is available only on Android._ @@ -241,6 +248,14 @@ RNCallKeep.updateDisplay(uuid, displayName, handle) - Name of the caller to be displayed on the native UI - `handle`: string - Phone number of the caller +- `options`: object (optional) + - `ios`: object + - `hasVideo`: boolean (optional) + - `supportsHolding`: boolean (optional) + - `supportsDTMF`: boolean (optional) + - `supportsGrouping`: boolean (optional) + - `supportsUngrouping`: boolean (optional) + - `android`: object (currently no-op) ### endCall From 4654eb1f596554462c7ac6a0294e71d163c13bb2 Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Tue, 14 Jul 2020 17:17:33 +0800 Subject: [PATCH 5/6] ios: clean/remove reportNewIncomingCall overloading api --- ios/RNCallKeep/RNCallKeep.h | 8 -------- ios/RNCallKeep/RNCallKeep.m | 33 --------------------------------- 2 files changed, 41 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index c7b4ef09..47ce98b3 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -36,14 +36,6 @@ continueUserActivity:(NSUserActivity *)userActivity supportsDTMF:(BOOL)supportsDTMF supportsGrouping:(BOOL)supportsGrouping supportsUngrouping:(BOOL)supportsUngrouping - fromPushKit:(BOOL)fromPushKit - payload:(NSDictionary * _Nullable)payload; - -+ (void)reportNewIncomingCall:(NSString *)uuidString - handle:(NSString *)handle - handleType:(NSString *)handleType - hasVideo:(BOOL)hasVideo - localizedCallerName:(NSString * _Nullable)localizedCallerName fromPushKit:(BOOL)fromPushKit payload:(NSDictionary * _Nullable)payload withCompletionHandler:(void (^_Nullable)(void))completion; diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index c1b042a6..04af4039 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -428,17 +428,6 @@ + (void)reportNewIncomingCall:(NSString *)uuidString supportsUngrouping:(BOOL)supportsUngrouping fromPushKit:(BOOL)fromPushKit payload:(NSDictionary * _Nullable)payload -{ - [RNCallKeep reportNewIncomingCall:uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit:fromPushKit payload:payload withCompletionHandler:nil]; -} - -+ (void)reportNewIncomingCall:(NSString *)uuidString - handle:(NSString *)handle - handleType:(NSString *)handleType - hasVideo:(BOOL)hasVideo - localizedCallerName:(NSString * _Nullable)localizedCallerName - fromPushKit:(BOOL)fromPushKit - payload:(NSDictionary * _Nullable)payload withCompletionHandler:(void (^_Nullable)(void))completion { #ifdef DEBUG @@ -483,28 +472,6 @@ + (void)reportNewIncomingCall:(NSString *)uuidString }]; } -// --- overloading functions for backward compatibility and simple api -+ (void)reportNewIncomingCall:(NSString *)uuidString - handle:(NSString *)handle - handleType:(NSString *)handleType - hasVideo:(BOOL)hasVideo - localizedCallerName:(NSString * _Nullable)localizedCallerName - fromPushKit:(BOOL)fromPushKit -{ - [RNCallKeep reportNewIncomingCall: uuidString - handle: handle - handleType: handleType - hasVideo: hasVideo - localizedCallerName: localizedCallerName - supportsHolding: YES - supportsDTMF: YES - supportsGrouping: YES - supportsUngrouping: YES - fromPushKit: fromPushKit - payload: nil - withCompletionHandler: nil]; -} - - (BOOL)lessThanIos10_2 { if (_version.majorVersion < 10) { From a0eb87a2e8a343eea9b6ae5e32e84bcd31f78492 Mon Sep 17 00:00:00 2001 From: zxcpoiu Date: Tue, 14 Jul 2020 18:10:52 +0800 Subject: [PATCH 6/6] readme: update `reportNewIncomingCall` example in `AppDelegate.m` --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d486374a..4c51ebde 100644 --- a/README.md +++ b/README.md @@ -790,7 +790,18 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic // NSString *handle = @"caller number here"; // 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` */ - [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:extra withCompletionHandler:completion]; + [RNCallKeep reportNewIncomingCall: uuid + handle: handle + handleType: @"generic" + hasVideo: NO + localizedCallerName: callerName + supportsHolding: YES + supportsDTMF: YES + supportsGrouping: YES + supportsUngrouping: YES + fromPushKit: YES + payload: extra + withCompletionHandler: completion]; } ```