浏览代码

1.客户端连接盒子失败 不在上传日志到服务器 把对应key给到打洞日志的失败原因

huangxiaodong 4 月之前
父节点
当前提交
fdd0e99327

+ 6 - 1
创维盒子/code/netWork/addLog/addLogObject.h

@@ -9,11 +9,16 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+/**
+ *  成功请求Block返回的字典
+ */
+typedef void (^AddLog_Success) (NSString* key);
+
 @interface addLogObject : NSObject
 @property(nonatomic,assign) BOOL canUploadNowType;//当前是否可以上传日志 正常上传中 不可再次上传
 
 +(addLogObject *)shareInstance;
-- (void)gotoAddLogFun;
+- (void)gotoAddLogFunBySuccess:(AddLog_Success)success;
 @end
 
 NS_ASSUME_NONNULL_END

+ 38 - 29
创维盒子/code/netWork/addLog/addLogObject.m

@@ -38,10 +38,11 @@ static addLogObject *addlog_ShareInstance = nil;
 //1.读取日志
 //2.上传到文件中心
 //3.拿到key上传到盒子服务器
-- (void)gotoAddLogFun
+- (void)gotoAddLogFunBySuccess:(AddLog_Success)success
 {
     //HLog(@"hxd beginTime");
     if(!_canUploadNowType){
+        success(@"");
         return;
     }
     
@@ -50,6 +51,7 @@ static addLogObject *addlog_ShareInstance = nil;
     if(preSecondNum){
         long seconds =  [iTools getNowTimeStamp];
         if(seconds - preSecondNum.longValue <= 60*60){
+            success(@"");
             return;
         }
     }
@@ -89,6 +91,7 @@ static addLogObject *addlog_ShareInstance = nil;
     
     if(!logData || [logData length]==0){
         _canUploadNowType = YES;
+        success(@"");
         return;
     }
     
@@ -104,6 +107,7 @@ static addLogObject *addlog_ShareInstance = nil;
     [paraDict setValue:filename forKey:@"filename"];
     [paraDict setValue:@7 forKey:@"days"];
     
+    KWeakSelf
     [[netWorkManager shareInstance] doUploadFileToFileServiceWithParams:paraDict data:logData success:^(id  _Nonnull responseObject) {
         HLog(@"%@",responseObject);
         
@@ -111,17 +115,22 @@ static addLogObject *addlog_ShareInstance = nil;
         if(model.code == 200){
             NSString * fileKey = model.data.fileKey;
             if(fileKey && fileKey.length >0){
-                [self uploadKeyToServerFunBy:fileKey];
+                success(fileKey);
+                [weakSelf markAddLogTimeFun];
+                //[self uploadKeyToServerFunBy:fileKey];
             }
             else{
+                success(@"");
                 self->_canUploadNowType = YES;
             }
         }
         else{
+            success(@"");
             self->_canUploadNowType = YES;
         }
         
     } faild:^(NSError * _Nonnull error) {
+        success(@"");
         self->_canUploadNowType = YES;
     }];
     
@@ -130,33 +139,33 @@ static addLogObject *addlog_ShareInstance = nil;
 }
 
 //3.拿到key上传到盒子服务器
