UNPKG

fcc-core

Version:

Fusion communication center.

100 lines (97 loc) 3.07 kB
// import { XWPrivate } from '../../core/XW' import { addMonitorRecord, changeMonitorRecord, addOPTRecord, changeOPTRecord } from '../monitor' let resId let MONITOR_SNO let OPT_SNO let localXw export default async function (xw, params) { localXw = xw await xw.validate(params, { // 入参校验 resId: { type: 'string', required: true }, name: { type: 'string' }, x: { type: 'string' }, y: { type: 'string' }, width: { type: 'number' }, height: { type: 'number' } }) if (params.resIdKey && params.resIdKey === 'deviceCode') { resId = params.resId } else { resId = await getDeviceCode(params.resId, xw) } return new Promise((resolve, reject) => { let resType = xw.getSysParam('RES_TYPE') xw.exe.emit('OpenMonitor', { // 调用exe监控接口 winId: '0000', resType: resType || '0', resId: resId, name: params.name || params.resId, x: params.x || '0', y: params.y || '0', width: params.width || '600', height: params.height || '480' }) const timer = setTimeout(() => { reject(new xw.BaseException(562)) }, xw.timeout) xw.exe.once('OnOpenMonitor', async res => { if (res.resultCode === 0) { clearTimeout(timer) MONITOR_SNO = await addMonitorRecord({ MONITOR_USER_CODE: xw.userInfo.USER_CODE, // 监控开启人 MONITOR_OBJ_ID: params.resId // 监控对象ID }, xw) OPT_SNO = await addOPTRecord({ USER_CODE: xw.userInfo.USER_CODE, // 用户编号 REMARK: '打开监控成功' }, xw) xw.exe.emit('SetVideoSerialNo', { serailType: '2', serialNo: MONITOR_SNO, monitorResId: resId }) xw.exe.on('OnCloseMonitor', onCloseMonitor, this) resolve() } else { OPT_SNO = await addOPTRecord({ USER_CODE: xw.userInfo.USER_CODE, // 用户编号 IS_SUCCESS: '0', // 开启监控失败 REMARK: '打开监控失败' }, xw) reject(new xw.BaseException(561)) } }) }) } async function onCloseMonitor (data) { console.log('localXw', localXw) if (data.data.resId === resId) { MONITOR_SNO && changeMonitorRecord(MONITOR_SNO, { MONITOR_DURA: 0, // 监控时长 REC_ADD: 'test', // 录屏地址 CALL_REMARK: '设备监控关闭,修改监控时长' }, localXw) OPT_SNO && changeOPTRecord(OPT_SNO, { OPT_DURATION: 0, REC_ADD: 'test', // 录屏地址 REMARK: '设备监控关闭,修改监控时长' }, localXw) } localXw.exe.off('OnCloseMonitor', onCloseMonitor) } async function getDeviceCode (deviceId, xw) { const params = { service: 'E1404406', OBJ_ID: deviceId, OBJ_TYPE: '2' } let deviceCode = await xw.ajaxRequest([params]).then(res => { if (res.code === '0') { return res.data[0].FACILITY_NUMBER } else { return '' } }) return deviceCode }