当前位置: 首页 > Web前端 > vue.js

【记录】Vue中使用海康视频插件(监控)

时间:2023-03-31 23:41:00 vue.js

使用条件1.导入依赖文件jsencrypt.min.jsjsWebControl-1.0.0.min.js注意:必须在vue的根index.html文件中引入,在main.js中引入无效;相关文章介绍:传送门>>>依赖文件及官网示例:下载>>>2.template

3.methods/*获取视频代码*/asyncgetVideoCode(){this.realTimeData.videoLoad=true;constparams={area:"",enterprise:this.realTimeData.enterpriseName,street:"",};const{data}=awaitgetCamera(params)constvideoCode=data.list.map(({cameraIndexCode})=>({cameraIndexCode,}));this.realTimeData.videoConfig=videoCode.map((item)=>{return{code:item.cameraIndexCode,id:Math.floor(Math.random()*100),};});this.initPlugin(videoCode);},/*创建插件实例*/initPlugin(codeArr=this.realTimeData.videoConfig){constdll={dllPath:"./VideoPluginConnect.dll"};codeArr.forEach((item,index)=>{letoWebControl=newWebControl({szPluginContainer:`playWnd${index}`,//指定容器idiServicePortStart:15900,iServicePortEnd:15909,szClassId:"23BF3B0A-2C56-4D97-9C03-0CB103AA8F11",//clsidcbConnectSuccessforIE10usingActiveX:()=>{oWebControl.JS_StartService("window",dll).then(()=>{oWebControl.JS_SetWindowControlCallback({cbIntegrationCallBack:(msg)=>{//注意:不能使用外部函数调用,无效if(msg?.responseMsg?.msg?.result){const{result}=msg.responseMsg.msg;if(result==1024){oWebControl.JS_HideWnd();//放大并隐藏其他视频窗口}elseif(result==1025){oWebControl.JS_ShowWnd();//缩小所有窗口}}},});//成功启动插件服务oWebControl.JS_CreateWnd(`playWnd${index}`,260,160).then(()=>{//JS_CreateWnd创建视频播放窗口,宽高可设置this.initVideo(oWebControl,item.cameraIndexCode);//创建回放实例成功后初始化});});},//插件服务启动失败,尝试启动cbConnectError:()=>{oWebControl=null;WebControl.JS_WakeUp("VideoWebPlugin://");setTimeout(()=>{this.initPlugin();},3000)}});这。plug.example.push(oWebControl);});},/*获取公钥*/asyncinitVideo(oWebControl,code){constparams={funcName:"getRSAPubKey",argument:JSON.stringify({keyLength:1024}),};const{responseMsg}=awaitoWebControl.JS_RequestInterface(params)if(responseMsg.data){this.plug.pubKey=responseMsg.data;this.getVideoConfig(oWebControl);this.getClickAction(oWebControl,代码);}},/*视频插件配置*/getVideoConfig(oWebControl){const{offsetWidth,offsetHeight}=document.getElementById("playWnd0");constconfigObj={funcName:"init",argument:JSON.stringify({appkey:"xxxxxx",//API网关提供的appkeysecret:this.setEncrypt("xxxxxx"),//API网关提供的secretip:"xxx.xxx.xxx.xxx",//API网关IP地址playMode:0,//播放模式:0实时预览,1视频播放端口:8443,//端口snapDir:"D:\\SnapDir",//快照存储路径videoDir:"D:\\VideoDir",//紧急视频或视频片段存储路径layout:"1x1",//布局enableHTTPS:1,//是否开启HTTPS协议encryptedFields:"secret",//加密字段showToolbar:1,//是否显示工具栏showSmart:1,//是否显示智能信息buttonIDs:"0,16,256,257,258,259,260,512,513,514,515,516,517,768,769",//自定义工具栏按钮}),};oWebControl.JS_RequestInterface(configObj).then(()=>{oWebControl.JS_Resize(offsetWidth,offsetHeight);});},/*视频流RSA加密*/setEncrypt(value){constencrypt=newJSEncrypt();encrypt.setPublicKey(this.plug.pubKey);returnencrypt.encrypt(value);},/*视频播放*/getClickAction(oWebControl,code){code=code.trim();oWebControl.JS_RequestInterface({funcName:"startPreview",argument:JSON.stringify({cameraIndexCode:code,//监控点编号streamMode:0,//主副码流标识:0-主码流,1-sub-streamtransMode:1,//传输协议:0-UDP,1-TCPgpuMode:0,//是否开启GPU硬解,0-关闭,1-开启wndId:-1,//播放窗口序号(可以在上面的布局中指定播放窗口2x2)}),});this.realTimeData.videoLoad=false;},/*销毁视频实例*/getDestruction(){this.plug.example.forEach((item)=>{item.JS_HideWnd();item.JS_DestroyWnd().then((res)=>{});//item.JS_Disconnect().then((res)=>{});});}四、使用效果图,功能:1.实时监控/2.截图/3.屏幕录制/4.摄像头控制/5.语音命令(硬件支持)/6.即时回放