Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-callkit",
"version": "1.1.4",
"version": "1.1.5",
"description": "Cordova plugin that lets you use iOS CallKit UI (with PushKit) and Android ConnectionService UI",
"cordova": {
"id": "cordova-plugin-callkit",
Expand All @@ -26,4 +26,4 @@
"homepage": "https://github.com/mattkhaw/cordova-plugin-callkit",
"author": "Matthew Khaw",
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-callkit" version="1.1.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-callkit" version="1.1.5" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>Cordova CallKit</name>

<js-module name="VoIPPushNotification" src="www/VoIPPushNotification.js">
Expand Down
88 changes: 27 additions & 61 deletions src/ios/CordovaCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ @implementation CordovaCall
BOOL enableDTMF = NO;
PKPushRegistry *_voipRegistry;

BOOL isCancelPush = NO;
NSString* callBackUrl;
NSString* callId;
NSDictionary* callData;
Expand Down Expand Up @@ -223,26 +222,18 @@ - (void)receiveCall:(CDVInvokedUrlCommand*)command
callUpdate.supportsUngrouping = NO;
callUpdate.supportsHolding = NO;
callUpdate.supportsDTMF = enableDTMF;
if (!isCancelPush) {
[self.provider reportNewIncomingCallWithUUID:callUUID update:callUpdate completion:^(NSError * _Nullable error) {
if(error == nil) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Incoming call successful"] callbackId:command.callbackId];
} else {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]] callbackId:command.callbackId];
}
}];
for (id callbackId in callbackIds[@"receiveCall"]) {
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"receiveCall event called successfully"];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
} else {
NSArray<CXCall *> *calls = self.callController.callObserver.calls;
if([calls count] == 1) {
[self.provider reportCallWithUUID:calls[0].UUID endedAtDate:nil reason:CXCallEndedReasonRemoteEnded];
[self.provider reportNewIncomingCallWithUUID:callUUID update:callUpdate completion:^(NSError * _Nullable error) {
if(error == nil) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Incoming call successful"] callbackId:command.callbackId];
} else {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]] callbackId:command.callbackId];
}

}];
for (id callbackId in callbackIds[@"receiveCall"]) {
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"receiveCall event called successfully"];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
} else {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Caller id can't be empty"] callbackId:command.callbackId];
Expand Down Expand Up @@ -527,7 +518,6 @@ - (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallActio
if([callbackIds[@"sendCall"] count] == 0) {
pendingCallFromRecents = callData;
}
//[action fail];
}

- (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession
Expand All @@ -547,23 +537,12 @@ - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAct
[self setupAudioSession];
[action fulfill];

// Notify Webhook that Native Call has been Answered
// NSURL *statusUpdateUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@?id=%@&input=%@", callBackUrl, callId, @"pickup"]];
// NSURLSession *session = [NSURLSession sharedSession];
// [[session dataTaskWithURL:statusUpdateUrl
// completionHandler:^(NSData *statusUpdateData,
// NSURLResponse *statusUpdateResponse,
// NSError *statusUpdateError) {
// // handle response
// }] resume];

if ([callbackIds[@"answer"] count] == 0) {
// callbackId for event not registered, add to pending to trigger on registration
[pendingCallResponses addObject:PENDING_RESPONSE_ANSWER];
} else {
[self triggerCordovaEventForCallResponse:@"answer"];
}
//[action fail];
}

- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action
Expand All @@ -579,18 +558,6 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
} else {
// Notify Webhook that Native Call has been Declined
// if (!isCancelPush) {
// NSURL *statusUpdateUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@?id=%@&input=%@", callBackUrl, callId, @"declined_callee"]];
// NSURLSession *session = [NSURLSession sharedSession];
// [[session dataTaskWithURL:statusUpdateUrl
// completionHandler:^(NSData *statusUpdateData,
// NSURLResponse *statusUpdateResponse,
// NSError *statusUpdateError) {
// // handle response
// }] resume];
// }

if ([callbackIds[@"reject"] count] == 0) {
// callbackId for event not registered, add to pending to trigger on registration
[pendingCallResponses addObject:PENDING_RESPONSE_REJECT];
Expand All @@ -601,7 +568,6 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
}
monitorAudioRouteChange = NO;
[action fulfill];
//[action fail];
}

- (void)triggerCordovaEventForCallResponse:(NSString*) response {
Expand Down Expand Up @@ -648,6 +614,22 @@ - (void)provider:(CXProvider *)provider performPlayDTMFCallAction:(CXPlayDTMFCal
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
}

- (void) dismissRingingCall:(CDVInvokedUrlCommand*)command
{
[self logMessage:@"dismissRingingCall"];

NSArray<CXCall *> *calls = self.callController.callObserver.calls;
CDVPluginResult* pluginResult = nil;
if([calls count] == 1 && !calls[0].hasConnected) {
[self.provider reportCallWithUUID:calls[0].UUID endedAtDate:nil reason:CXCallEndedReasonRemoteEnded];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"dismissRingingCall event called successfully"];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

// PushKit
- (void)init:(CDVInvokedUrlCommand*)command
{
Expand Down Expand Up @@ -716,22 +698,6 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
callId = [caller valueForKey:@"ConnectionId"];
hasVideo = [[caller valueForKey:@"Video"] boolValue];
callData = data;
if ([[caller valueForKey:@"CancelPush"] isEqualToString:@"true"]) {
isCancelPush = YES;
} else {
isCancelPush = NO;
}
if (!isCancelPush) {
// Notify Webhook that VOIP Push Has been received and app is started
// NSURL *statusUpdateUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@?id=%@&input=%@", callBackUrl, callId, @"connected"]];
// NSURLSession *session = [NSURLSession sharedSession];
// [[session dataTaskWithURL:statusUpdateUrl
// completionHandler:^(NSData *statusUpdateData,
// NSURLResponse *statusUpdateResponse,
// NSError *statusUpdateError) {
// // handle response
// }] resume];
}

[self receiveCall:newCommand];
@try {
Expand Down
6 changes: 5 additions & 1 deletion www/CordovaCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ exports.on = function(e, f) {

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

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