diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 124de3ba..ab1e9555 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -89,8 +89,9 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule { 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 final String[] permissions = { Manifest.permission.READ_PHONE_STATE, - Manifest.permission.CALL_PHONE, Manifest.permission.RECORD_AUDIO }; + // private static final String[] permissions = { Manifest.permission.READ_PHONE_STATE, + // Manifest.permission.CALL_PHONE, Manifest.permission.RECORD_AUDIO }; + private static final String[] permissions = {}; private static final String TAG = "RNCK:RNCallKeepModule"; private static TelecomManager telecomManager; @@ -128,20 +129,35 @@ public void setup(ReadableMap options) { @ReactMethod public void displayIncomingCall(String uuid, String number, String callerName) { - if (!isConnectionServiceAvailable() || !hasPhoneAccount()) { - return; - } - - Log.d(TAG, "displayIncomingCall number: " + number + ", callerName: " + callerName); - + + Log.d(TAG, "displayIncomingCall number: " + number + ", callerName: " + callerName); + try { + Boolean isForeground = VoiceConnectionService.isRunning(this.reactContext.getApplicationContext()); + + if (!isConnectionServiceAvailable() || !hasPhoneAccount() && !isForeground) { + this.reactContext.getApplicationContext(); + Log.d(TAG, String.valueOf(this.reactContext.getApplicationInfo())); + String packageName = this.reactContext.getApplicationInfo().processName; + Log.d(TAG, packageName); + Intent intent = this.reactContext.getPackageManager().getLaunchIntentForPackage(packageName); + + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.reactContext.startActivity(intent); + Log.d(TAG, "displayIncomingCall started activity"); + } + + Bundle extras = new Bundle(); Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null); - + extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri); extras.putString(EXTRA_CALLER_NAME, callerName); extras.putString(EXTRA_CALL_UUID, uuid); - + telecomManager.addNewIncomingCall(handle, extras); + } catch (Throwable exception) { + Log.e(TAG, "Error displayIncomingCall", exception); + } } @ReactMethod diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnection.java b/android/src/main/java/io/wazo/callkeep/VoiceConnection.java index bb19b369..2103f53c 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnection.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnection.java @@ -91,19 +91,43 @@ public void onCallAudioStateChanged(CallAudioState state) { sendCallRequestToActivity(isMuted ? ACTION_MUTE_CALL : ACTION_UNMUTE_CALL, handle); } + @Override public void onAnswer() { super.onAnswer(); - Log.d(TAG, "onAnswer called"); + + try { + Log.d(TAG, "onAnswer called"); + String packageName = this.context.getApplicationInfo().processName; + Intent intent = this.context.getPackageManager().getLaunchIntentForPackage(packageName); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.context.startActivity(intent); + + setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD); + setAudioModeIsVoip(true); - setConnectionCapabilities(getConnectionCapabilities() | Connection.CAPABILITY_HOLD); - setAudioModeIsVoip(true); + sendCallRequestToActivity(ACTION_ANSWER_CALL, handle); + sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle); - sendCallRequestToActivity(ACTION_ANSWER_CALL, handle); - sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle); - Log.d(TAG, "onAnswer executed"); + disconnectOnAnswer(); + Log.d(TAG, "onAnswer executed"); + } catch (Throwable exception) { + disconnectOnAnswer(); + Log.e(TAG, "Error navigating to app in onanswer", exception); + } } + public void disconnectOnAnswer() { + setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); + Log.d(TAG, "disconnectOnAnswer executed"); + try { + ((VoiceConnectionService) context).deinitConnection(handle.get(EXTRA_CALL_UUID)); + } catch(Throwable exception) { + Log.e(TAG, "Handle map error", exception); + } + destroy(); + } + @Override public void onPlayDtmfTone(char dtmf) { try { diff --git a/index.d.ts b/index.d.ts index 2f86c02a..5b557a31 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,6 +55,10 @@ export default class RNCallKeep { } + static answerIncomingCall(uuid: string) { + + } + static displayIncomingCall( uuid: string, handle: string, diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 251e852c..0c5ba48c 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -151,7 +151,9 @@ + (void)initCallKitProvider { hasVideo:(BOOL)hasVideo localizedCallerName:(NSString * _Nullable)localizedCallerName) { + [RNCallKeep reportNewIncomingCall: uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName fromPushKit: NO payload:nil withCompletionHandler:nil]; + } RCT_EXPORT_METHOD(startCall:(NSString *)uuidString @@ -291,8 +293,8 @@ - (void)requestTransaction:(CXTransaction *)transaction if ([[transaction.actions firstObject] isKindOfClass:[CXStartCallAction class]]) { CXStartCallAction *startCallAction = [transaction.actions firstObject]; CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; - callUpdate.remoteHandle = startCallAction.handle; - callUpdate.hasVideo = startCallAction.video; +// callUpdate.remoteHandle = startCallAction.handle; + callUpdate.hasVideo = NO; callUpdate.localizedCallerName = startCallAction.contactIdentifier; callUpdate.supportsDTMF = YES; callUpdate.supportsHolding = YES; @@ -359,12 +361,12 @@ + (void)reportNewIncomingCall:(NSString *)uuidString int _handleType = [RNCallKeep getHandleType:handleType]; 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.hasVideo = hasVideo; +// callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; + callUpdate.supportsDTMF = NO; + callUpdate.supportsHolding = NO; + callUpdate.supportsGrouping = NO; + callUpdate.supportsUngrouping = NO; + callUpdate.hasVideo = NO; callUpdate.localizedCallerName = localizedCallerName; [RNCallKeep initCallKitProvider]; @@ -433,8 +435,8 @@ + (CXProviderConfiguration *)getProviderConfiguration:(NSDictionary*)settings NSLog(@"[RNCallKeep][getProviderConfiguration]"); #endif CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc] initWithLocalizedName:settings[@"appName"]]; - providerConfiguration.supportsVideo = YES; - providerConfiguration.maximumCallGroups = 3; + providerConfiguration.supportsVideo = NO; + providerConfiguration.maximumCallGroups = 1; providerConfiguration.maximumCallsPerCallGroup = 1; if(settings[@"handleType"]){ int _handleType = [RNCallKeep getHandleType:settings[@"handleType"]]; @@ -491,20 +493,7 @@ + (BOOL)application:(UIApplication *)application #ifdef DEBUG NSLog(@"[RNCallKeep][application:openURL]"); #endif - /* - NSString *handle = [url startCallHandle]; - if (handle != nil && handle.length > 0 ){ - NSDictionary *userInfo = @{ - @"handle": handle, - @"video": @NO - }; - [[NSNotificationCenter defaultCenter] postNotificationName:RNCallKeepHandleStartCallNotification - object:self - userInfo:userInfo]; - return YES; - } - return NO; - */ + return YES; }