index.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var express = require('express');
var router = express.Router();
const { spawn } = require('child_process');
const fs = require("fs");
const method = require("../config/method")
const config = require("../config/config")
const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config
const { YesterdayTime, getRequestClassIds } = method
const { startTime, endTime } = YesterdayTime()
let siteIds = GETCLASSURLPARAMETER.siteId
let classid = []
let className = ""
/**
*
* @param {*} id 课堂id
*/
function mediaCreat(id) {
let mediaDir = PROJECTCATALOG+"/media/"
let dir = PROJECTCATALOG+"/media/"+className
if (!fs.existsSync(mediaDir)){
fs.mkdirSync(mediaDir);
}
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
let url = `web_capture_c -o=../media/${className}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}" -d=${BACKMEDIACONFIG.d} -s=${BACKMEDIACONFIG.s} -fa=${BACKMEDIACONFIG.fa}`
var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
workerProcess.stdout.on('data', async function (data) {
if(classid.length){
let id = classid.shift()
mediaCreat(id['classId'])
}else{
if (siteIds.length) {
// 如果有多家需要录制,继续录制下一家
className = siteIds.shift()
let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime)
if (result.data && result.data.code == 0) {
// 返回成功
classid = result.data.data.list
if(classid.length){
let id = classid.shift()
mediaCreat(id['classId'])
}
}
}
}
});
// workerProcess.stderr.on('data', function (data) {
// console.log('stderr: ' + data);
// });
// workerProcess.on('close', function (code) {
// console.log('子进程已退出,退出码 '+code);
// });
}
router.get('/', async function (req, res, next) {
className = siteIds.shift()
let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime)
if (result.data && result.data.code == 0) {
// 成功
classid = result.data.data.list
if (classid.length) {
for (let i = 0; i < 10; i++) {
let id = classid.shift()
if (id) {
mediaCreat(id['classId'])
}else{
return false
}
}
}
}
res.render('index', { title: 'Express' });
});
module.exports = router;