From fa513c5e8e9b3820a3fbd52598dd8ee8ebc7ed2f Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 22 Jun 2022 15:43:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A4=E7=9F=B3=E7=8A=B6=E6=80=81=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/controllers/camera/create.js | 10 ++++- .../api/app/lib/schedule/freshYingshiState.js | 39 +++++++++++++++++-- .../client/src/layout/actions/webSocket.js | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js index ef67449..b725f09 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js @@ -36,12 +36,18 @@ async function createYingshi (ctx) { errMsg = (handleCameraId ? '修改' : '添加') + errMsg const beloneSecret = await verifyYingshiInfo({ serialNo }) - + const corGbYingshiRes = await models.GbCamera.findOne({ + where: { + streamid: String(serialNo).toUpperCase(), + ipctype: 'yingshi' + } + }) let storageData = { type: 'yingshi', name, cloudControl, highDefinition, memoryCard, voice, longitude, latitude, kindId, rtmp, serialNo: String(serialNo).toUpperCase(), - yingshiSecretId: beloneSecret.id + yingshiSecretId: beloneSecret.id, + gbId: corGbYingshiRes ? corGbYingshiRes.id : null } if (handleCameraId) { diff --git a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js index b26fe11..4db3167 100644 --- a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js +++ b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js @@ -4,7 +4,7 @@ const moment = require('moment') module.exports = function (app, opts) { const freshYingshiState = schedule.scheduleJob( // '* * 4 * * *', - '*/3 * * * *', + '*/1 * * * *', async () => { try { @@ -54,15 +54,46 @@ module.exports = function (app, opts) { // 状态推送 const { connected } = app.socket.sockets const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial + let cameraName = '' if (connected) { for (let c in connected) { - connected[c].join(roomId) + const { client: { conn: { request: { _query } } } } = connected[c] + if (_query && _query.token) { + let userInfo = await app.redis.hget(_query.token, 'userInfo'); + if (userInfo) { + userInfo = JSON.parse(userInfo) + const corCameraRes = await models.Camera.findOne({ + where: { + gbId: existD.id, + createUserId: userInfo.id + } + }) + // TODO 管理员判断 + if (corCameraRes) { + cameraName = corCameraRes.name + connected[c].join(roomId) + } + } + } } - app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, }) + + app.socket.to(roomId).emit('CAMERA_ONLINE', { + ipctype: 'yingshi', + online: storageD.online, + gbId: existD.id, + name: cameraName + }) } } } else { - await models.GbCamera.create(storageD) + const yingshiRes = await models.GbCamera.create(storageD) + await models.Camera.update({ + gbId: yingshiRes.id + }, { + where: { + serialNo: d.deviceSerial + } + }) } } pageStart++ diff --git a/code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js b/code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js index 71ca171..ddb496c 100644 --- a/code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js +++ b/code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js @@ -18,7 +18,7 @@ export function initWebSocket ({ ioUrl, token }) { type: '', } } - console.log(ioUrl); + return dispatch => { const socket = io(ioUrl, { query: {