Skip to content
Closed
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
36 changes: 26 additions & 10 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
36 changes: 30 additions & 6 deletions android/src/main/java/io/wazo/callkeep/VoiceConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default class RNCallKeep {

}

static answerIncomingCall(uuid: string) {

}

static displayIncomingCall(
uuid: string,
handle: string,
Expand Down
37 changes: 13 additions & 24 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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"]];
Expand Down Expand Up @@ -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;
}

Expand Down