Skip to content
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

upstream #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ RNCallKeep.displayIncomingCall(uid, handle, localizedCallerName = '', handleType
- `supportsUngrouping`: boolean (optional, default true)
- `android`: object (currently no-op)

Returns a promise on iOS.

### answerIncomingCall

Use this to tell the sdk a user answered a call from the app UI.
Expand Down Expand Up @@ -410,6 +412,7 @@ RNCallKeep.startCall(uuid, handle, contactIdentifier);
- `false` (default)
- `true` (you know... when not false)

Returns a promise on iOS.

### updateDisplay
Use this to update the display after an outgoing call has started.
Expand Down Expand Up @@ -444,13 +447,16 @@ RNCallKeep.endCall(uuid);
- `uuid`: string
- The `uuid` used for `startCall` or `displayIncomingCall`

Returns a promise on iOS.

### endAllCalls

End all ongoing calls.

```js
RNCallKeep.endAllCalls();
```
Returns a promise on iOS.

### rejectCall

Expand All @@ -463,6 +469,8 @@ RNCallKeep.rejectCall(uuid);
- `uuid`: string
- The `uuid` used for `startCall` or `displayIncomingCall`

Returns a promise on iOS.

### reportEndCallWithUUID

Report that the call ended without the user initiating.
Expand Down Expand Up @@ -502,6 +510,8 @@ RNCallKeep.setMutedCall(uuid, true);
- uuid of the current call.
- `muted`: boolean

Returns a promise on iOS.

### setOnHold

Set a call on/off hold.
Expand All @@ -528,6 +538,8 @@ RNCallKeep.setConnectionState(uuid, state)
- uuid of the current call.
- `state`: [See Connection.STATE_*](https://developer.android.com/reference/android/telecom/Connection#STATE_ACTIVE) documentation

Returns a promise on iOS.

### checkIfBusy

_This feature is available only on IOS._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ private void stopForegroundService() {
Log.d(TAG, "[VoiceConnectionService] Discarding stop foreground service, no service configured");
return;
}
stopForeground(FOREGROUND_SERVICE_TYPE_MICROPHONE);

stopForeground(true);
stopSelf();
}

