Commit e95b55ca authored by zhangjianqian's avatar zhangjianqian

修改配置

parent 20ace91e
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* video工具类
* @author savage
* @version 1.0.2
* @update 2017-02-10 13:53:46
* @author xiyongqiang
* @version 1.4.3
* @update 2019-12-13
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
} else if (typeof exports === 'object') {
// Node, CommonJS之类的
module.exports = factory(require('jquery'));
} else {
} else {
// 浏览器全局变量(root 即 window)
root.scooper = root.scooper || {};
root.scooper.video = factory(root.jQuery);
}
}(this, function ($) {
}
}(window, function ($) {
"use strict";
window.console = window.console || (function(){
......@@ -68,6 +68,7 @@ if (typeof define === 'function' && define.amd) {
}
/**
* 公共方法
* 克隆对象
* 让新出来的对象是独立的
*/
......@@ -92,27 +93,83 @@ if (typeof define === 'function' && define.amd) {
* 公共方法
* 提示
*/
var showPrompt = true;
function promptSuccess(msg, type) {
console.log(msg);
//panduanpromptView弹层对象是否引入
"undefined" != typeof(promptView) && promptView.showSuccess(msg);
'undefined' != typeof(promptView) && showPrompt && promptView.showSuccess(msg);
}
function promptFailed(msg, type) {
console.error(msg);
"undefined" != typeof(promptView) && promptView.showFailed(msg);
'undefined' != typeof(promptView) && showPrompt && promptView.showFailed(msg);
}
function promptAlarm(msg, type) {
console.info(msg);
"undefined" != typeof(promptView) && promptView.showAlarm(msg);
'undefined' != typeof(promptView) && showPrompt && promptView.showAlarm(msg);
}
/**
* 公共方法
* 判断能否获取本地声卡设备
*/
function checkUserMediaAvailable() {
return Janus.isGetUserMediaAvailable() && !checkIsHttp() && window.hasAudioInputDevices;
}
/**
* 公共方法
* 是否有声卡设备
* 异步方法 结果保存在window.hasAudioInputDevices中 true or false
*/
function hasMediaDevices() {
if (window.checkAudioDevicesStatus != undefined && window.hasAudioInputDevices != undefined) {
//已检测
return;
}
//参数初始化,防止为空报错
window.checkAudioDevicesStatus = false;
window.hasAudioInputDevices = false;
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
console.log("Not support enumerateDevices() .");
return;
}
var startTime = new Date().getTime();
// 列出相机和麦克风.
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
if (device.kind == "audioinput") {
//判断到1个就返回true
window.hasAudioInputDevices = true;
}
});
window.checkAudioDevicesStatus = true;
console.log("检查音频输入设备总计耗时: " + (new Date().getTime() - startTime) + "ms");
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
});
}
/**
* 公共方法
* 判断是否是安全连接
* 判断是否是http 或者 https
*/
function checkIsHttp() {
var protocolStr = document.location.protocol;
if(protocolStr == "http:" && window.location.hostname != "localhost" ) return true;
if(protocolStr == "http:" || window.location.hostname == "localhost" ) return true;
return false;
}
/**
* 公共方法
* 判断是否是https 和检测http分开的目的是还有本地打开的情况(前缀为file:)
* webrtc规定打开摄像头、麦克风需要加密传输 所以需要再https环境下, 本地打开不需要加密 可以正常获取
* 这也是分开的另一个目的
*/
function checkIsHttps() {
var protocolStr = document.location.protocol;
if(protocolStr == "https:") return true;
return false;
}
......@@ -140,11 +197,30 @@ if (typeof define === 'function' && define.amd) {
return;
clearInterval(this.timerId);
this.timerId = 0;
if (waitTimerId) {
clearTimeout(waitTimerId);
waitTimerId = null;
}
};
return PollTimer;
}());
//事件
var waitTimerId = 0;
function wait(time) {
return new Promise(function(resolve, reject) {
if (waitTimerId) {
clearTimeout(waitTimerId);
waitTimerId = null;
}
waitTimerId = setTimeout(resolve, time);
});
}
/**
* 事件
*/
function Listener() {
// 在构造函数中进行初始化
this._listeners = {};
......@@ -156,7 +232,7 @@ if (typeof define === 'function' && define.amd) {
/**
* 添加事件
*/
addListener: function(type,handler,key){
addListener: function(type, handler, key){
if (typeof handler != 'function') {
return;
}
......@@ -179,7 +255,7 @@ if (typeof define === 'function' && define.amd) {
/**
* 删除事件
*/
removeListener: function(type,handler){
removeListener: function(type, handler){
type.indexOf("on") != 0 && (type = "on" + type);
var t = this._listeners;
if (!t[type]) {
......@@ -196,10 +272,11 @@ if (typeof define === 'function' && define.amd) {
t[type] = {};
}
},
/**
* 派发事件
*/
dispatch: function(e,options){
dispatch: function(e, options){
if (typeof e == 'string') {
e = new VideoEvent(e);
}
......@@ -218,6 +295,13 @@ if (typeof define === 'function' && define.amd) {
}
}
return e.returnValue;
},
/**
* 清空事件
*/
removeAllListeners: function () {
this._listeners = {};
}
}
......@@ -286,7 +370,8 @@ if (typeof define === 'function' && define.amd) {
playByOrder: function(video, id, opts){
var freeWindow = this._getMinIndexFreeWindow(0);
if(freeWindow == -1){
if(freeWindow == -1 &&
(this._getChoiceWindow() != -1 && !this.getInChoiceVideo())){
return this.playInChoice(video,id,opts);
}
return this.play(freeWindow,video,id,opts);
......@@ -299,7 +384,9 @@ if (typeof define === 'function' && define.amd) {
var freeWindow = this._getMinIndexFreeWindow(0);
while (this._opts.windows < 16 && freeWindow == -1) {
var maxWindows = this._opts.windowsNum || 16;
while (this._opts.windows < maxWindows && freeWindow == -1) {
var zoom = Math.sqrt(this._opts.windows*1)+1;
if (this._opts.windows == 6) {
......@@ -363,14 +450,32 @@ if (typeof define === 'function' && define.amd) {
},
/**
* 关闭语音
* @param window
* 判断指定窗口是否正在播放视频
*/
isPlayingByIndex: function(index){
return this.videoStatus[index] && true;
},
/**
* 获取视频数据
*/
closeVoice : function(window) {
getVideoData: function(){
return this.videoStatus;
},
this._obj.CWebVoiceComControl(window,0);
/**
* 关闭语音
* @param index
*/
closeVoice: function(index) {
this._obj.SCWebVoiceComControl(this.videoStatus[index].video, this.videoStatus[index].playId, 0);
},
/**
* 根据playId获取窗口
* @param playId
* IE下才有该方法
*/
getWindowByPlayId: function(playId) {
var index = -1;
$.each(this.videoStatus,function(key,val){
......@@ -382,6 +487,11 @@ if (typeof define === 'function' && define.amd) {
return index;
},
/**
* 根据窗口获取playId
* @param index
* IE下才有该方法
*/
getPlayIdBywindow : function(index) {
return this.videoStatus[index].playId;
},
......@@ -389,7 +499,7 @@ if (typeof define === 'function' && define.amd) {
/**
* 关闭指定窗口的视频
*/
close: function(index,isSave){
close: function(index, isSave){
if (!this.videoStatus[index] || index >= this._opts.windows || this._disableClosed.indexOf(index*1) > -1 ) {
return;
......@@ -405,12 +515,37 @@ if (typeof define === 'function' && define.amd) {
},
/**
* 关闭指定视频编号正在播放的视频
*/
closeByVideo: function(video, isSave){
var me = this;
if (video == undefined) {
console.info('video参数错误');
return;
}
var videoData = me.videoStatus;
if (!videoData || videoData.length == 0) {
return;
}
for (var i in videoData) {
if (video == videoData[i].video) {
me.close(videoData[i].index);
}
}
},
/**
*
*/
closeHistory: function(playId) {
var close = this._obj.SCWebStopRealPlay(playId);
console.log("close = "+close);
var index = this._getChoiceWindow();
delete this.videoStatus[index];
},
/**
......@@ -421,9 +556,11 @@ if (typeof define === 'function' && define.amd) {
var me = this;
isSave || (this._disableClosed = []);
var windows = me._obj.SCWebGetRealPlayWindows();
console.log('要关闭的视频窗:' + windows);
if (windows) {
$.each(windows.split(','),function(i,index){
me.close(index,isSave);
console.log('窗口:' + i);
});
}
},
......@@ -450,6 +587,7 @@ if (typeof define === 'function' && define.amd) {
getWindowsNum: function() {
return this._opts.windows;
},
/**
* 是否还有空闲窗口
*/
......@@ -519,8 +657,17 @@ if (typeof define === 'function' && define.amd) {
nowNum = 0 ;
me.saveList();
this._polltimer = new PollTimer(function(firstRun){
//延迟
me.delayTimeId = 0;
me._polltimer = new PollTimer(function(firstRun){
me.closeAll();
if (me.delayTimeId) {
clearTimeout(me.delayTimeId);
}
me.delayTimeId = setTimeout(function() {
for(var i = 0; i < windowNum; i++) {
if(nowNum == maxNum){
nowNum = 0;
......@@ -535,6 +682,7 @@ if (typeof define === 'function' && define.amd) {
if (firstRun) {
me.dispatch('startpoll', array);
}
}, 1000)
}, time);
},
......@@ -623,7 +771,7 @@ if (typeof define === 'function' && define.amd) {
}
$.extend(_opts,opts);
this._obj.SCWebPTZControl(video, 0,
typeVal, _opts.speed, _opts.group, _opts.present, _opts.time);
typeVal, _opts.speed, _opts.group, 1, _opts.time);
console.log('设备号:'+ video +', 云台移动-->'+ type);
},
......@@ -634,7 +782,28 @@ if (typeof define === 'function' && define.amd) {
* @return playId
*/
playHistory: function(video,startTime,endTime,opts) {
return this._obj.SCWebHistoryPlay(video,startTime,endTime);
var me = this;
var playId = me._obj.SCWebHistoryPlay(video, startTime, endTime);
console.log("play = " + playId);
if (playId < 0) {
var name = opts.name || '视频';
promptFailed(name + '播放失败!');
return playId;
}
var index = me._getChoiceWindow();
opts = opts || {};
playId > 0 && (me.videoStatus[index] = {
video: video,
id: video,
playId: playId,
opts: opts,
isPlayBack: true
}, me.dispatch('playsuccess', me.videoStatus[index]));
return playId;
},
/**
......@@ -737,6 +906,15 @@ if (typeof define === 'function' && define.amd) {
return this._opts;
},
/**
* 获取截屏数据
*/
getScreenCaptureData: function(index, callback) {
var msg = 'IE下暂不支持获取截屏数据!';
console.log(msg)
throw Error(msg);
},
/**
* 添加事件
*/
......@@ -757,6 +935,13 @@ if (typeof define === 'function' && define.amd) {
videoListener.dispatch(e,options);
},
/**
* 获取ocx的版本信息
*/
getOcxVersion: function() {
return this._obj.SCWebDecoderGetVersion();
},
/*
* 总的初始化
* 参数示例:
......@@ -813,10 +998,14 @@ if (typeof define === 'function' && define.amd) {
return;
}
//是否提示
me._opts.showPrompt === false && (showPrompt = false);
//事件注册区域
me._addStopHandler();
me._addClickHandler();
me._addHishandler();
me._addHisHandler();
me._addCapPicHandler();
me._addHistoryPlayHandler();
//浏览器刷新/关闭前执行
me._beforeUnload();
......@@ -844,6 +1033,7 @@ if (typeof define === 'function' && define.amd) {
console.log('init:' + init);
//是否开启抓图
conf.ip == '127.0.0.1' && (conf.ip = location.hostname);
var login;
if(conf.token && conf.token.length > 0 && me._obj.SCWebDecoderLoginInVS_Token) {
......@@ -917,7 +1107,7 @@ if (typeof define === 'function' && define.amd) {
/**
* 切换分屏
*/
/* _changeWindowsAction: function(num) {
/* _changeWindowsAction: function(num) {
var me = this,
old = me._opts.windows,
now = num,
......@@ -1034,8 +1224,14 @@ if (typeof define === 'function' && define.amd) {
_addStopHandler: function() {
var me = this;
window.stopVideo = function(playId,videoId) {
if (me.getWindowByPlayId(playId) != -1 &&
me.videoStatus[me.getWindowByPlayId(playId)].isPlayBack) {
me.closeHistory(playId);
} else {
me.close(me.getWindowByPlayId(playId));
me.dispatch('streamoff');
}
me.dispatch('streamoff', {playId:playId,videoId:videoId});
};
me._regEvent('SCWebStopVideoEvent(playId,videoId)', 'stopVideo(playId,videoId);');
......@@ -1049,7 +1245,7 @@ if (typeof define === 'function' && define.amd) {
me._regEvent('SCWebDecoderClick(playId,type)', 'clickVideo(playId);');
},
_addHishandler: function() {
_addHisHandler: function() {
var me = this;
window.playbackVideo = function(playId,videoId,historytime) {
me.dispatch('playback',{playId:playId,videoId:videoId,historyTime:historytime});
......@@ -1057,6 +1253,24 @@ if (typeof define === 'function' && define.amd) {
me._regEvent('SCWebHistoryPlayTime(playId,videoId,historytime)', 'playbackVideo(playId,videoId,historytime);');
},
//监听截图事件
_addCapPicHandler: function() {
var me = this;
window.getCapPicPath = function(playId, capPicPath, capPicName) {
me.dispatch('getCapPicPath', {playId:playId, capPicPath:capPicPath, capPicName: capPicName});
};
me._regEvent('SCWebGetCapPicPathName(playId, capPicPath, capPicName)', 'getCapPicPath(playId, capPicPath, capPicName);');
},
//监听点击视频框的历史回放
_addHistoryPlayHandler: function() {
var me = this;
window.historyPlay = function(playId, videoId) {
me.dispatch('historyPlay', {playId:playId, videoId:videoId});
};
me._regEvent('SCWebHistoryPlayEvent(playId, videoId)', 'historyPlay(playId, videoId);');
},
_regEvent: function(eventName,handlerName) {
window._addScriptFlag = true;
var script;
......@@ -1094,11 +1308,28 @@ if (typeof define === 'function' && define.amd) {
* 使用webRtc方式的video工具类
*/
function VideoWebRtc($dom,opts){
var _self = this;
if (!opts) {
console.error('VideoWebRtc的参数opts不能为空');
return;
}
this._init($dom,opts);
hasMediaDevices();
//检测声卡设备为异步方法,耗时在几十毫秒左右,因此需要做延迟
//默认检查次数为40 间隔为20ms
var count = 0;
var index = setInterval(function () {
if (count == 40) {
clearInterval(index);
_self._init($dom,opts);
} else {
if (window.checkAudioDevicesStatus) {
clearInterval(index);
_self._init($dom,opts);
}
}
count++;
}, 20);
}
/**
......@@ -1112,13 +1343,19 @@ if (typeof define === 'function' && define.amd) {
/**
* 播放视频
* 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
* opts.businessType 0:调度业务 1:勤指
* 返回true/false
*/
play: function(index, video, id, opts){
var me = this;
if (me.isPlaying(id) != -1) {
console.info('该视频正在播放');
return false;
// if (me.isPlaying(id) != -1) {
// console.info('该视频正在播放');
// return false;
// }
// 启用播放队列时,当前位置正在关闭上一个视频,则加入播放队列
if (me.waitPlayQueueSwitch && me.VIDEO_DATA[index].isClosing) {
me._addWaitingVideo(index, video, id, opts);
return ;
}
console.log("play >>> " + "video=" + video + "; id=" + id + "; index=" + index);
me.dispatch('beforeplay',{index:index, video:video, id:id});
......@@ -1148,9 +1385,11 @@ if (typeof define === 'function' && define.amd) {
playByOrder: function(video, id, opts){
var freeWindow = this._getMinIndexFreeWindow();
if(freeWindow == -1){
return this.playInChoice(video, id, opts);
if(freeWindow == -1 &&
(this._getChoiceWindow() != -1 && !this.getInChoiceVideo() && this._opts.windowsNum > 1)){
return this.playInChoice(video,id,opts);
}
return this.play(freeWindow, video, id, opts);
},
......@@ -1167,7 +1406,9 @@ if (typeof define === 'function' && define.amd) {
// freeWindow = this._getMinIndexFreeWindow(0);
// }
while (freeWindow == -1) {
var maxWindows = this._opts.windowsNum || 16;
while (me._opts.windows < maxWindows && freeWindow == -1) {
var zoom = Math.sqrt(this._opts.windows*1)+1;
if (this._opts.windows == 6) {
......@@ -1212,14 +1453,15 @@ if (typeof define === 'function' && define.amd) {
var me = this;
var selView = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li.sel');
if(selView.length){
if (me.VIDEO_DATA[selView.index()].playing) {
me.close(selView.index());
var index = selView.attr("index");
if (me.VIDEO_DATA[index].playing) {
me.close(index);
//延时打开 禁止同时一关一开
setTimeout(function(){
me.play(selView.index(), video, id, opts);
me.play(index, video, id, opts);
}, 1000);
} else {
me.play(selView.index(), video, id, opts);
me.play(index, video, id, opts);
}
}
},
......@@ -1238,6 +1480,23 @@ if (typeof define === 'function' && define.amd) {
return index;
},
/**
* 判断指定窗口是否正在播放视频
*/
isPlayingByIndex: function(index){
var me = this;
if (index > me.VIDEO_DATA.length - 1 || index < 0) return false;
return me.VIDEO_DATA[index].playing;
},
/**
* 获取视频数据
*/
getVideoData: function(){
return this.VIDEO_DATA;
},
/**
* 关闭指定窗口的视频
*/
......@@ -1255,17 +1514,46 @@ if (typeof define === 'function' && define.amd) {
},
/**
* 关闭指定视频编号正在播放的视频
*/
closeByVideo: function(video, isSave){
var me = this;
if (video == undefined) {
console.info('video参数错误');
return;
}
var videoData = me.VIDEO_DATA;
if (!videoData || videoData.length == 0) {
return;
}
for (var i in videoData) {
if (video == videoData[i].video) {
me.close(videoData[i].index);
if (!isSave) {
me.dispatch('afterclose', videoData[i]);
}
}
}
},
/**
* 关闭所有视频
*/
closeAll: function(isSave){
var me = this;
// 清除所有等待播放队列
me._removeAllWaitingVideo();
var openVideos = [];
for(var i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
if(me.VIDEO_DATA[i].playing){
/*if(me.VIDEO_DATA[i].playing){
me.close(i, isSave)
}*/
me.close(i, isSave)
}
}
// if(!openVideos.length) return;
......@@ -1314,7 +1602,7 @@ if (typeof define === 'function' && define.amd) {
_li.eq(i).show();
}
//分屏切换事件
this.dispatch('screenchange', {windowNums:num});
this.dispatch('screenchange', {windowNums:num, flag:me._opts.flag});
},
/**
......@@ -1343,6 +1631,8 @@ if (typeof define === 'function' && define.amd) {
this._polltimer = new PollTimer(function(firstRun){
me.closeAll();
if (firstRun) {
for(var i = 0; i < windowNum; i++) {
if(nowNum == maxNum){
nowNum = 0;
......@@ -1354,8 +1644,20 @@ if (typeof define === 'function' && define.amd) {
me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
nowNum++;
}
if (firstRun) {
me.dispatch('startpoll', array);
} else {
wait(1500).then(function(){
for(var i = 0; i < windowNum; i++) {
if(nowNum == maxNum){
nowNum = 0;
if(maxNum < windowNum) {
break;
}
}
me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
nowNum++;
}
})
}
}, time);
},
......@@ -1417,6 +1719,7 @@ if (typeof define === 'function' && define.amd) {
console.error('窗口编号获取失败!')
}
me.setChoiceWindow(index);
me.VIDEO_DATA[index].opts = opts;
return me.VIDEO_DATA[index].playback(video,startTime,endTime);
},
......@@ -1424,7 +1727,9 @@ if (typeof define === 'function' && define.amd) {
/**
* 关闭历史流
*/
closeHistory: function(index) {
closeHistory: function(video, index) {
if (!video) return;
var me = this;
if (!index) {
......@@ -1434,7 +1739,7 @@ if (typeof define === 'function' && define.amd) {
}
}
return me.VIDEO_DATA[index].close("stop");
return me.VIDEO_DATA[index].playbackControl(video, "stop", 0);
},
/**
......@@ -1479,8 +1784,8 @@ if (typeof define === 'function' && define.amd) {
getInChoiceVideo: function() {
var me = this;
var selView = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li.sel');
if(selView.length && me.VIDEO_DATA[selView.index()].video){
return me.VIDEO_DATA[selView.index()];
if(selView.length && me.VIDEO_DATA[selView.attr("index")].video){
return me.VIDEO_DATA[selView.attr("index")];
}
return undefined;
},
......@@ -1491,6 +1796,7 @@ if (typeof define === 'function' && define.amd) {
setFullScreen: function() {
this._fullScreenEvent(document.getElementById("video-main-web-rtc"));
},
/**
* 获取当前视频控件的配置项
*/
......@@ -1499,82 +1805,257 @@ if (typeof define === 'function' && define.amd) {
},
/**
* 添加事件
* 获取截屏数据
* @param callback 回调函数
*/
addListener: function(type,handler,key){
videoListener.addListener(type,handler,key);
getScreenCaptureData: function(index, callback) {
var me = this;
//如果index为空则使用选中窗口的index
var dataObj = me.VIDEO_DATA[index != undefined ? index : me._getChoiceWindow()];
if (!dataObj.playing) {
promptAlarm('请选择播放的视频源!');
return;
}
var canvasObj = document.getElementById('myCanvas');
var videoObj = dataObj.tagBox.get(0);
if (videoObj == undefined) {
return;
}
// 取流中 取视频框尺寸
// 播放中 取视频画面尺寸
if (dataObj.tagBox.parent().find(".stream-loading").length != 0) {
canvasObj.width = dataObj.tagBox.width();
canvasObj.height = dataObj.tagBox.height();
} else {
canvasObj.width = videoObj.videoWidth;
canvasObj.height = videoObj.videoHeight;
}
var ctx = canvasObj.getContext("2d");
ctx.drawImage(videoObj, 0, 0, videoObj.videoWidth, videoObj.videoHeight);
var dataUrl = canvasObj.toDataURL('image/jpeg');
callback ? callback(dataUrl) : null;
},
/**
* 删除事件
* 开始录像
*/
removeListener: function(type,handler){
videoListener.removeListener(type,handler);
startAvRecord: function(index) {
var me = this;
return me.VIDEO_DATA[index].recordAv("start_av_record", recordAvBusinessId);
},
/**
* 派发事件
* 结束录像
*/
dispatch: function(e,options){
videoListener.dispatch(e,options);
stopAvRecord: function(index) {
var me = this;
return me.VIDEO_DATA[index].recordAv("stop_av_record", recordAvBusinessId);
},
/**
* 获取编号最小的空闲窗口的编号
* 改变分辨率
* @param resolution 新分辨率
*/
_getMinIndexFreeWindow: function(index) {
changeResolution: function(index, resolution) {
var me = this;
index = index || me._opts.windowsBeginIndex;
for (; index < me._opts.windowsBeginIndex + me._opts.windows ; index++) {
if (!me.VIDEO_DATA[index].playing) {
return index;
}
}
return -1;
return me.VIDEO_DATA[index].changeResolution("change_resolution", resolution);
},
/**
* 获取选中的窗口的index
* 开启对讲预呼叫
* @param pocNo 对讲号码
* @param centerTel 调度中心号
*/
_getChoiceWindow: function() {
openPocCall: function(pocNo, centerTel) {
var me = this;
var selView = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li.sel');
if (selView.length) {
return selView.index();
var index;
//对讲预呼叫默认使用一个窗口
if (me._opts.windowsNum == 1) {
index = me._opts.windowsBeginIndex;
} else {
index = me._getMinIndexFreeWindow();
}
return -1;
if (index < 0) {
console.error('窗口编号获取失败!')
}
//保存对讲号码
window.pocNo = pocNo;
return me.VIDEO_DATA[index].pocCall("open_poccall", pocNo, centerTel);
},
/**
* 获取下一窗口
* 关闭对讲预呼叫
* @param pocNo 对讲号码
* @param centerTel 调度中心号
*/
_getNextWindowsNum: function(old) {
closePocCall: function(pocNo, centerTel) {
var me = this;
var windowsArr = me._windowsArr;
for (var index in windowsArr){
if (index == windowsArr.length - 1) {
return windowsArr[index]
}
if (old == windowsArr[index]) {
return windowsArr[Number(index) + Number(1)];
var index;
//对讲预呼叫默认使用一个窗口
if (me._opts.windowsNum == 1) {
index = me._opts.windowsBeginIndex;
} else {
index = me._getMinIndexFreeWindow();
}
if (index < 0) {
console.error('窗口编号获取失败!')
}
me.VIDEO_DATA[index].stream = null;
window.pocNo = null;
return me.VIDEO_DATA[index].pocCall("close_poccall", pocNo, centerTel);
},
/**
* 设置鼠标选中窗口
* 设置录像的businessId
* @param businessId 业务ID
*/
_clickWindow: function() {
var me = this;
//视频窗口选中
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').click(function(){
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').removeClass("sel");
$(this).addClass("sel");
//如果视频正在播放则分发点击消息
if (me.getInChoiceVideo()) {
me.dispatch('click', me.getInChoiceVideo());
}
});
setRecordAvBusinessId: function(businessId) {
//var me = this;
recordAvBusinessId = businessId;
},
/**
* 开启音频
*/
sendAudio: function(index) {
var me = this;
var index = (index != undefined ? index : me._opts.windowsBeginIndex);
me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = true;
},
/**
* 关闭音频
*/
unSendAudio: function(index) {
var me = this;
var index = (index != undefined ? index : me._opts.windowsBeginIndex);
me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = false;
},
/**
* 添加事件
*/
addListener: function(type, handler, key){
videoListener.addListener(type, handler, key);
},
/**
* 删除事件
*/
removeListener: function(type, handler){
videoListener.removeListener(type, handler);
},
/**
* 派发事件
*/
dispatch: function(e, options){
videoListener.dispatch(e, options);
},
/**
* 清空事件
*/
removeAllListeners: function() {
videoListener.removeAllListeners();
},
/**
* 获取编号最小的空闲窗口的编号, 正在播放或有视频在等待播放标识不是空闲窗口
*/
_getMinIndexFreeWindow: function(index) {
var me = this;
index = index || me._opts.windowsBeginIndex;
for (; index < me._opts.windowsBeginIndex + me._opts.windows ; index++) {
if (!me.VIDEO_DATA[index].playing && !me.VIDEO_DATA[index].isWaiting) {
return index;
}
}
return -1;
},
/**
* 获取选中的窗口的index
*/
_getChoiceWindow: function() {
var me = this;
var selView = $('[video-flag="' + me._opts.windowsBeginIndex+'"]>li.sel');
if (selView.length) {
return selView.attr("index");
}
return -1;
},
/**
* 获取下一窗口
*/
_getNextWindowsNum: function(old) {
var me = this;
var windowsArr = me._windowsArr;
for (var index in windowsArr){
if (index == windowsArr.length - 1) {
return windowsArr[index]
}
if (old == windowsArr[index]) {
return windowsArr[Number(index) + Number(1)];
}
}
},
/**
* 设置鼠标选中窗口
*/
_initWindowEvent: function() {
var me = this;
//视频窗口选中
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').click(function(){
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').removeClass("sel");
$(this).addClass("sel");
//如果视频正在播放则分发点击消息
if (me.getInChoiceVideo()) {
me.dispatch('click', me.getInChoiceVideo());
}
});
// 设置视频窗可拖拽
var src = null;
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').bind("dragstart", function (ev) {
src = $(this);
})
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').bind("dragover", function (ev) {
ev.preventDefault();
})
$('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').bind("drop", function (ev) {
ev.preventDefault();
if(src.prop("outerHTML") === $(this).prop("outerHTML")){
return;
}
var target = $(this);
var srcIndex = src.index();
var targetIndex = target.index();
if (srcIndex > targetIndex) {
src.insertBefore(target);
target.insertAfter($('.video-main li').eq(srcIndex));
} else {
src.insertAfter(target);
target.insertBefore($('.video-main li').eq(srcIndex));
}
})
},
/*
......@@ -1597,7 +2078,12 @@ if (typeof define === 'function' && define.amd) {
windows: 4,
conf: {},
pollInterval: 10,
windowsNum: 16
windowsNum: 16,
isVideoTag: true, //true生成video标签 false生产audio标签 默认true
showVideoInfo: 1, //显示分辨率、码率等信息,1-显示左下角 2-显示左上角,为0时控制_showVideoInfo函数处理,默认1
waitPlayQueueSwitch: false, //播放队列开关,默认false
defaultBusinessType: 0, // 配置的默认业务类型 0:调度主线 1:勤指
videoTipTimeOut: 5, // 超时无首屏检测时间
};
$.extend(me._opts,opts);
......@@ -1619,20 +2105,174 @@ if (typeof define === 'function' && define.amd) {
me._opts.windowsBeginIndex = windowsSum;
//窗口总数
windowsSum += me._opts.windowsNum;
// 对讲号码初始化
window.pocNo = 0;
// 播放队列开关 默认打开
me.waitPlayQueueSwitch = opts.waitPlayQueueSwitch == undefined ? false : opts.waitPlayQueueSwitch;
//是否提示
me._opts.showPrompt === false && (showPrompt = false);
// 勤指业务下 设备检测
me._opts.defaultBusinessType == 1 && me._checkDevices();
//初始化界面
me._initView($dom);
me._opts.isVideoTag ? me._initVideoView($dom, me._opts.showVideoInfo) : me._initAudioView($dom);
//初始化Janus
me._initJanus();
//初始化按钮点击事件
me._initBtnEvent();
// 初始化事件监听
me._initEventListen();
//设置鼠标点击选中窗口
me._clickWindow();
me._initWindowEvent();
if (me._opts.showVideoInfo != 0) {
//显示视频信息:名称、分辨率、码率、丢包率
me._showVideoInfo();
}
//双击某个视频全屏
me._dbClickFullScreen();
},
/**
* 初始化按钮点击事件
*/
_initBtnEvent: function() {
var me = this;
var videoFlagObj = $('[video-flag="'+me._opts.windowsBeginIndex+'"]');
//锁定视频事件
videoFlagObj.find("button[name='lockVideo']").click(function(){
var index = Number($(this).parent().parent().attr("index"));
if (!me.VIDEO_DATA[index].playing) {
promptAlarm('请选择播放的视频源!');
return;
}
if ($(this).attr('class') == 'lock-video-btn') {
me.VIDEO_DATA[index].isLockVideo = false;
$(this).attr('class', 'unlock-video-btn');
} else {
me.VIDEO_DATA[index].isLockVideo = true;
$(this).attr('class', 'lock-video-btn');
}
});
//接收音频事件
videoFlagObj.find("button[name='recvAudio']").click(function(){
var _self = this;
var index = Number($(this).parent().parent().attr("index"));
// 优先当前窗口参数设置的业务类型 其次配置的默认业务类型
var businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
if (!me.VIDEO_DATA[index].playing) {
promptAlarm('请选择播放的视频源!');
return;
}
if ($(this).attr('class') == 'recv-audio-btn') {
//发送停止播放音频的请求
me.VIDEO_DATA[index].operateAudio("stop_audio")
$(this).attr('class', 'unrecv-audio-btn');
me.VIDEO_DATA[index].tagBox.prop("muted", true);
} else {
if (businessType == 0) {
//发送前先关闭其它音频通道(包括接收和发送音频)
var lis = $($(_self).parent().parent().parent()).children();
for (var i = 0; i < lis.length; i++) {
var btnIndex = Number($(lis[i]).attr("index"));
if (index == btnIndex) {
continue;
}
var recvBtn = $($(lis[i]).find("button[name='recvAudio']")[0]);
var sendBtn = $($(lis[i]).find("button[name='sendAudio']")[0]);
if (recvBtn.attr("class") == 'recv-audio-btn') {
if (me.VIDEO_DATA[btnIndex].playing) {
recvBtn.click();
}
}
if (sendBtn.attr("class") == 'send-audio-btn') {
if (me.VIDEO_DATA[btnIndex].playing) {
sendBtn.click();
}
}
}
//发送播放音频的请求
$(_self).attr('class', 'recv-audio-btn');
setTimeout(function () {
me.VIDEO_DATA[index].operateAudio("recv_audio");
me.VIDEO_DATA[index].tagBox.prop("muted", false);
}, 1000);
} else if (businessType == 1) {
// poc新模式支持回传多个音频,因此不关闭
//发送播放音频的请求
$(_self).attr('class', 'recv-audio-btn');
me.VIDEO_DATA[index].operateAudio("recv_audio");
me.VIDEO_DATA[index].tagBox.prop("muted", false)
}
}
});
//发送音频事件
videoFlagObj.find("button[name='sendAudio']").click(function(){
var index = Number($(this).parent().parent().attr("index"));
// 优先当前窗口参数设置的业务类型 其次配置的默认业务类型 最后默认调度业务
var businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
if (!me.VIDEO_DATA[index].playing) {
promptAlarm('请选择播放的视频源!');
return;
}
if (businessType == 0) {
// 主线业务
if ($(this).attr('class') == 'send-audio-btn') {
me.VIDEO_DATA[index].operateAudio("unsend_audio")
$(this).attr('class', 'unsend-audio-btn');
me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = false;
} else {
me.VIDEO_DATA[index].operateAudio("send_audio");
$(this).attr('class', 'send-audio-btn');
// $(this).parent().find("button[name='recvAudio']").attr('class', 'recv-audio-btn')
me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = true;
}
} else if (businessType == 1) {
// 勤指业务
if ($(this).attr('class') == 'send-audio-btn') {
$(this).attr('class', 'unsend-audio-btn');
//关闭点对点对讲
me.VIDEO_DATA[index].ptopPoc("close_ptop_poc", window.pocNo);
} else {
$(this).attr('class', 'send-audio-btn');
//发起点对点对讲
me.VIDEO_DATA[index].ptopPoc("open_ptop_poc", window.pocNo);
}
}
});
//关闭视频事件
videoFlagObj.find("button[name='closeVideo']").click(function(){
var index = Number($(this).parent().parent().attr("index"));
me.close(index);
});
},
/**
* 初始化事件监听
*/
_initEventListen: function () {
var _self = this;
// 打开视频 {index, video, id, opts} index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
_self.addListener('openVideo', function (e) {
_self.play(e.index, e.video, e.id, e.opts);
})
// janus通知后台已关闭视频
_self.addListener('notifyCloseVideo', function (e) {
_self._notifyWaitingVideo(e.index);
});
},
/**
* 双击某个视频全屏
*/
......@@ -1678,27 +2318,53 @@ if (typeof define === 'function' && define.amd) {
var number = Number(i) + Number(1);
var videoObj = document.getElementById('video-' + number);
if (!videoObj) continue;
var width = videoObj.videoWidth;
var height = videoObj.videoHeight;
//码率
var bitrate = me.VIDEO_DATA[i].sipcall.getBitrate();
if (width == 0 || !bitrate || bitrate.indexOf("kbits") == -1) {
if (!width || !height || !bitrate || bitrate.indexOf("kbits") == -1 || bitrate.indexOf("NaN") != -1) {
continue;
}
var config = me.VIDEO_DATA[i].sipcall.webrtcStuff;
me._setPacketsLostRate(i, config, me);
var resolution = width + "×" + height;
switch(height + '') {
case '1080':
resolution = "1080P";
break;
case '720':
resolution = "720P";
break;
case '480':
resolution = "480P";
break;
case '288':
resolution = "CIF";
break;
default:
break;
}
var videoInfoObj = document.getElementById('info-' + number);
var videoName = me.VIDEO_DATA[i].opts && me.VIDEO_DATA[i].opts.name ?
me.VIDEO_DATA[i].opts.name : me.VIDEO_DATA[i].video;
videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + width + "×" + height +
'<br>' + bitrate + '&nbsp;&nbsp;Lost:' + me.VIDEO_DATA[i].packetsLostRate;
videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + resolution +
'<br>丢包率:' + me.VIDEO_DATA[i].packetsLostRate + '&nbsp;&nbsp;' + bitrate.replace("kbits/sec", "kbps");
}
}
}
var timer = setInterval(clock, 1000);
//已存在则清除
if (me.videoInfoTimer) {
clearInterval(me.videoInfoTimer);
me.videoInfoTimer = null;
}
me.videoInfoTimer = setInterval(clock, 1000);
},
/**
* 获取设置丢包率
......@@ -1725,19 +2391,21 @@ if (typeof define === 'function' && define.amd) {
if(inStats) {
if (res.hasOwnProperty("packetsLost")) {
//console.info('丢包率:' + res.packetsLost);
if (!res.packetsLost || isNaN(res.packetsLost) || Number(res.packetsLost) == '0') {
me.VIDEO_DATA[index].packetsLostRate = 0;
if (!res.packetsLost || isNaN(res.packetsLost) || Number(res.packetsLost) == '0' || res.packetsLost == 'NaN') {
me.VIDEO_DATA[index].packetsLostRate = '0.00%';
} else {
var packetsLost = Number(res.packetsLost) - Number(me.VIDEO_DATA[index].packetsLostSum);
var packetsReceived = Number(res.packetsReceived) - Number(me.VIDEO_DATA[index].packetsReceivedSum);
me.VIDEO_DATA[index].packetsLostSum = res.packetsLost;
me.VIDEO_DATA[index].packetsReceivedSum = res.packetsReceived;
var packetsLostRate = 0;
//防止分母是0
if (packetsLost > 0) {
var packetsLostRate = (Number(packetsLost) / (Number(packetsLost) + Number(packetsReceived))) * 100;
}
me.VIDEO_DATA[index].packetsLostRate = packetsLostRate.toFixed(2) + '%';
}
//window.VIDEO_DATA[index].packetsLostRate = (Number(res.packetsLost) / (Number(res.packetsLost) + Number(res.packetsReceived))) * 100;
/* videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + width + "×" + height +
/* videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + width + "×" + height +
'<br>' + bitrate + '&nbsp;&nbsp;Lost:' + res.packetsLost;*/
}
}
......@@ -1748,24 +2416,112 @@ if (typeof define === 'function' && define.amd) {
},
/**
* 界面的初始化,在传过来的dom中创建界面
* 设备可用性检查(扬声器、麦克风、分辨率、浏览器类型)
* 1. 未检测(status == undefined)询问进入检测界面
* 2. 检测完成按相应结果给予相应提示
* 3. 拒绝检测按所有检测通过处理
* 4. 程序自行检测,并将是否加载声卡结果放入window对象
* @private
*/
_checkDevices: function() {
var tipCountKey = "DEVICES_CHECK_TIP_COUNT";
var statusKey = "DEVICES_CHECK_STATUS";
var checkCompleted = "completed";
var checkRejected = "rejected";
var microResultKey = "MICRO_RESULT";
var speakerResultKey = "SPEAKER_RESULT";
var screenResultKey = "SCREEN_RESULT";
var resultPass = "pass";
var resultNotPass = "not pass";
var tipCount = sessionStorage.getItem(tipCountKey);
var status = localStorage.getItem(statusKey);
if ((tipCount == undefined || tipCount == "0") && status == undefined) {
sessionStorage.setItem(tipCountKey, "1");
//弹窗讯问是否进入检测界面
if (confirm("您还没有检测硬件设备,是否先进行检测?")) {
window.open("/scooper-video/new/checkDevices");
} else {
localStorage.setItem(statusKey, checkRejected);
}
return;
}
if (status == checkCompleted) {
var microResult = (localStorage.getItem(microResultKey) == undefined) ? resultPass : localStorage.getItem(microResultKey);
var speakerResult = (localStorage.getItem(speakerResultKey) == undefined) ? resultPass : localStorage.getItem(speakerResultKey);
var screenResult = (localStorage.getItem(screenResultKey) == undefined) ? resultPass : localStorage.getItem(screenResultKey);
var msg = "";
if (microResult == resultNotPass || speakerResult == resultNotPass) {
msg += "您的声卡异常!";
}
if (screenResult === resultNotPass) {
msg += "您的屏幕分辨率过低,可能导致页面布局混乱!";
//提示并派发消息
}
var userAgent = navigator.userAgent;
if (userAgent.toLowerCase().indexOf("chrome") < 0 && userAgent.toLowerCase().indexOf("firefox") < 0 && userAgent.toLowerCase().indexOf("edge") < 0) {
msg += "当前浏览器下部分功能可能存在兼容问题,建议使用谷歌浏览器!";
}
if (msg != "") {
//提示并派发消息
promptAlarm(msg);
//防止外部未监听消息就派发事件
setTimeout(function () {
videoListener.dispatch('msginfo', {'msg' : msg});
}, 3000);
}
}
},
/**
* 视频界面的初始化,在传过来的dom中创建界面
* @param infoPosition 视频码率等信息显示位置,1-显示左下角 2-显示左上角,为0时控制_showVideoInfo函数处理,默认左下角
*/
_initView: function($dom) {
_initVideoView: function($dom, infoPosition) {
var me = this;
var position;
switch (infoPosition) {
case 1: position = "info-bottom"; break;
case 2: position = "info-top"; break;
default : position = "info-bottom";
}
var objClass = (me._opts.windowsNum == 1 ? 'video-main-full mode-' : 'video-main mode-') + me._opts.windows;
var videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc" video-flag="'+me._opts.windowsBeginIndex+'">';
var index = me._opts.windowsBeginIndex + 1;
for (var i = index; i < index + me._opts.windowsNum; i++) {
videoHtml += '<li class="screen-' + i +'" index="' + (i - 1) +'"><video class="video-box" id="video-' + i +'" autoplay ></video>' +
'<div class="info hide" id="info-' + i +'"></div>' +
videoHtml += '<li class="screen-' + i +'" index="' + (i - 1) +'" draggable="true"><video muted class="video-box" id="video-' + i +'" autoplay ></video>' +
'<div class="hide info ' + position + '" id="info-' + i +'"></div>' +
'<div class="operate-btn">';
videoHtml +='<button type="button" class="unlock-video-btn hide" name="lockVideo"></button>';
checkUserMediaAvailable() && (videoHtml += '<button type="button" class="unsend-audio-btn hide" name="sendAudio"></button>');
videoHtml += '<button type="button" class="unrecv-audio-btn hide" name="recvAudio"></button>' +
'<button type="button" class="close-btn hide" name="closeVideo"></button>' +
'</div>' +
'</li>';
}
videoHtml += '</ul>' ;
videoHtml += '</ul> <div class="canvasBox hide"><canvas id="myCanvas" ></canvas></div>';
$dom.append(videoHtml);
me.setWindowsNum(me._opts.windows);
},
/**
* 音频界面的初始化,在传过来的dom中创建界面
*/
_initAudioView: function($dom) {
var me = this;
var objClass = (me._opts.windowsNum == 1 ? 'video-main-full mode-' : 'video-main mode-') + me._opts.windows;
var videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc" video-flag="'+me._opts.windowsBeginIndex+'">';
var index = me._opts.windowsBeginIndex + 1;
for (var i = index; i < index + me._opts.windowsNum; i++) {
videoHtml += '<audio id="audio-' + i +'" autoplay ></audio>';
}
$dom.append(videoHtml);
},
/**
* Janus的初始化
*/
......@@ -1782,22 +2538,54 @@ if (typeof define === 'function' && define.amd) {
alert("不支持WEB-RTC");
return;
}
var janus = new Janus({
server: me._opts.conf.janusUrl,
var janusUrl = me._opts.conf.janusUrl;
checkIsHttps() && (janusUrl = janusUrl.replace('ws:','wss:'));
janusUrl.indexOf("127.0.0.1") > 0 && (janusUrl = janusUrl.replace('127.0.0.1', location.hostname));
me._opts.janus = new Janus({
//如果是https 则用页面的url头(已保证用nginx代理为前提) 否则用后台配置的
server: location.protocol == "https:" ? janusUrl.split("//")[0] + "//" + (location.host) + "/janus/" : janusUrl,
success: function(){
console.log("janusServer连接成功");
me._initSVideo(janus);
console.log("Janus服务连接成功!");
me._initSVideo(me._opts.janus);
},
error: function(error) {
alert('连接失败:'+ error);
//只提示一次,防止Janus挂了一直重连
!me._opts.isNotFistTip && promptFailed('Janus服务连接失败!');
me._opts.isNotFistTip = true;
console.error('Janus服务连接失败:'+ error)
me.closeAll();
me._removeAllWaitingVideo();
me._initJanus();
},
destroyed: function() {
me._opts.isNotFistTip = true;
}
});
}});
},
/**
* 销毁:Janus销毁、资源释放
*/
destoryJanus: function() {
var me = this;
me._opts.janus.destroy({
success: function() {
window.windowsSum = 0;
//userToken = null;
registered = false;
},
asyncRequest: true,
notifyDestroyed: true,
});
me.removeAllListeners();
},
reLoginJanusItvIndex : -1,
/**
* 初始化插件、登陆,初始化窗口
*/
......@@ -1820,10 +2608,10 @@ if (typeof define === 'function' && define.amd) {
//初始化一个插件,用来登陆,不能用此插件播放视频。
var _loginSipCall = null;
janus.attach({
plugin: "janus.plugin.sip",
plugin: me._opts.conf.janusPlugin ? me._opts.conf.janusPlugin : "janus.plugin.videoserver",
opaqueId: "siptest-" + Janus.randomString(12),
success: function(pluginHandle) {
console.log("janus登陆插件初始化成功");
console.log("Janus登陆插件初始化成功!");
_loginSipCall = pluginHandle;
var register = {
"request" : "register",
......@@ -1833,12 +2621,13 @@ if (typeof define === 'function' && define.amd) {
_loginSipCall.send({"message": register});
},
error: function(error) {
console.error("janus登陆插件初始化失败");
promptFailed('Janus登陆插件初始化失败!');
console.error("Janus登陆插件初始化失败:" + error);
},
onmessage: function(msg, jsep) {
if (msg.error_code) {
console.error(msg.error)
promptFailed(FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
promptFailed(CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
return false;
}
......@@ -1846,26 +2635,53 @@ if (typeof define === 'function' && define.amd) {
var event = result["event"];
if (result.error_code && result.error_code != 0) {
promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
promptFailed(CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
}
if(result !== null && result !== undefined && result["event"] !== undefined && result["event"] !== null) {
console.log("result event:" + event);
if(event === 'registration_failed') {
promptFailed("janus登陆失败: " + result["code"] + " " + result["reason"]);
if(me.reLoginJanusItvIndex == -1) {
me.reLoginJanusItvIndex = setInterval(function () {
console.log("尝试重新登陆janus!");
me._initJanus(janus);
}, 5000);
}
return;
}
if (event === 'video_server_closed') {
if(me.reLoginJanusItvIndex == -1) {
me.reLoginJanusItvIndex = setInterval(function () {
console.log("尝试重新登陆janus!");
me._initJanus(janus);
}, 5000);
}
return;
}
if(event === 'registered') {
userToken = result["userToken"];
var userToken = result["userToken"];
console.log('janus登陆成功')
registered = true;
if (me.reLoginJanusItvIndex != -1) {
clearInterval(me.reLoginJanusItvIndex);
me.reLoginJanusItvIndex = -1;
}
//生成主界面
//相对序号,用于标识当前janus连接初始化的序号窗口
var relativeIndex = 0;
for(var i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
me.VIDEO_DATA[i] = new SVideo({
index:i,
janus:janus
index: i,
userToken: userToken,
janus: janus,
windowsNum: me._opts.windowsNum,
relativeIndex: relativeIndex++,
flag: me._opts.flag,
isVideoTag: me._opts.isVideoTag,
janusPlugin: me._opts.conf.janusPlugin,
videoTipTimeOut: me._opts.videoTipTimeOut
});
}
}
......@@ -1874,9 +2690,128 @@ if (typeof define === 'function' && define.amd) {
});
},
/* ----------------------------- 播放队列 --------------------------- */
// 记录等待中的视频
WAITING_DATA: [],
// 播放队列开关 默认关闭
waitPlayQueueSwitch: false,
/**
* 添加等待视频数据
* 同一位置再次打开,则覆盖上一次的
* 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
*/
_addWaitingVideo: function (index, video, id, opts) {
var _self = this;
var isOverride = false;
$.each(_self.WAITING_DATA, function (i, obj) {
if (obj.index == index) {
console.log("播放队列中 index = " + index + ", video = " + obj.video + " 替换为 video = " + video);
_self.WAITING_DATA[i] = {
index: index,
video: video,
id: id,
opts: opts
}
isOverride = true;
return false;
}
});
if (!isOverride) {
_self.WAITING_DATA.push({
index: index,
video: video,
id: id,
opts: opts
});
console.log("index = " + index + ", video = " + video + " 加入播放队列");
}
_self.VIDEO_DATA[index].isWaiting = true;
},
var FAILED_CODE = {
/**
* 删除等待视频数据
*/
_removeWaitingVideo: function (index, video) {
var _self = this;
$.each(_self.WAITING_DATA, function (i, obj) {
if (obj.index == index && obj.video == video) {
_self.WAITING_DATA.splice(i, 1);
_self.VIDEO_DATA[index].isWaiting = false;
console.log("index = " + index + ", video = " + video + " 从播放队列移除");
return false;
}
});
},
/**
* 删除所有等待播放视频的数据
*/
_removeAllWaitingVideo: function () {
var _self = this;
_self.WAITING_DATA = [];
var index = _self._opts.windowsBeginIndex;
for (; index < _self._opts.windowsBeginIndex + _self._opts.windows ; index++) {
_self.VIDEO_DATA[index].isWaiting = false;
}
},
/**
* 上一个视频关闭后,如果该位置由等待视频,通知打开新视频
* @param index
*/
_notifyWaitingVideo: function (index) {
var _self = this;
$.each(_self.WAITING_DATA, function (i, obj) {
if (obj.index == index) {
_self.play(obj.index, obj.video, obj.id, obj.opts);
_self._removeWaitingVideo(obj.index, obj.video);
return false;
}
});
}
}
var CONST_CODE = {
VIDEO_CODE: {
2002 : "打开失败,未找到该ID的视频源",
2003 : "打开失败,请确认视频服务版本",
3001 : "打开失败,未接收到引流包,请检查端口映射",
3002 : "",
3003 : "打开失败,对方拒绝视频请求",
4001 : "打开失败,视频流中断",
4002 : "终端挂机或超时未接听",
7000 : "打开失败,无法连接视频设备",
7001 : "打开失败,无法连接视频设备",
7002 : "打开失败,无法连接视频设备",
},
OTHER_CODE: {
453 : "videoServer连接失败,错误码453",
454 : "视频窗口已被占用,请选择其它窗口打开或停止播放",
455 : "操作失败,该段时间无视频录像",
499 : "操作异常,错误码499",
440 : "操作异常,错误码440",
441 : "操作异常,错误码441",
442 : "操作异常,错误码442",
443 : "操作异常,错误码443",
444 : "操作异常,错误码444",
445 : "操作异常,错误码445",
446 : "操作异常,错误码446",
447 : "操作异常,错误码447",
448 : "操作异常,错误码448",
449 : "操作异常,错误码449",
450 : "操作异常,错误码450",
451 : "操作异常,错误码451",
452 : "操作异常,错误码452",
456 : "设备已处于对讲状态或不支持对讲",
6001 : "录像失败"
},
FAILED_CODE: {
1001 : "账号或密码错误",
1002 : "该帐号已连接",
1004 : "没有鉴权",
......@@ -1886,24 +2821,117 @@ if (typeof define === 'function' && define.amd) {
3001 : "nat通道未建立",
3002 : "该视频流已在传输",
3003 : "无法获取远端视频流",
4001 : "视频流断开连接",
4001 : "视频流异常断开连接",
4002 : "获取视频失败",
5000 : "内部错误",
8001 : "设备不支持该指令",
8001 : "该设备不支持云台操作",
453 : "videoServer连接失败",
454 : "录像回放窗口已占用,请先停止播放",
455 : "无视频录像,操作失败"
455 : "无视频录像,操作失败",
5001 : "呼叫异常断开",
5002 : "禁止修改分辨率",
401 : "禁止修改分辨率",
4003 : "音频重置",
4004 : "音频被占用",
4005 : "客户端已打开对讲",
4006 : "终端离开云眼音频",
6001 : "录像失败",
499 : "内部创建失败",
440 : "请求消息内容为空",
441 : "json格式错误",
442 : "无效的请求",
443 : "消息内容缺失",
444 : "消息缺少参数",
445 : "账户已登陆",
446 : "收到的videoserver消息有误",
447 : "消息参数错误",
448 : "SDP创建失败",
449 : "未使用",
450 : "创建端口失败",
451 : "SDP创建失败",
452 : "未使用加密的RTP",
456 : "对讲未打开",
7000 : "URL账号密码错误(RTSP)",
7001 : "URL地址不通(RTSP)",
7002 : "URL格式错误(RTSP)"
},
/**
* 以下的错误状态不会关闭视频
*/
STATUS_CODE_ARR: ['5002', '401', '4003', '4004', '4005', '4006', '8001', '6001']
}
/**
* 显示播放错误内容, 4002特殊处理
* @param videoObj 视频对象
* @param code 状态码(包含错误码)
* @param isShowReplayBtn 是否显示重新播放按钮
* @param video 打开错误的视频Id
*/
function showResult(videoObj, code, isShowReplayBtn, video) {
var videoDom = videoObj.tagBox.parent();
videoDom.addClass("result");
videoDom.find('.operate-btn .close-btn').show();
if (CONST_CODE.FAILED_CODE[code] && code != "4002") {
var resultHtml = "<div class='real-result'>错误码" + code + ": " + CONST_CODE.FAILED_CODE[code] + "</div>"
videoDom.append(resultHtml);
}
var resultHtml = "<div class='result'><div class='result-tip'>" + CONST_CODE.VIDEO_CODE[code] + "</div>";
if(isShowReplayBtn && code != "4002") {
resultHtml += "<div class='result-replay'><span id='replay-" + videoObj.index + "' class='replay'>点击重试</span></div>"
}
resultHtml += "</div>";
videoDom.append(resultHtml);
if(isShowReplayBtn && code != "4002") {
$("#replay-" + videoObj.index).unbind("click").click(function () {
videoListener.dispatch("openVideo", {index: videoObj.index, video: video, id: videoObj.id, opts: videoObj.opts});
});
}
if (code == "4002") {
setTimeout(function () {
clearResult(videoDom);
}, 5000);
}
}
/**
* 清除显示内容 videoDom: 视频Dom对象
*/
function clearResult(videoDom, videoObj) {
videoDom.removeClass("result");
videoDom.find(".real-result").remove();
videoDom.find(".result").remove();
if (!videoObj.playing) {
// bug id 18654: 增加是否正在播放判断
videoDom.find('.operate-btn .close-btn').hide();
}
}
//window.VIDEO_DATA = [];//记录视频各分屏的状态
window.windowsSum = 0; //当前页面的视频总数,可能有多个VideoWebRtc对象
var userToken = null;
//var userToken = null;
var registered = false;
var recordAvBusinessId = null;
function SVideo (opts) {
this.janus = opts.janus;
this.userToken = opts.userToken;
this.sipcall = null;
this.index = opts.index;
this.videoBox = $('#video-' + (this.index + 1));
this.relativeIndex = opts.relativeIndex;
this.tagBox = opts.isVideoTag ? $('#video-' + (this.index + 1)) : $('#audio-' + (this.index + 1));
this.windowsNum = opts.windowsNum;
this.flag = opts.flag;
this.isVideoTag = opts.isVideoTag;
this.janusPlugin = opts.janusPlugin;
this.isClosing = false; // 当前分屏是否正在关闭视频
this.isWaiting = false; // 当前分屏是否有视频在等待播放
this.playSucTimeOutIndex = -1; // 超时提示定时器index
this.videoTipTimeOut = opts.videoTipTimeOut; // 超时无首屏时间
this.init();
}
......@@ -1919,12 +2947,16 @@ if (typeof define === 'function' && define.amd) {
var self = this;
self.janus.attach({
plugin: "janus.plugin.sip",
plugin: self.janusPlugin ? self.janusPlugin : "janus.plugin.videoserver",
opaqueId:"siptest-" + Janus.randomString(12),
success: function(pluginHandle) {
console.log("视频插件初始化成功:" + self.index);
self.sipcall = pluginHandle;
if (self.relativeIndex + 1 >= self.windowsNum) {
videoListener.dispatch('initsucc', self);
}
},
error: function(error) {
......@@ -1940,55 +2972,73 @@ if (typeof define === 'function' && define.amd) {
promptFailed("请先登陆");
}
var video = self.video;
if (msg.error_code) {
console.error(msg.error)
promptFailed(FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
console.error("错误码:" + msg.error_code + " " + CONST_CODE.FAILED_CODE[msg.error_code]);
if (CONST_CODE.VIDEO_CODE[msg.error_code]) {
showResult(self, msg.error_code, true, video);
} else {
promptFailed(CONST_CODE.OTHER_CODE[msg.error_code] || CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
}
videoListener.dispatch('msginfo', {'code': msg.error_code, 'msg' : CONST_CODE.OTHER_CODE[msg.error_code] || CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code});
return false;
}
var result = msg["result"];
var event = result["event"];
if (!result) return;
if (result.error_code && result.error_code != 0) {
console.error("错误码:" + result.error_code + " " + CONST_CODE.FAILED_CODE[result.error_code]);
if (!CONST_CODE.STATUS_CODE_ARR.includes(result.error_code + '')) {
//播放失败 关闭视频
self.close('err');
if (self.isLockVideo) {
setTimeout(function () {
self.play(video);
}, 1500);
} else {
videoListener.dispatch('afterclose', self);
}
}
//播放失败
self.sipcall.hangup();//插件挂断
self.videoBox.hide();//视频窗video标签隐藏
self.playing = false;//缓存数据-是否播放视频置否
self.video = null;//缓存数据-视频video置空
self.packetsLostRate = 0;//丢包率 每秒刷新
self.packetsLostSum = 0;//丢包数
self.packetsReceivedSum = 0;//接收数
//隐藏视频信息
self.videoBox.parent().find('.info').hide();
self.videoBox.parent().removeClass("loading").find(".stream-loading").remove();//移除loading标签
promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
videoListener.dispatch('msginfo', {'code': result.error_code, 'msg' : CONST_CODE.OTHER_CODE[result.error_code] || CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code});
if (CONST_CODE.VIDEO_CODE[result.error_code]) {
showResult(self, result.error_code, true, video);
} else {
promptFailed(CONST_CODE.OTHER_CODE[result.error_code] || CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
}
self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
}
//事件响应
var event = result["event"];
if (!event) return;
switch(event) {
//即将播放视频
case 'incomingcall':
self.sipcall.createAnswer({
jsep: jsep,
media: { audioSend: false, videoSend:false, audioRecv: true , videoRecv: true },
media: { audioSend: checkUserMediaAvailable(), videoSend:false, audioRecv: true, videoRecv: true},
success: function(jsep) {
var body = {
request:"accept",
videoidentify:result["videoidentify"],
playseq:parseInt(result["playseq"])
videoidentify: result["videoidentify"],
playseq: parseInt(result["playseq"]),
userToken: self.userToken,
};
self.sipcall.send({"message": body, "jsep": jsep});
},
error: function(error) {
console.error(error);
var body = { "request": "decline", "code": 480 };
self.sipcall.send({"message": body});
}
});
break;
case 'accepted' :
self.playSucTimeOutIndex = setTimeout(function () {
var _li = self.tagBox.parent();
_li.append('<div class="video-tip">网络环境较差,可能无法正常加载视频</div>');
}, self.videoTipTimeOut * 1000);
break;
//呼叫失败
case 'callfaild':
//promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
......@@ -1999,39 +3049,138 @@ if (typeof define === 'function' && define.amd) {
//历史流控制
case 'av_control':
break;
//录像通知
case 'start_av_record':
if (result && result.filename) {
self.videoFileName = result.filename;
videoListener.dispatch('startRecordVideo', self);
console.log('录像地址:' + result.filename);
}
break;
case 'stop_av_record':
if (result && result.filename) {
self.videoFileName = result.filename;
videoListener.dispatch('stopRecordVideo', self);
console.log('录像地址:' + result.filename);
}
break;
//修改分辨率
case 'ser_notify_resolution':
if (result && result.resolution) {
self.resolution = result.resolution;
videoListener.dispatch('notifyresolution', self);
console.log('接收notifyresolution:' + result.resolution);
//promptAlarm('当前分辨率:' + result.resolution);
}
break;
//建立预呼叫响应
case 'open_poccall':
console.log('建立预呼叫');
self.sipcall.createAnswer({
jsep: jsep,
media: {audioSend: checkUserMediaAvailable(), videoSend:false, audioRecv: true , videoRecv: false},
success: function(jsep) {
var body = {
request:"accept",
userToken: self.userToken,
};
self.sipcall.send({"message": body, "jsep": jsep});
},
error: function(error) {
console.error(error);
promptFailed("发生未知错误,请重试或联系管理员!");
videoListener.dispatch('msginfo', {'msg' : "发生未知错误,请重试或联系管理员!"});
}
});
break
//预呼叫异常断开
case 'ser_close_poccall':
console.log('预呼叫异常断开');
break;
case 'ser_stop_audio':
self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
console.log('音频异常关闭!');
break;
case 'close_down_audio':
self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
promptSuccess("通话时间到");
console.log('通话时间到!');
break;
case 'ser_notify_dispatch_close_ptop_poc':
self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
console.log('调度通知点对点对讲关闭!');
break;
case 'ser_close_ptop_poc':
self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
console.log('点对点对讲关闭!');
break;
case 'ser_open_ptop_poc':
self.tagBox.parent().find('.unsend-audio-btn').attr("class", "send-audio-btn");
console.log('点对点对讲打开!');
break;
// 视频关闭通知
case 'ser_close_video':
console.log('视频框 ' + self.index + ' 视频已关闭');
self.isClosing = false;
videoListener.dispatch('notifyCloseVideo', self);
break;
default:
console.log('event:' + event);
break;
}
},
//处理远程流
onremotestream: function(stream) {
console.log('onremotestream:分屏=' + (self.index + 1) + ', video=' + self.video);
Janus.attachMediaStream(self.videoBox.get(0), stream);
Janus.attachMediaStream(self.tagBox.get(0), stream);
},
//处理本地流
onlocalstream: function(stream) {
stream.getAudioTracks()[0].enabled = false;
self.stream = stream;
},
//清理
oncleanup: function() {
console.log('oncleanup:分屏=' + (self.index + 1));
}
});
//<video>注册playing/canplay事件,用于判断视频播放成功
self.videoBox.bind("canplay play playing", function () {
self.tagBox.bind("canplay play playing", function () {
if(self.video){
if (self.videoBox.is(':visible')) return;
if (self.tagBox.is(':visible')) return;
// 清除播放监测定时任务,清除内容
self.playSucTimeOutIndex > 0 && clearTimeout(self.playSucTimeOutIndex);
self.tagBox.parent().find(".video-tip").remove();
console.log('分屏=' + (self.index + 1) + ', ' + self.video + ' 播放成功');
promptSuccess('分屏' + (self.index + 1) + ' 播放成功');
self.videoBox.show();
self.videoBox.parent().removeClass("loading").find(".stream-loading").remove();
self.tagBox.show();
//self.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
self.tagBox.parent().find(".stream-loading").remove();
//显示视频信息
self.videoBox.parent().find('.info').show();
self.tagBox.parent().find('.info').show();
//显示音频按钮
self.tagBox.parent().find('.operate-btn button').show();
if (self.isPlayBack) {
self.tagBox.parent().find('.unrecv-audio-btn').hide();
}
self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
var width = this.videoWidth;
var height = this.videoHeight;
//保持长宽比例填充video视频框
if (width <= height && width != '0') {
self.tagBox.css('object-fit', 'contain');
}
}
});
},
......@@ -2049,48 +3198,65 @@ if (typeof define === 'function' && define.amd) {
var body = {
request: "call",
videoidentify: video,
playseq:this.index,
userToken:userToken,
autoack:true
playseq: this.index,
userToken: this.userToken,
autoack: true
};
this.sipcall.send({"message": body });
this.video = video;
this.playing = true;
this.packetsLostRate = 0;
this.packetsLostRate = '0.00%';
this.packetsLostSum = 0;
this.packetsReceivedSum = 0;
//loading
var _li = this.videoBox.parent();
var _li = this.tagBox.parent();
clearResult(_li, this);
if(!_li.hasClass("loading")){
_li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
}
_li.find('.operate-btn .close-btn').show();
console.log("视频播放:分屏=" + (this.index + 1) + ",设备ID=" + video);
},
close:function(type){
var reqType = type ? type : "hangup";
if (!type) {
this.isLockVideo = false;
this.tagBox.parent().find('.lock-video-btn').attr("class", "unlock-video-btn");
}
//清除结果提示内容
clearResult(this.tagBox.parent(), this);
//var reqType = type ? type : "hangup";
if(!this.playing) return;
var _hangup = {
"request": reqType,
"videoidentify":this.video,
"playseq": this.index,
"token": userToken
request: "hangup",
videoidentify: this.video,
playseq: this.index,
userToken: this.userToken
};
this.sipcall.send({"message": _hangup});
this.sipcall.hangup();
this.videoBox.hide();
this.tagBox.hide();
this.isClosing = true;
this.playing = false;
this.video = null;
this.packetsLostRate = 0;
this.packetsLostRate = '0.00%';
this.packetsLostSum = 0;
this.packetsReceivedSum = 0;
//清除显示的视频信息
document.getElementById('info-' + (Number(this.index) + Number(1))).innerHTML = '';
//隐藏视频信息
this.videoBox.parent().find('.info').hide();
this.tagBox.parent().find('.info').hide();
//隐藏音频喇叭
this.tagBox.parent().find('.operate-btn button').hide();
//避免没收到成功时就点击关闭,清除loading框
this.videoBox.parent().removeClass("loading").find(".stream-loading").remove();
this.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
//清除object-fit
this.tagBox.css('object-fit', '');
// 清除内容提示
this.playSucTimeOutIndex > 0 && clearTimeout(this.playSucTimeOutIndex);
this.tagBox.parent().find(".video-tip").remove();
},
/**
......@@ -2124,7 +3290,6 @@ if (typeof define === 'function' && define.amd) {
*/
holder: function(type, opts, isStop) {
if(!this.video || !this.playing){
//alert("请输入视频ID");
promptAlarm('未选中播放的视频!');
return;
}
......@@ -2144,7 +3309,7 @@ if (typeof define === 'function' && define.amd) {
request: "ptz",
videoidentify: this.video,
playseq: this.index,
userToken: userToken,
userToken: this.userToken,
};
body.cmd = {
......@@ -2172,7 +3337,6 @@ if (typeof define === 'function' && define.amd) {
*/
playback: function(video, startTime, stopTime) {
if(!video){
//alert("请输入视频ID");
promptAlarm('视频ID不能为空');
return;
}
......@@ -2181,7 +3345,7 @@ if (typeof define === 'function' && define.amd) {
request: "av_playback",
videoidentify: video,
playseq: this.index,
userToken:userToken,
userToken: this.userToken,
start_time: startTime,
stop_time: stopTime
};
......@@ -2190,15 +3354,18 @@ if (typeof define === 'function' && define.amd) {
this.sipcall.send({"message": body });
this.video = video;
this.playing = true;
this.packetsLostRate = 0;
this.packetsLostRate = '0.00%';
this.packetsLostSum = 0;
this.packetsReceivedSum = 0;
this.isPlayBack = true;
//loading
var _li = this.videoBox.parent();
var _li = this.tagBox.parent();
clearResult(_li, this);
if(!_li.hasClass("loading")){
_li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
}
_li.find('.operate-btn .close-btn').show();
console.log("历史回放:分屏=" + (this.index + 1) + ",视频ID=" + video);
},
......@@ -2213,7 +3380,7 @@ if (typeof define === 'function' && define.amd) {
request: "av_control",
videoidentify: video,
playseq: self.index,
userToken: userToken,
userToken: self.userToken,
start_time: startTime,
rate: String(playSpeed),
cmd: playType
......@@ -2226,16 +3393,24 @@ if (typeof define === 'function' && define.amd) {
//}, 1000);
if (playType == 'stop') {
self.videoBox.hide();
self.close();
self.tagBox.hide();
self.playing = false;
self.video = null;
self.packetsLostRate = 0;
self.packetsLostRate = '0.00%';
self.packetsLostSum = 0;
self.packetsReceivedSum = 0;
self.isPlayBack = false;
//清除显示的视频信息
document.getElementById('info-' + (Number(self.index) + Number(1))).innerHTML = '';
//隐藏音频喇叭
this.tagBox.parent().find('.operate-btn button').hide();
//避免没收到成功时就点击关闭,清除loading框
self.videoBox.parent().removeClass("loading").find(".stream-loading").remove();
self.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
//清除object-fit
self.tagBox.css('object-fit', '');
}
},
......@@ -2247,7 +3422,6 @@ if (typeof define === 'function' && define.amd) {
var self = this;
if(!self.video){
//alert("请输入视频ID");
promptAlarm('视频ID不能为空');
return;
}
......@@ -2255,11 +3429,100 @@ if (typeof define === 'function' && define.amd) {
request: requestType,
videoidentify: self.video,
playseq: self.index,
userToken: userToken,
userToken: self.userToken,
};
self.sipcall.send({"message": body });
self.sipcall.send({"message": body });
console.log("音频操作="+ requestType +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video);
},
/**
* 录像操作
* requstType: start_av_record(开启录像)、stop_av_record(停止录像)
*/
recordAv: function(requestType, businessId) {
var self = this;
if(!self.video){
promptAlarm('视频ID不能为空');
return;
}
var body = {
request: requestType,
videoidentify: self.video,
playseq: self.index,
userToken: self.userToken,
businessid: businessId || null
};
self.sipcall.send({"message": body });
console.log("录像操作="+ requestType +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video + ",业务ID=" + (businessId || null));
},
/**
* 修改分辨率
* requstType: change_resolution
* CIF 480P 720P 1080P
*/
changeResolution: function(requestType, resolution) {
var self = this;
if(!self.video){
promptAlarm('视频ID不能为空');
return;
}
var body = {
request: requestType,
videoidentify: self.video,
playseq: self.index,
resolution: resolution,
userToken: self.userToken,
};
self.sipcall.send({"message": body });
console.log("修改分辨率操作="+ resolution +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video);
},
/**
* 对象预呼叫
* requstType: open_poccall(开启) close_poccall(关闭)
* pocno
* centerTel
*/
pocCall: function(requestType, pocNo, centerTel) {
var self = this;
var body = {
request: requestType,
pocno: pocNo,
playseq: self.index,
center_tel: centerTel,
userToken: self.userToken,
};
self.sipcall.send({"message": body });
console.log("预呼叫操作="+ requestType +", 对讲号码=" + pocNo + ",调度中心号码=" + centerTel);
},
/**
* 点对点对讲
* requstType: open_ptop_poc(开启) close_poc_poc(关闭)
* pocno
*/
ptopPoc: function(requestType, pocNo) {
var self = this;
var body = {
request: requestType,
pocno: pocNo,
playseq: self.index,
pocmember: self.video,
userToken: self.userToken,
};
self.sipcall.send({"message": body });
console.log("点对点对讲操作="+ requestType +", 主叫号码=" + pocNo + ",被叫号码=" + self.video);
}
}
......
// var videoPlatUrl = 'http://27.128.189.131:8089';
// var apiUrl = 'http://47.104.61.232:8902';
// var pushUrl = 'http://47.104.61.232:8905';
// var wsUrl = 'ws://47.104.61.232:8905/iocdata/websocket';
// var iocUrl = 'http://47.104.61.232:8902/ioc';
// var iocWsUrl = 'ws://47.104.61.232:8902/ioc/websocket';
var videoPlatUrl = 'http://27.128.189.131:8089';
var apiUrl = 'http://36.148.23.59:8901';
var pushUrl = 'http://36.148.23.59:8901';
var wsUrl = 'ws://36.148.23.59:8901/iocdata/websocket';
var iocUrl = 'http://36.148.23.59:8901/ioc';
var iocWsUrl = 'ws://36.148.23.59:8901/ioc/websocket';
// var apiUrl = 'http://localhost:8902';
// var pushUrl = 'http://localhost:8905';
// var wsUrl = 'ws://localhost:8905/iocdata/websocket';
// var iocUrl = 'http://localhost:8902/ioc';
// var iocWsUrl = 'ws://localhost:8902/ioc/websocket';
var videoPlatUrl = 'http://'+window.location.hostname+":18902";
var apiUrl = 'http://'+window.location.hostname+":8902";
var pushUrl = 'http://'+window.location.hostname+":8905";
var wsUrl = 'ws://'+window.location.hostname+':8905/iocdata/websocket';
var iocUrl = 'http://'+window.location.hostname+':8902/ioc';
var iocWsUrl = 'ws://'+window.location.hostname+':8902/ioc/websocket';
//var videoPlatUrl = 'http://27.128.189.131:8089';
// var apiUrl = 'http://36.148.23.59:8901';
// var pushUrl = 'http://36.148.23.59:8901';
// var wsUrl = 'ws://36.148.23.59:8901/iocdata/websocket';
// var iocUrl = 'http://36.148.23.59:8901/ioc';
// var iocWsUrl = 'ws://36.148.23.59:8901/ioc/websocket';
......@@ -61,8 +54,8 @@ var apis = {
getEnterpriseCameraById: apiUrl + '/ioc/frontApi/getEnterpriseCameraById',
getEleDeviceInfoListByUserId: apiUrl + '/ioc/frontApi/getEleDeviceInfoListByUserId',
mapSearch: apiUrl + '/ioc/frontApi/mapSearch',
getPreviewURLs: apiUrl + '/ioc/artemis/getPreviewURLs',
videoControlling: apiUrl + '/ioc/artemis/videoControlling',
getPreviewURLs: apiUrl + '/ioc/Artemis/getPreviewURLs',
videoControlling: apiUrl + '/ioc/Artemis/videoControlling',
scooper: {
cometd: videoPlatUrl + '/scooper-msg-queue/cometd',
queryGisTrails: videoPlatUrl + '/scooper-app-msg/gis/queryGisTrails',
......@@ -467,11 +460,11 @@ function initVideo(ele) {
user: conf['video.username'],
passwd: conf['video.password'],
// ip: conf['video.ip'],
ip: '27.128.189.131',
ip: window.location.hostname,
//videoServer port
port: conf['video.port'],
// janusUrl: conf['video.janus.url']
janusUrl: 'ws://27.128.189.131:8188',
janusUrl: 'ws://'+window.location.hostname+':8188',
},
//码流类型,默认0
streamType: conf['video.stream'],
......@@ -1173,7 +1166,7 @@ function login() {
var opts = {
url: apis.scooper.loginTo,
type: 'post',
data: { accUsername: 'psxyj2', accPassword: sha256_digest('abc123') },
data: { accUsername: 'admin', accPassword: sha256_digest('scooper') },
contentType: 'application/x-www-form-urlencoded',
success: function (res) {
if (res.code == 0) {
......@@ -1434,9 +1427,13 @@ function getVideoUrl(cameraIndexCode,optionId) {
borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
}
});
player.JS_Play(res.data.url,
{playURL: res.data.url, mode:"0" }, "0").then(() => { console.log('realplay success') },
var dataUrl = JSON.parse(data);
var url =dataUrl.data.url
if(window.location.hostname!="192.168.3.3"){
url = url.replace("192.168.3.7","27.128.187.38");
}
player.JS_Play(url,
{playURL: url, mode:"0" }, "0").then(() => { console.log('realplay success') },
e => { console.error(e) }
)
......
//只需配置ip和端口即可
var videoPlatIp = '27.128.189.131';
var videoPlatPort = '8089';
var videoPlatUrl = 'http://' + videoPlatIp + ':' + videoPlatPort;
//var videoPlatUrl = 'http://' + videoPlatIp + ':' + videoPlatPort;
var videoPlatUrl = window.location.hostname+":18902";
document.write('<link rel="stylesheet" media="screen" href="'+videoPlatUrl+'/scooper-video/css/new/scooper.video.css"/>');
// document.write('<link rel="stylesheet" media="screen" href="./main.css"/>');
......
......@@ -46,12 +46,11 @@ function handleGetQuery(name) {
passwd: conf['video.password'],
//videoServer ip
// ip: conf['video.ip'],
ip: '27.128.189.131',
ip: window.location.hostname,
//videoServer port
port: conf['video.port'],
//janus地址
// janusUrl: conf['video.janus.url']
janusUrl: 'ws://27.128.189.131:8188',
janusUrl: 'ws://'+window.location.hostname+':8188',
},
//码流类型,默认0
streamType: conf['video.stream'],
......
......@@ -96,12 +96,11 @@ var video_ids = {
passwd: conf['video.password'],
//videoServer ip
// ip: conf['video.ip'],
ip: '27.128.189.131',
ip: window.location.hostname,
//videoServer port
port: conf['video.port'],
//janus地址
// janusUrl: conf['video.janus.url']
janusUrl: 'ws://27.128.189.131:8188'
janusUrl: 'ws://'+window.location.hostname+':8188',
},
//码流类型,默认0
streamType: conf['video.stream'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment