From 50318a586e5ad38ea23fd411a43b9921ac17910f Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 1 Feb 2019 10:58:57 +0100 Subject: [PATCH] Implement provider did end call. Signed-off-by: Ivan Sein --- VideoCalls/CallKitManager.h | 1 + VideoCalls/CallKitManager.m | 7 ++++++- VideoCalls/CallViewController.m | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/VideoCalls/CallKitManager.h b/VideoCalls/CallKitManager.h index 7d076bf1..4e618455 100644 --- a/VideoCalls/CallKitManager.h +++ b/VideoCalls/CallKitManager.h @@ -9,6 +9,7 @@ #import extern NSString * const CallKitManagerDidAnswerCallNotification; +extern NSString * const CallKitManagerDidEndCallNotification; @interface CallKitManager : NSObject diff --git a/VideoCalls/CallKitManager.m b/VideoCalls/CallKitManager.m index dc7b14fd..cad85da7 100644 --- a/VideoCalls/CallKitManager.m +++ b/VideoCalls/CallKitManager.m @@ -13,7 +13,8 @@ #import "NCAudioController.h" #import "NCRoomsManager.h" -NSString * const CallKitManagerDidAnswerCallNotification = @"CallKitManagerDidAnswerCallNotification"; +NSString * const CallKitManagerDidAnswerCallNotification = @"CallKitManagerDidAnswerCallNotification"; +NSString * const CallKitManagerDidEndCallNotification = @"CallKitManagerDidEndCallNotification"; @interface CallKitManager () @@ -116,6 +117,10 @@ NSString * const CallKitManagerDidAnswerCallNotification = @"CallKitManagerDidA - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action { + NSDictionary *userInfo = [NSDictionary dictionaryWithObject:_currentCallToken forKey:@"roomToken"]; + [[NSNotificationCenter defaultCenter] postNotificationName:CallKitManagerDidEndCallNotification + object:self + userInfo:userInfo]; self.currentCallUUID = nil; self.currentCallToken = nil; [action fulfill]; diff --git a/VideoCalls/CallViewController.m b/VideoCalls/CallViewController.m index 5384ec81..95f2c614 100644 --- a/VideoCalls/CallViewController.m +++ b/VideoCalls/CallViewController.m @@ -25,6 +25,7 @@ #import "NCRoomsManager.h" #import "NCSettingsController.h" #import "UIImageView+AFNetworking.h" +#import "CallKitManager.h" typedef NS_ENUM(NSInteger, CallState) { CallStateJoining, @@ -84,6 +85,7 @@ typedef NS_ENUM(NSInteger, CallState) { [AvatarBackgroundImageView setSharedImageDownloader:imageDownloader]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didJoinRoom:) name:NCRoomsManagerDidJoinRoomNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(providerDidEndCall:) name:CallKitManagerDidEndCallNotification object:nil]; return self; } @@ -177,6 +179,16 @@ typedef NS_ENUM(NSInteger, CallState) { } } +- (void)providerDidEndCall:(NSNotification *)notification +{ + NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"]; + if (![roomToken isEqualToString:_room.token]) { + return; + } + + [self hangup]; +} + #pragma mark - Local video - (void)setLocalVideoRect