Bladeren bron

1.ping 进行中

huangxiaodong 11 maanden geleden
bovenliggende
commit
a7fd1f7d2a

+ 1 - 0
创维盒子/双子星云手机/AppDelegate/SceneDelegate.m

@@ -358,6 +358,7 @@
             
             if(!ksharedAppDelegate.bestWebrtcServerModel){
                 webrtcServerModel *model = curModel.data.webrtcServerList.firstObject;
+                ksharedAppDelegate.bestWebrtcServerModel = model;
             }
             
             [[webRtcManager shareManager] beginToLinkWebRtcFun];

+ 4 - 3
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.m

@@ -112,13 +112,14 @@
     }
     
     webRtcMsgModel * _webRtcMsgMod = ksharedAppDelegate.DeviceWebRtcMsgMod;
+    webrtcServerModel * webrtcServerMod = ksharedAppDelegate.bestWebrtcServerModel;
     
     //链接用
-    NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
+    NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.signallingIp,webrtcServerMod.signallingPort];
     NSURL *url = [NSURL URLWithString:signallingUrl];
     
     //ice用
-    NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
+    NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.turnIp,webrtcServerMod.turnPort];
     
     NSMutableDictionary *ice = [NSMutableDictionary new];
     if(iceUrl){
@@ -129,7 +130,7 @@
     
     NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
     
-    [cachesFileManager writeLogsWithMsg:@"webrtc channel startUploadChannel"];
+    [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"webrtc channel startUploadChannel--%@",signallingUrl]];
     
     //1.盒子开始写20秒日志
     [_mediaStream setCardLogToFile:@"/sdcard/webrtc_box.log" captureTime:@"20"];

+ 28 - 2
创维盒子/双子星云手机/webRtc/webRtcPingManager/webRtcPingManager.m

@@ -59,6 +59,17 @@
         roomInternetIp = model.turnIp;
     }
     else{//完成遍历了
+        
+        NSString *logstr = [[NSString alloc] initWithFormat:@"ping 结束 当前最佳机房IP:%@--延时:%.02fms",ksharedAppDelegate.bestWebrtcServerModel.turnIp,ksharedAppDelegate.bestWebrtcServerModel.delayedms];
+        
+        HLog(@"%@",logstr)
+        [cachesFileManager writeLogsWithMsg:logstr];
+        
+        NSDictionary *bestdict = [ksharedAppDelegate.bestWebrtcServerModel toDictionary];
+        if(bestdict){
+            [HWDataManager setObjectWithKey:@"Const_best_webRtc_IPRoom" value:bestdict];
+        }
+        [[webRtcManager shareManager] relinkWebRtcFun];
         return;
     }
     
@@ -133,16 +144,31 @@
     if (allTimeInPingOneIP > 0) {
         CGFloat averageDelayedms = allTimeInPingOneIP/pingOneIPNumber;
         
-        webrtcServerModel*preBestModel = ksharedAppDelegate.DeviceWebRtcMsgMod;
+        webrtcServerModel*preBestModel = ksharedAppDelegate.bestWebrtcServerModel;
         
         NSArray<webrtcServerModel>* webrtcServerList = ksharedAppDelegate.DeviceWebRtcMsgMod.data.webrtcServerList;
         if (!webrtcServerList || webrtcServerList.count > pingRoomIndex) {
             webrtcServerModel *model = webrtcServerList[pingRoomIndex];
             model.delayedms = averageDelayedms;
             
-            if([model.turnIp isEqualToString:preBestModel.turnIp];)
+            NSString *logstr = [[NSString alloc] initWithFormat:@"time: 平均:%f --%@",averageDelayedms,model.turnIp];
+            HLog(@"%@",logstr)
+            
+            [cachesFileManager writeLogsWithMsg:logstr];
+            
+            if([model.turnIp isEqualToString:preBestModel.turnIp]){
+                preBestModel.delayedms = averageDelayedms;
+            }
+            else{
+                if(preBestModel.delayedms > 0 && model.delayedms < preBestModel.delayedms){
+                    //找到耗时更短的机房
+                    ksharedAppDelegate.bestWebrtcServerModel = model;
+                }
+            }
         }
     }
+    
+    [self startPingNextFun];
 }
 
 @end

+ 6 - 3
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController.m

@@ -180,12 +180,14 @@
 #pragma mark 链接webrtc
 - (void)linkWebRtcFunWithSize:(CGSize)phoneSize
 {
+    webrtcServerModel * webrtcServerMod = ksharedAppDelegate.bestWebrtcServerModel;
+    
     //链接用
-    NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
+    NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.signallingIp,webrtcServerMod.signallingPort];
     NSURL *url = [NSURL URLWithString:signallingUrl];
     
     //ice用
-    NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
+    NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",webrtcServerMod.turnIp,webrtcServerMod.turnPort];
     
     NSMutableDictionary *ice = [NSMutableDictionary new];
     if(iceUrl){
@@ -217,7 +219,8 @@
     //filePathName = /sdcard/webrtc_box.log    captureTime = 30s
     [_mediaStream setCardLogToFile:@"/sdcard/webrtc_box.log" captureTime:@"20"];
 
-    [cachesFileManager writeLogsWithMsg:@"webRtcPlayer start link"];
+    NSString *logstr = [[NSString alloc] initWithFormat:@"webRtcPlayer start link--%@",signallingUrl];
+    [cachesFileManager writeLogsWithMsg:logstr];
     
     //2.客户端开始写日志
     [ksharedAppDelegate.WebRtcLogger start];