-- (void)uploadKeyToServerFunBy:(NSString*)fileKey
-{
-    NSMutableDictionary *paraDict = [NSMutableDictionary new];
-    [paraDict setValue:@"ios" forKey:@"type"];
-    
-    NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
-    if(!snStr){
-        _canUploadNowType = YES;
-        return;
-    }
-    [paraDict setValue:snStr forKey:@"sn"];
-    [paraDict setValue:fileKey forKey:@"key"];
-    
-    KWeakSelf
-    [[netWorkManager shareInstance] CommonPostCallBackCode:addLogFun Parameters:paraDict success:^(id  _Nonnull responseObject) {
-        SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
-        if(model.code == 0){
-            [weakSelf markAddLogTimeFun];
-        }
-        else{
-            self->_canUploadNowType = YES;
-        }
-        
-    } failure:^(NSError * _Nonnull error) {
-        self->_canUploadNowType = YES;
-    }];
-}
+//- (void)uploadKeyToServerFunBy:(NSString*)fileKey
+//{
+//    NSMutableDictionary *paraDict = [NSMutableDictionary new];
+//    [paraDict setValue:@"ios" forKey:@"type"];
+//    
+//    NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
+//    if(!snStr){
+//        _canUploadNowType = YES;
+//        return;
+//    }
+//    [paraDict setValue:snStr forKey:@"sn"];
+//    [paraDict setValue:fileKey forKey:@"key"];
+//    
+//    KWeakSelf
+//    [[netWorkManager shareInstance] CommonPostCallBackCode:addLogFun Parameters:paraDict success:^(id  _Nonnull responseObject) {
+//        SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
+//        if(model.code == 0){
+//            [weakSelf markAddLogTimeFun];
+//        }
+//        else{
+//            self->_canUploadNowType = YES;
+//        }
+//        
+//    } failure:^(NSError * _Nonnull error) {
+//        self->_canUploadNowType = YES;
+//    }];
+//}
 
 - (void)markAddLogTimeFun
 {

+ 2 - 2
创维盒子/code/webRtc/webRtcManager/webRtcManager+StatisticsReport.h

@@ -11,10 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface webRtcManager (StatisticsReport)
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId withLogKey:(NSString*)logkey;
 
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId  withLogKey:(NSString*)logkey;
 
 @end
 

+ 10 - 6
创维盒子/code/webRtc/webRtcManager/webRtcManager+StatisticsReport.m

@@ -9,11 +9,11 @@
 
 @implementation webRtcManager (StatisticsReport)
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId  withLogKey:(NSString*)logkey
 {
     //HLog(@"444444 %@",stats)
     if(!stats){
-        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:0 withPublicIp:@"" withPublicPort:@"" withPrivateIp:@"" withPrivatePort:@"" withSessionId:@""];
+        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:0 withPublicIp:@"" withPublicPort:@"" withPrivateIp:@"" withPrivatePort:@"" withSessionId:@"" withLogKey:logkey];
         return;
     }
     
@@ -159,10 +159,10 @@
         //[self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:1 withPublicIp:publicIp withPublicPort:publicPort withPrivateIp:privateIp withPrivatePort:privatePort];
     }
     
-    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:publicIp withPublicPort:publicPort withPrivateIp:privateIp withPrivatePort:privatePort withSessionId:sessionId];
+    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:publicIp withPublicPort:publicPort withPrivateIp:privateIp withPrivatePort:privatePort withSessionId:sessionId withLogKey:logkey];
 }
 
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStatus:(int)linkState withPublicIp:(NSString*)publicIp withPublicPort:(NSString*)publicPort withPrivateIp:(NSString*)privateIp withPrivatePort:(NSString*)privatePort withSessionId:(NSString*)sessionId
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStatus:(int)linkState withPublicIp:(NSString*)publicIp withPublicPort:(NSString*)publicPort withPrivateIp:(NSString*)privateIp withPrivatePort:(NSString*)privatePort withSessionId:(NSString*)sessionId  withLogKey:(NSString*)logkey
 {
     
     NSMutableDictionary *paraDict = [NSMutableDictionary new];
@@ -192,6 +192,10 @@
         [paraDict setValue:privatePort forKey:@"privatePort"];
     }
     
+    if(logkey){
+        [paraDict setValue:logkey forKey:@"failureReason"];
+    }
+    
     if(ksharedAppDelegate.bestWebrtcServerModel){
         
         NSString * turnMsg = [[NSString alloc] initWithFormat:@"%@:%@",ksharedAppDelegate.bestWebrtcServerModel.turnIp,ksharedAppDelegate.bestWebrtcServerModel.turnPort];
@@ -217,7 +221,7 @@
 }
 
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId{
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId  withLogKey:(NSString*)logkey{
     
     // candidate:504853897 1 udp 41885695 115.227.9.195 35762 typ relay raddr 115.227.9.184 rport 43877 generation 0 ufrag OP7P network-id 1
     NSString*localSdpStr = local.sdp;
@@ -267,7 +271,7 @@
         linkState = 1;
     }
     
-    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:remoteIp withPublicPort:remotePort withPrivateIp:localIp withPrivatePort:localPort withSessionId:sessionId];
+    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:remoteIp withPublicPort:remotePort withPrivateIp:localIp withPrivatePort:localPort withSessionId:sessionId withLogKey:logkey];
 }
 
 @end

+ 2 - 2
创维盒子/code/webRtc/webRtcManager/webRtcManager.h

