Skip to content

ios: support additional options pass from js #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -775,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];
}
```

Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare module 'react-native-callkeep' {
localizedCallerName?: string,
handleType?: HandleType,
hasVideo?: boolean,
options?: object,
): void

static startCall(
Expand All @@ -75,6 +76,7 @@ declare module 'react-native-callkeep' {
uuid: string,
displayName: string,
handle: string,
options?: object,
): void

static checkPhoneAccountEnabled(): Promise<boolean>;
Expand Down
25 changes: 22 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ 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);
// 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);
};

answerIncomingCall = (uuid) => {
Expand Down Expand Up @@ -200,7 +206,20 @@ 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;
}

let iosOptions = {};
if (options && options.ios) {
iosOptions = {
...options.ios,
}
}
RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions);
};

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

Expand Down
14 changes: 5 additions & 9 deletions ios/RNCallKeep/RNCallKeep.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ continueUserActivity:(NSUserActivity *)userActivity
handleType:(NSString *)handleType
hasVideo:(BOOL)hasVideo
localizedCallerName:(NSString * _Nullable)localizedCallerName
fromPushKit:(BOOL)fromPushKit
payload:(NSDictionary * _Nullable)payload;

+ (void)reportNewIncomingCall:(NSString *)uuidString
handle:(NSString *)handle
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
withCompletionHandler:(void (^_Nullable)(void))completion;
Expand All @@ -49,4 +45,4 @@ continueUserActivity:(NSUserActivity *)userActivity

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

@end
@end
77 changes: 48 additions & 29 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -264,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);
Expand All @@ -274,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];
}

Expand Down Expand Up @@ -390,17 +422,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
handleType:(NSString *)handleType
hasVideo:(BOOL)hasVideo
localizedCallerName:(NSString * _Nullable)localizedCallerName
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
supportsHolding:(BOOL)supportsHolding
supportsDTMF:(BOOL)supportsDTMF
supportsGrouping:(BOOL)supportsGrouping
supportsUngrouping:(BOOL)supportsUngrouping
fromPushKit:(BOOL)fromPushKit
payload:(NSDictionary * _Nullable)payload
withCompletionHandler:(void (^_Nullable)(void))completion
Expand All @@ -412,10 +437,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;

Expand All @@ -428,6 +453,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 : @"",
}];
Expand All @@ -443,16 +472,6 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
}];
}

+ (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 fromPushKit: fromPushKit payload:nil withCompletionHandler:nil];
}

- (BOOL)lessThanIos10_2
{
if (_version.majorVersion < 10) {
Expand Down