hb_zhgd_screen/plugin/hk_video_plugin/video_connect.js

678 lines
24 KiB
JavaScript
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.

// 已登录设备、设备端口、RTSP端口
let ip = null, deviceport = null, rtspport = null;
// 码流类型(1.主码流 2.子码流 3.第三码流 4.转码码流)
let streamtype = 2;
// 数字通道为false、零通道为true
let bZero = 'false';
// 回放码流类型 1.主码流 2.子码流
let record_streamtype = 1;
let oSel = [
{ title: '球机', parentId: '-1', id: '0' }], deviceStatusList = [];
// 初始化插件
// 全局保存当前选中窗口
var g_iWndIndex = 0; //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
var g_oLocalConfig = null; //本地配置
//错误码
//通用错误
var ERROR_CODE_UNKNOWN = 1000; //未知错误
var ERROR_CODE_NETWORKERROR = 1001; //网络错误
var ERROR_CODE_PARAMERROR = 1002; //缺少插件元素
//登录模块
var ERROR_CODE_LOGIN_NOLOGIN = 2000; // 未登录
var ERROR_CODE_LOGIN_REPEATLOGIN = 2001; //设备已登录,重复登录
var ERROR_CODE_LOGIN_NOSUPPORT = 2002; //当前设备不支持Digest登录
//预览播放
var ERROR_CODE_PLAY_PLUGININITFAIL = 3000; //插件初始化失败
var ERROR_CODE_PLAY_NOREPEATPLAY = 3001; //当前窗口已经在预览
var ERROR_CODE_PLAY_PLAYBACKABNORMAL = 3002; //回放异常
var ERROR_CODE_PLAY_PLAYBACKSTOP = 3003; //回放停止
var ERROR_CODE_PLAY_NOFREESPACE = 3004; //录像过程中,硬盘容量不足
//对讲
var ERROR_CODE_TALK_FAIL = 5000; //语音对讲失败
var version = "V3.3.0build20230322"
$(function () {
// 初始化插件参数及插入插件
WebVideoCtrl.I_InitPlugin({
bWndFull: true, //是否支持单窗口双击全屏,默认支持 true:支持 false:不支持
iWndowType: 1,
// aIframe: ["test"],
cbSelWnd: function (xmlDoc) {
g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
var szInfo = "当前选择的窗口编号:" + g_iWndIndex;
showCBInfo(szInfo);
},
cbDoubleClickWnd: function (iWndIndex, bFullScreen) {
var szInfo = "当前放大的窗口编号:" + iWndIndex;
if (!bFullScreen) {
szInfo = "当前还原的窗口编号:" + iWndIndex;
}
showCBInfo(szInfo);
},
cbEvent: function (iEventType, iParam1, iParam2) {
if (2 == iEventType) {// 回放正常结束
showCBInfo("窗口" + iParam1 + "回放结束!");
} else if (-1 == iEventType) {
showCBInfo("设备" + iParam1 + "网络错误!");
} else if (3001 == iEventType) {
clickStopRecord(g_szRecordType, iParam1);
}
},
cbInitPluginComplete: function () {
WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin").then(() => {
// 检查插件是否最新
WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {
if (bFlag) {
alert("检测到新的插件版本双击开发包目录里的HCWebSDKPluginsUserSetup.exe升级");
}
});
}, () => {
alert("插件初始化失败请确认是否已安装插件如果未安装请双击开发包目录里的HCWebSDKPluginsUserSetup.exe安装");
});
}
});
// 窗口事件绑定
$(window).bind({
resize: function () {
//WebVideoCtrl.I_Resize($("body").width(), $("body").height());
}
});
//初始化日期时间
var szCurTime = dateFormat(new Date(), "yyyy-MM-dd");
$("#starttime").val(szCurTime + " 00:00:00");
$("#endtime").val(szCurTime + " 23:59:59");
$("#downloadstarttime").val(szCurTime + " 00:00:00");
$("#downloadendtime").val(szCurTime + " 23:59:59");
});
// 格式化时间
function dateFormat(oDate, fmt) {
var o = {
"M+": oDate.getMonth() + 1, //月份
"d+": oDate.getDate(), //日
"h+": oDate.getHours(), //小时
"m+": oDate.getMinutes(), //分
"s+": oDate.getSeconds(), //秒
"q+": Math.floor((oDate.getMonth() + 3) / 3), //季度
"S": oDate.getMilliseconds()//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
// 显示回调信息
function showCBInfo(szInfo) {
szInfo = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo + "</div>";
$("#cbinfo").html(szInfo + $("#cbinfo").html());
}
// 窗口分割数
function changeWndNum(iType) {
iType = parseInt(iType, 10);
WebVideoCtrl.I_ChangeWndNum(iType);
}
// 登录
function clickLogin(szProtoType) {
var szIP = login_config.loginip,
szPort = login_config.port,
szUsername = login_config.username,
szPassword = login_config.password;
if ("" == szIP || "" == szPort) {
return;
}
var szDeviceIdentify = szIP + "_" + szPort;
let loadingMsg = parent.layer.msg("设备初始化中,请稍后...", { icon: 16, scrollbar: false, time: 0, offset: 't' });
WebVideoCtrl.I_Login(szIP, szProtoType, szPort, szUsername, szPassword, {
timeout: 3000,
success: function (xmlDoc) {
/* showOPInfo(szDeviceIdentify + " 登录成功!");
$("#ip").prepend("<option value='" + szDeviceIdentify + "'>" + szDeviceIdentify + "</option>"); */
console.log(szDeviceIdentify + " 登录成功!");
setTimeout(function () {
// $("#ip").val(szDeviceIdentify);
ip = szDeviceIdentify;
setTimeout(function () {
getChannelInfo();
setTimeout(() => {
setTreeData(loadingMsg);
}, 1000);
}, 1000);
getDevicePort();
}, 10);
},
error: function (oError) {
if (ERROR_CODE_LOGIN_REPEATLOGIN === status) {
// showOPInfo(szDeviceIdentify + " 已登录过!");
console.log(szDeviceIdentify + " 已登录过!");
} else {
if (oError.errorCode === 401) {
// showOPInfo(szDeviceIdentify + " 登录失败,已自动切换认证方式!");
console.log(szDeviceIdentify + " 登录失败,已自动切换认证方式!");
} else {
// showOPInfo(szDeviceIdentify + " 登录失败!", oError.errorCode, oError.errorMsg);
console.log(szDeviceIdentify + " 登录失败!", oError.errorCode, oError.errorMsg);
}
}
}
});
}
// 获取通道
function getChannelInfo() {
var szDeviceIdentify = ip;
// oSel = $("#channels").empty();
// oSel = null;
if (null == szDeviceIdentify) {
return;
}
// 模拟通道
WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
success: function (xmlDoc) {
var oChannels = $(xmlDoc).find("VideoInputChannel");
$.each(oChannels, function (i) {
var id = $(this).find("id").eq(0).text(),
name = $(this).find("name").eq(0).text();
if ("" == name) {
name = "Camera " + (i < 9 ? "0" + (i + 1) : (i + 1));
}
// oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
// oSel += "<option value='" + id + "' bZero='false'>" + name + "</option>";
oSel.push({ id: id, bZero: 'false', name: name, parentId: '0' })
});
console.log(szDeviceIdentify + " 获取模拟通道成功!");
},
error: function (oError) {
console.log(szDeviceIdentify + " 获取模拟通道失败!", oError.errorCode, oError.errorMsg);
}
});
// 数字通道
WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
success: function (xmlDoc) {
var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
$.each(oChannels, function (i) {
var id = $(this).find("id").eq(0).text(),
name = $(this).find("name").eq(0).text(),
online = $(this).find("online").eq(0).text();
if ("false" == online) {// 过滤禁用的数字通道
return true;
}
if ("" == name) {
name = "IPCamera " + (i < 9 ? "0" + (i + 1) : (i + 1));
}
// oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
// oSel += "<option value='" + id + "' bZero='false'>" + name + "</option>";
oSel.push({ id: id, bZero: 'false', name: name, parentId: '0' })
});
console.log(szDeviceIdentify + " 获取数字通道成功!");
},
error: function (oError) {
console.log(szDeviceIdentify + " 获取数字通道失败!", oError.errorCode, oError.errorMsg);
}
});
// 零通道
/* WebVideoCtrl.I_GetZeroChannelInfo(szDeviceIdentify, {
success: function (xmlDoc) {
var oChannels = $(xmlDoc).find("ZeroVideoChannel");
$.each(oChannels, function (i) {
var id = $(this).find("id").eq(0).text(),
name = $(this).find("name").eq(0).text();
if ("" == name) {
name = "Zero Channel " + (i < 9 ? "0" + (i + 1) : (i + 1));
}
if ("true" == $(this).find("enabled").eq(0).text()) {// 过滤禁用的零通道
// oSel.append("<option value='" + id + "' bZero='true'>" + name + "</option>");
// oSel += "<option value='" + id + "' bZero='true'>" + name + "</option>";
oSel.push({ id: id, bZero: 'true', name: name, parentId: '0' })
}
});
console.log(szDeviceIdentify + " 获取零通道成功!");
},
error: function (oError) {
console.log(szDeviceIdentify + " 获取零通道失败!", oError.errorCode, oError.errorMsg);
}
}); */
}
// 获取端口
function getDevicePort() {
var szDeviceIdentify = ip;
if (null == szDeviceIdentify) {
return;
}
var oPort = WebVideoCtrl.I_GetDevicePort(szDeviceIdentify).then((oPort) => {
/* $("#deviceport").val(oPort.iDevicePort);
$("#rtspport").val(oPort.iRtspPort); */
deviceport = oPort.iDevicePort;
rtspport = oPort.iRtspPort;
console.log(szDeviceIdentify + " 获取端口成功!");
}, (oError) => {
var szInfo = "获取端口失败!";
console.log(szDeviceIdentify + szInfo, oError.errorCode, oError.errorMsg);
});
}
// 获取数字通道
async function clickGetDigitalChannelInfo() {
var szDeviceIdentify = ip,
iAnalogChannelNum = 0;
// $("#digitalchannellist").empty();
if (null == szDeviceIdentify) {
return;
}
// 模拟通道
try {
var oAnalogChannelInfo = await WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {});
iAnalogChannelNum = $(oAnalogChannelInfo).find("VideoInputChannel").length;
} finally {
// 数字通道
WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
success: function (xmlDoc) {
var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
$.each(oChannels, function () {
var id = parseInt($(this).find("id").eq(0).text(), 10),
ipAddress = $(this).find("ipAddress").eq(0).text(),
srcInputPort = $(this).find("srcInputPort").eq(0).text(),
managePortNo = $(this).find("managePortNo").eq(0).text(),
online = $(this).find("online").eq(0).text(),
proxyProtocol = $(this).find("proxyProtocol").eq(0).text();
deviceStatusList.push({ id: id, online: online === 'true' ? '1' : '0' });
});
console.log(szDeviceIdentify + " 获取数字通道成功!");
},
error: function (oError) {
console.log(szDeviceIdentify + " 没有数字通道!", oError.errorCode, oError.errorMsg);
}
});
}
}
// 开始预览
function clickStartRealPlay(iStreamType, iChannelID, bZero) {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
szDeviceIdentify = ip,
iRtspPort = parseInt(rtspport, 10),
iChannelID = iChannelID,
bZeroChannel = bZero == "true" ? true : false,
// bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
szInfo = "";
iStreamType = streamtype;
if (null == szDeviceIdentify) {
return;
}
var startRealPlay = function () {
WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, {
iStreamType: iStreamType,
iChannelID: iChannelID,
bZeroChannel: bZeroChannel,
iPort: iRtspPort,
success: function () {
szInfo = "开始预览成功!";
console.log(szDeviceIdentify + " " + szInfo);
parent.layer.msg('开始预览成功!', { icon: 1, offset: 't' });
},
error: function (oError) {
console.log(szDeviceIdentify + " 开始预览失败!", oError.errorCode, oError.errorMsg);
parent.layer.msg('开始预览失败!', { icon: 2, offset: 't' });
}
});
};
if (oWndInfo != null) {// 已经在播放了,先停止
WebVideoCtrl.I_Stop({
success: function () {
startRealPlay();
}
});
} else {
startRealPlay();
}
}
// 停止预览
function clickStopRealPlay() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
szInfo = "";
if (oWndInfo != null) {
WebVideoCtrl.I_Stop({
success: function () {
szInfo = "停止预览成功!";
console.log(oWndInfo.szDeviceIdentify + " " + szInfo);
},
error: function (oError) {
console.log(szDeviceIdentify + " 停止预览失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
// PTZ控制 9为自动1,2,3,4,5,6,7,8为方向PTZ
var g_bPTZAuto = false;
function mouseDownPTZControl(iPTZIndex) {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
bZeroChannel = false,
iPTZSpeed = 4;
if (bZeroChannel) {// 零通道不支持云台
return;
}
if (oWndInfo != null) {
if (9 == iPTZIndex && g_bPTZAuto) {
iPTZSpeed = 0;// 自动开启后速度置为0可以关闭自动
} else {
g_bPTZAuto = false;// 点击其他方向,自动肯定会被关闭
}
WebVideoCtrl.I_PTZControl(iPTZIndex, false, {
iPTZSpeed: iPTZSpeed,
success: function (xmlDoc) {
if (9 == iPTZIndex && g_bPTZAuto) {
console.log(oWndInfo.szDeviceIdentify + " 停止云台成功!");
} else {
console.log(oWndInfo.szDeviceIdentify + " 开启云台成功!");
}
if (9 == iPTZIndex) {
g_bPTZAuto = !g_bPTZAuto;
}
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 开启云台失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
// 方向PTZ停止
function mouseUpPTZControl() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(1, true, {
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 停止云台成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 停止云台失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZZoomIn() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(10, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 调焦+成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 调焦+失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZZoomout() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(11, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 调焦-成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 调焦-失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZZoomStop() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(11, true, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 调焦停止成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 调焦停止失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZFocusIn() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(12, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦+成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦+失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZFoucusOut() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(13, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦-成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦-失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZFoucusStop() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(12, true, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦停止成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 聚焦停止失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZIrisIn() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(14, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 光圈+成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 光圈+失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZIrisOut() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(15, false, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 光圈-成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 光圈-失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
function PTZIrisStop() {
var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
if (oWndInfo != null) {
WebVideoCtrl.I_PTZControl(14, true, {
iWndIndex: g_iWndIndex,
success: function (xmlDoc) {
console.log(oWndInfo.szDeviceIdentify + " 光圈停止成功!");
},
error: function (oError) {
console.log(oWndInfo.szDeviceIdentify + " 光圈停止失败!", oError.errorCode, oError.errorMsg);
}
});
}
}
// 关闭全部视频播放
function stopAllPlay() {
WebVideoCtrl.I_StopAllPlay().then(() => {
console.log('关闭全部视频播放成功!')
}).catch(() => {
console.log('失败!')
})
}
// 退出
function clickLogout() {
var szDeviceIdentify = ip;
if (null == szDeviceIdentify) {
return;
}
WebVideoCtrl.I_Logout(szDeviceIdentify).then(() => {
$("#ip option:contains(" + szDeviceIdentify + ")").remove();
console.log(szDeviceIdentify + " " + "退出成功!");
}, () => {
console.log(szDeviceIdentify + " " + "退出失败!");
});
}
function destroyPlugin() {
WebVideoCtrl.I_DestroyPlugin().then(() => {
document.querySelectorAll('a').forEach(link => {
link.removeAttribute('onclick'); // 移除内联事件
link.removeAttribute('href');
link.setAttribute('aria-disabled', 'true'); // 辅助技术可识别
link.style.cursor = 'default'; // 移除手型光标
// 创建一个无事件的新节点替换
const newLink = link.cloneNode(false);
newLink.textContent = link.textContent;
link.parentNode.replaceChild(newLink, link);
});
// 销毁后不能再预览了
console.log('销毁成功!')
}).catch(() => {
console.log('销毁失败!')
})
}
function showPlugin() {
WebVideoCtrl.I_ShowPlugin().then(() => {
console.log('展示成功!')
}).catch(() => {
console.log('展示失败!')
})
}
function hidPlugin() {
WebVideoCtrl.I_HidPlugin().then(() => {
console.log('隐藏成功!')
}).catch(() => {
console.log('隐藏失败!')
})
}
// 添加球机树数据
function setTreeData(loadingMsg) {
// 查询设备状态
clickGetDigitalChannelInfo();
setTimeout(() => {
let data = oSel;
data.forEach(itemA => {
const matchingItemB = deviceStatusList.find(itemB => parseInt(itemB.id) === parseInt(itemA.id));
if (matchingItemB) {
itemA.online = matchingItemB.online;
}
});
let totalNum = 0, onlineNum = 0, offLineNum = 0;
$.each(data, function (index, item) {
if (item.id !== '0') {
totalNum++;
let titleName = item.name;
if (item.name.length > 20) {
titleName = item.name.substr(0, 20) + '...';
}
if (item.online === '1') {
onlineNum++;
item.title = '<img src="../../img/video/ball_online.png"><span data-mtpis="' + item.name + '" online=' + item.online + ' id=' + item.id + ' bZero=' + item.bZero + '>' + titleName + '</span>'
} else {
offLineNum++;
item.title = '<img src="../../img/video/ball_offline.png"><span data-mtpis="' + item.name + '" online=' + item.online + ' id=' + item.id + ' bZero=' + item.bZero + '>' + titleName + '</span>'
}
}
})
videoTree = dtree.render({
elem: "#video-tree",
width: "96%", // 指定树的宽度
data: data,
dataFormat: "list",
skin: "laySimple",
line: false, // 显示树线
});
// 设备在线情况
$('.device-status').eq(0).html('全部(' + totalNum + '')
$('.device-status').eq(1).html('在线(' + onlineNum + '')
$('.device-status').eq(2).html('离线(' + offLineNum + '')
parent.layer.close(loadingMsg);
}, 1000);
}