|
|
@ -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) { |
|
|
|
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++ |
|
|
|