Browse Source

1.减少推拉流页的timer 剩下一个 3秒跑一次

huangxiaodong 1 year ago
parent
commit
13552e19a4

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+AdjustBtnFrame.m

@@ -165,7 +165,7 @@
 - (void)extensionAdjustBtnFrameCheckAdjustTime {
     self.adjustTime--;
     
-    if (self.adjustTime == 0) {
+    if (self.adjustTime <= 0) {
 //        HLog(@"云手机圆形浮标自动隐藏倒计时 3s倒计时结束");
         [self adjustPlayerViewControlBtnFrame1];
     }else {

+ 29 - 103
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.mm

@@ -113,12 +113,8 @@ UIDocumentPickerDelegate>
     NSString *hidenTextFieldOldStr;
     
     PhoneTimeInfoDataModel *phoneTimeInfoDataModel;
-    
-    
-    NSTimer *forceStartTimer;//请知重启timer
-    
     int preIFrameNum;
-    
+
 }
 @property (nonatomic, strong, nullable) RCVideoRecoderManager *recoderManager;
 @property (nonatomic, strong, nullable) RCAudioRecoderMamager *audioRecoderMamager;
@@ -131,26 +127,13 @@ UIDocumentPickerDelegate>
 
 @property (nonatomic, copy)   NSString           *screenShotFileName;
 
-@property (nonatomic, copy)   NSTimer            *timer; // 定时器-控制按钮
+@property (nonatomic, copy)   NSTimer            *playerSecondTimer; // 定时器-控制按钮
 /**30s后 渲染时间戳无更新 自动断开链接*/
 @property (nonatomic, assign) NSInteger          concentTime; // 拉流数据 渲染更新时间戳
 
-/**定时器计数*/
-@property (nonatomic, assign) NSInteger          currentTime;
-/**定时器计数*/
-@property (nonatomic, assign) NSInteger          webSocketTime;
-/**定时器计数*/
-@property (nonatomic, assign) NSInteger          offlineNotTime;
-
-/**定时器计数 任务检测*/
-@property (nonatomic, assign) NSInteger          webSocketTaskTime;
-
 /**是否是收入进入云手机*/
 @property (nonatomic, assign) BOOL          isFirstEnterPhone;
 
-@property (nonatomic, strong)   NSTimer            *checkThridConnectTimer; // 检查瑞云那边连接完成没
-@property (nonatomic, assign) NSInteger          checkThridConnectNum;//
-
 //音频和图片是否可以刷新
 @property (nonatomic, assign) BOOL canShowImgAndVoiceType;
 
@@ -195,7 +178,6 @@ UIDocumentPickerDelegate>
     outputVolumeKVO = NO;
     
     rbdNotification = 0;
-    _offlineNotTime = 0;
     preIFrameNum = 0;
     
     // 初始化
@@ -226,29 +208,18 @@ UIDocumentPickerDelegate>
 #pragma mark 启动检测瑞云的timer
  - (void)startCheckThridRuiYunTimerFun
 {
-    if(_checkThridConnectTimer ){
-        [_checkThridConnectTimer invalidate];
-    }
-    
-    _checkThridConnectNum = 0;
-    
-    _checkThridConnectTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(checkThridRuiYunFun) userInfo:nil repeats:YES];
-    [[NSRunLoop currentRunLoop] addTimer:_checkThridConnectTimer forMode:NSRunLoopCommonModes];
+    [self checkThridRuiYunFun];
 }
 
 #pragma mark 检测融云链接是否完成
 - (void)checkThridRuiYunFun{
     
-    _checkThridConnectNum += 1;
-    
-    if(_checkThridConnectNum >= 30 && [[connectDeviceManager shareInstance] curConnectDeviceState] <= 3 ){
-//hxd del 20240720 流程改变 这个弹框不在这里处理了 改到瑞云链接那边处理 因为要先先ws
-//        [[addLogObject shareInstance] gotoAddLogFun];
-//        [self showNetErrorAlertFun:11];
-        
-        _checkThridConnectNum = 0;
-//        [_checkThridConnectTimer invalidate];
-//        return;
+    KWeakSelf
+    if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3 ){
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            [weakSelf checkThridRuiYunFun];
+        });
+        return;
     }
     
     HLog(@"瑞云连接状态:%d",[[connectDeviceManager shareInstance] curConnectDeviceState]);
