Commit f5a932ea authored by Kevin Reynaldo's avatar Kevin Reynaldo
Browse files

• Updated version to 0.3.0

• Handled accept incoming call when app is not on foreground
parent 2839dd9b
......@@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "MeetTalk"
s.version = "0.2.3"
s.version = "0.3.0"
s.summary = "MeetTalk iOS SDK is an extension of TapTalk.io SDK, providing complete in-app chat SDK with the addition of voice and video call feature."
s.homepage = "https://taptalk.io"
......
......@@ -638,7 +638,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.2;
MARKETING_VERSION = 0.3.0;
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${SRCROOT}/MeetTalk/Supporting Files/MeetTalk.modulemap\"",
......@@ -714,7 +714,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.2;
MARKETING_VERSION = 0.3.0;
OTHER_CFLAGS = (
"$(inherited)",
"-fmodule-map-file=\"${SRCROOT}/MeetTalk/Supporting Files/MeetTalk.modulemap\"",
......
......@@ -67,6 +67,8 @@ typedef NS_ENUM(NSInteger, MeetTalkCallState) {
- (BOOL)launchMeetTalkCallViewControllerWithRoom:(TAPRoomModel *)room
activeUserName:(NSString *)activeUserName
activeUserAvatarUrl:(NSString *)activeUserAvatarUrl;
- (void)checkAndShowOngoingCallLocalNotification;
- (void)dismissOngoingCallLocalNotification;
- (void)checkAndHandleCallNotificationFromMessage:(TAPMessageModel *)message activeUser:(TAPUserModel *)activeUser;
- (MeetTalkParticipantInfo *)generateParticipantInfoWithRole:(NSString *)role
startWithAudioMuted:(BOOL)startWithAudioMuted
......
......@@ -10,6 +10,7 @@
#import "MeetTalkConfigs.h"
#import <TapTalk/TAPConnectionManager.h>
#import <TapTalk/TAPCoreMessageManager.h>
#import <TapTalk/TAPEncryptorManager.h>
#import <TapTalk/TAPUtil.h>
#import <TapTalk/TAPTypes.h>
#import <CallKit/CallKit.h>
......@@ -27,6 +28,7 @@
@property (nonatomic, strong) NSString *answeredCallID;
@property (nonatomic, strong) NSTimer *missedCallTimer;
@property (nonatomic, strong) NSMutableArray<NSString *> *handledCallNotificationMessageLocalIDs;
@property (nonatomic, strong) UILocalNotification *ongoingCallNotification;
@property (nonatomic, weak) UIApplication *application;
@property (nonatomic) BOOL shouldHandleConnectionManagerDelegate;
@property (nonatomic) TapTalkSocketConnectionMode savedSocketConnectionMode;
......@@ -273,7 +275,6 @@
#endif
self.currentCallUUID = nil;
[self clearPendingIncomingCall];
if (self.delegate && [self.delegate respondsToSelector:@selector(callDidEnd)]) {
[self.delegate callDidEnd];
......@@ -431,22 +432,22 @@
phoneNumber = displayPhoneNumber;
}
MeetTalkConferenceInfo *conferenceInfo = [MeetTalkConferenceInfo fromMessageModel:message];
NSString *incomingCallString;
if (conferenceInfo != nil && conferenceInfo.startWithVideoMuted) {
incomingCallString = NSLocalizedString(@"Incoming Video Call", @"");
}
else {
incomingCallString = NSLocalizedString(@"Incoming Voice Call", @"");
}
NSString *contentText;
if (phoneNumber.length > 0) {
contentText = [NSString stringWithFormat:@"%@ - %@", incomingCallString, phoneNumber];
}
else {
contentText = incomingCallString;
}
// MeetTalkConferenceInfo *conferenceInfo = [MeetTalkConferenceInfo fromMessageModel:message];
// NSString *incomingCallString;
// if (conferenceInfo != nil && conferenceInfo.startWithVideoMuted) {
// incomingCallString = NSLocalizedString(@"Incoming Video Call", @"");
// }
// else {
// incomingCallString = NSLocalizedString(@"Incoming Voice Call", @"");
// }
//
// NSString *contentText;
// if (phoneNumber.length > 0) {
// contentText = [NSString stringWithFormat:@"%@ - %@", incomingCallString, phoneNumber];
// }
// else {
// contentText = incomingCallString;
// }
// Show incoming call
self.callState = MeetTalkCallStateRinging;
......@@ -464,7 +465,7 @@
}
NSUUID *uuid = [NSUUID new];
[self reportIncomingCallForUUID:uuid phoneNumber:contentText];
[self reportIncomingCallForUUID:uuid phoneNumber:phoneNumber];
[self startMissedCallTimer];
#ifdef DEBUG
NSLog(@">>>> showIncomingCallWithMessage: %@ %@", uuid, phoneNumber);
......@@ -476,7 +477,7 @@
//#endif
}
- (void)dismissIncomingCall {
- (void)dismissIncomingCall:(BOOL)clearPendingIncomingCall {
if (self.currentCallUUID == nil) {
return;
}
......@@ -494,7 +495,10 @@
#endif
}
}];
[self clearPendingIncomingCall];
if (clearPendingIncomingCall) {
[self clearPendingIncomingCall];
}
// Trigger delegate callback
if ([MeetTalk sharedInstance].delegate &&
......@@ -508,17 +512,18 @@
if (self.activeCallMessage == nil) {
return;
}
BOOL answerHandled = YES;
if ([MeetTalk sharedInstance].delegate &&
[[MeetTalk sharedInstance].delegate respondsToSelector:@selector(meetTalkDidAnswerIncomingCall)]
) {
[[MeetTalk sharedInstance].delegate meetTalkDidAnswerIncomingCall];
}
else {
[self joinPendingIncomingConferenceCall];
answerHandled = [self joinPendingIncomingConferenceCall];
}
self.answeredCallID = self.activeCallMessage.localID;
[self clearPendingIncomingCall];
[self dismissIncomingCall];
[self dismissIncomingCall:answerHandled];
[self checkAndShowOngoingCallLocalNotification];
}
- (void)rejectIncomingCall {
......@@ -608,19 +613,35 @@
- (void)rejectPendingIncomingConferenceCall {
if (self.activeCallMessage != nil) {
[self sendRejectedCallNotification:self.activeCallMessage.room];
[[TapTalk sharedInstance] connectWithSuccess:^{
[self sendPendingCallNotificationMessages];
[self clearPendingIncomingCall];
}
failure:^(NSError * _Nonnull error) {
[self sendPendingCallNotificationMessages];
[self clearPendingIncomingCall];
}];
}
[self clearPendingIncomingCall];
}
- (BOOL)joinPendingIncomingConferenceCall {
if (self.pendingIncomingCallRoomID == nil || self.activeCallMessage == nil) {
return NO;
}
[self sendAnsweredCallNotification:self.activeCallMessage.room];
[self launchMeetTalkCallViewController];
self.pendingIncomingCallRoomID = nil;
self.pendingIncomingCallPhoneNumber = nil;
return YES;
if ([self launchMeetTalkCallViewController]) {
[self sendAnsweredCallNotification:self.activeCallMessage.room];
self.pendingIncomingCallRoomID = nil;
self.pendingIncomingCallPhoneNumber = nil;
[[TapTalk sharedInstance] connectWithSuccess:^{
[self sendPendingCallNotificationMessages];
}
failure:^(NSError * _Nonnull error) {
}];
return YES;
}
return NO;
}
- (void)closeIncomingCall {
......@@ -709,6 +730,9 @@
[callViewController setDataWithConferenceOptions:options activeCallRoom:self.activeCallMessage.room activeConferenceInfo:self.activeConferenceInfo];
[topViewController presentViewController:callViewController animated:YES completion:^{
}];
[self checkAndShowOngoingCallLocalNotification];
#ifdef DEBUG
NSLog(@">>>> launchMeetTalkCallViewController conferenceRoomID: %@", conferenceRoomID);
#endif
......@@ -716,6 +740,37 @@
return YES;
}
- (void)checkAndShowOngoingCallLocalNotification {
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive ||
self.activeCallMessage == nil
) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissOngoingCallLocalNotification];
self.ongoingCallNotification = [[UILocalNotification alloc] init];
self.ongoingCallNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0.1f];
self.ongoingCallNotification.alertBody = NSLocalizedString(@"You have an ongoing call, tap here to return.", @"");
self.ongoingCallNotification.timeZone = [NSTimeZone defaultTimeZone];
self.ongoingCallNotification.soundName = UILocalNotificationDefaultSoundName;
self.ongoingCallNotification.applicationIconBadgeNumber = 0;
NSMutableDictionary *userInfoDictionary = [NSMutableDictionary dictionary];
NSMutableDictionary *dataDictionary = [NSMutableDictionary dictionary];
[dataDictionary setObject:[TAPEncryptorManager encryptToDictionaryFromMessageModel:self.activeCallMessage] forKey:@"message"];
[userInfoDictionary setObject:dataDictionary forKey:@"data"];
self.ongoingCallNotification.userInfo = userInfoDictionary;
[[UIApplication sharedApplication] scheduleLocalNotification:self.ongoingCallNotification];
});
}
- (void)dismissOngoingCallLocalNotification {
if (self.ongoingCallNotification == nil) {
return;
}
[[UIApplication sharedApplication] cancelLocalNotification:self.ongoingCallNotification];
}
- (UIViewController *_Nullable) topViewController {
UIViewController *topViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
if (topViewController == nil) {
......@@ -758,7 +813,8 @@
[NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970] * 1000.0f].longValue - message.created.longValue < INCOMING_CALL_TIMEOUT_DURATION
) {
if (self.callState == MeetTalkCallStateIdle) {
if (message.data == nil) {
MeetTalkConferenceInfo *conferenceInfo = [MeetTalkConferenceInfo fromMessageModel:message];
if (conferenceInfo == nil) {
// Received call initiated notification with no data, fetch data from API
NSLog(@">>>> checkAndHandleCallNotificationFromMessage: CALL_INITIATED - Fetch data from API");
[[TAPCoreMessageManager sharedManager] getNewerMessagesAfterTimestamp:message.created
......@@ -1216,7 +1272,10 @@
}
failure:^(TAPMessageModel * _Nullable message, NSError * _Nonnull error) {
#ifdef DEBUG
NSLog(@">>>> MeetTalkCallManager failure add to pending array: %@", message.action);
#endif
[self.pendingCallNotificationMessages addObject:message];
}];
}
else {
......@@ -1269,6 +1328,7 @@
self.activeCallMessage = nil;
self.activeConferenceInfo = nil;
self.callState = MeetTalkCallStateIdle;
[self dismissOngoingCallLocalNotification];
}
- (void)startMissedCallTimer {
......@@ -1300,7 +1360,7 @@
- (void)handleAppExiting:(UIApplication *_Nonnull)application {
_application = application;
[self dismissIncomingCall];
[self dismissIncomingCall:YES];
if (self.pendingCallNotificationMessages.count > 0 ||
(self.activeCallMessage != nil &&
self.activeConferenceInfo != nil &&
......
......@@ -9,7 +9,9 @@
#import "MeetTalkCallManager.h"
#import <TapTalk/TapTalk.h>
#import <TapTalk/TAPChatManager.h>
#import <TapTalk/TAPDataManager.h>
#import <TapTalk/TAPCoreMessageManager.h>
#import <TapTalk/TAPUtil.h>
#import <Intents/Intents.h>
#import <PushKit/PushKit.h>
......@@ -126,6 +128,7 @@
- (void)applicationDidEnterBackground:(UIApplication *_Nonnull)application {
[[TapTalk sharedInstance] applicationDidEnterBackground:application];
[[MeetTalkCallManager sharedManager] checkAndShowOngoingCallLocalNotification];
}
- (void)applicationWillEnterForeground:(UIApplication *_Nonnull)application {
......@@ -134,6 +137,14 @@
- (void)applicationDidBecomeActive:(UIApplication *_Nonnull)application {
[[TapTalk sharedInstance] applicationDidBecomeActive:application];
[[MeetTalkCallManager sharedManager] dismissOngoingCallLocalNotification];
// FIXME: TOP VIEW CONTROLLER IS NULL IF NOT DELAYED
NSTimeInterval delayInSeconds = 0.2f;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[[MeetTalkCallManager sharedManager] joinPendingIncomingConferenceCall];
});
}
- (void)applicationWillTerminate:(UIApplication *_Nonnull)application {
......@@ -141,13 +152,20 @@
}
- (void)application:(UIApplication *_Nonnull)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *_Nonnull)deviceToken {
[[TapTalk sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *_Nonnull)application didReceiveRemoteNotification:(NSDictionary *_Nonnull)userInfo fetchCompletionHandler:(void (^_Nonnull)(UIBackgroundFetchResult result))completionHandler {
[[TapTalk sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
NSDictionary *messageDictionary = [NSDictionary dictionary];
messageDictionary = [userInfo valueForKeyPath:@"data.message"];
TAPMessageModel *message = [TAPDataManager messageModelFromPayloadWithUserInfo:messageDictionary];
NSLog(@">>>> MeetTalk didReceiveRemoteNotification message: %@", message.body);
[[MeetTalkCallManager sharedManager] checkAndHandleCallNotificationFromMessage:message activeUser:[[TapTalk sharedInstance] getTapTalkActiveUser]];
}
#pragma mark Delegates
......@@ -180,6 +198,7 @@
if (self.delegate && [self.delegate respondsToSelector:@selector(tapTalkDidTappedNotificationWithMessage:fromActiveController:)]) {
[self.delegate tapTalkDidTappedNotificationWithMessage:message fromActiveController:currentActiveController];
}
[[MeetTalkCallManager sharedManager] joinPendingIncomingConferenceCall];
}
- (void)userLogout {
......@@ -191,7 +210,8 @@
#pragma mark - PKPushRegistryDelegate
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)pushCredentials forType:(PKPushType)type {
NSString *pushToken = [TAPUtil hexadecimalStringFromData:pushCredentials.token];
NSLog(@">>>> MeetTalk pushRegistry didUpdatePushCredentials: %@", pushToken);
if ([pushCredentials.token length] == 0) {
return;
}
......@@ -199,17 +219,9 @@
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
NSString *uuidString = payload.dictionaryPayload[@"UUID"];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
NSString *phoneNumber = payload.dictionaryPayload[@"PhoneNumber"];
// TapCallViewController *callViewController = [[TapCallViewController alloc] init];
// callViewController.phoneNumber = phoneNumber;
// callViewController.isIncoming = YES;
// callViewController.uuid = uuid;
// UINavigationController *callNavigationViewController = [[UINavigationController alloc] initWithRootViewController:callViewController];
// callNavigationViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
// [self presentViewController:callNavigationViewController animated:YES completion:nil];
// NSString *uuidString = payload.dictionaryPayload[@"UUID"];
// NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
// NSString *phoneNumber = payload.dictionaryPayload[@"PhoneNumber"];
}
#pragma mark - TAPChatManagerDelegate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment