浏览代码

fix:兼容webRTC连接失败的场景

leo 1 年之前
父节点
当前提交
76e4961638
共有 2 个文件被更改,包括 16 次插入5 次删除
  1. 9 4
      static/webRtcYJ/WXtrialInterface.html
  2. 7 1
      static/webRtcYJ/rtcEngine.min.js

+ 9 - 4
static/webRtcYJ/WXtrialInterface.html

@@ -83,8 +83,9 @@
     </div>
     <div id="wine">
       <div id="box">
+        <!-- 默认webRTC是关闭状态的 -->
         <video muted poster=""  autoplay="autoplay" webkit-playsinline="" playsinline=""
-        style="object-fit: contain;" id="playVideo"></video>
+        style="object-fit: contain;display: none;" id="playVideo"></video>
         <canvas id="playCanvas" width="450" height="800"></canvas>
       </div>
       <div class="count-view" id="countView">
@@ -340,7 +341,6 @@
     // }
     // 判断是否支持webRTC
     let isVideo = !!(typeof RTCPeerConnection !== 'undefined' && typeof RTCIceCandidate !== 'undefined' && typeof RTCSessionDescription !== 'undefined')
-    $(isVideo ? '#playCanvas' : '#playVideo').css('display', 'none')
     var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
     var url = window.location.href;
     url = url.split('/');
@@ -1081,7 +1081,6 @@
     Module.onRuntimeInitialized = function () {
       isFinish = true;
     };
-
     function decodeAAC(data) {
       var retPtr = Module._malloc(4 * 5 * 1024); //接收的数据
       var inputPtr = Module._malloc(4 * data.length); //输入数据
@@ -1174,6 +1173,12 @@
           console.log('鉴权失败');
         }
     }
+    function successCallback() {
+      console.log('webRTC请求成功了')
+      // 如果支持webRTC,就直接切换成webRTC的画面显示
+      $('#playVideo').show()
+      $('#playCanvas').hide()
+    }
     let extranetIp, extranetPort
     function doConnectBusiness(res) {
       if(isVideo) {
@@ -1222,8 +1227,8 @@
           mode: mode, //可选,默认为自动切换,可以强行指定模式
           debug: true, //可选
           callback: statusCallBack, //回调函数
+          successCallback // 成功请求WEBRTC回调
         };
-        console.log(option, 123456)
         engine = new RtcEngine(option);
         let myVideo = document.getElementById('playVideo');
         // 禁用 <video> 元素的默认控件(例如播放按钮、进度条等)

+ 7 - 1
static/webRtcYJ/rtcEngine.min.js

@@ -8519,6 +8519,7 @@
 						anwser.type = 'answer';
 						log(this.TAG, 'answer:', ret.sdp);
 						this.pc.setRemoteDescription(anwser).then(() => {
+							this.options.successCallback()
 							log(this.TAG, 'set remote sucess');
 						}).catch(e => {
 							error(this.TAG, e);
@@ -8818,6 +8819,7 @@
 	        this.url            = option.url;
 	        this.videoId        = option.videoId;
 	        this.rtcUrl         = option.rtcUrl;
+			this.successCallback = option.successCallback;
 	    }
 
 	    stateCallBack(eventName, value, desc) {
@@ -8869,6 +8871,7 @@
 	            videoEnable:true,
 	            recvOnly:true,
 	            usedatachannel:false,
+				successCallback: this.successCallback
 	        });
 
 	        this.player.on(Events.WEBRTC_ON_REMOTE_STREAMS,function(e)
@@ -8993,6 +8996,7 @@
 			this.rtcUrl = options.rtcUrl;
 			this.mode = options.mode;
 			this.debug = options.debug;
+			this.successCallback = options.successCallback;
 		}
 
 		checkSupportLevel() {
@@ -9062,7 +9066,9 @@
 				videoId:this.videoId,
 				callback:this.callback,
 				rtcUrl:this.rtcUrl,
-				debug:this.debug
+				debug:this.debug,
+				successCallback: this.successCallback
+
 			};
 
 			if(this.mode != undefined) {