Browse Source

Merge branch 'dev_trial' of https://gitea.free-sun.vip/free-sun/FS-IOT into dev_trial

release_0.0.2
wenlele 2 years ago
parent
commit
8d29279fd9
  1. 196
      code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js
  2. 14
      code/VideoAccess-VCMP/api/app/lib/service/socket.js
  3. 2
      code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js
  4. 27
      code/VideoAccess-VCMP/web/client/src/app.jsx
  5. 16
      code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js
  6. 5
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  7. 4
      code/VideoAccess-VCMP/web/package.json

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

@ -7,107 +7,107 @@ module.exports = function (app, opts) {
'*/1 * * * *',
async () => {
// try {
// const startTime = moment()
// const { models } = app.fs.dc
// const { token4yingshi } = app.fs.utils
// const secretRes = await models.SecretYingshi.findAll()
// let deviceList = []
// for (let s of secretRes) {
// const tokenYingshi = await token4yingshi(s.dataValues)
// // 查询所有设备
// let pageStart = 0
// while (pageStart >= 0) {
// const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
// query: {
// accessToken: tokenYingshi,
// pageStart,
// pageSize: 50
// }
// })
// if (deviceRes.code == 200) {
// if (deviceRes.data.length) {
// deviceList = deviceList.concat.apply(deviceList, deviceRes.data)
// for (let d of deviceRes.data) {
// const existD = await models.GbCamera.findOne({
// where: {
// streamid: d.deviceSerial
// }
// })
try {
const startTime = moment()
const { models } = app.fs.dc
const { token4yingshi } = app.fs.utils
const secretRes = await models.SecretYingshi.findAll()
let deviceList = []
for (let s of secretRes) {
const tokenYingshi = await token4yingshi(s.dataValues)
// 查询所有设备
let pageStart = 0
while (pageStart >= 0) {
const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
query: {
accessToken: tokenYingshi,
pageStart,
pageSize: 50
}
})
if (deviceRes.code == 200) {
if (deviceRes.data.length) {
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
// }
// })
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
// // 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)
// // }
// // }
// // }
// // }
// 状态推送
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
// // })
// // }
// }
// } else {
// const yingshiRes = await models.GbCamera.create(storageD)
// await models.Camera.update({
// gbId: yingshiRes.id
// }, {
// where: {
// serialNo: d.deviceSerial
// }
// })
// }
// }
// pageStart++
// } else {
// pageStart = -1
// }
// }
// }
// }
// // console.log(deviceList);
// console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`)
// } catch (error) {
// app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
// }
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)
await models.Camera.update({
gbId: yingshiRes.id
}, {
where: {
serialNo: d.deviceSerial
}
})
}
}
pageStart++
} else {
pageStart = -1
}
}
}
}
// console.log(deviceList);
console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`)
} catch (error) {
app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
}
});
return {

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

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

2
code/VideoAccess-VCMP/api/app/lib/utils/xlsxDownload.js

@ -10,7 +10,7 @@ module.exports = function (app, opts) {
//递归创建目录 同步方法
async function makeDir (dir) {
if (!fs.existsSync(dir)) {
this.makeDir(path.dirname(dir))
makeDir(path.dirname(dir))
fs.mkdirSync(dir, function (err) {
if (err) {
throw err

27
code/VideoAccess-VCMP/web/client/src/app.jsx

@ -16,21 +16,22 @@ import application from './sections/application';
import member from './sections/member';
const App = props => {
const { projectName } = props
const { projectName } = props
useEffect(() => {
document.title = projectName;
}, [])
useEffect(() => {
document.title = projectName;
}, [])
return (
<Layout
title={projectName}
sections={[Example,
Auth, Monitor, EquipmentWarehouse, AiAbility, offline,
openness, journaling, archive, application, member, system
]}
/>
)
return (
<Layout
title={projectName}
sections={[
// Example,
Auth, Monitor, EquipmentWarehouse, AiAbility, offline,
openness, journaling, archive, application, member, system
]}
/>
)
}
export default App;

16
code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js

@ -23,27 +23,11 @@ export function initWebSocket ({ ioUrl, token }) {
const socket = io(
ioUrl
// 'http://127.0.0.1:4000'
// '_api/'
, {
query: {
token: token
},
});
socket.on("connect", () => {
console.log('connect');
});
socket.io.on("error", (error) => {
console.error(error);
});
socket.io.on("reconnect_error", (error) => {
console.error(error);
});
socket.io.on("reconnect_failed", () => {
console.error(error);
});
socket.on('TEST', function (msg) {
console.info(msg);
});
dispatch({
type: INIT_WEB_SOCKET,
payload: {

5
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -84,10 +84,6 @@ const Root = props => {
}
}
useEffect(async () => {
let innerRoutes = []
let outerRoutes = []
@ -158,7 +154,6 @@ const Root = props => {
// IOT system cross
window.addEventListener('message', async function (e) { // message
const { data } = e
console.log(e);
if (data && data.action) {
if (data.action == 'initUser') {
await store.dispatch(actions.auth.initAuth(data.user))

4
code/VideoAccess-VCMP/web/package.json

@ -66,8 +66,8 @@
"perfect-scrollbar": "^1.5.5",
"qs": "^6.10.5",
"screenfull": "5.2.0",
"socket.io-client": "^4.5.0",
"socket.io-parser": "^4.2.0",
"socket.io-client": "^1.7.4",
"socket.io-parser": "^3.4.1",
"superagent": "^6.1.0",
"webpack": "^5.3.2",
"webpack-bundle-analyzer": "^4.1.0",

Loading…
Cancel
Save