import {ElMessage} from 'element-plus' // 初始化控件 export function initPlugin(iWndowType: number, id: string, bWndFull: boolean, callback: any, cbDoubleClickWnd: any) { // 检查浏览器是否支持无插件 // if (!WebVideoCtrl.I_SupportNoPlugin()) { // ElMessage.warning("当前浏览器不支持无插件预览监控视频,已自动切换成插件模式,如果还未安装插件请安装") // // 检查插件是否已经安装 // // } const isInstall = WebVideoCtrl.I_CheckPluginInstall() if (isInstall == -1) { ElMessage.warning('您还未安装过插件,请先下载WebComponentsKit.exe双击安装!') // 后面推下载文件 return } // 初始化插件参数及插入插件 WebVideoCtrl.I_InitPlugin({ szColorProperty: 'plugin-background:ffffff; sub-background:00000; sub-border:D0DAE4; sub-border-select:409EFF', bWndFull, // 是否支持单窗口双击全屏,默认支持 true:支持 false:不支持 iWndowType, cbSelWnd(xmlDoc) { const g_iWndIndex = parseInt(document.getElementById(xmlDoc).find('SelectWnd').eq(0).text(), 10) console.log(`当前选择的窗口编号:${g_iWndIndex}`) }, cbDoubleClickWnd(iWndIndex, bFullScreen, event) { var szInfo = `当前放大的窗口编号:${iWndIndex}` if (!bFullScreen) { szInfo = `当前还原的窗口编号:${iWndIndex}` } console.log(szInfo) cbDoubleClickWnd() }, cbEvent(iEventType, iParam1, iParam2) { if (iEventType == 2) { // 回放正常结束 console.log(`窗口${iParam1}回放结束!`) } else if (iEventType == -1) { console.log(`设备${iParam1}网络错误!`) } else if (iEventType == 3001) { // clickStopRecord(g_szRecordType, iParam1) } }, cbInitPluginComplete() { // window.m_pluginOBJECT = m_pluginOBJECT WebVideoCtrl.I_InsertOBJECTPlugin(`hkPlugin${id}`).then(() => { if (callback !== null) { callback() } // 检查插件是否最新 WebVideoCtrl.I_CheckPluginVersion().then((bFlag: any) => { if (bFlag) { ElMessage.warning('检测到新的插件版本,双击开发包目录里的HCWebSDKPlugin.exe升级!') } }) }, () => { ElMessage.warning('插件初始化失败,请确认是否已安装插件;如果未安装,请双击开发包目录里的HCWebSDKPlugin.exe安装!') }) }, }) } // 登录设备 export function playBack(deviceData, szStartTime, szEndTime) { WebVideoCtrl.I_StartPlayback(`${deviceData.nvrIp}_80`, { iRtspPort: 554, iStreamType: 1, iChannelID: parseInt(deviceData.nvrChannel, 10), szStartTime, szEndTime, success() { console.log('开始回放成功!') }, error(oError: any) { console.log('开始回放失败!', oError.errorCode, oError.errorMsg) }, }) } // 登录设备 export function onlyLogin(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr = false, szChannel='') { if (szIP == '' || szPort == '') { return } const szDeviceIdentify = `${szIP}_${szPort}` WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, { timeout: 3000, success(xmlDoc) { console.log(`${szDeviceIdentify} 登录成功!`) // preview(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr, szChannel) }, error(oError) { if (status === 2001) { console.log(`${szDeviceIdentify} 已登录过!`) } else { console.log(`${szDeviceIdentify} 登录失败!`, oError.errorCode, oError.errorMsg) } }, }) } // 登录设备 export function login(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr = false, szChannel='') { if (szIP == '' || szPort == '') { return } const szDeviceIdentify = `${szIP}_${szPort}` WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, { timeout: 3000, success(xmlDoc) { console.log(`${szDeviceIdentify} 登录成功!`) preview(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr, szChannel) }, error(oError) { if (status === 2001) { console.log(`${szDeviceIdentify} 已登录过!`) } else { console.log(`${szDeviceIdentify} 登录失败!`, oError.errorCode, oError.errorMsg) } }, }) } export function loginForCallback(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr = false, szChannel = '', callback) { if (szIP == '' || szPort == '') { return } const szDeviceIdentify = `${szIP}_${szPort}` WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, { timeout: 3000, success(xmlDoc) { console.log(`${szDeviceIdentify} 登录成功!`) if (callback !== null) { callback() } }, error(oError) { if (status === 2001) { console.log(`${szDeviceIdentify} 已登录过!`) } else { console.log(`${szDeviceIdentify} 登录失败!`, oError.errorCode, oError.errorMsg) } }, }) } // 预览 export function preview(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr = false, szChannel='') { var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex) var szDeviceIdentify = szIP + '_80' var iRtspPort = parseInt('554', 10) var iChannelID = parseInt('1', 10) if(isNvr) { iChannelID = parseInt(szChannel, 10) } var bZeroChannel = false var iStreamType = parseInt('1', 10) // 主码流 if (szDeviceIdentify == null) { return } var startRealPlay = function () { WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, { iStreamType, iChannelID, bZeroChannel, iPort: iRtspPort, iWndIndex: g_iWndIndex, success() { console.log(`${szDeviceIdentify} 开始预览成功`) }, error(oError) { console.log(`${szDeviceIdentify} 开始预览失败!`, oError.errorCode, oError.errorMsg) }, }) } if (oWndInfo != null) { // 已经在播放了,先停止 WebVideoCtrl.I_Stop({ success() { startRealPlay() }, }) } else { startRealPlay() } } // 登出设备 export function logout(ip) { WebVideoCtrl.I_Logout(ip).then(() => { console.log(`${ip}登出成功`) }, () => { console.log(`${ip}登出失败`) }) }