Procházet zdrojové kódy

1.wenrtc上报新需求

huangxiaodong před 6 měsíci
rodič
revize
669e929f58

+ 2 - 2
创维盒子/双子星云手机/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;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId;
 
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId;
 
 @end
 

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

@@ -9,11 +9,11 @@
 
 @implementation webRtcManager (StatisticsReport)
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId
 {
     //HLog(@"444444 %@",stats)
     if(!stats){
-        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:0 withPublicIp:@"" withPublicPort:@"" withPrivateIp:@"" withPrivatePort:@""];
+        [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:0 withPublicIp:@"" withPublicPort:@"" withPrivateIp:@"" withPrivatePort:@"" withSessionId:@""];
         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];
+    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:publicIp withPublicPort:publicPort withPrivateIp:privateIp withPrivatePort:privatePort withSessionId:sessionId];
 }
 
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStatus:(int)linkState withPublicIp:(NSString*)publicIp withPublicPort:(NSString*)publicPort withPrivateIp:(NSString*)privateIp withPrivatePort:(NSString*)privatePort
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStatus:(int)linkState withPublicIp:(NSString*)publicIp withPublicPort:(NSString*)publicPort withPrivateIp:(NSString*)privateIp withPrivatePort:(NSString*)privatePort withSessionId:(NSString*)sessionId
 {
     
     NSMutableDictionary *paraDict = [NSMutableDictionary new];
@@ -172,6 +172,9 @@
     [paraDict setValue:[NSNumber numberWithInt:channelType] forKey:@"channelType"];
     int clientNetworkStatus = [pingManager shareManager].isPingOk ? 0 : 1;
     [paraDict setValue:[NSNumber numberWithInt:clientNetworkStatus] forKey:@"clientNetworkStatus"];
+    if(sessionId){
+        [paraDict setValue:sessionId forKey:@"sessionId"];
+    }
     
     if(publicIp){
         [paraDict setValue:publicIp forKey:@"publicIp"];
@@ -205,7 +208,7 @@
 }
 
 // IsChannel:是否是P2P通道
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote{
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId{
     
     // 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;
@@ -240,7 +243,22 @@
     NSString* remoteRelatedPort = remoteSdpArr[11];
     //NSString* remoteNetworkId = remoteSdpArr[11];// 可能为 null
     
-    HLog(@"11");
+   
+    int linkState = 1;
+    if([localType isEqualToString:@"host"]
+       && [remoteType isEqualToString:@"host"]){//内网
+        linkState = 3;
+    }
+    else if([localType isEqualToString:@"relay"]
+       ||[remoteType isEqualToString:@"relay"]){
+        linkState = 2;
+        
+    }
+    else{
+        linkState = 1;
+    }
+    
+    [self reportWebRtcRePoportTypeIsChannel:IsChannel withStatus:linkState withPublicIp:remoteIp withPublicPort:remotePort withPrivateIp:localIp withPrivatePort:localPort withSessionId:sessionId];
 }
 
 @end

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

@@ -26,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
 + (instancetype)shareManager;
 
 @property (nonatomic, strong) AMediaStream *mediaStream;
-@property (nonatomic, assign) BOOL didReportWebRtcType;
+@property (nonatomic, assign) BOOL didReportWebRtcOKType;
+@property (nonatomic, assign) BOOL didReportWebRtcFailType;
 
 @property(nonatomic,assign)BOOL isRebootIngType;//是否重启中
 @property(nonatomic,assign)BOOL isResetingType;//是否恢复出厂中
@@ -45,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
 //下载nas ws 文件 保存到文件 正在弹框中
 @property (nonatomic, assign) BOOL isShowingFileDocumentPickerType;
 
+@property(nonatomic,copy) NSString* webRtcChannelSessionId;//第一次链接webrtc信令的时间
 
 #pragma mark 开始链接
 - (void)beginToLinkWebRtcFun;
@@ -89,7 +91,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 
 #pragma mark 上报打洞是否成功
-- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats;
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withStats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats withSessionId:(NSString*)sessionId;
+
+// IsChannel:是否是P2P通道
+- (void)reportWebRtcRePoportTypeIsChannel:(BOOL)IsChannel withLocal:(RTC_OBJC_TYPE(RTCIceCandidate) *)local remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote withSessionId:(NSString*)sessionId;
 @end
 
 NS_ASSUME_NONNULL_END

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

@@ -44,6 +44,8 @@
         [ksharedAppDelegate.WebRtcLogger start];
         HLog(@"webrtc :%@",ksharedAppDelegate.WebRtcLogger)
         
+        _webRtcChannelSessionId = [iTools getNowTimeStampString];
+        
         _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
         [_mediaStream setEventDelegate:self];
         
@@ -68,11 +70,11 @@
           && _ConnectionState != RTCIceConnectionStateCompleted)
        ){
         
-        if(!_didReportWebRtcType){//还没上报过通道链接情况
+        if(!_didReportWebRtcFailType){//还没上报过通道链接情况
             tryRelinkNum ++;
             if(tryRelinkNum == 2){
-                _didReportWebRtcType = YES;
-                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil];
+                _didReportWebRtcFailType = YES;
+                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcChannelSessionId];
             }
         }
         
