瀏覽代碼

1.客户端上报打洞状态

huangxiaodong 1 年之前
父節點
當前提交
fb6476a3da

+ 12 - 0
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -484,6 +484,10 @@
 		6B467BBA2BC7F7D70039A6A6 /* fileUploadToFileCenterModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B467BB72BC7F7D70039A6A6 /* fileUploadToFileCenterModel.m */; };
 		6B467BBB2BC7F7D70039A6A6 /* fileUploadToFileCenterModel.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B467BB62BC7F7D70039A6A6 /* fileUploadToFileCenterModel.h */; };
 		6B4835FD2B9172D7001FC9BA /* usbInsertAnimation.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B4835FC2B9172D7001FC9BA /* usbInsertAnimation.json */; };
+		6B49BFBB2C90472600E17406 /* webRtcManager+StatisticsReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */; };
+		6B49BFBC2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */; };
+		6B49BFBD2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */; };
+		6B49BFBE2C90472600E17406 /* webRtcManager+StatisticsReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */; };
 		6B4C0F622C0314BA0070EF2E /* DFPlayerFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */; };
 		6B4C0F632C0314BA0070EF2E /* DFPlayerFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */; };
 		6B4C0F642C0314BA0070EF2E /* DFPlayerFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4C0F4D2C0314BA0070EF2E /* DFPlayerFileManager.m */; };
@@ -1816,6 +1820,8 @@
 		6B467BB62BC7F7D70039A6A6 /* fileUploadToFileCenterModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fileUploadToFileCenterModel.h; sourceTree = "<group>"; };
 		6B467BB72BC7F7D70039A6A6 /* fileUploadToFileCenterModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = fileUploadToFileCenterModel.m; sourceTree = "<group>"; };
 		6B4835FC2B9172D7001FC9BA /* usbInsertAnimation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = usbInsertAnimation.json; sourceTree = "<group>"; };
+		6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "webRtcManager+StatisticsReport.h"; sourceTree = "<group>"; };
+		6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "webRtcManager+StatisticsReport.m"; sourceTree = "<group>"; };
 		6B4B0B692BEF087E00B62C22 /* 隐私保护.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "隐私保护.entitlements"; sourceTree = "<group>"; };
 		6B4B0B6A2BEF16F200B62C22 /* 计算器.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "计算器.entitlements"; sourceTree = "<group>"; };
 		6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DFPlayerFileManager.h; sourceTree = "<group>"; };
@@ -3056,6 +3062,8 @@
 			children = (
 				6B3E7A802C89CC1300B032C4 /* webRtcManager.h */,
 				6B3E7A812C89CC1300B032C4 /* webRtcManager.m */,
+				6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */,
+				6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */,
 			);
 			path = webRtcManager;
 			sourceTree = "<group>";
@@ -4166,6 +4174,7 @@
 				6B5D40152B47F27A000965CF /* couldPhoneCommonModel.h in Headers */,
 				6B2C1E962C070ADE00FDCF82 /* ZFPlayerMediaPlayback.h in Headers */,
 				6B6ABEDA2BFF3AA400480BAC /* receiveView.h in Headers */,
+				6B49BFBC2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */,
 				18BB18412AC417CB00A36F63 /* RYShearDeviceUDPManager.h in Headers */,
 				6B9354952BF33F2700AA8D31 /* editShareView.h in Headers */,
 				184C8AD52A949D5900F26650 /* AboutViewController.h in Headers */,
@@ -4450,6 +4459,7 @@
 				6BD506F02B9576A4006E7CB0 /* couldPhoneCommonModel.h in Headers */,
 				6B2C1E972C070ADE00FDCF82 /* ZFPlayerMediaPlayback.h in Headers */,
 				6B6ABEDC2BFF3AA400480BAC /* receiveView.h in Headers */,
+				6B49BFBD2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */,
 				6BD506F12B9576A4006E7CB0 /* RYShearDeviceUDPManager.h in Headers */,
 				6B9354962BF33F2700AA8D31 /* editShareView.h in Headers */,
 				6BD506F22B9576A4006E7CB0 /* AboutViewController.h in Headers */,
@@ -4967,6 +4977,7 @@
 				6BD5072D2B9576A4006E7CB0 /* backupsFilerecordTableView.m in Sources */,
 				6B2C1E1F2C070ADE00FDCF82 /* ZFAVPlayerManager.m in Sources */,
 				6B7E042F2C3E5A98004B4948 /* customDownloadManager.m in Sources */,
+				6B49BFBE2C90472600E17406 /* webRtcManager+StatisticsReport.m in Sources */,
 				6B7EA79B2BF5B4A6002D5CC2 /* NASFilePicModel.m in Sources */,
 				6BD5072E2B9576A4006E7CB0 /* HWToolListCell.m in Sources */,
 				6BD5072F2B9576A4006E7CB0 /* cloudPhoneExtraFileListModel.m in Sources */,
@@ -5333,6 +5344,7 @@
 				6B1FBD3B2B467A8000926382 /* backupsFilerecordTableView.m in Sources */,
 				6B2C1E1E2C070ADE00FDCF82 /* ZFAVPlayerManager.m in Sources */,
 				6B7E042E2C3E5A98004B4948 /* customDownloadManager.m in Sources */,
