diff --git a/package.json b/package.json index a9b29a2..0be5654 100644 --- a/package.json +++ b/package.json @@ -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", @@ -26,4 +26,4 @@ "homepage": "https://github.com/mattkhaw/cordova-plugin-callkit", "author": "Matthew Khaw", "license": "MIT" -} +} \ No newline at end of file diff --git a/plugin.xml b/plugin.xml index 44b85b1..93d1447 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + Cordova CallKit diff --git a/src/ios/CordovaCall.m b/src/ios/CordovaCall.m index f862bc4..b7d01f7 100644 --- a/src/ios/CordovaCall.m +++ b/src/ios/CordovaCall.m @@ -17,7 +17,6 @@ @implementation CordovaCall BOOL enableDTMF = NO; PKPushRegistry *_voipRegistry; -BOOL isCancelPush = NO; NSString* callBackUrl; NSString* callId; NSDictionary* callData; @@ -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 *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]; @@ -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 @@ -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 @@ -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]; @@ -601,7 +568,6 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) } monitorAudioRouteChange = NO; [action fulfill]; - //[action fail]; } - (void)triggerCordovaEventForCallResponse:(NSString*) response { @@ -648,6 +614,22 @@ - (void)provider:(CXProvider *)provider performPlayDTMFCallAction:(CXPlayDTMFCal [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } } + +- (void) dismissRingingCall:(CDVInvokedUrlCommand*)command +{ + [self logMessage:@"dismissRingingCall"]; + + NSArray *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 { @@ -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 { diff --git a/www/CordovaCall.js b/www/CordovaCall.js index 0c3f4c4..2519484 100644 --- a/www/CordovaCall.js +++ b/www/CordovaCall.js @@ -97,4 +97,8 @@ exports.on = function(e, f) { exports.checkCallPermission = function(error) { exec(null, error, "CordovaCall", "checkCallPermission", []); -}; \ No newline at end of file +}; + +exports.dismissRingingCall = function(success) { + exec(success, null, "CordovaCall", "dismissRingingCall", []); +} \ No newline at end of file