|
@@ -87,9 +87,6 @@
|
|
</div>
|
|
</div>
|
|
<div id="wine">
|
|
<div id="wine">
|
|
<div id="box">
|
|
<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>
|
|
<canvas id="playCanvas" width="450" height="800"></canvas>
|
|
</div>
|
|
</div>
|
|
<div class="count-view" id="countView">
|
|
<div class="count-view" id="countView">
|
|
@@ -351,23 +348,6 @@
|
|
// let vc = new VConsole()
|
|
// let vc = new VConsole()
|
|
let webSocketWorker = null
|
|
let webSocketWorker = null
|
|
let getResidueTimeBool = true
|
|
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 =
|
|
var isDev =
|
|
/^192\.168\./.test(location.host) || /^localhost/.test(location.host);
|
|
/^192\.168\./.test(location.host) || /^localhost/.test(location.host);
|
|
@@ -387,7 +367,6 @@
|
|
var username = parameters['username'];
|
|
var username = parameters['username'];
|
|
var connectStatus = parameters['connectStatus'];
|
|
var connectStatus = parameters['connectStatus'];
|
|
var isTips = +parameters['isTips'];
|
|
var isTips = +parameters['isTips'];
|
|
- var isWeixin = +parameters['isWeixin'];
|
|
|
|
var videoTimer = null,
|
|
var videoTimer = null,
|
|
videoTime = 0,
|
|
videoTime = 0,
|
|
adType = 0,
|
|
adType = 0,
|
|
@@ -484,7 +463,7 @@
|
|
|
|
|
|
request.onsuccess = function (event) {
|
|
request.onsuccess = function (event) {
|
|
console.log('主键查询结果: ', request.result);
|
|
console.log('主键查询结果: ', request.result);
|
|
- if (request.result && !isVideo) {
|
|
|
|
|
|
+ if (request.result) {
|
|
socketURL = request.result.socketURL;
|
|
socketURL = request.result.socketURL;
|
|
cUrl = request.result.cUrl;
|
|
cUrl = request.result.cUrl;
|
|
cardToken = request.result.cardToken;
|
|
cardToken = request.result.cardToken;
|
|
@@ -1219,86 +1198,8 @@
|
|
}
|
|
}
|
|
return obj;
|
|
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;
|
|
let extranetIp, extranetPort, connectClearSetInterval, numberOfTimes = 1;
|
|
function doConnectBusiness(res) {
|
|
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(
|
|
webSocketWorker = new Worker(
|
|
'websocket.js?socketURL=' +
|
|
'websocket.js?socketURL=' +
|
|
encodeURIComponent(socketURL) +
|
|
encodeURIComponent(socketURL) +
|
|
@@ -1308,7 +1209,7 @@
|
|
window.webSocketWorker = webSocketWorker;
|
|
window.webSocketWorker = webSocketWorker;
|
|
webSocketWorker.onmessage = function (event) {
|
|
webSocketWorker.onmessage = function (event) {
|
|
var input = event.data;
|
|
var input = event.data;
|
|
- if (input[0] == 0xff && isAudioPlay && !isVideo) {
|
|
|
|
|
|
+ if (input[0] == 0xff && isAudioPlay) {
|
|
decodeAAC(input);
|
|
decodeAAC(input);
|
|
}
|
|
}
|
|
if (
|
|
if (
|
|
@@ -1339,7 +1240,6 @@
|
|
return
|
|
return
|
|
}
|
|
}
|
|
numberOfTimes++
|
|
numberOfTimes++
|
|
- engine && engine.disconnect();
|
|
|
|
wsss && wsss.close();
|
|
wsss && wsss.close();
|
|
webSocketWorker && webSocketWorker.postMessage('endRequest');
|
|
webSocketWorker && webSocketWorker.postMessage('endRequest');
|
|
decodeWoker && decodeWoker.postMessage('close');
|
|
decodeWoker && decodeWoker.postMessage('close');
|
|
@@ -1426,7 +1326,6 @@
|
|
type: 'get',
|
|
type: 'get',
|
|
dataType: 'json',
|
|
dataType: 'json',
|
|
success: function (res) {
|
|
success: function (res) {
|
|
- console.log(res);
|
|
|
|
let obj = res.data;
|
|
let obj = res.data;
|
|
if (res.status === 0) {
|
|
if (res.status === 0) {
|
|
resolve(obj);
|
|
resolve(obj);
|
|
@@ -1903,7 +1802,6 @@
|
|
let quitBool = true
|
|
let quitBool = true
|
|
function quit() {
|
|
function quit() {
|
|
// 退出云机页时,把所有链接都关闭掉
|
|
// 退出云机页时,把所有链接都关闭掉
|
|
- engine && engine.disconnect();
|
|
|
|
wsss && wsss.close();
|
|
wsss && wsss.close();
|
|
decodeWoker && decodeWoker.postMessage('close');
|
|
decodeWoker && decodeWoker.postMessage('close');
|
|
decodeWoker && decodeWoker.terminate();
|
|
decodeWoker && decodeWoker.terminate();
|