// // HDLLinPhoneSDK.m // HDLLinPhoneSDK // // Created by 陈启扬 on 2021/8/3. // Copyright © 2021 陈启扬. All rights reserved. // #import "HDLLinPhoneSDK.h" #import "HDLLinphoneManager.h" #import "HDLLinphoneIntercomVC.h" #import "HDLLinPhoneCommon.h" #import "HDLLPOnMonitorViewController.h" @interface HDLLinPhoneSDK() @property (strong, nonatomic) HDLLinphoneIntercomVC* presentingIntercomVC;//当前展示的来点控制器,用于存放正在展示的来点控制器,避免重复弹出界面 @end @implementation HDLLinPhoneSDK + (instancetype)instance{ static HDLLinPhoneSDK *service = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ service = [[HDLLinPhoneSDK alloc] init]; [NSNotificationCenter.defaultCenter addObserver:service selector:@selector(registrationUpdate:) name:@"LinphoneRegistrationUpdate" object:nil]; [NSNotificationCenter.defaultCenter addObserver:service selector:@selector(linphoneCallUpdate:) name:@"LinphoneCallUpdate" object:nil]; }); return service; } -(void)dealloc{ // [NSNotificationCenter.defaultCenter remo]; } -(void)login:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain{ [HDLLinphoneManager.instance login:username password:pwd domain:domain]; } -(void)tcpLogin:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain { [HDLLinphoneManager.instance tcpLogin:username password:pwd domain:domain ]; } -(void)udpLogin:(NSString*)username password:(NSString*)pwd domain:(NSString*) domain { [HDLLinphoneManager.instance udpLogin:username password:pwd domain:domain ]; } - (void)registrationUpdate:(NSNotification *)notif { LinphoneRegistrationState state = [[notif.userInfo objectForKey:@"state"] intValue]; if (state == LinphoneRegistrationFailed){ NSLog(@"登录失败"); }else if (state == LinphoneRegistrationCleared){ NSLog(@"登录清空"); } else if (state == LinphoneRegistrationOk) { // HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init]; // [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ // // }]; NSLog(@"登录成功啦"); } } -(void)linphoneCallUpdate:(NSNotification *)notif{ // self.IsAutoJumpCallView=YES; NSString *userName=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"userName"]]; LinphoneCallState state = [[notif.userInfo objectForKey:@"state"] intValue]; if (state == LinphoneCallIncomingReceived) { [self.hdlLinphoneCallDelegate onIncomingCall:userName]; if(self.IsAutoJumpCallView){ // HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init]; //// vc.CallId=callId; // vc.hasVideo=YES; // vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate; // vc.modalPresentationStyle = UIModalPresentationFullScreen; //// self.IntercomVC=vc; // [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ // // }]; [self gotoHDLLinphoneIntercomVC:nil]; } } } -(void)initalLinPhone{ [HDLLinphoneManager.instance initalLinPhonal]; } -(void)callWithUserName:(NSString*)username title:(NSString *)title{ HDLLPOnMonitorViewController *vc=[[HDLLPOnMonitorViewController alloc]init]; // vc.CallId=callId; // vc.hasVideo=YES; vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate; vc.modalPresentationStyle = UIModalPresentationFullScreen; vc.userName=username; vc.titleName=title; [HDLLinphoneManager instance].deviceType=HDLLPType_Default; [HDLLinphoneManager instance].isResettingVideoEnable=NO; // self.CallVC=vc; [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ }]; } /** * 呼叫(自研可视对讲) * * @param username 用户账号 * @param title 页面标题 */ -(void)callHDLSRWithUserName:(NSString*)username title:(NSString *)title{ HDLLPOnMonitorViewController *vc=[[HDLLPOnMonitorViewController alloc]init]; // vc.CallId=callId; // vc.hasVideo=YES; vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate; vc.modalPresentationStyle = UIModalPresentationFullScreen; vc.userName=username; vc.titleName=title; [HDLLinphoneManager instance].deviceType=HDLLPType_HDLSR; [HDLLinphoneManager instance].isResettingVideoEnable=NO; // self.CallVC=vc; [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ }]; } /** * 跳转呼叫页面 * * @param titleName 标题 */ -(void)gotoHDLLinphoneIntercomVC:(NSString*)titleName{ // NSString *callId=[NSString stringWithFormat:@"%@",[notif.userInfo objectForKey:@"callID"]]; // BOOL hasVideo=(BOOL)[notif.userInfo objectForKey:@"hasVideo"]; // NSLog(@"顶层视图:%@",[HDLLinPhoneCommon topMostController]); if ([HDLLinPhoneCommon rootPresentVCContent:[HDLLinphoneIntercomVC class]]||[HDLLinPhoneCommon rootPresentVCContent:[HDLLPOnMonitorViewController class]]) { if ([[HDLLinPhoneCommon topMostController] isKindOfClass:[UIAlertController class]]) { NSLog(@"顶层视图是视频通话页"); __weak typeof(self) weakSelf = self; [[HDLLinPhoneCommon topMostController] dismissViewControllerAnimated:NO completion:^{ UIViewController *topVC=[HDLLinPhoneCommon topMostController]; if ([topVC isKindOfClass:[HDLLPOnMonitorViewController class]]) { [topVC dismissViewControllerAnimated:NO completion:^{ [weakSelf toLinphoneIntercomVC:titleName deviceType:HDLLPType_Default userName:@""]; }]; }else if ([topVC isKindOfClass:[HDLLinphoneIntercomVC class]]) { [topVC dismissViewControllerAnimated:NO completion:^{ [weakSelf toLinphoneIntercomVC:titleName deviceType:HDLLPType_Default userName:@""]; }]; } }]; } // UIViewController *topVC=[HDLLinPhoneCommon topMostController]; // if ([topVC isKindOfClass:[HDLLinphoneIntercomVC class]]) { // [topVC dismissViewControllerAnimated:NO completion:nil]; // } return; } [self toLinphoneIntercomVC:titleName deviceType:HDLLPType_Default userName:@""]; // if (self.presentingIntercomVC) { // __weak typeof(self) weakSelf = self; // [self.presentingIntercomVC dismissViewControllerAnimated:NO completion:^{ // NSLog(@"页面退出了"); // weakSelf.presentingIntercomVC=nil; // [weakSelf toLinphoneIntercomVC:titleName]; // }]; // // return; // } // NSLog(@"执行到我了"); // [self toLinphoneIntercomVC:titleName]; // HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init]; //// vc.CallId=callId; // vc.hasVideo=YES; // vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate; // if (titleName) { // vc.titleName=titleName; // } // vc.modalPresentationStyle = UIModalPresentationFullScreen; // self.presentingIntercomVC=vc; // [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ // // }]; } /** * 跳转自研呼叫页面 * * @param titleName 标题 */ -(void)gotoHDLSRLinphoneIntercomVC:(NSString*)titleName userName:(NSString*)username{ if ([HDLLinPhoneCommon rootPresentVCContent:[HDLLinphoneIntercomVC class]]||[HDLLinPhoneCommon rootPresentVCContent:[HDLLPOnMonitorViewController class]]) { if ([[HDLLinPhoneCommon topMostController] isKindOfClass:[UIAlertController class]]) { NSLog(@"顶层视图是视频通话页"); __weak typeof(self) weakSelf = self; [[HDLLinPhoneCommon topMostController] dismissViewControllerAnimated:NO completion:^{ UIViewController *topVC=[HDLLinPhoneCommon topMostController]; if ([topVC isKindOfClass:[HDLLPOnMonitorViewController class]]) { [topVC dismissViewControllerAnimated:NO completion:^{ [weakSelf toLinphoneIntercomVC:titleName deviceType:HDLLPType_HDLSR userName:username]; }]; }else if ([topVC isKindOfClass:[HDLLinphoneIntercomVC class]]) { [topVC dismissViewControllerAnimated:NO completion:^{ [weakSelf toLinphoneIntercomVC:titleName deviceType:HDLLPType_HDLSR userName:username]; }]; } }]; } return; } [self toLinphoneIntercomVC:titleName deviceType:HDLLPType_HDLSR userName:username]; } -(void)hideIntercomeVC{ if ([[HDLLinPhoneCommon topMostController] isKindOfClass:[HDLLinphoneIntercomVC class]]) { [[HDLLinPhoneCommon topMostController] dismissViewControllerAnimated:YES completion:^{ }]; } } /** 发送sip message */ -(void)sendMessage:(NSString*)message sipAccount:(NSString*)sipAccount domain:(NSString*)domain{ LinphoneAddress *tmpAddr = linphone_address_new([NSString stringWithFormat:@"sip:%@@%@",sipAccount,domain].UTF8String); LinphoneChatRoom *chatRomm=linphone_core_get_chat_room([HDLLinphoneManager getLc], tmpAddr); [[HDLLinphoneManager instance] send:message toChatRoom:chatRomm]; } -(void)toLinphoneIntercomVC:(NSString*)titleName deviceType:(HDLLPType)deviceType userName:(NSString *)userName{ HDLLinphoneIntercomVC *vc=[[HDLLinphoneIntercomVC alloc]init]; // vc.CallId=callId; vc.hasVideo=YES; vc.hdlLinphoneCallDelegate=self.hdlLinphoneCallDelegate; if (titleName) { vc.titleName=titleName; } vc.deviceType=deviceType; vc.userName=userName; vc.modalPresentationStyle = UIModalPresentationFullScreen; [HDLLinphoneManager instance].deviceType=deviceType; [HDLLinphoneManager instance].isResettingVideoEnable=NO; // self.presentingIntercomVC=vc; [[HDLLinPhoneCommon topMostController] presentViewController:vc animated:YES completion:^{ }]; } -(void)logoutAllLinphoneUser{ [HDLLinphoneManager.instance removeAllAccounts]; } -(void)clearAllConfigs{ } -(void)enterBackground{ [HDLLinphoneManager.instance enterBackgroundMode]; } -(void)becomactive{ [HDLLinphoneManager.instance becomeActive]; } -(void)willResignActive{ // [HDLLinphoneManager.instance willResignActive]; } @end