diff --git a/README.md b/README.md index 7ab81672..f2305377 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,21 @@ Be sure to set this only after your call is ready for two way audio; used both i RNCallKeep.setCurrentCallActive(uuid); ``` +- `uuid`: string + - The `uuid` used for `startCall` or `displayIncomingCall` + +### isCallActive +_This feature is available only on IOS._ + +Returns true if the UUID passed matches an existing and answered call. +This will return true ONLY if the call exists and the user has already answered the call. It will return false +if the call does not exist or has not been answered. This is exposed to both React Native and Native sides. +This was exposed so a call can be canceled if ringing and the user answered on a different device. + +```js +RNCallKeep.isCallActive(uuid); +``` + - `uuid`: string - The `uuid` used for `startCall` or `displayIncomingCall` @@ -513,6 +528,14 @@ So we have to check if the application is reachable before making a call from th RNCallKeep.addEventListener('checkReachability', () => { RNCallKeep.setReachable(); }); + +``` +### removeEventListener + +Allows to remove the listener on an event. + +```js +RNCallKeep.removeEventListener('checkReachability'); ``` ## Example @@ -665,9 +688,7 @@ 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]; - - completion(); + [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:extra withCompletionHandler:completion]; } ``` diff --git a/android/src/main/java/io/wazo/callkeep/Constants.java b/android/src/main/java/io/wazo/callkeep/Constants.java new file mode 100644 index 00000000..4310de56 --- /dev/null +++ b/android/src/main/java/io/wazo/callkeep/Constants.java @@ -0,0 +1,19 @@ +package io.wazo.callkeep; + +public class Constants { + public static final String ACTION_ANSWER_CALL = "ACTION_ANSWER_CALL"; + public static final String ACTION_AUDIO_SESSION = "ACTION_AUDIO_SESSION"; + public static final String ACTION_CHECK_REACHABILITY = "ACTION_CHECK_REACHABILITY"; + public static final String ACTION_DTMF_TONE = "ACTION_DTMF_TONE"; + public static final String ACTION_END_CALL = "ACTION_END_CALL"; + public static final String ACTION_HOLD_CALL = "ACTION_HOLD_CALL"; + public static final String ACTION_MUTE_CALL = "ACTION_MUTE_CALL"; + public static final String ACTION_ONGOING_CALL = "ACTION_ONGOING_CALL"; + public static final String ACTION_UNHOLD_CALL = "ACTION_UNHOLD_CALL"; + public static final String ACTION_UNMUTE_CALL = "ACTION_UNMUTE_CALL"; + public static final String ACTION_WAKE_APP = "ACTION_WAKE_APP"; + + public static final String EXTRA_CALL_NUMBER = "EXTRA_CALL_NUMBER"; + public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID"; + public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME"; +} diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepBackgroundMessagingService.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepBackgroundMessagingService.java index 8770342f..c0690727 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepBackgroundMessagingService.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepBackgroundMessagingService.java @@ -26,9 +26,9 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.jstasks.HeadlessJsTaskConfig; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID; +import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME; +import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; +import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; import javax.annotation.Nullable; diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index bb88d135..a8cbf2c4 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -55,6 +55,7 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.HeadlessJsTaskService; import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter; import java.lang.reflect.Array; @@ -67,27 +68,26 @@ import static android.support.v4.app.ActivityCompat.requestPermissions; +import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME; +import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; +import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; +import static io.wazo.callkeep.Constants.ACTION_END_CALL; +import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL; +import static io.wazo.callkeep.Constants.ACTION_MUTE_CALL; +import static io.wazo.callkeep.Constants.ACTION_UNMUTE_CALL; +import static io.wazo.callkeep.Constants.ACTION_DTMF_TONE; +import static io.wazo.callkeep.Constants.ACTION_HOLD_CALL; +import static io.wazo.callkeep.Constants.ACTION_UNHOLD_CALL; +import static io.wazo.callkeep.Constants.ACTION_ONGOING_CALL; +import static io.wazo.callkeep.Constants.ACTION_AUDIO_SESSION; +import static io.wazo.callkeep.Constants.ACTION_CHECK_REACHABILITY; +import static io.wazo.callkeep.Constants.ACTION_WAKE_APP; + // @see https://github.com/kbagchiGWC/voice-quickstart-android/blob/9a2aff7fbe0d0a5ae9457b48e9ad408740dfb968/exampleConnectionService/src/main/java/com/twilio/voice/examples/connectionservice/VoiceConnectionServiceActivity.java public class RNCallKeepModule extends ReactContextBaseJavaModule { public static final int REQUEST_READ_PHONE_STATE = 1337; public static final int REQUEST_REGISTER_CALL_PROVIDER = 394859; - public static final String CHECKING_PERMS = "CHECKING_PERMS"; - public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME"; - public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID"; - public static final String EXTRA_CALL_NUMBER = "EXTRA_CALL_NUMBER"; - public static final String ACTION_END_CALL = "ACTION_END_CALL"; - public static final String ACTION_ANSWER_CALL = "ACTION_ANSWER_CALL"; - public static final String ACTION_MUTE_CALL = "ACTION_MUTE_CALL"; - public static final String ACTION_UNMUTE_CALL = "ACTION_UNMUTE_CALL"; - public static final String ACTION_DTMF_TONE = "ACTION_DTMF_TONE"; - public static final String ACTION_HOLD_CALL = "ACTION_HOLD_CALL"; - public static final String ACTION_UNHOLD_CALL = "ACTION_UNHOLD_CALL"; - public static final String ACTION_ONGOING_CALL = "ACTION_ONGOING_CALL"; - public static final String ACTION_AUDIO_SESSION = "ACTION_AUDIO_SESSION"; - public static final String ACTION_CHECK_REACHABILITY = "ACTION_CHECK_REACHABILITY"; - public static final String ACTION_SHOW_INCOMING_CALL_UI = "ACTION_SHOW_INCOMING_CALL_UI"; - private static final String E_ACTIVITY_DOES_NOT_EXIST = "E_ACTIVITY_DOES_NOT_EXIST"; private static final String REACT_NATIVE_MODULE_NAME = "RNCallKeep"; private static String[] permissions = { Manifest.permission.READ_PHONE_STATE, Manifest.permission.CALL_PHONE, Manifest.permission.RECORD_AUDIO }; @@ -132,6 +132,7 @@ public void setup(ReadableMap options) { this.registerPhoneAccount(this.getAppContext()); voiceBroadcastReceiver = new VoiceBroadcastReceiver(); registerReceiver(); + VoiceConnectionService.setPhoneAccountHandle(handle); VoiceConnectionService.setAvailable(true); } } @@ -603,6 +604,18 @@ public void onReceive(Context context, Intent intent) { args.putString("name", attributeMap.get(EXTRA_CALLER_NAME)); sendEventToJS("RNCallKeepShowIncomingCallUi", args); break; + case ACTION_WAKE_APP: + Intent headlessIntent = new Intent(reactContext, RNCallKeepBackgroundMessagingService.class); + headlessIntent.putExtra("callUUID", attributeMap.get(EXTRA_CALL_UUID)); + headlessIntent.putExtra("name", attributeMap.get(EXTRA_CALLER_NAME)); + headlessIntent.putExtra("handle", attributeMap.get(EXTRA_CALL_NUMBER)); + Log.d(TAG, "wakeUpApplication: " + attributeMap.get(EXTRA_CALL_UUID) + ", number : " + attributeMap.get(EXTRA_CALL_NUMBER) + ", displayName:" + attributeMap.get(EXTRA_CALLER_NAME)); + + ComponentName name = reactContext.startService(headlessIntent); + if (name != null) { + HeadlessJsTaskService.acquireWakeLockNow(reactContext); + } + break; } } } diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnection.java b/android/src/main/java/io/wazo/callkeep/VoiceConnection.java index b662239e..00ceb325 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnection.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnection.java @@ -37,18 +37,17 @@ import java.util.HashMap; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_ANSWER_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_AUDIO_SESSION; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_DTMF_TONE; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_END_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_HOLD_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_MUTE_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNHOLD_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNMUTE_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_SHOW_INCOMING_CALL_UI; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID; +import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL; +import static io.wazo.callkeep.Constants.ACTION_AUDIO_SESSION; +import static io.wazo.callkeep.Constants.ACTION_DTMF_TONE; +import static io.wazo.callkeep.Constants.ACTION_END_CALL; +import static io.wazo.callkeep.Constants.ACTION_HOLD_CALL; +import static io.wazo.callkeep.Constants.ACTION_MUTE_CALL; +import static io.wazo.callkeep.Constants.ACTION_UNHOLD_CALL; +import static io.wazo.callkeep.Constants.ACTION_UNMUTE_CALL; +import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME; +import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; +import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; @TargetApi(Build.VERSION_CODES.M) public class VoiceConnection extends Connection { diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index d1e084ca..57c03e5e 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -41,10 +41,6 @@ import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; -import com.facebook.react.HeadlessJsTaskService; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.common.LifecycleState; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -54,20 +50,13 @@ import java.util.UUID; import java.util.stream.Collectors; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_ANSWER_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_AUDIO_SESSION; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_DTMF_TONE; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_END_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_HOLD_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_MUTE_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_ONGOING_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNHOLD_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_UNMUTE_CALL; -import static io.wazo.callkeep.RNCallKeepModule.ACTION_CHECK_REACHABILITY; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALLER_NAME; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_NUMBER; -import static io.wazo.callkeep.RNCallKeepModule.EXTRA_CALL_UUID; -import static io.wazo.callkeep.RNCallKeepModule.handle; +import static io.wazo.callkeep.Constants.ACTION_AUDIO_SESSION; +import static io.wazo.callkeep.Constants.ACTION_ONGOING_CALL; +import static io.wazo.callkeep.Constants.ACTION_CHECK_REACHABILITY; +import static io.wazo.callkeep.Constants.ACTION_WAKE_APP; +import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME; +import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; +import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; // @see https://github.com/kbagchiGWC/voice-quickstart-android/blob/9a2aff7fbe0d0a5ae9457b48e9ad408740dfb968/exampleConnectionService/src/main/java/com/twilio/voice/examples/connectionservice/VoiceConnectionService.java @TargetApi(Build.VERSION_CODES.M) @@ -77,6 +66,7 @@ public class VoiceConnectionService extends ConnectionService { private static Boolean isReachable; private static String notReachableCallUuid; private static ConnectionRequest currentConnectionRequest; + private static PhoneAccountHandle phoneAccountHandle; private static String TAG = "RNCK:VoiceConnectionService"; public static Map currentConnections = new HashMap<>(); public static Boolean hasOutgoingCall = false; @@ -98,6 +88,10 @@ public VoiceConnectionService() { currentConnectionService = this; } + public static void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { + VoiceConnectionService.phoneAccountHandle = phoneAccountHandle; + } + public static void setAvailable(Boolean value) { Log.d(TAG, "setAvailable: " + (value ? "true" : "false")); if (value) { @@ -196,19 +190,11 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool } private void wakeUpApplication(String uuid, String number, String displayName) { - Intent headlessIntent = new Intent( - this.getApplicationContext(), - RNCallKeepBackgroundMessagingService.class - ); - headlessIntent.putExtra("callUUID", uuid); - headlessIntent.putExtra("name", displayName); - headlessIntent.putExtra("handle", number); - Log.d(TAG, "wakeUpApplication: " + uuid + ", number : " + number + ", displayName:" + displayName); - - ComponentName name = this.getApplicationContext().startService(headlessIntent); - if (name != null) { - HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext()); - } + HashMap extrasMap = new HashMap(); + extrasMap.put(EXTRA_CALL_UUID, uuid); + extrasMap.put(EXTRA_CALLER_NAME, displayName); + extrasMap.put(EXTRA_CALL_NUMBER, number); + sendCallRequestToActivity(ACTION_WAKE_APP, extrasMap); } private void wakeUpAfterReachabilityTimeout(ConnectionRequest request) { @@ -287,9 +273,7 @@ public void onConference(Connection connection1, Connection connection2) { VoiceConnection voiceConnection1 = (VoiceConnection) connection1; VoiceConnection voiceConnection2 = (VoiceConnection) connection2; - PhoneAccountHandle phoneAccountHandle = RNCallKeepModule.handle; - - VoiceConference voiceConference = new VoiceConference(handle); + VoiceConference voiceConference = new VoiceConference(phoneAccountHandle); voiceConference.addConnection(voiceConnection1); voiceConference.addConnection(voiceConnection2); diff --git a/index.d.ts b/index.d.ts index 9d941a34..449db32d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,7 +43,7 @@ export default class RNCallKeep { } - static removeEventListener(type: Events, handler: (args: any) => void) { + static removeEventListener(type: Events) { } @@ -114,7 +114,9 @@ export default class RNCallKeep { static setReachable() { } + static isCallActive(uuid: string): Promise { + } /** * @description supportConnectionService method is available only on Android. */ diff --git a/index.js b/index.js index b4e848e0..53df5d9b 100644 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ class RNCallKeep { return; }; - displayIncomingCall = (uuid, handle, localizedCallerName, handleType = 'number', hasVideo = false) => { + displayIncomingCall = (uuid, handle, localizedCallerName = '', handleType = 'number', hasVideo = false) => { if (!isIOS) { RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName); return; @@ -108,6 +108,8 @@ class RNCallKeep { } }; + isCallActive = async(uuid) => await RNCallKeepModule.isCallActive(uuid); + endCall = (uuid) => RNCallKeepModule.endCall(uuid); endAllCalls = () => RNCallKeepModule.endAllCalls(); diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index fbb6104d..ef92ea02 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -35,8 +35,19 @@ continueUserActivity:(NSUserActivity *)userActivity 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; + + (void)endCallWithUUID:(NSString *)uuidString reason:(int)reason; + (BOOL) getIsSetup; + (CXProvider *) getProvider; ++ (BOOL)isCallActive:(NSString *)uuidString; + @end \ No newline at end of file diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 13084e38..54cbb674 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -163,7 +163,7 @@ + (CXProvider *) getProvider { hasVideo:(BOOL)hasVideo localizedCallerName:(NSString * _Nullable)localizedCallerName) { - [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil]; + [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil withCompletionHandler:nil]; } RCT_EXPORT_METHOD(startCall:(NSString *)uuidString @@ -285,6 +285,14 @@ + (CXProvider *) getProvider { [self requestTransaction:transaction]; } +RCT_EXPORT_METHOD(isCallActive:(NSString *)uuidString) +{ +#ifdef DEBUG + NSLog(@"[RNCallKeep][isCallActive] uuid = %@", uuidString); +#endif + [RNCallKeep isCallActive: uuidString]; +} + - (void)requestTransaction:(CXTransaction *)transaction { #ifdef DEBUG @@ -316,6 +324,20 @@ - (void)requestTransaction:(CXTransaction *)transaction }]; } ++ (BOOL)isCallActive:(NSString *)uuidString +{ + CXCallObserver *callObserver = [[CXCallObserver alloc] init]; + NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; + + for(CXCall *call in callObserver.calls){ + NSLog(@"[RNCallKeep] isCallActive %@ %d ?", call.UUID, [call.UUID isEqual:uuid]); + if([call.UUID isEqual:[[NSUUID alloc] initWithUUIDString:uuidString]] && !call.hasConnected){ + return true; + } + } + return false; +} + + (void)endCallWithUUID:(NSString *)uuidString reason:(int)reason { @@ -352,6 +374,18 @@ + (void)reportNewIncomingCall:(NSString *)uuidString 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 + fromPushKit:(BOOL)fromPushKit + payload:(NSDictionary * _Nullable)payload + withCompletionHandler:(void (^_Nullable)(void))completion { #ifdef DEBUG NSLog(@"[RNCallKeep][reportNewIncomingCall] uuidString = %@", uuidString); @@ -370,13 +404,24 @@ + (void)reportNewIncomingCall:(NSString *)uuidString [RNCallKeep initCallKitProvider]; [sharedProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) { RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil]; - [callKeep sendEventWithName:RNCallKeepDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"", @"callUUID": uuidString, @"handle": handle, @"localizedCallerName": localizedCallerName, @"hasVideo": hasVideo ? @"1" : @"0", @"fromPushKit": fromPushKit ? @"1" : @"0", @"payload": payload }]; + [callKeep sendEventWithName:RNCallKeepDidDisplayIncomingCall body:@{ + @"error": error && error.localizedDescription ? error.localizedDescription : @"", + @"callUUID": uuidString, + @"handle": handle, + @"localizedCallerName": localizedCallerName ? localizedCallerName : @"", + @"hasVideo": hasVideo ? @"1" : @"0", + @"fromPushKit": fromPushKit ? @"1" : @"0", + @"payload": payload ? payload : @"", + }]; if (error == nil) { // Workaround per https://forums.developer.apple.com/message/169511 if ([callKeep lessThanIos10_2]) { [callKeep configureAudioSession]; } } + if (completion != nil) { + completion(); + } }]; } @@ -387,7 +432,7 @@ + (void)reportNewIncomingCall:(NSString *)uuidString localizedCallerName:(NSString * _Nullable)localizedCallerName fromPushKit:(BOOL)fromPushKit { - [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil]; + [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: fromPushKit payload:nil withCompletionHandler:nil]; } - (BOOL)lessThanIos10_2 @@ -425,7 +470,12 @@ + (CXProviderConfiguration *)getProviderConfiguration:(NSDictionary*)settings providerConfiguration.supportsVideo = YES; providerConfiguration.maximumCallGroups = 3; providerConfiguration.maximumCallsPerCallGroup = 1; - providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], nil]; + if(settings[@"handleType"]){ + int _handleType = [RNCallKeep getHandleType:settings[@"handleType"]]; + providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:_handleType], nil]; + }else{ + providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], nil]; + } if (settings[@"supportsVideo"]) { providerConfiguration.supportsVideo = [settings[@"supportsVideo"] boolValue]; } diff --git a/package.json b/package.json index 1e53d9f3..8d6e5072 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-callkeep", - "version": "3.0.11", + "version": "3.0.13", "description": "iOS 10 CallKit and Android ConnectionService Framework For React Native", "main": "index.js", "scripts": {},