张艾宸

默认录制时长改为6个小时

添加接口recording,可选择录制的课堂
... ... @@ -18,7 +18,7 @@
"portalPort":80,
"channels":2,
"playRecord":1,
"d":1800000,
"d":21600000,
"s":3000,
"fa":15,
"k":0,
... ...
... ... @@ -15,6 +15,15 @@ const methods = {
ymd:year + "-" + month + "-" + date
}
},
dayTimeYMD() {
let dayTimeDate = new Date()
let year = dayTimeDate.getFullYear()
let month = dayTimeDate.getMonth() + 1
let date = dayTimeDate.getDate()
return {
ymd:year + "-" + month + "-" + date
}
},
async getRequestClassIds(url, siteId, key, startTime, endTime,page) {
let axiosUrl = `${url}?siteId=${siteId}&key=${key}&from=${startTime}&to=${endTime}&page=${page}`
let result = await axios.get(axiosUrl)
... ...
... ... @@ -7,7 +7,7 @@ const method = require("../config/method")
const config = require("../config/config")
// const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config
const { YesterdayTime, getRequestClassIds } = method
const { YesterdayTime, getRequestClassIds,dayTimeYMD } = method
const { startTime, endTime, ymd } = YesterdayTime()
let siteIds = []
... ... @@ -101,6 +101,57 @@ class MediaCreat {
}
});
}
async recordingCreat(id, siteId) {
let fileConfig = await new MediaCreat().getConfigFileJson()
if(!fileConfig) return false
const { BACKMEDIACONFIG,PROJECTWINCATALOG,PROJECTCATALOG } = JSON.parse(fileConfig)
let mediaDir = PROJECTCATALOG + "/media/"
let recordingDir = mediaDir + "recording/"
let classDir = recordingDir + siteId +"/"
let dateDir = classDir + dayTimeYMD().ymd
if (!fs.existsSync(mediaDir)) {
fs.mkdirSync(mediaDir);
}
if (!fs.existsSync(recordingDir)) {
fs.mkdirSync(recordingDir);
}
if (!fs.existsSync(classDir)) {
fs.mkdirSync(classDir);
}
if (!fs.existsSync(dateDir)) {
fs.mkdirSync(dateDir);
}
let url = `web_capture_c -o=../media/recording/${siteId}/${dayTimeYMD().ymd}/${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} -k=${BACKMEDIACONFIG.k} -w=${BACKMEDIACONFIG.w} -h=${BACKMEDIACONFIG.h}`
var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
// workerProcess.stdout.on('data', async function (data) {
// });
workerProcess.on('close', async function (code) {
let files = fs.readdirSync(dateDir);
if (files.indexOf(id + ".mp4") == -1) {
//当前课堂没有写入到文件夹,进入重录
new MediaCreat().recordingCreat(id, siteId)
return false
} else {
if (parentData[siteId].indexOf(id.toString()) != -1) {
parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1)
}
if (parentData[siteId].length == 0) {
// //全部录制完毕
fs.writeFile(dateDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
if (err) {
console.log(err);
}
});
}
if (classid.length) {
let shiftData = classid.shift()
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])
}
}
});
}
async getConfigFileJson(){
const buffer= fs.readFileSync(process.cwd()+"/config/config.json")
... ... @@ -137,4 +188,35 @@ router.get('/', async function (req, res, next) {
}
});
/**
* {
* "classId":[{ classId: '389675110', siteId: 'kuaikuenglish' }]
* }
*/
router.post('/recording', async function (req, res, next) {
let fileConfig = await new MediaCreat().getConfigFileJson()
if(!fileConfig) return false
const { classId } = req.body
if(classId && classId.length){
classid = classId
const { PROJECTCATALOG,GETCLASSURLPARAMETER } = JSON.parse(fileConfig)
for(let i=0;i<classId.length;i++){
if(!Array.isArray(parentData[classId[i].siteId])){
parentData[classId[i].siteId] = []
}
parentData[classId[i].siteId].push(classId[i].classId)
}
for(let i=0;i<GETCLASSURLPARAMETER.maxMedia;i++){
let shiftData = classid.shift()
if (shiftData) {
new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId'])
} else {
return false
}
}
}
res.send({ code: "0" });
})
module.exports = router;
... ...