Browse Source

yingshi state

release_0.0.2
巴林闲侠 3 years ago
parent
commit
cfc281eddc
  1. 56
      code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js
  2. 25
      code/VideoAccess-VCMP/api/app/lib/schedule/index.js
  3. 23
      code/VideoAccess-VCMP/api/app/lib/service/socket.js

56
code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js

@ -4,18 +4,19 @@ const moment = require('moment')
module.exports = function (app, opts) { module.exports = function (app, opts) {
const freshYingshiState = schedule.scheduleJob( const freshYingshiState = schedule.scheduleJob(
// '* * 4 * * *', // '* * 4 * * *',
'*/8 * * * * *', '*/3 * * * *',
async () => { async () => {
try { try {
const startTime = moment()
const { models } = app.fs.dc const { models } = app.fs.dc
const { varifyYingshiBelongSecretBySerialNo, token4yingshi } = app.fs.utils const { token4yingshi } = app.fs.utils
const secretRes = await models.SecretYingshi.findAll() const secretRes = await models.SecretYingshi.findAll()
let deviceList = []
for (let s of secretRes) { for (let s of secretRes) {
const tokenYingshi = await token4yingshi(s.dataValues) const tokenYingshi = await token4yingshi(s.dataValues)
// 查询所有设备 // 查询所有设备
let pageStart = 0 let pageStart = 0
let deviceList = []
while (pageStart >= 0) { while (pageStart >= 0) {
const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', { const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
query: { query: {
@ -27,21 +28,52 @@ module.exports = function (app, opts) {
if (deviceRes.code == 200) { if (deviceRes.code == 200) {
if (deviceRes.data.length) { if (deviceRes.data.length) {
deviceList = deviceList.concat.apply(deviceList, deviceRes.data) deviceList = deviceList.concat.apply(deviceList, deviceRes.data)
for (let d of deviceRes.data) {
const existD = await models.GbCamera.findOne({
where: {
streamid: d.deviceSerial
}
})
let storageD = {
level: 0,
ipctype: 'yingshi',
streamid: d.deviceSerial,
online: d.status ? 'ON' : 'OFF',
name: d.deviceName,
}
if (existD) {
if (existD.online != storageD.online) {
// 状态更新
await models.GbCamera.update(storageD, {
where: {
id: existD.id
}
})
// 状态推送
const { connected } = app.socket.sockets
const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial
if (connected) {
for (let c in connected) {
connected[c].join(roomId)
}
app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
}
}
} else {
await models.GbCamera.create(storageD)
}
}
pageStart++ pageStart++
} else { } else {
pageStart = -1 pageStart = -1
} }
} }
} }
console.log(deviceList);
} }
// console.log(deviceList);
// const await models.UserToken.destroy({ console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`)
// where: {
// expired: { $lt: now }
// }
// })
} catch (error) { } catch (error) {
app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
} }

25
code/VideoAccess-VCMP/api/app/lib/schedule/index.js

@ -1,18 +1,19 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
// 将定时任务汇集未来可根据需要选取操作 // 将定时任务汇集未来可根据需要选取操作
module.exports = async function (app, opts) { module.exports = async function (app, opts) {
fs.readdirSync(__dirname).forEach((filename) => { fs.readdirSync(__dirname).forEach((filename) => {
if (!['index.js'].some(f => filename == f)) { if (!['index.js'].some(f => filename == f)) {
const schedule = require(`./${filename}`)(app, opts) const schedule = require(`./${filename}`)(app, opts)
for (let k of Object.keys(schedule)) { for (let k of Object.keys(schedule)) {
console.info(`定时任务 ${k} 启动`); console.info(`定时任务 ${k} 启动`);
} }
app.fs.schedule = { app.fs.schedule = {
...app.fs.schedule, ...app.fs.schedule,
...schedule, ...schedule,
} }
} }
}); });
}; };

23
code/VideoAccess-VCMP/api/app/lib/service/socket.js

@ -10,16 +10,17 @@ module.exports = async function factory (app, opts) {
}) })
// 使用测试 保持链接 // 使用测试 保持链接
// setInterval(async () => { setInterval(async () => {
// // const { connected } = app.socket.sockets const { connected } = app.socket.sockets
// // const roomId = 'ROOM_' + Math.random()
// // if (connected) {
// // for (let c in connected) {
// // connected[c].join(roomId)
// // }
// // app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
// // }
// app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', }) const roomId = 'ROOM_' + Math.random()
// }, 1000) if (connected) {
for (let c in connected) {
connected[c].join(roomId)
}
app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
}
app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', })
}, 1000)
} }

Loading…
Cancel
Save