webRtcPlayerViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. //
  2. // webRtcPlayerViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/9/2.
  6. //
  7. #import "webRtcPlayerViewController.h"
  8. #import "webRtcPlayerViewController+AdjustBtnFrame.h"
  9. #import "webRtcPlayerViewController+AdjustPlayerViewFrame.h"
  10. #import "UIInterface+HXRotation.h"
  11. #import "playerSetView.h"
  12. @interface webRtcPlayerViewController ()<MediaStreamClientEventsDelegate>
  13. {
  14. BOOL outputVolumeKVO;/*标记声音监听通知*/
  15. }
  16. @property (nonatomic, copy) NSTimer *playerSecondTimer; // 定时器-控制按钮
  17. @property (nonatomic, assign) RTCIceConnectionState linkState;
  18. @property (nonatomic, assign) BOOL didHandleRotation;//第一次处理旋转
  19. @end
  20. @implementation webRtcPlayerViewController
  21. @synthesize controlBtn;
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self.toolBar setHidden:YES];
  26. [self.navigationBar setHidden:YES];
  27. [self.navBarBGView setHidden:YES];
  28. [self.view setBackgroundColor:[UIColor blackColor]];
  29. if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
  30. ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying){
  31. _isCodeSuspendAudioType = YES;
  32. [[DFPlayer sharedPlayer] df_pause];
  33. }
  34. }
  35. - (void)viewWillAppear:(BOOL)animated {
  36. [super viewWillAppear:animated];
  37. // 屏幕常亮
  38. [UIApplication sharedApplication].idleTimerDisabled = YES;
  39. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  40. }
  41. - (void)viewDidAppear:(BOOL)animated
  42. {
  43. [super viewDidAppear:animated];
  44. [self noEnablePanRightBack];
  45. [self addKVOObserverFun];
  46. ksharedAppDelegate.supportScreenRotateType = YES;
  47. }
  48. - (void)viewDidDisappear:(BOOL)animated{
  49. [super viewDidDisappear:animated];
  50. [UIApplication sharedApplication].idleTimerDisabled = NO;
  51. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  52. [_mediaStream disconnect];
  53. _mediaStream = nil;
  54. [self enablePanRightBack];
  55. [self removeKVOObserverFun];
  56. ksharedAppDelegate.supportScreenRotateType = NO;
  57. [self removeNewIndicator];
  58. [_playerSecondTimer invalidate];
  59. _webRtcMsgMod = nil;
  60. }
  61. - (void)setWebRtcMsgMod:(webRtcMsgModel *)webRtcMsgMod
  62. {
  63. _webRtcMsgMod = webRtcMsgMod;
  64. [self beginWebRtcPlayFun];
  65. }
  66. #pragma mark 开始拉流
  67. - (void)beginWebRtcPlayFun
  68. {
  69. _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
  70. [_mediaStream setEventDelegate:self];
  71. [self.view addSubview:_mediaStream];
  72. [_mediaStream mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(0.f);
  74. make.bottom.mas_equalTo(0.f);
  75. make.right.mas_equalTo(0.f);
  76. make.top.mas_equalTo(0.f);
  77. }];
  78. //判断是否是全屏
  79. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  80. CGSize phoneSize = CGSizeMake(1080.0, 1920.0);
  81. if(fullscreenType){
  82. phoneSize = [RCCommandHelp commondToSetFullScreenPhoneSizeBySize];
  83. }
  84. [self linkWebRtcFunWithSize:phoneSize];
  85. [self initBaseUIFun];
  86. [self setTimerCountDown];
  87. //CGFloat curRate = 1080.0/1920.0;
  88. //CGFloat curRate = phoneSize.width/phoneSize.height;
  89. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  90. }
  91. #pragma mark 链接webrtc
  92. - (void)linkWebRtcFunWithSize:(CGSize)phoneSize
  93. {
  94. //链接用
  95. NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
  96. NSURL *url = [NSURL URLWithString:signallingUrl];
  97. //ice用
  98. NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
  99. NSMutableDictionary *ice = [NSMutableDictionary new];
  100. if(iceUrl){
  101. [ice setValue:iceUrl forKey:@"CHINANET"];
  102. [ice setValue:iceUrl forKey:@"CMNET"];
  103. [ice setValue:iceUrl forKey:@"UNICOM"];
  104. }
  105. NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
  106. NSInteger result = [_mediaStream start:url
  107. ice:ice
  108. sn:roomName
  109. direct:0
  110. fmt:1//1(h264) 5(h265)
  111. videoWidth:(NSInteger)phoneSize.width
  112. videoHeight:(NSInteger)phoneSize.height
  113. fps:30
  114. bitrate:3000
  115. cardWidth:0//1080//0
  116. cardHeight:0//1920//0
  117. cardDensity:0
  118. token:@"vclusters"];
  119. HLog(@"result:%ld",result)
  120. }
  121. #pragma mark 重连
  122. - (void)relinkWebRtcFun
  123. {
  124. if(_linkState == RTCIceConnectionStateConnected
  125. || _linkState == RTCIceConnectionStateCompleted)
  126. {//链接中 不处理重连事件
  127. HLog(@"链接中 不处理重连事件")
  128. return;
  129. }
  130. HLog(@"发起重连 ......")
  131. KWeakSelf
  132. mainBlock(^{
  133. [weakSelf showNewIndicatorWithCanBack:YES canTouch:NO];
  134. //判断是否是全屏
  135. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  136. CGSize phoneSize = CGSizeMake(1080.0, 1920.0);
  137. if(fullscreenType){
  138. phoneSize = [RCCommandHelp commondToSetFullScreenPhoneSizeBySize];
  139. }
  140. [weakSelf linkWebRtcFunWithSize:phoneSize];
  141. });
  142. }
  143. #pragma mark 初始化其他UI
  144. - (void)initBaseUIFun
  145. {
  146. _bottomContrView = [[webRtcPlayerBottomContrView alloc] init];
  147. [self.view addSubview:_bottomContrView];
  148. [self getPlayerBottomNavShowOrHidefun];
  149. KWeakSelf
  150. _bottomContrView.didClickButtonFun = ^(NSInteger tag) {
  151. [weakSelf didClickBottomFunBy:tag];
  152. };
  153. /*控制按钮*/
  154. UIImage *driftBtnImage = [UIImage imageNamed:@"you_icon"];
  155. controlBtn = [[UIButton alloc] init];
  156. [controlBtn setBackgroundColor:[UIColor clearColor]];
  157. [controlBtn setBackgroundImage:driftBtnImage forState:(UIControlStateNormal)];
  158. [controlBtn addTarget:self
  159. action:@selector(controlBtnPressed:)
  160. forControlEvents:(UIControlEventTouchUpInside)];
  161. [self.view addSubview:controlBtn];
  162. //拖拽事件等
  163. UIPanGestureRecognizer *gester = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(controlBtnPanGestureCallback:)];
  164. [controlBtn addGestureRecognizer:gester];
  165. //gester.delegate = self;
  166. [self initPointForControlBtnFun];
  167. }
  168. #pragma mark 设置 controlBtn 的初始位置
  169. - (void)initPointForControlBtnFun
  170. {
  171. CGFloat h_w_controlBtn = 60.f;
  172. /*区分横竖屏*/
  173. if (_mediaStream.hw_w > _mediaStream.hw_h){
  174. [controlBtn setFrame:CGRectMake((_mediaStream.hw_w - h_w_controlBtn)/2.f, _mediaStream.hw_h - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
  175. }else{
  176. //默认居右
  177. //[mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
  178. //默认居左
  179. [controlBtn setFrame:CGRectMake( h_w_controlBtn + 10.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
  180. }
  181. }
  182. #pragma mark 定时器
  183. - (void)setTimerCountDown {
  184. HLog(@"开启一个");
  185. if (_playerSecondTimer) {
  186. // 取消定时器
  187. [_playerSecondTimer invalidate];
  188. _playerSecondTimer = nil;
  189. }
  190. // 初始化值计时数据
  191. //self.adjustTime = 1;
  192. //self.concentTime = [iTools getNowTimeStamp];
  193. _playerSecondTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  194. [[NSRunLoop currentRunLoop] addTimer:_playerSecondTimer forMode:NSRunLoopCommonModes];
  195. }
  196. #pragma mark 定时器响应事件
  197. - (void)timerChange {
  198. [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
  199. //[self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
  200. }
  201. #pragma mark 控制按钮点击事件
  202. - (void)controlBtnPressed:(UIButton*)but
  203. {
  204. playerSetView *nextVC = [[playerSetView alloc] init];
  205. [ksharedAppDelegate.window addSubview:nextVC];
  206. [nextVC mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.left.mas_equalTo(0);
  208. make.right.mas_equalTo(0);
  209. make.top.mas_equalTo(0.f);
  210. make.bottom.mas_equalTo(0.f);
  211. }];
  212. KWeakSelf
  213. nextVC.didClickButtonFun = ^(NSInteger tag) {
  214. switch (tag) {
  215. case 10:
  216. {//截图
  217. //self->needScreenShotType = YES;
  218. }
  219. break;
  220. #pragma mark 重启盒子
  221. case 11:
  222. {
  223. [weakSelf didClickRestartFun];
  224. }
  225. break;
  226. case 12:
  227. {//退出云机
  228. [weakSelf exitCloudPhoneFun];
  229. }
  230. break;
  231. case 100:
  232. {
  233. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  234. if(fullscreenType){
  235. [weakSelf showOpenTVP2PFun];
  236. }
  237. else{
  238. [weakSelf openTvShowFun];
  239. }
  240. }
  241. break;
  242. case 101:
  243. {
  244. weakSelf.controlBtn.userInteractionEnabled = NO;
  245. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  246. self->controlBtn.userInteractionEnabled = YES;
  247. });
  248. [weakSelf showCloseTVP2PFun];
  249. }
  250. break;
  251. default:
  252. break;
  253. }
  254. };
  255. }
  256. #pragma mark 点击了重启云机
  257. - (void)didClickRestartFun
  258. {
  259. KWeakSelf
  260. /*弹窗提示重启*/
  261. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil)
  262. msg:@""
  263. imageStr:@""
  264. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  265. okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO
  266. didClickOk:^{
  267. [weakSelf needToRebootFun];
  268. //提示语
  269. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  270. } didClickCancel:^{
  271. }];
  272. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  273. [self presentViewController:nextVC animated:YES completion:^{
  274. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  275. }];
  276. }
  277. #pragma mark p2p通道 重启云机
  278. - (void)needToRebootFun
  279. {
  280. [[webRtcManager shareManager] needToRebootFun];
  281. [self startForceStartTimerFun];
  282. //最后一帧 没显示正在重启问题
  283. //_canShowImgAndVoiceType = YES;
  284. [webRtcManager shareManager].isRebootIngType = YES;
  285. }
  286. #pragma mark X 秒后检查是否软件重启成功
  287. - (void)startForceStartTimerFun
  288. {
  289. KWeakSelf
  290. //1. 5秒后跟硬件发起硬重启
  291. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  292. [weakSelf updateForceStartFun];
  293. });
  294. //2. 20秒后尝试重连
  295. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  296. [weakSelf relinkWebRtcFun];
  297. [[webRtcManager shareManager] relinkWebRtcFun];
  298. });
  299. }
  300. #pragma mark 需要强制重启
  301. - (void)updateForceStartFun{
  302. NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  303. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  304. [paraDict setValue:curSn forKey:@"sn"];
  305. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  306. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  307. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  308. if (model.status == 0) {
  309. }
  310. else
  311. {
  312. }
  313. } failure:^(NSError * _Nonnull error) {
  314. HLog(@"%@", error);
  315. }];
  316. }
  317. #pragma mark 退出云机
  318. - (void)exitCloudPhoneFun
  319. {
  320. //[self setShowImgAndVoiceTypeFun:NO];
  321. if(_isCodeSuspendAudioType){
  322. [[DFPlayer sharedPlayer] df_play];
  323. }
  324. [self.navigationController popViewControllerAnimated:YES];
  325. }
  326. #pragma mark 显示关闭投屏提示语
  327. - (void)showOpenTVP2PFun{
  328. /*弹窗提示TV投屏*/
  329. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  330. msg:NSLocalizedString(@"cloudPhone_fullscreen_tvshow_tip",nil)
  331. imageStr:@""
  332. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  333. okTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) isOkBtnHighlight:YES
  334. didClickOk:^{
  335. [self openTvShowFun];
  336. //关闭全屏屏
  337. [HWDataManager setBoolWithKey:Consn_player_full_screen_show value:NO];
  338. [self setPlayerFullScreenNotFun];
  339. } didClickCancel:^{
  340. }];
  341. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  342. [self presentViewController:nextVC animated:YES completion:^{
  343. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  344. }];
  345. }
  346. #pragma mark 开始投屏
  347. - (void)openTvShowFun
  348. {
  349. self.controlBtn.userInteractionEnabled = NO;
  350. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  351. self->controlBtn.userInteractionEnabled = YES;
  352. });
  353. [[webRtcManager shareManager] onTvFun];
  354. [[iToast makeText:NSLocalizedString(@"cloudPhone_TV_show_tip",nil)] show];
  355. //数据埋点
  356. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Cloud_tv"];
  357. }
  358. #pragma mark 显示关闭投屏提示语
  359. - (void)showCloseTVP2PFun{
  360. /*弹窗提示TV投屏*/
  361. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_close_TV_p2p_tip",nil)
  362. msg:@""
  363. imageStr:@""
  364. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  365. okTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) isOkBtnHighlight:YES
  366. didClickOk:^{
  367. [self gotoCloseTVP2PFun];
  368. } didClickCancel:^{
  369. //HLog(@"2222");
  370. }];
  371. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  372. [self presentViewController:nextVC animated:YES completion:^{
  373. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  374. }];
  375. }
  376. #pragma mark 确认开始TV投屏
  377. -(void)gotoCloseTVP2PFun
  378. {
  379. [[webRtcManager shareManager] offTvFun];
  380. }
  381. #pragma mark 底部按钮事件
  382. - (void)didClickBottomFunBy:(NSInteger)tag
  383. {
  384. int keyType = 0;
  385. if(tag == 1){//task
  386. keyType = 187;
  387. }
  388. else if(tag == 2){//home
  389. keyType = 3;
  390. }
  391. else if(tag == 3){//back
  392. keyType = 4;
  393. }
  394. if(keyType > 0){
  395. [self didClickKeyEventFunBy:keyType];
  396. }
  397. }
  398. #pragma mark 按键事件
  399. // home 3 back 4 task 187 volumeUp 24 volumeDown 25
  400. - (void)didClickKeyEventFunBy:(int)keyType
  401. {
  402. [_mediaStream sendKey:keyType];
  403. }
  404. #pragma mark 云机交互的消息发送
  405. -(void)send_data:(NSString*)commandStr
  406. {
  407. [[webRtcManager shareManager] send_data:commandStr];
  408. }
  409. #pragma mark -- /*底部导航栏开关通知*/
  410. - (void)getPlayerBottomNavShowOrHidefun
  411. {
  412. BOOL haveShowBottonNavType = ![HWDataManager getBoolWithKey:Consn_player_Nav_hide];
  413. if(haveShowBottonNavType){
  414. _bottomContrView.hidden = NO;
  415. }
  416. else{
  417. _bottomContrView.hidden = YES;
  418. }
  419. }
  420. #pragma mark -- /*全面屏开关通知*/
  421. - (void)setPlayerFullScreenNotFun
  422. {
  423. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  424. CGFloat tempRate = 0.0;
  425. //重新设置分辨率
  426. if(fullscreenType){
  427. NSInteger cardDensity = 380;//480;//422;//380;//460;
  428. CGSize size = [RCCommandHelp commondToSetFullScreenPhoneSizeBySize];
  429. if(isLan){
  430. if(size.width < size.height){
  431. size = CGSizeMake(size.height,size.width);
  432. }
  433. }
  434. [self setCardSize:size.width cardHeight:size.height cardDensity:cardDensity];
  435. tempRate = (size.width *1.0)/(size.height *1.0);
  436. }
  437. else{
  438. CGSize size = CGSizeMake(1080.0, 1920.0);
  439. if(isLan){
  440. size = CGSizeMake(1920.0, 1080.0);
  441. }
  442. [self setCardSize:(NSInteger)size.width cardHeight:(NSInteger)size.height cardDensity:480];
  443. tempRate = size.width/size.height;
  444. }
  445. //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  446. if (tempRate > 1) {/*横屏*/
  447. [self setLanMas_makeWithImageRate:tempRate];
  448. }else{/*竖屏*/
  449. [self setPoMas_makeWithImageRate:tempRate];
  450. }
  451. // });
  452. }
  453. #pragma mark -- /*推流中修改卡的分辨率*/
  454. - (void)setCardSize:(NSInteger)cardWidth
  455. cardHeight:(NSInteger)cardHeight
  456. cardDensity:(NSInteger)cardDensit
  457. {
  458. if(isLan){
  459. HLog(@"云机屏幕 设置 宽:%ld 高:%ld",cardHeight,cardWidth);
  460. [_mediaStream setCardSize:cardHeight cardHeight:cardWidth cardDensity:cardDensit];
  461. [_mediaStream setVideoSize:cardHeight videoHeight:cardWidth];
  462. }
  463. else{
  464. HLog(@"云机屏幕 设置 宽:%ld 高:%ld",cardWidth,cardHeight);
  465. [_mediaStream setCardSize:cardWidth cardHeight:cardHeight cardDensity:cardDensit];
  466. [_mediaStream setVideoSize:cardWidth videoHeight:cardHeight];
  467. }
  468. }
  469. #pragma mark -- /*通知添加与移除*/
  470. - (void)addKVOObserverFun
  471. {
  472. outputVolumeKVO = YES;
  473. [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(void *)[AVAudioSession sharedInstance]];
  474. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getPlayerBottomNavShowOrHidefun) name:getPlayerBottomNavNotification object:nil];
  475. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPlayerFullScreenNotFun) name:setPlayerFullScreenNotification object:nil];
  476. }
  477. - (void)removeKVOObserverFun
  478. {
  479. if (outputVolumeKVO)
  480. {
  481. [[AVAudioSession sharedInstance] removeObserver:self forKeyPath:@"outputVolume" context:(void *)[AVAudioSession sharedInstance]];
  482. outputVolumeKVO = NO;
  483. }
  484. [[NSNotificationCenter defaultCenter] removeObserver:self];
  485. }
  486. #pragma mark 系统音量键监听
  487. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  488. if(context == (__bridge void *)[AVAudioSession sharedInstance])
  489. {
  490. /*音量开关打开时 允许发送指令 否则直接返回*/
  491. float newValue = [[change objectForKey:@"new"] floatValue];
  492. float oldValue = [[change objectForKey:@"old"] floatValue];
  493. //HLog(@"音量 --old: %f ---new: %f",oldValue,newValue)
  494. if (newValue > oldValue)
  495. {
  496. HLog(@"\n-----音量增加");
  497. [self didClickKeyEventFunBy:24];
  498. }
  499. else
  500. {
  501. HLog(@"\n-----音量降低");
  502. [self didClickKeyEventFunBy:25];
  503. }
  504. }
  505. }
  506. #pragma mark 监听到云机的宽高以及屏幕方向
  507. - (void)handlUIAfterGetCloudPhoneVideoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation
  508. {
  509. HLog(@"云机屏幕 回调 宽:%d 高:%d 横竖屏:%d",videoWidth,videoHeight,rotation);
  510. CGFloat curRate = (CGFloat)videoWidth/(CGFloat)videoHeight;
  511. if(lastVideoWHRate == curRate){
  512. return;
  513. }
  514. didAdjusBtnType = NO;
  515. if(rotation == 0){//竖屏
  516. //切换到竖屏
  517. isLan = NO;
  518. [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  519. [self setPoMas_makeWithImageRate:curRate];
  520. }
  521. else if(rotation == 1){//横屏
  522. //切换到横屏屏
  523. isLan = YES;
  524. [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
  525. [self setLanMas_makeWithImageRate:curRate];
  526. }
  527. _didHandleRotation = YES;
  528. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  529. [self extensionAdjustBtnFrameCheckAdjustTime];
  530. });
  531. }
  532. #pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
  533. #pragma mark - 宽高变化
  534. -(void)onFrameResolutionChangedFromPeerName:(NSString*)peerName videoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation {
  535. HLog(@"onFrameResolutionChangedFromPeerName:%@---%d---%d--%d",peerName,videoWidth,videoHeight,rotation)
  536. mainBlock(^{
  537. [self handlUIAfterGetCloudPhoneVideoWidth:videoWidth videoHeight:videoHeight rotation:rotation];
  538. });
  539. }
  540. //code 0 成功 1失败
  541. -(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
  542. {
  543. HLog(@"onAuthResultFromPeerName:%@---%d---%@",peerName,code,descriptions)
  544. }
  545. #pragma mark 链接发生变化
  546. -(void)onChangeConnectionStateFromPeerName:(NSString*)peerName didChangeIceConnectionState:(RTCIceConnectionState)state
  547. {
  548. HLog(@"onChangeConnectionStateFromPeerName: state:%ld",state)
  549. _linkState = state;
  550. switch (state) {
  551. case RTCIceConnectionStateConnected:{
  552. //链接成功
  553. mainBlock(^{
  554. [self removeNewIndicator];
  555. });
  556. }
  557. break;
  558. case RTCIceConnectionStateCompleted:
  559. //链接完成
  560. break;
  561. case RTCIceConnectionStateFailed:
  562. //链接失败
  563. [self relinkWebRtcFun];
  564. break;
  565. case RTCIceConnectionStateDisconnected:
  566. //链接断开
  567. [self relinkWebRtcFun];
  568. break;
  569. case RTCIceConnectionStateClosed:
  570. //链接关闭
  571. if([webRtcManager shareManager].isRebootIngType){
  572. [self relinkWebRtcFun];
  573. }
  574. break;
  575. default:
  576. break;
  577. }
  578. }
  579. - (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state{
  580. ;
  581. }
  582. //-(void)onIceConnectedFromPeerName:(NSString*)peerName{
  583. // HLog(@"onIceConnectedFromPeerName:%@",peerName);
  584. // mainBlock(^{
  585. // [self removeNewIndicator];
  586. // });
  587. //}
  588. -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
  589. HLog(@"stats:%@",stats);
  590. }
  591. @end