webRtcPlayerViewController.m 23 KB

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