IntelligentRecognition/ah-jjsp-web/.svn/pristine/5b/5b61ba99581465747a56ace7dbd...

278 lines
7.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let tokens;
let start = [];
function hint() {
layer.msg('视频播放失败,请检查网络!!!', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
// 执行一次函数的定时器
let time = setTimeout(hint, 1000 * 30);
$(function () {
if (isNumber(puId)) {
createVideo();
connect();
} else {
alert("puId错误!!!")
}
});
/**
* post 请求
* @param router
* @param params
* @param callback
*/
function requestPost(router, params, callback) {
$.ajax({
type: 'post',
url: _cf.q2http_url + router,
data: params,
traditional: true,
dataType: 'json',
async: false,
complete: function (rv) {
$('#hint').show();
setTimeout(" $('#hint').hide();", 3000);
if (typeof callback == 'function') callback(rv)
}
})
}
/**
* 创建平台连接
*/
function connect() {
// let params = {
// "address": _cf.connParams.address,
// "port": _cf.connParams.port,
// "user": _cf.connParams.user,
// "password": _cf.connParams.password,
// "epid": _cf.connParams.epid,
// "fixaddr": _cf.connParams.bfix
// }
var allDataParams="address="+_cf.connParams.address+"&port="+_cf.connParams.port+
"&user="+ _cf.connParams.user+"&password="+_cf.connParams.password+"&epid="+_cf.connParams.epid+"&fixaddr="+_cf.connParams.bfix;
let params = {
"params":videoEncrypt(allDataParams)
}
console.log(params)
requestPost('login2', params, function (rv) {
let result = {
errcode: -1,
token: ''
}
let respJSON = JSON.parse(rv.responseText);
if (respJSON.hasOwnProperty('errcode')) {
result.errcode = respJSON.errcode;
}
if (respJSON.hasOwnProperty('token')) {
result.token = respJSON.token;
result.errcode = 0;
tokens = result.token;
if (!isEmpty(tokens)) {
playVideo(puId, "0");
}
}
});
}
/**
* 播放视频
* @param puId
* @param idx
*/
function playVideo(puId, idx) {
//播视频接口
let url = _cf.q2http_url + "stream.flv?puid=" + puId + "&idx=" + idx + "&stream=0&token=" + tokens;
console.log(url);
if (flvjs.isSupported()) {
let videoElement = document.getElementById('video_html5_api');
let flvPlayer = flvjs.createPlayer({
type: 'flv',
isLive: true,
hasAudio: false,
url: url
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
}
}
function createVideo() {
let play = videojs('video', {
muted: true,
controls: false,
loop: true,
preload: "auto",
autoplay: true,
});
play.play();
$('.vjs-loading-spinner').hide();
$('.vjs-big-play-button').hide();
$('.vjs-poster').removeAttr("class");
var elevideo = document.getElementById("video_html5_api");
elevideo.addEventListener('play', function () { //播放开始执行的函数
console.log(time);
clearTimeout(time);
});
}
function shot() {
screenshot($('#video_html5_api'));
}
//缩放功能
function zoomcontrol(option) {
let params = {
puid: puId,
idx: "0"
}
switch (option) {
case "stop":
//停止缩放接口
requestPost('PTZ/C_PTZ_StopPictureZoom?token=' + tokens, params, rv => {
})
break;
case "zoomin":
//放大图像接口
requestPost('PTZ/C_PTZ_ZoomInPicture?token=' + tokens, params, rv => {
})
break;
default:
//缩小图像接口
requestPost('PTZ/C_PTZ_ZoomOutPicture?token=' + tokens, params, rv => {
})
break;
}
}
//远近焦点功能
function focuscontrol(option) {
let params = {
puid: puId,
idx: "0"
}
switch (option) {
case "near":
requestPost('PTZ/C_PTZ_MakeFocusNear?token=' + tokens, params, rv => {
console.log(rv)
})
break;
case "faraway":
requestPost('PTZ/C_PTZ_MakeFocusFar?token=' + tokens, params, rv => {
console.log(rv)
})
break;
default:
requestPost('PTZ/C_PTZ_StopFocusMove?token=' + tokens, params, rv => {
console.log(rv)
})
break;
}
}
function aperture(option) {
let camera = {
puid: puId,
idx: "0"
};
let xml = "";
switch (option) {
case "augment":
xml = `<?xml version="1.0" encoding="UTF-8"?>
<M Type="ComReq">
<C Type="G" Prio="1" EPID="${_cf.connParams.epid}" Lang="zh_CN">
<Res Type="IV" Idx="${camera.idx}" OptID="C_PTZ_AugmentAperture" Stream="0"><Param></Param></Res>
</C>
</M>`;
requestPost(`RawRequest?dstType=201&dstID=${camera.puid}&token=${tokens}`, {xml: xml}, rv => {
console.log(rv);
});
break;
case "minish":
xml = `<?xml version="1.0" encoding="UTF-8"?>
<M Type="ComReq">
<C Type="G" Prio="1" EPID="${_cf.connParams.epid}" Lang="zh_CN">
<Res Type="IV" Idx="${camera.idx}" OptID="C_PTZ_MinishAperture" Stream="0"><Param></Param></Res>
</C>
</M>`;
requestPost(`RawRequest?dstType=201&dstID=${camera.puid}&token=${tokens}`, {xml: xml}, rv => {
console.log(rv)
});
break;
default:
xml = `<?xml version="1.0" encoding="UTF-8"?>
<M Type="ComReq">
<C Type="G" Prio="1" EPID="${_cf.connParams.epid}" Lang="zh_CN">
<Res Type="IV" Idx="${camera.idx}" OptID="C_PTZ_StopApertureZoom" Stream="0"><Param></Param></Res>
</C>
</M>`;
requestPost(`RawRequest?dstType=201&dstID=${camera.puid}&token=${tokens}`, {xml: xml}, rv => {
console.log(rv);
});
break;
}
}
//旋转平台功能
async function turncontrol(option) {
let params = {
puid: puId,
idx: "0",
motion: option
};
if (!isEmpty(option)) {
requestPost('PTZ/C_PTZ_Turn?token=' + tokens, params, (rv) => {
});
}
}
function control(key) {
switch (key) {
case 0:
turncontrol('stop');
break;
case 1:
turncontrol('up');
break;
case 2:
turncontrol('down');
break;
case 3:
turncontrol('left');
break;
case 4:
turncontrol('right');
break;
case 5:
zoomcontrol('zoomin');
break;
case 6:
zoomcontrol('zoominout');
break;
case 7:
focuscontrol('near');
break;
case 8:
focuscontrol('faraway');
break;
case 9:
zoomcontrol('stop');
break;
case 10:
focuscontrol('stop');
break;
default:
break;
}
}