Kaynağa Gözat

去除旧版webRTC

leo 9 ay önce
ebeveyn
işleme
2a47bf4ef5
2 değiştirilmiş dosya ile 3 ekleme ve 106 silme
  1. 1 2
      static/webRtcYJ/WXdraw.js
  2. 2 104
      static/webRtcYJ/WXtrialInterface.html

+ 1 - 2
static/webRtcYJ/WXdraw.js

@@ -106,7 +106,7 @@ function doConnectDirectives() {
     // 获取虚拟场景状态
     intervalerPing = setInterval(() => {
       if (wsss.readyState === 1) {
-        wsss.send('ping');
+        wsss.send(JSON.stringify({type: 'ping'}));
       } else {
         clearInterval(intervalerPing);
       }
@@ -453,7 +453,6 @@ $('.PictureQuality').on('click', function () {
   decodeWoker.postMessage(cmd); //通知解码器worker切换分辨率
   var buffer = makeSharpness(Number(id));
   webSocketWorker.postMessage(buffer);
-  engine && engine.switchShapness(Number(id))
   $('.control-right-img').attr({
     'data-id': '1',
   });

+ 2 - 104
static/webRtcYJ/WXtrialInterface.html

@@ -87,9 +87,6 @@
     </div>
     <div id="wine">
       <div id="box">
-        <!-- 默认webRTC是关闭状态的 -->
-        <video muted poster="" autoplay="autoplay" webkit-playsinline="" playsinline=""
-          style="object-fit: contain; display: none" id="playVideo"></video>
         <canvas id="playCanvas" width="450" height="800"></canvas>
       </div>
       <div class="count-view" id="countView">
@@ -351,23 +348,6 @@
     // let vc = new VConsole()
     let webSocketWorker = null
     let getResidueTimeBool = true
-    // 判断是否是苹果手机
-    let isiPhone = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
-    // 判断是否支持webRTC
-    let isVideo = !!(
-      typeof RTCPeerConnection !== 'undefined' &&
-      typeof RTCIceCandidate !== 'undefined' &&
-      typeof RTCSessionDescription !== 'undefined'
-    );
-    // 判断是否是uc浏览器
-    let isUc = navigator.userAgent.indexOf('UCBrowser') > -1;
-    // 判断是否是QQ浏览器
-    let isQQ = navigator.userAgent.indexOf('MQQBrowser') > -1;
-    // 判断是否是Safari浏览器
-    let isSafari = navigator.userAgent.indexOf("Safari") > -1;
-    // 如果是苹果手机、且是uc浏览器或者是QQ浏览器或者是Safari浏览器,就不显示webRTC
-    let isShowiPhoneWebRTC = isiPhone && (isUc || isQQ || isSafari)
-    let engine = null;
     // 开发环境
     var isDev =
       /^192\.168\./.test(location.host) || /^localhost/.test(location.host);
@@ -387,7 +367,6 @@
     var username = parameters['username'];
     var connectStatus = parameters['connectStatus'];
     var isTips = +parameters['isTips'];
-    var isWeixin = +parameters['isWeixin'];
     var videoTimer = null,
       videoTime = 0,
       adType = 0,
@@ -484,7 +463,7 @@
 
       request.onsuccess = function (event) {
         console.log('主键查询结果: ', request.result);
-        if (request.result && !isVideo) {
+        if (request.result) {
           socketURL = request.result.socketURL;
           cUrl = request.result.cUrl;
           cardToken = request.result.cardToken;
@@ -1219,86 +1198,8 @@
       }
       return obj;
     }
-    //状态回调以及处理
-    function statusCallBack(event) {
-      if (event.type == 'open') {
-        $('.weui-mask_transparent').hide();
-        $('.weui-toast').hide();
-        // $('.loading').hide();
-        console.log('流已经打开');
-      }
-
-      if (event.type == 'screenChange') {
-        console.log('横竖屏切换事件:' + event.val);
-      }
-
-      if (event.type == 'verifyFailed') {
-        console.log('鉴权失败');
-      }
-    }
-    function successCallback() {
-      console.log('webRTC请求成功了');
-      // 如果支持webRTC,就直接切换成webRTC的画面显示
-      $('#playVideo').show();
-      $('#playCanvas').hide();
-    }
     let extranetIp, extranetPort, connectClearSetInterval, numberOfTimes = 1;
     function doConnectBusiness(res) {
-      if (isVideo && !isShowiPhoneWebRTC && !isWeixin) {
-        var url0 = url[0]; //协议
-        let ip = res.data.internetIp; //服务器拿到的ip
-        let port = res.data.internetVideoPort; //服务器拿到的端口
-        extranetIp = res.data.internetIp;
-        extranetPort = res.data.internetVideoPort;
-
-        let rtcUrl, wsUrl;
-        if (url0 == 'https:') {
-          rtcUrl =
-            'https://' +
-            res.data.internetHttps +
-            '/webrtc?cardIp=' +
-            res.data.localIp;
-          wsUrl =
-            'wss://' +
-            res.data.internetHttps +
-            '/plugflow?cardIp=' +
-            res.data.localIp;
-        } else {
-          rtcUrl =
-            'http://' +
-            ip +
-            ':' +
-            port +
-            '/index/api/webrtc?app=live&stream=h264&type=play';
-          wsUrl = 'ws://' + ip + ':' + port + '/plugflow';
-        }
-        let token = res.data.cardToken;
-        let videoId = 'playVideo';
-        let mode = 'webrtc'; //指定解码模式, 目前支持mse、webrtc
-        // let ip = res.data.internetIp; //服务器拿到的ip
-        // let port = res.data.internetVideoPort; //服务器拿到的端口
-        // let rtcUrl = "http://" + ip + ":" + port + "/index/api/webrtc?app=live&stream=test&type=play";
-        // let wsUrl = "ws://" + ip + ":" + port + '/plugflow';
-        // let token = res.data.cardToken;
-        // let videoId = "playCanvas";
-        // let mode = "webrtc"; //指定解码模式, 目前支持mse、webrtc
-        let option = {
-          url: wsUrl, //websocket url
-          rtcUrl: rtcUrl, //webrtc 推流地址,webrtc 推流时必须要填
-          token: token, //用于校验的token
-          videoId: videoId, //视频标签ID
-          mode: mode, //可选,默认为自动切换,可以强行指定模式
-          debug: true, //可选
-          callback: statusCallBack, //回调函数
-          successCallback, // 成功请求WEBRTC回调
-        };
-        engine = new RtcEngine(option);
-        let myVideo = document.getElementById('playVideo');
-        // 禁用 <video> 元素的默认控件(例如播放按钮、进度条等)
-        myVideo.controls = false;
-        // 启动视频流连接过程。这将根据之前配置的参数建立与服务器的 WebSocket 连接,并开始视频流的传输和播放。
-        engine.connect();
-      }
       webSocketWorker = new Worker(
         'websocket.js?socketURL=' +
         encodeURIComponent(socketURL) +
@@ -1308,7 +1209,7 @@
       window.webSocketWorker = webSocketWorker;
       webSocketWorker.onmessage = function (event) {
         var input = event.data;
-        if (input[0] == 0xff && isAudioPlay && !isVideo) {
+        if (input[0] == 0xff && isAudioPlay) {
           decodeAAC(input);
         }
         if (
@@ -1339,7 +1240,6 @@
                   return
                 }
                 numberOfTimes++
-                engine && engine.disconnect();
                 wsss && wsss.close();
                 webSocketWorker && webSocketWorker.postMessage('endRequest');
                 decodeWoker && decodeWoker.postMessage('close');
@@ -1426,7 +1326,6 @@
           type: 'get',
           dataType: 'json',
           success: function (res) {
-            console.log(res);
             let obj = res.data;
             if (res.status === 0) {
               resolve(obj);
@@ -1903,7 +1802,6 @@
     let quitBool = true
     function quit() {
       // 退出云机页时,把所有链接都关闭掉
-      engine && engine.disconnect();
       wsss && wsss.close();
       decodeWoker && decodeWoker.postMessage('close');
       decodeWoker && decodeWoker.terminate();