private void wakeUpApplication(String uuid, String number, String displayName) {
Expand Down Expand Up @@ -413,7 +415,7 @@ private Connection createConnection(ConnectionRequest request) {
Log.d(TAG, "[VoiceConnectionService] createConnection, callerNumber:" + callerNumber);

if (callerNumber.contains(":")) {
//CallerNumber contains a schema which we'll separate out
// CallerNumber contains a schema which we'll separate out
int schemaIndex = callerNumber.indexOf(":");
String number = callerNumber.substring(schemaIndex + 1);
String schema = callerNumber.substring(0, schemaIndex);
Expand Down
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RNCallKeep {
let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true);
let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true);

RNCallKeepModule.displayIncomingCall(
return RNCallKeepModule.displayIncomingCall(
uuid,
handle,
handleType,
Expand All @@ -121,7 +121,7 @@ class RNCallKeep {
return;
}

RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
return RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
};

checkPhoneAccountEnabled = async () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ class RNCallKeep {
if (!isIOS) {
RNCallKeepModule.rejectCall(uuid);
} else {
RNCallKeepModule.endCall(uuid);
return RNCallKeepModule.endCall(uuid);
}
};

Expand All @@ -186,9 +186,7 @@ class RNCallKeep {

hasOutgoingCall = async () => (isIOS ? null : await RNCallKeepModule.hasOutgoingCall());

setMutedCall = (uuid, shouldMute) => {
RNCallKeepModule.setMutedCall(uuid, shouldMute);
};
setMutedCall = (uuid, shouldMute) => RNCallKeepModule.setMutedCall(uuid, shouldMute);

sendDTMF = (uuid, key) => RNCallKeepModule.sendDTMF(uuid, key);
/**
Expand Down
82 changes: 65 additions & 17 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ + (void)setup:(NSDictionary *)options {
supportsHolding:(BOOL)supportsHolding
supportsDTMF:(BOOL)supportsDTMF
supportsGrouping:(BOOL)supportsGrouping
supportsUngrouping:(BOOL)supportsUngrouping)
supportsUngrouping:(BOOL)supportsUngrouping
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[RNCallKeep reportNewIncomingCall: uuidString
handle: handle
Expand All @@ -276,7 +278,9 @@ + (void)setup:(NSDictionary *)options {
supportsUngrouping: supportsUngrouping
fromPushKit: NO
payload: nil
withCompletionHandler: nil];
withCompletionHandler: nil
resolver:resolve
rejecter:reject];

NSDictionary *settings = [RNCallKeep getSettings];
NSNumber *timeout = settings[@"displayCallReachabilityTimeout"];
Expand Down Expand Up @@ -315,7 +319,9 @@ + (void)setup:(NSDictionary *)options {
handle:(NSString *)handle
contactIdentifier:(NSString * _Nullable)contactIdentifier
handleType:(NSString *)handleType
video:(BOOL)video)
video:(BOOL)video
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][startCall] uuidString = %@", uuidString);
Expand All @@ -329,10 +335,10 @@ + (void)setup:(NSDictionary *)options {

CXTransaction *transaction = [[CXTransaction alloc] initWithAction:startCallAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(answerIncomingCall:(NSString *)uuidString)
RCT_EXPORT_METHOD(answerIncomingCall:(NSString *)uuidString resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][answerIncomingCall] uuidString = %@", uuidString);
Expand All @@ -342,10 +348,10 @@ + (void)setup:(NSDictionary *)options {
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:answerCallAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(endCall:(NSString *)uuidString)
RCT_EXPORT_METHOD(endCall:(NSString *)uuidString resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][endCall] uuidString = %@", uuidString);
Expand All @@ -354,22 +360,22 @@ + (void)setup:(NSDictionary *)options {
CXEndCallAction *endCallAction = [[CXEndCallAction alloc] initWithCallUUID:uuid];
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:endCallAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(endAllCalls)
RCT_EXPORT_METHOD(endAllCalls:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][endAllCalls] calls = %@", self.callKeepCallController.callObserver.calls);
#endif
for (CXCall *call in self.callKeepCallController.callObserver.calls) {
CXEndCallAction *endCallAction = [[CXEndCallAction alloc] initWithCallUUID:call.UUID];
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:endCallAction];
[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}
}

RCT_EXPORT_METHOD(setOnHold:(NSString *)uuidString :(BOOL)shouldHold)
RCT_EXPORT_METHOD(setOnHold:(NSString *)uuidString:(BOOL)shouldHold resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][setOnHold] uuidString = %@, shouldHold = %d", uuidString, shouldHold);
Expand All @@ -379,7 +385,7 @@ + (void)setup:(NSDictionary *)options {
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:setHeldCallAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(_startCallActionEventListenerAdded)
Expand Down Expand Up @@ -434,7 +440,7 @@ + (void)setup:(NSDictionary *)options {
[self.callKeepProvider reportCallWithUUID:uuid updated:callUpdate];
}

RCT_EXPORT_METHOD(setMutedCall:(NSString *)uuidString :(BOOL)muted)
RCT_EXPORT_METHOD(setMutedCall:(NSString *)uuidString :(BOOL)muted resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][setMutedCall] muted = %i", muted);
Expand All @@ -444,10 +450,10 @@ + (void)setup:(NSDictionary *)options {
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:setMutedAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(sendDTMF:(NSString *)uuidString dtmf:(NSString *)key)
RCT_EXPORT_METHOD(sendDTMF:(NSString *)uuidString dtmf:(NSString *)key resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][sendDTMF] key = %@", key);
Expand All @@ -457,7 +463,7 @@ + (void)setup:(NSDictionary *)options {
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:dtmfAction];

[self requestTransaction:transaction];
[self requestTransaction:transaction resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(isCallActive:(NSString *)uuidString
Expand Down Expand Up @@ -644,7 +650,7 @@ + (NSString *) getSelectedAudioRoute
return [RNCallKeep getAudioInputType: selectedOutput.portType];
}

- (void)requestTransaction:(CXTransaction *)transaction
- (void)requestTransaction:(CXTransaction *)transaction resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][requestTransaction] transaction = %@", transaction);
Expand All @@ -655,6 +661,7 @@ - (void)requestTransaction:(CXTransaction *)transaction
[self.callKeepCallController requestTransaction:transaction completion:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"[RNCallKeep][requestTransaction] Error requesting transaction (%@): (%@)", transaction.actions, error);
reject(@"requestTransaction", @"Error requesting transaction", error);
} else {
NSLog(@"[RNCallKeep][requestTransaction] Requested transaction successfully");

Expand All @@ -671,6 +678,8 @@ - (void)requestTransaction:(CXTransaction *)transaction
callUpdate.supportsUngrouping = YES;
[self.callKeepProvider reportCallWithUUID:startCallAction.callUUID updated:callUpdate];
}

resolve(@TRUE);
}
}];
}
Expand Down Expand Up @@ -739,6 +748,37 @@ + (void)endCallWithUUID:(NSString *)uuidString
}
}

+ (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
{
[RNCallKeep reportNewIncomingCall:uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName supportsHolding:supportsHolding supportsDTMF:supportsDTMF supportsGrouping:supportsGrouping supportsUngrouping:supportsUngrouping fromPushKit:fromPushKit payload:payload withCompletionHandler:nil resolver:nil rejecter: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 (^)(void))completion
{
[RNCallKeep reportNewIncomingCall:uuidString handle:handle handleType:handleType hasVideo:hasVideo localizedCallerName:localizedCallerName supportsHolding:supportsHolding supportsDTMF:supportsDTMF supportsGrouping:supportsGrouping supportsUngrouping:supportsUngrouping fromPushKit:fromPushKit payload:payload withCompletionHandler:completion resolver:nil rejecter:nil];
}

+ (void)reportNewIncomingCall:(NSString *)uuidString
handle:(NSString *)handle
handleType:(NSString *)handleType
Expand All @@ -751,6 +791,8 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
fromPushKit:(BOOL)fromPushKit
payload:(NSDictionary * _Nullable)payload
withCompletionHandler:(void (^_Nullable)(void))completion
resolver:(RCTPromiseResolveBlock _Nullable)resolve
rejecter:(RCTPromiseRejectBlock _Nullable)reject
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][reportNewIncomingCall] uuidString = %@", uuidString);
Expand Down Expand Up @@ -792,6 +834,12 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
if (completion != nil) {
completion();
}

if (error != nil && reject != nil) {
reject(@"reportNewIncomingCall", @"Error trying to display incoming call", error);
} else if (error == nil && resolve != nil) {
resolve(@TRUE);
}
}];
}

Expand Down