@@ -275,8 +246,6 @@ UIDocumentPickerDelegate>
 
 #pragma mark 走局域网或者瑞云SDK链接OK
 - (void)didCanConnectServerFun{
-    [_checkThridConnectTimer invalidate];
-    
     [self connectVideoServer];
     
 }
@@ -356,8 +325,8 @@ UIDocumentPickerDelegate>
         self.didRecyclResource = YES;
         
         // 销毁定时器
-        [self cancelTimer];
-        
+        [_playerSecondTimer invalidate];
+        _playerSecondTimer = nil;
         
         //globalBlock(^{
             [self.liveStreamManager rc_release];
@@ -386,18 +355,7 @@ UIDocumentPickerDelegate>
         [self toStopAudioRecoder];
 
         [self removeNSNotification];
-        
-        
-        if(forceStartTimer){
-            [forceStartTimer invalidate];
-            forceStartTimer = nil;
-        }
-        
-        if(_checkThridConnectTimer){
-            [_checkThridConnectTimer invalidate];
-            _checkThridConnectTimer = nil;
-        }
-        
+
     }
 }
 
@@ -451,12 +409,6 @@ UIDocumentPickerDelegate>
 }
 
 
-- (void)keepWebSocketOKFun
-{
-    self.webSocketTime = 0;
-}
-
-
 - (void)keyboardFeedbackBeanFun
 {
     [self->hidenTextField becomeFirstResponder];
@@ -837,7 +789,7 @@ UIDocumentPickerDelegate>
             }
             
             //重启后重连 出来的
-            if([webSocketManager shareInstance].isRebootIngType && !forceStartTimer){
+            if([webSocketManager shareInstance].isRebootIngType){
                 mainBlock(^{
                     [[iToast makeText:NSLocalizedString(@"player_link_reboot_suc_Tips",nil)] show];
                 });
@@ -1416,34 +1368,23 @@ NSDate *lastVideoTome;/*上一帧数据时间*/
     
 }
 
-#pragma mark 启动timer 秒后检查是否软件重启成功
+#pragma mark X 秒后检查是否软件重启成功
 - (void)startForceStartTimerFun
 {
-    if(forceStartTimer){
-        [forceStartTimer invalidate];
-        forceStartTimer = nil;
-    }
-    
-    forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
-    [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
-}
-
-- (void)gotoUpdateForceStartFun
-{
-    [self updateForceStartFun];
-    
     KWeakSelf
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+    //1.  5秒后跟硬件发起硬重启
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        [weakSelf updateForceStartFun];
+    });
+    
+    //2.  20秒后尝试重连
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
         [weakSelf reconnectDevice];
         [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
     });
 }
 
 
-
-
-
-
 #pragma mark 单点登录被挤下线弹框
 - (void)LogoutByOtherFun
 {
@@ -2228,39 +2169,24 @@ static int  couneeee = 0;
 - (void)setTimerCountDown {
     HLog(@"开启一个");
     
-    if (_timer) {
+    if (_playerSecondTimer) {
         // 取消定时器
-        [self cancelTimer];
+        [_playerSecondTimer invalidate];
+        _playerSecondTimer = nil;
     }
     
     // 初始化值计时数据
-    self.adjustTime = 3;
+    self.adjustTime = 1;
     self.concentTime = [iTools getNowTimeStamp];
-    self.currentTime = 0;
-    self.webSocketTime = 0;
-    self.webSocketTaskTime = 0;
-    
-    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
-    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
+ 
+    _playerSecondTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
+    [[NSRunLoop currentRunLoop] addTimer:_playerSecondTimer forMode:NSRunLoopCommonModes];
 }
 
-- (void)cancelTimer {
-    // 取消定时器
-    if(_timer){
-        [_timer invalidate];
-        _timer = nil;
-    }
-}
 
 
 - (void)timerChange {
-    
-    //self.currentTime++;// 0、定时器计数
-    //HLog(@"111111111111111");
-    
     [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
-    
-    
     [self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
 }
 
@@ -2273,7 +2199,7 @@ static int  couneeee = 0;
     if (self.concentTime == 0) { //云手机未连接成功
         HLog(@"云手机未连接成功");
         
-    }else if (timeDiff >= 30) { // 30s 无渲染数据
+    }else if (timeDiff >= 10) { // 30s 无渲染数据
         
         if(!_needToDissconnectType && !_isLoginAgainType && [self isPlayerViewIsTopVCFun]){
              HLog(@"云手机30s 无渲染数据 自动断开连接");