+				6B49BFBB2C90472600E17406 /* webRtcManager+StatisticsReport.m in Sources */,
 				6B7EA7992BF5B4A6002D5CC2 /* NASFilePicModel.m in Sources */,
 				A084D68E27E859D300054880 /* HWToolListCell.m in Sources */,
 				6B45C4FE2B57BC87007E6911 /* cloudPhoneExtraFileListModel.m in Sources */,

+ 9 - 0
创维盒子/双子星云手机/netWork/newWorkInterface.h

@@ -145,4 +145,13 @@
  返回数据模型 */
 #define webrctQueryByClient  @"/box/webrtc/identifier/queryByClient"
 
+/*22 webrtc 链接打洞是否成功  POST请求
+输入参数
+ type 类型 1=apk 2=ios 3=pc
+ status 状态 0=失败 1=打洞连接成功 2=中转连接成功
+ channelType 状态 通道类型 1=数据通道 2=音视频通道
+ clientNetworkStatus 客户端网络状态 0=局域网 1=公网
+ 
+ 返回数据模型 */
+#define webrctLogAdd  @"/box/webrtc/log/add"
 #endif /* newWorkInterface_h */

+ 17 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager+StatisticsReport.h

@@ -0,0 +1,17 @@
+//
+//  webRtcManager+StatisticsReport.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/10.
+//
+
+#import "webRtcManager.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface webRtcManager (StatisticsReport)
+// IsChannel:是否是P2P通道
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats;
+@end
+
+NS_ASSUME_NONNULL_END

+ 83 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager+StatisticsReport.m

@@ -0,0 +1,83 @@
+//
+//  webRtcManager+StatisticsReport.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/10.
+//
+
+#import "webRtcManager+StatisticsReport.h"
+
+@implementation webRtcManager (StatisticsReport)
+// IsChannel:是否是P2P通道
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
+{
+    if(!stats){
+        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:0];
+        return;
+    }
+    
+    NSDictionary *remoteCandidateDict = nil;
+    NSDictionary *localCandidateDict = nil;
+    for (NSString *key in [stats.statistics allKeys]) {
+        RTCStatistics *rtcStatistics = [stats.statistics objectForKey:key];
+        //HLog(@"%@",rtcStatistics)
+        
+        if ([rtcStatistics.type isEqualToString:@"remote-candidate"]) {
+            remoteCandidateDict = rtcStatistics.values;
+            continue;
+        }
+        
+        if ([rtcStatistics.type isEqualToString:@"local-candidate"]) {
+            localCandidateDict = rtcStatistics.values;
+            continue;
+        }
+        
+        if(localCandidateDict && remoteCandidateDict){
+            break;
+        }
+    }
+    
+    if([[localCandidateDict allKeys] containsObject:@"candidateType"]
+       &&[[remoteCandidateDict allKeys] containsObject:@"candidateType"]){
+        NSString *localCandidateType = localCandidateDict[@"candidateType"];
+        NSString *remoteCandidateType = remoteCandidateDict[@"candidateType"];
+        
+        if([localCandidateType isEqualToString:@"relay"]
+           ||[remoteCandidateType isEqualToString:@"relay"]){
+            [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:2];
+        }
+        else{
+            [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:1];
+        }
+        
+    }else{
+        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:2];
+    }
+}
+
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStatus:(int)linkState
+{
+    
+    NSMutableDictionary *paraDict = [NSMutableDictionary new];
+    [paraDict setValue:@2 forKey:@"type"];
+    [paraDict setValue:[NSNumber numberWithInt:linkState] forKey:@"status"];
+    int channelType = IsChannel ? 1 : 2;
+    [paraDict setValue:[NSNumber numberWithInt:channelType] forKey:@"channelType"];
+    int clientNetworkStatus = [pingManager shareManager].isPingOk ? 0 : 1;
+    [paraDict setValue:[NSNumber numberWithInt:clientNetworkStatus] forKey:@"clientNetworkStatus"];
+    
+    [[netWorkManager shareInstance] CommonPostCallBackCode:webrctLogAdd Parameters:paraDict success:^(id  _Nonnull responseObject){
+        
+        SuperModel *curModel = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
+        if(curModel && curModel.status == 0){
+            
+        }
+        else
+        {
+        }
+        
+    } failure:^(NSError * _Nonnull error) {
+        HLog(@"")
+    }];
+}
+@end

+ 1 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.h

@@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
 + (instancetype)shareManager;
 
 @property (nonatomic, strong) AMediaStream *mediaStream;
+@property (nonatomic, assign) BOOL needToReportWebRtcType;
 
 - (void)beginToLinkWebRtcFun;
 @end

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

@@ -6,6 +6,7 @@
 //
 
 #import "webRtcManager.h"
+#import "webRtcManager+StatisticsReport.h"
 
 @interface webRtcManager ()<MediaStreamClientEventsDelegate>
 
@@ -70,11 +71,11 @@
 //                          token:@"vclusters"];
     
     HLog(@"result:%ld",result)
-    //[_mediaStream setShouldGetStats:YES];
+    [_mediaStream setShouldGetStats:YES];
 }
 
 - (void)relinkWebRtcFun{
-    [self relinkWebRtcFun];
+    [self beginToLinkWebRtcFun];
 }
 
 
@@ -119,6 +120,11 @@
 -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
 {
     //HLog(@"didGetStats:%@",stats)
+    if(!_needToReportWebRtcType){
+        [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats];
+        _needToReportWebRtcType = YES;
+        [_mediaStream setShouldGetStats:NO];
+    }
 }
 -(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
 {