@@ -939,8 +941,9 @@
         case RTCIceConnectionStateFailed:
         case RTCIceConnectionStateDisconnected:
         case RTCIceConnectionStateClosed:{
-            if(!_didReportWebRtcType){//还没上报过通道链接情况
-                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil];
+            if(!_didReportWebRtcFailType){//还没上报过通道链接情况
+                _didReportWebRtcFailType = YES;
+                [self reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcChannelSessionId];
                 
                 //[[addLogObject shareInstance] gotoAddLogFun];
             }
@@ -1008,10 +1011,11 @@
 -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats
 {
     //HLog(@"didGetStats:%@",stats)
-    if(!_didReportWebRtcType
+    if(!_didReportWebRtcOKType
        && (self.ConnectionState == RTCIceConnectionStateConnected ||self.ConnectionState == RTCIceConnectionStateCompleted)){
-        [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats];
-        _didReportWebRtcType = YES;
+        [self reportWebRtcRePoportTypeIsChannel:YES withStats:stats withSessionId:_webRtcChannelSessionId];
+        _didReportWebRtcOKType = YES;
+        _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
         [_mediaStream setShouldGetStats:NO];
     }
 }
@@ -1027,7 +1031,7 @@
                changeReason:(NSString *)reason
 {
     //HLog(@"webRtc P2P didChangeLocalCandidate")
-    [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote];
+    [self reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcChannelSessionId];
 }
 
 @end

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

@@ -35,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic,strong) webRtcMsgModel * webRtcMsgMod;
 @property(nonatomic,assign) BOOL isCodeSuspendAudioType;//手动暂停播放音乐
 
+@property(nonatomic,copy) NSString* webRtcPlayerSessionId;//进入推流的时间
+
 #pragma mark 重连
 - (void)relinkWebRtcFunByBecomeActive;
 

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

@@ -32,7 +32,8 @@
 @property (nonatomic, copy)   NSTimer      *playerSecondTimer; // 定时器-控制按钮
 @property (nonatomic, assign) RTCIceConnectionState linkState;
 @property (nonatomic, assign) BOOL didHandleRotation;//第一次处理旋转
-@property (nonatomic, assign) BOOL didReportWebRtcType;//上报打洞是否成功
+@property (nonatomic, assign) BOOL didReportWebRtcOKType;//上报打洞是否成功
+@property (nonatomic, assign) BOOL didReportWebRtcFailType;//上报打洞是否成功
 
 @property (nonatomic, strong)playerSetView *playerSetV;//推流设置页
 @end
@@ -50,6 +51,8 @@
     [self.navBarBGView setHidden:YES];
     [self.view setBackgroundColor:[UIColor blackColor]];
     
+    _webRtcPlayerSessionId = [iTools getNowTimeStampString];
+    
     if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
        ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying){
         _isCodeSuspendAudioType = YES;
@@ -387,12 +390,12 @@
         if(_linkState != RTCIceConnectionStateConnected
            && _linkState != RTCIceConnectionStateCompleted){
             
-            if(!_didReportWebRtcType){//还没上报过通道链接情况
+            if(!_didReportWebRtcFailType){//还没上报过通道链接情况
                 tryRelinkNum ++;
                 if(tryRelinkNum == 2){
                     tryRelinkNum = 0;
-                    _didReportWebRtcType = YES;
-                    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil];
+                    _didReportWebRtcFailType = YES;
+                    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcPlayerSessionId];
                     [self showLinkPhoneErrorFun];
                 }
             }
@@ -1114,8 +1117,9 @@
         case RTCIceConnectionStateFailed:
         case RTCIceConnectionStateDisconnected:
         case RTCIceConnectionStateClosed:{
-            if(!_didReportWebRtcType){//还没上报过通道链接情况
-                [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil];
+            if(!_didReportWebRtcFailType){//还没上报过通道链接情况
+                _didReportWebRtcFailType  = YES;
+                [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withStats:nil withSessionId:_webRtcPlayerSessionId];
                 
                 //[[addLogObject shareInstance] gotoAddLogFun];
             }
@@ -1176,9 +1180,10 @@
 
 -(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
     
-    if(!_didReportWebRtcType){
-        [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:NO withStats:stats];
-        _didReportWebRtcType = YES;
+    if(!_didReportWebRtcOKType){
+        [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:NO withStats:stats withSessionId:_webRtcPlayerSessionId];
+        _didReportWebRtcOKType = YES;
+        _didReportWebRtcFailType = NO;//链接成功后 失败要重新上报
     }
     
     NSString *selectedCandidatePairId = nil;
@@ -1406,6 +1411,16 @@
     
 }
 
+- (void)connectionChange:(NSString*)peerName
+    didChangeLocalCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)local
+            remoteCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)remote
+             lastReceivedMs:(int)lastDataReceivedMs
+               changeReason:(NSString *)reason
+{
+    //HLog(@"webRtc P2P didChangeLocalCandidate")
+    [[webRtcManager shareManager] reportWebRtcRePoportTypeIsChannel:YES withLocal:local remoteCandidate:remote withSessionId:self.webRtcPlayerSessionId];
+}
+
 #pragma mark 更新悬浮图标的颜色
 - (void)updateControlBtnBgImageWith:(NSInteger)delayedMS{
     if (delayedMS < 50) {