Skip to content

Commit

Permalink
#4489 - Add answerCall method for answering incoming calls from appli…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
amuzacz committed Nov 8, 2019
1 parent c3be446 commit 321ad27
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/android/CordovaCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.checkCallPermission();
}
return true;
} else if (action.equals("answerCall")) {
Connection conn = MyConnectionService.getConnection();
if(conn != null) {
if(conn.getState() == Connection.STATE_NEW) {
conn.onAnswer();

this.callbackContext.success("Call answered successfully");
}
}
return true;
} else if (action.equals("sendCall")) {
Connection conn = MyConnectionService.getConnection();
if(conn != null) {
Expand Down
25 changes: 24 additions & 1 deletion src/ios/CordovaCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (void)setIcon:(CDVInvokedUrlCommand*)command;
- (void)setRingtone:(CDVInvokedUrlCommand*)command;
- (void)setIncludeInRecents:(CDVInvokedUrlCommand*)command;
- (void)receiveCall:(CDVInvokedUrlCommand*)command;
- (void)answerCall:(CDVInvokedUrlCommand*)command;
- (void)sendCall:(CDVInvokedUrlCommand*)command;
- (void)connectCall:(CDVInvokedUrlCommand*)command;
- (void)endCall:(CDVInvokedUrlCommand*)command;
Expand Down Expand Up @@ -213,6 +214,28 @@ - (void)receiveCall:(CDVInvokedUrlCommand*)command
}
}

- (void)answerCall:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSArray<CXCall *> *calls = self.callController.callObserver.calls;

if([calls count] == 1) {
CXAnswerCallAction *answerCallAction = [[CXAnswerCallAction alloc] initWithCallUUID:calls[0].UUID];
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:answerCallAction];
[self.callController requestTransaction:transaction completion:^(NSError * _Nullable error) {
if (error == nil) {
} else {
NSLog(@"%@",[error localizedDescription]);
}
}];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Call answered successfully"];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No call exists for you to connect"];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)sendCall:(CDVInvokedUrlCommand*)command
{
BOOL hasId = ![[command.arguments objectAtIndex:1] isEqual:[NSNull null]];
Expand Down Expand Up @@ -330,7 +353,7 @@ - (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallActio
callUpdate.supportsUngrouping = NO;
callUpdate.supportsHolding = NO;
callUpdate.supportsDTMF = enableDTMF;

[self.provider reportCallWithUUID:action.callUUID updated:callUpdate];
[action fulfill];
NSDictionary *callData = @{@"callName":action.contactIdentifier, @"callId": action.handle.value, @"isVideo": action.video?@YES:@NO, @"message": @"sendCall event called successfully"};
Expand Down
4 changes: 4 additions & 0 deletions www/CordovaCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ exports.receiveCall = function(from, id, success, error) {
exec(success, error, "CordovaCall", "receiveCall", [from, id]);
};

exports.answerCall = function(success, error) {
exec(success, error, "CordovaCall", "answerCall", []);
};

exports.sendCall = function(to, id, success, error) {
if(typeof id == "function") {
error = success;
Expand Down

0 comments on commit 321ad27

Please sign in to comment.