|
|
@ -4,13 +4,12 @@ const moment = require('moment') |
|
|
|
module.exports = function (app, opts) { |
|
|
|
const freshYingshiState = schedule.scheduleJob( |
|
|
|
// '* * 4 * * *',
|
|
|
|
// '*/10 * * * *',
|
|
|
|
'0 27 4 * * *', |
|
|
|
'*/10 * * * *', |
|
|
|
async () => { |
|
|
|
try { |
|
|
|
const startTime = moment() |
|
|
|
const { models } = app.fs.dc |
|
|
|
const { token4yingshi, getYingshiPlayUrl } = app.fs.utils |
|
|
|
const { token4yingshi, getYingshiPlayUrl, cameraStatePush } = app.fs.utils |
|
|
|
const secretRes = await models.SecretYingshi.findAll() |
|
|
|
let deviceList = [] |
|
|
|
for (let s of secretRes) { |
|
|
@ -57,38 +56,43 @@ module.exports = function (app, opts) { |
|
|
|
// 状态更新 END
|
|
|
|
|
|
|
|
// 状态推送
|
|
|
|
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) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cameraStatePush({ |
|
|
|
gbId: existD.id, |
|
|
|
online: storageD.online, |
|
|
|
ipctype: storageD.ipctype, |
|
|
|
}) |
|
|
|
// 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('CAMERA_ONLINE', { |
|
|
|
ipctype: 'yingshi', |
|
|
|
online: storageD.online, |
|
|
|
gbId: existD.id, |
|
|
|
name: cameraName |
|
|
|
}) |
|
|
|
} |
|
|
|
// app.socket.to(roomId).emit('CAMERA_ONLINE', {
|
|
|
|
// ipctype: 'yingshi',
|
|
|
|
// online: storageD.online,
|
|
|
|
// gbId: existD.id,
|
|
|
|
// name: cameraName
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} else { |
|
|
|
const yingshiRes = await models.GbCamera.create(storageD) |
|
|
|