<template>
<div style="height: 100%; width: 100%; position: relative;">
<el-button v-if="playText !=''" style="position: absolute;top: 0;right: 0;left: 0; bottom: 0;margin: auto;height: 40px;width: 100px;" type="primary" @click="frontDownload">下载插件</el-button>
<div style="width:800px;height:600px;overflow:hidden;" :style="{'width':Width,'height':Height}">
<div id="playWnd" class="playWnd" ref="playWnd" />
</div>
</div>
</template>
<script>
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
var oWebControl = null
var that = null;
var initCount = 0;
var pubKey = ''
var playWndWidth = 800;
var playWndHeight = 800;
//初始化
function initConfig(){
var appkey = "xxxxx";//综合安防管理平台提供的appkey,必填 var secret = setEncrypt("xxxxx"); //综合安防管理平台提供的secret,必填
var ip = "x.x.x.x"; //综合安防管理平台IP地址,必填
var playMode = 0; //初始播放模式:0-预览,1-回放
var port = 443; //综合安防管理平台端口,若启用HTTPS协议,默认443
var snapDir = "D:\\SnapDir"; //抓图存储路径
var videoDir = "D:\\VideoDir"; //紧急录像或录像剪辑存储路径
var layout = "5x5"; //playMode指定模式的布局
var enableHTTPS = 1; //是否启用HTTPS协议与综合安防管理平台交互,这里总是填1
var encryptedFields = 'secret'; //加密字段,默认加密领域为secret
var showToolbar = 1; //是否显示工具栏,0-不显示,非0-显示
var showSmart = 1; //是否显示智能信息(如配置移动侦测后画面上的线框),0-不显示,非0-显示
var buttonIDs = "0,16,256,257,258,259,260,512,513,514,515,516,517,768,769"; //自定义工具条按钮
oWebControl.JS_RequestInterface({
funcName: "init",
argument: JSON.stringify({
appkey: appkey, //API网关提供的appkey
secret: secret, //API网关提供的secret
ip: ip, //API网关IP地址
playMode: playMode, //播放模式(决定显示预览还是回放界面)
port: port, //端口
snapDir: snapDir, //抓图存储路径
videoDir: videoDir, //紧急录像或录像剪辑存储路径
layout: layout, //布局
enableHTTPS: enableHTTPS, //是否启用HTTPS协议
encryptedFields: encryptedFields, //加密字段
showToolbar: showToolbar, //是否显示工具栏
showSmart: showSmart, //是否显示智能信息
buttonIDs: buttonIDs //自定义工具条按钮
})
}).then(function (oData) {
console.log('!!!!!!!!!!!!!!!!!!!!',oData)
oWebControl.JS_Resize( playWndWidth,playWndHeight); // 初始化后resize一次,规避firefox下首次显示窗口后插件窗口未与DIV窗口重合问题
}).catch(err=>{
console.log('+++++++++++++++++++++++',err)
});
}
//获取公钥
function getPubKey (callback) {
oWebControl.JS_RequestInterface({
funcName: "getRSAPubKey",
argument: JSON.stringify({
keyLength: 1024
})
}).then(function (oData) {
console.log(oData);
if (oData.responseMsg.data) {
pubKey = oData.responseMsg.data;
callback()
}else{
console.log('获取公钥失败')
}
})
}
//RSA加密
function setEncrypt (value) {
var encrypt = new JSEncrypt();
encrypt.setPublicKey(pubKey);
return encrypt.encrypt(value);
}
/**
* video 初始化及配置
* @param {*video挂载的dom id} id
* @param {*连接成功的回调} cbConnectSuccess
* @param {*连接报错的回调} cbConnectError
* @param {*连接关闭的回调} cbConnectClose
*/
function WebControlInit(id, cbConnectSuccess, cbConnectError, cbConnectClose) {
return new WebControl({
szPluginContainer: id,
iServicePortStart: 15900, // 对应 LocalServiceConfig.xml 中的ServicePortStart值
iServicePortEnd: 15909, // 对应 LocalServiceConfig.xml 中的ServicePortEnd值
szClassId:"23BF3B0A-2C56-4D97-9C03-0CB103AA8F11",
cbConnectSuccess,
cbConnectError,
cbConnectClose
})
}
// 监听视频控件的事件
function cbIntegrationCallBack(oData) {
}
function cbConnectSuccess() {
// 设置窗口控制回调
oWebControl.JS_SetWindowControlCallback({
cbIntegrationCallBack: cbIntegrationCallBack
})
//创建视频窗口
oWebControl
.JS_StartService('window', {
dllPath: './VideoPluginConnect.dll'
})
.then(function () {
oWebControl
.JS_CreateWnd('playWnd', playWndWidth,playWndHeight)
.then(function () {
getPubKey( initConfig )
that.startPreview();
that.playText = ''
console.log('JS_CreateWnd success')
})
})
}
function cbConnectError() {
console.log('cbConnectError')
oWebControl = null
that.playText = '插件未启动,正在尝试启动,请稍候...'
console.error('确认本地进程是否已安装并开启成功!')
oWebControl.JS_WakeUp("VideoWebPlugin://"); // 程序未启动时执行error函数,采用wakeup来启动程序
initCount ++;
if (initCount < 3) {
setTimeout(function () {
WebControlInit();
}, 3000)
} else {
that.playText = '插件启动失败,请检查插件是否安装!'
}
}
function cbConnectClose(bNormalClose) {
// 连接异常断开:bNormalClose = false
// JS_Disconnect正常断开:bNormalClose = true
console.log('cbConnectClose')
oWebControl = null
}
//销毁视频控件
function WebControlDistory() {
// var bIE = !!window.ActiveXObject || 'ActiveXObject' in window // 是否为IE浏览器
if (oWebControl != null) {
oWebControl.JS_DestroyWnd().then(
function () {
console.log('JS_DestroyWnd')
},
function () {}
)
oWebControl.JS_StopService('window').then(function () {
oWebControl.JS_Disconnect().then(
function () {
console.log('JS_Disconnect')
},
function () {}
)
})
}
}
window.onscroll = function () {
if (oWebControl != null) {
oWebControl.JS_Resize( playWndWidth,playWndHeight);
}
}
window.onresize = function () {
if (oWebControl != null) {
oWebControl.JS_Resize( playWndWidth,playWndHeight);
}
}
window.onunload = () => {
try {
oWebControl.JS_HideWnd()
WebControlDistory()
} catch (error) {
console.error(error)
}
}
window.onpagehide = () => {
try {
oWebControl.JS_HideWnd()
} catch (error) {
console.error(error)
}
}
export default {
props: ['mode', 'code','StyleObj','resetData'],
data() {
return {
playText: '',
cameraIndexCode:'34020000001320000018',
text:'插件未启动,正在尝试启动,请稍候...',
callbackMessage: '', //显示回调信息
tips: '调用成功',
successTip: false,
tipsShow: false,
Width:0,
Height:0
}
},
computed: {
},
beforeDestroy() {
if (oWebControl != null){
oWebControl.JS_HideWnd(); // 先让窗口隐藏,规避插件窗口滞后于浏览器消失问题
oWebControl.JS_Disconnect().then(function(){}, function() {});
}
this.$bus.$off('fun')
},
created(){
if(this.StyleObj){
this.Width = this.StyleObj.W?this.StyleObj.W+'px':'800px';
this.Height = this.StyleObj.H?this.StyleObj.H+'px':'800px';
playWndWidth = this.StyleObj.W?this.StyleObj.W: 800;
playWndHeight = this.StyleObj.H?this.StyleObj.H: 800;
}
this.$bus.$on('fun',this.editPreview)
},
mounted() {
// console.log(location.pathname)
that = this;
oWebControl = WebControlInit(
'playWnd',
cbConnectSuccess,
cbConnectError,
cbConnectClose,
)
window.onload = function(){
that.startPreview();
}
},
methods: {
frontDownload() {
var a = document.createElement('a') // 创建一个<a></a>标签
a.href = process.env.VUE_APP_Download + 'VideoWebPlugin.exe'
a.download = 'VideoWebPlugin.exe'
a.style.display = 'none' // 障眼法藏起来a标签
document.body.appendChild(a) // 将a标签追加到文档对象中
a.click() // 模拟点击了a标签,会触发a标签的href的读取,浏览器就会自动下载了
a.remove() // 一次性的,用完就删除a标签
},
/**
* 设置事件回调信息
*/
showCBInfo(message) {
this.callbackMessage = this.callbackMessage + JSON.stringify(message) + '\n'
},
startPreview(){
var cameraIndexCode = this.cameraIndexCode; //获取输入的监控点编号值,必填
cameraIndexCode = cameraIndexCode.replace(/(^\s*)/g, "");
cameraIndexCode = cameraIndexCode.replace(/(\s*$)/g, "");
let equipmentArr = this.resetData;
let arraySize = equipmentArr.length;
// 获取当前窗口个数 默认一个
var WndNum = 1;
oWebControl.JS_RequestInterface({
funcName: "getLayout"
}).then(function (oData) {
console.log(oData)
//分析窗口数
var Data = JSON.stringify(oData.responseMsg.data);
// Data = Data.replace(/\\n/g, "");
// Data = Data.replace(/\\/g, "");
// Data = Data.replace(/\"{/g, "{");
// Data = Data.replace(/}\"/g, "}");
// WndNum = JSON.parse(Data).wndNum;
if(WndNum>arraySize){
WndNum = arraySize
}
console.log(WndNum);
var multiPlayParam = {
"argument": {
"list": []
},
"funcName": "startMultiPreviewByCameraIndexCode"
}
for (let i = 0; i < 25; i++){
var PlayParam = {
"authUuid": "",
"cameraIndexCode": equipmentArr[i % arraySize],
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": i+1
}
multiPlayParam.argument.list.push(PlayParam);
}
console.log(multiPlayParam);
oWebControl.JS_RequestInterface(
multiPlayParam
)
})
},
editPreview(e){
var cameraIndexCode = e; //获取输入的监控点编号值,必填
cameraIndexCode = cameraIndexCode.replace(/(^\s*)/g, "");
cameraIndexCode = cameraIndexCode.replace(/(\s*$)/g, "");
oWebControl.JS_RequestInterface({
funcName: "getLayout"
}).then(function (oData) {
console.log(oData)
var previewParam = {
argument:JSON.stringify( {
authUuid: "",
cameraIndexCode:e,
ezvizDirect: 0,
gpuMode: 0,
streamMode: 0,
transMode: 1,
wndId: 1
}),
funcName: "startPreview",
};
oWebControl.JS_RequestInterface(
previewParam
)
})
},
}
}
</script>
<style lang="scss" scoped>
.playWnd {
width: 100%;
height: 100%;
background: #000;
}
</style>