Skip to content
Merged
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
66 changes: 37 additions & 29 deletions src/ios/CordovaCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation CordovaCall
BOOL isCancelPush = NO;
NSString* callBackUrl;
NSString* callId;
NSDictionary* callData;

NSMutableArray* pendingCallResponses;
NSString* const PENDING_RESPONSE_ANSWER = @"pendingResponseAnswer";
Expand Down Expand Up @@ -522,14 +523,14 @@ - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAct
[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];
// 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
Expand All @@ -553,16 +554,16 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
}
} 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 (!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
Expand All @@ -580,10 +581,15 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
- (void)triggerCordovaEventForCallResponse:(NSString*) response {
if ([response isEqualToString:@"answer"]) {
for (id callbackId in callbackIds[@"answer"]) {
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"answer event called successfully"];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:callData];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
callData = nil; // clear out the data in case CordovaCall.receiveCall('caller'); called from JS side

// CDVPluginResult* pluginResult = nil;
// pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"answer event called successfully"];
// [pluginResult setKeepCallbackAsBool:YES];
// [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
} else if ([response isEqualToString:@"reject"]) {
for (id callbackId in callbackIds[@"reject"]) {
Expand Down Expand Up @@ -664,7 +670,8 @@ - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPush
[self sendTokenPluginResult];
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion
{
{
NSLog(@"[objC] didReceiveIncomingPush: %@", payload);
NSDictionary *payloadDict = payload.dictionaryPayload[@"aps"];
NSLog(@"[objC] didReceiveIncomingPushWithPayload: %@", payloadDict);

Expand All @@ -685,21 +692,22 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
// Store URL and Call Id so they can be used for call Answer/Reject
callBackUrl = [caller valueForKey:@"CallbackUrl"];
callId = [caller valueForKey:@"ConnectionId"];
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];
// 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];
Expand Down