Newer
Older
smartcity_video / src / utils / HKVideo.js
dutingting on 6 Jan 7 KB 监控改4路,双击放大
// 初始化控件
export function initPlugin(iWndowType, id, bWndFull, callback, cbDoubleClickWnd) {
  // 检查浏览器是否支持无插件
  // if (!WebVideoCtrl.I_SupportNoPlugin()) {
  //   this.$message.warning("当前浏览器不支持无插件预览监控视频,已自动切换成插件模式,如果还未安装插件请安装")
  //   // 检查插件是否已经安装
  //
  // }
  const isInstall = WebVideoCtrl.I_CheckPluginInstall()
  if (isInstall === -1) {
    this.$message.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(iWndIndex, bFullScreen, event)
    },
    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
      console.log(WebVideoCtrl)
      console.log(window.WebVideoCtrl)
      console.log(JSVideoPlugin)
      WebVideoCtrl.I_InsertOBJECTPlugin(`divPlugin${id}`).then(() => {
        if (callback !== null) {
          callback()
        }
        // 检查插件是否最新
        WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {
          if (bFlag) {
            this.$message.warning('检测到新的插件版本,双击开发包目录里的HCWebSDKPlugin.exe升级!')
          }
        })
      }, () => {
        this.$message.warning('插件初始化失败,请确认是否已安装插件;如果未安装,请双击开发包目录里的HCWebSDKPlugin.exe安装!')
      })
    },
  })
}

// 登录设备
export function playBack(deviceData, szStartTime, szEndTime) {

  WebVideoCtrl.I_StartPlayback(`${deviceData.nvrIp}_${deviceData.nvrPort}`, {
    iRtspPort: 554,
    iStreamType: 1,
    iChannelID: parseInt(deviceData.nvrChannel, 10),
    szStartTime,
    szEndTime,
    success() {
      console.log('开始回放成功!')
      setTimeout(() => {
        preview(deviceData.deviceIp, '80', deviceData.deviceUser, deviceData.devicePassword, 0)
      }, 30 * 1000)
    },
    error(oError) {
      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}`
  console.log(szDeviceIdentify)
  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)
      }
    },
  })
}

function getChannelInfo(szDeviceIdentify) {
  // 模拟通道
  WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
    success(xmlDoc) {
      console.log('1 success')
    },
    error(oError) {
      console.log('1 error')
    }
  })
  // 数字通道
  WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
    success(xmlDoc) {
      console.log('2 success')
    },
    error(oError) {
      console.log('2 error')
    }
  })
  // 零通道
  WebVideoCtrl.I_GetZeroChannelInfo(szDeviceIdentify, {
    success(xmlDoc) {
      console.log('3 success')
    },
    error(oError) {
      console.log('3 error')
    }
  })
}

function getDevicePort(szDeviceIdentify, cb) {
  WebVideoCtrl.I_GetDevicePort(szDeviceIdentify).then((oPort) => {
    console.log('getDevicePort success')
    cb()
  }, (oError) => {
    console.log('getDevicePort error')
  })
}

// 登录设备
export function login(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr = false, szChannel= '', cb = null) {
  if (szIP == '' || szPort == '') {
    return
  }
  const szDeviceIdentify = `${szIP}_${szPort}`
  console.log(szDeviceIdentify)
  WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, {
    timeout: 3000,
    success(xmlDoc) {
      console.log(`${szDeviceIdentify} 登录成功!`)
      if (!isNvr) {
        preview(szIP, szPort, szUsername, szPassword, g_iWndIndex, isNvr, szChannel)
      } else {
        getDevicePort(szDeviceIdentify, cb)
      }
    },
    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
  var iRtspPort = parseInt('554', 10)
  var iChannelID = parseInt('1', 10)
  if(isNvr) {
    iChannelID = parseInt(szChannel, 10)
  }
  var bZeroChannel = false
  var szInfo = ''
  var iStreamType = parseInt('1', 10) // 主码流

  if (szDeviceIdentify == null) {
    return
  }
  var startRealPlay = function () {
    WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, {
      iStreamType: 1,
      iChannelID,
      bZeroChannel: false,
      iWndIndex: g_iWndIndex,
      success() {
        szInfo = '开始预览成功!'
        console.log(`${szDeviceIdentify} ${szInfo}`)
      },
      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}登出失败`)
  })
}
// 停止
export function stop(index) {
  WebVideoCtrl.I_Stop({
    iWndIndex: index,
    success() {
    },
    error(oError) {
    },
  })
}

// 启用电子放大
export function clickEnableEZoom() {
  var szDeviceIdentify = $("#ip").val();
  var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
      szInfo = "";

  if (oWndInfo != null) {
          WebVideoCtrl.I_EnableEZoom().then(() => {
          szInfo = "启用电子放大成功!";
          showOPInfo(szDeviceIdentify + " " + szInfo);
      }, (oError) => {
          szInfo = "启用电子放大失败!";
          showOPInfo(szDeviceIdentify + szInfo, oError.errorCode, oError.errorMsg);

      });
  }
}

// 全屏
export function clickFullScreen() {
  WebVideoCtrl.I_FullScreen(true).then(() => {
      showOPInfo("全屏成功");
  }, (oError) => {
      showOPInfo("全屏失败!", oError.errorCode, oError.errorMsg);
  });
}