@@ -95,10 +95,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 
 #pragma mark 上报打洞是否成功
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId withLogKey:(NSString*)logkey;
 
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId withLogKey:(NSString*)logkey;
 @end
 
 NS_ASSUME_NONNULL_END

+ 9 - 6
创维盒子/code/webRtc/webRtcManager/webRtcManager.m

@@ -75,8 +75,10 @@
             tryRelinkNum ++;
             if(tryRelinkNum == 2){
                 _didReportWebRtcFailType = YES;
-                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcChannelSessionId];
-                [[addLogObject shareInstance] gotoAddLogFun];
+                
+                [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
+                    [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcChannelSessionId withLogKey:key];
+                }];
                 
                 //检测盒子心跳
                 [self checkBoxHeartbeatFun];
@@ -977,9 +979,10 @@
         case RTCIceConnectionStateClosed:{
             if(!_didReportWebRtcFailType){//还没上报过通道链接情况
                 _didReportWebRtcFailType = YES;
-                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcChannelSessionId];
                 
-                //[[addLogObject shareInstance] gotoAddLogFun];
+                [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
+                    [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcChannelSessionId withLogKey:key];
+                }];
             }
             //链接关闭
             [self relinkWebRtcFun];
@@ -1047,7 +1050,7 @@
     //HLog(@"didGetStats:%@",stats)
     if(!_didReportWebRtcOKType
        && (self.ConnectionState == RTCIceConnectionStateConnected ||self.ConnectionState == RTCIceConnectionStateCompleted)){
-        [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats withSessionId:_webRtcChannelSessionId];
+        [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats withSessionId:_webRtcChannelSessionId withLogKey:@""];
         _didReportWebRtcOKType = YES;
         _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
         [_mediaStream setShouldGetStats:NO];
@@ -1065,7 +1068,7 @@
                changeReason:(NSString *)reason
 {
     //HLog(@"webRtc P2P didChangeLocalCandidate")
-    [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcChannelSessionId];
+    [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcChannelSessionId withLogKey:@""];
 }
 
 

+ 14 - 7
创维盒子/code/webRtc/webRtcPlayerViewController.m

@@ -427,7 +427,12 @@
                 if(tryRelinkNum == 2){
                     tryRelinkNum = 0;
                     _didReportWebRtcFailType = YES;
-                    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcPlayerSessionId];
+                    
+                    [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
+                        [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcPlayerSessionId withLogKey:key];
+                    }];
+                    
+                    
                     //[self showLinkPhoneErrorFun];
                     
                     //检测盒子心跳
@@ -443,7 +448,7 @@
 #pragma mark 云机连接不上
 - (void)showLinkPhoneErrorFun
 {
-    [[addLogObject shareInstance] gotoAddLogFun];
+    //[[addLogObject shareInstance] gotoAddLogFun];
     KWeakSelf
     [[errorAlertTool shareInstance] showNetErrorAlertFun:5 didClickBut:^(NSInteger tag) {
         if(tag == 1){
@@ -1162,9 +1167,10 @@
         case RTCIceConnectionStateClosed:{
             if(!_didReportWebRtcFailType){//还没上报过通道链接情况
                 _didReportWebRtcFailType  = YES;
-                [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcPlayerSessionId];
-                
-                //[[addLogObject shareInstance] gotoAddLogFun];
+               
+                [[addLogObject shareInstance] gotoAddLogFunBySuccess:^(NSString * _Nonnull key) {
+                    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:self->_webRtcPlayerSessionId withLogKey:key];
+                }];
             }
             //链接关闭
             [self relinkWebRtcFun];
@@ -1224,7 +1230,8 @@
 -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
     
     if(!_didReportWebRtcOKType){
-        [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:NO withStats:stats withSessionId:_webRtcPlayerSessionId];
+        [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:NO withStats:stats withSessionId:self->_webRtcPlayerSessionId withLogKey:@""];
+        
         _didReportWebRtcOKType = YES;
         _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
     }
@@ -1392,7 +1399,7 @@
                changeReason:(NSString *)reason
 {
     //HLog(@"webRtc P2P didChangeLocalCandidate")
-    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcPlayerSessionId];
+    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcPlayerSessionId withLogKey:@""];
 }
 
 #pragma mark 更新悬浮图标的颜色