Browse Source

定时任务即刻启用

release_0.0.2
巴林闲侠 2 years ago
parent
commit
9131be6873
  1. 53
      code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiMsg.js
  2. 29
      code/VideoAccess-VCMP/api/app/lib/schedule/index.js
  3. 15
      code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationTalk.jsx
  4. 3
      code/VideoAccess-VCMP/web/client/src/utils/videoCloudControl.js
  5. 2
      code/VideoAccess-VCMP/web/client/src/utils/videoVoice.js
  6. 1
      code/VideoAccess-VCMP/web/client/src/utils/webapi.js

53
code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiMsg.js

@ -2,10 +2,14 @@ const schedule = require('node-schedule');
const moment = require('moment')
module.exports = function (app, opts) {
const freshYingshiState = schedule.scheduleJob(
// '* * 4 * * *',
'*/10 * * * *',
const freshYingshiState = app.fs.scheduleInit(
{
// interval: '* * 4 * * *',
interval: '*/10 * * * *',
immediate: false,
},
async () => {
try {
const startTime = moment()
const { models } = app.fs.dc
@ -61,38 +65,6 @@ module.exports = function (app, opts) {
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
// })
// }
}
} else {
const yingshiRes = await models.GbCamera.create(storageD)
@ -121,10 +93,13 @@ module.exports = function (app, opts) {
}
});
const freshYingshiPlayUrl = schedule.scheduleJob(
// '0 0 4 */1 *',
// '*/30 * * * *',
'0 34 5 * * *',
const freshYingshiPlayUrl = app.fs.scheduleInit(
{
// interval: '0 0 4 */1 *',
// interval: '*/30 * * * *',
interval: '0 34 5 * * *',
immediate: true,
},
async () => {
try {
const { models } = app.fs.dc

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

@ -3,27 +3,30 @@
const fs = require('fs');
const nodeSchedule = require('node-schedule');
const schedule = ({
interval, immediate
}, callback) => {
const j = nodeSchedule.scheduleJob(interval, callback);
if (immediate) {
j.run();
}
return j;
}
// 将定时任务汇集未来可根据需要选取操作
module.exports = async function (app, opts) {
const scheduleInit = ({
interval, immediate
}, callback) => {
const j = nodeSchedule.scheduleJob(interval, callback);
if (immediate) {
setTimeout(callback, 0)
}
return j;
}
app.fs.scheduleInit = scheduleInit
fs.readdirSync(__dirname).forEach((filename) => {
if (!['index.js'].some(f => filename == f)) {
const schedule = require(`./${filename}`)(app, opts)
for (let k of Object.keys(schedule)) {
const scheduleList = require(`./${filename}`)(app, opts)
for (let k of Object.keys(scheduleList)) {
console.info(`定时任务 ${k} 启动`);
}
app.fs.schedule = {
...app.fs.schedule,
...schedule,
...scheduleList,
}
}
});

15
code/VideoAccess-VCMP/web/client/src/components/videoPlayer/videoOperationTalk.jsx

@ -1,6 +1,9 @@
import React, { useState, useEffect, useRef } from "react";
import { connect } from "react-redux";
import request from 'superagent'
import moment from "moment";
import { Request } from "@peace/utils";
import { ApiTable } from "$utils";
import './videoPlay.less';
import { DatePicker, Toast, ToastFactory, Space } from '@douyinfe/semi-ui';
import { checkAudioVideo, uploadVoice2Yingshi, sendVoice2YingshiCamera } from '$utils';
@ -28,7 +31,6 @@ const VideoOperationTalk = ({
}
const onStopTalk = async (data) => {
console.log('stopTalk', data.blob)
setRecordState(RecordState.STOP)
const { blob: audioData } = data;
if (!audioData) return;
@ -46,14 +48,13 @@ const VideoOperationTalk = ({
channelNo: videoObj.channelNo,
fileUrl: url
});
if (sendRes && sendRes.code == 200) {
ToastInCustomContainer.success('已发送');
ToastInCustomContainer.success('已发送');
} catch (error) {
if (error.msg) {
ToastInCustomContainer.error(error.msg);
} else {
console.log(sendRes)
ToastInCustomContainer.error('发送失败');
}
} catch (error) {
console.error(error);
}
}

3
code/VideoAccess-VCMP/web/client/src/utils/videoCloudControl.js

@ -28,8 +28,7 @@ export function ysptz (ac, { serialNo, yingshiToken, channelNo }) {
}
let startReqBody = Object.assign({}, params, { speed: 1 })
let stopReqBody = params
// let requestUrl = `https://open.ys7.com/api/lapp/device/ptz/`
let requestUrl = `/_yingshi/api/lapp/device/ptz/`
let requestUrl = `https://open.ys7.com/api/lapp/device/ptz/`
superagent
.post(requestUrl + 'start')
.send(startReqBody)

2
code/VideoAccess-VCMP/web/client/src/utils/videoVoice.js

@ -9,7 +9,6 @@ export const uploadVoice2Yingshi = async ({ voiceFile, accessToken, voiceName, }
fData.append("accessToken", accessToken)
fData.append("voiceName", voiceName || moment().format("YYYYMMDDHHmmssSSS"))
fData.append("force", true)
console.log(fData);
// TODO 代理转发为什么不行捏
// const upRslt = await YingshiRequest.post('api/lapp/voice/upload', fData)
@ -52,7 +51,6 @@ export const sendVoice2YingshiCamera = async ({ accessToken, deviceSerial, chann
}
})
})
console.log(sendRslt);
if (sendRslt.code === 200) {
return sendRslt.data
} else {

1
code/VideoAccess-VCMP/web/client/src/utils/webapi.js

@ -37,6 +37,7 @@ export const ApiTable = {
postVerifyIpc: "camera/verify/ipc", //验证IPC摄像头信息
postVerifyCascade: "camera/verify/cascade", //验证级联摄像头信息
getCascadeStream: "/camera/cascade_stream", //获取级联视频流
uploadYingshiVoice: 'camera/yingshi_voice/upload', //上传萤石语音
};
export const VideoServeApi = {

Loading…
Cancel
Save