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