正在显示
2 个修改的文件
包含
296 行增加
和
200 行删除
@@ -33,7 +33,7 @@ const methods = { | @@ -33,7 +33,7 @@ const methods = { | ||
33 | date = '0' + date | 33 | date = '0' + date |
34 | } | 34 | } |
35 | return { | 35 | return { |
36 | - ymd:year + "-" + month + "-" + date | 36 | + ymd:year+ month + date |
37 | } | 37 | } |
38 | }, | 38 | }, |
39 | async getRequestClassIds(url, siteId, key, startTime, endTime,page) { | 39 | async getRequestClassIds(url, siteId, key, startTime, endTime,page) { |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | -const { spawn } = require('child_process'); | 3 | +const {spawn, exec} = require('child_process'); |
4 | const fs = require("fs"); | 4 | const fs = require("fs"); |
5 | +var path = require('path') | ||
5 | 6 | ||
6 | const method = require("../config/method") | 7 | const method = require("../config/method") |
7 | const config = require("../config/config") | 8 | const config = require("../config/config") |
8 | 9 | ||
9 | // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config | 10 | // const { GETCLASSURL, GETCLASSURLPARAMETER, PROJECTCATALOG, PROJECTWINCATALOG, BACKMEDIACONFIG } = config |
10 | -const { YesterdayTime, getRequestClassIds,dayTimeYMD } = method | 11 | +const {YesterdayTime, getRequestClassIds, dayTimeYMD} = method |
11 | 12 | ||
12 | -const { startTime, endTime, ymd } = YesterdayTime() | ||
13 | let siteIds = [] | 13 | let siteIds = [] |
14 | 14 | ||
15 | let classid = [] | 15 | let classid = [] |
16 | let parentData = {} | 16 | let parentData = {} |
17 | var classobj = {}; | 17 | var classobj = {}; |
18 | let className = "" | 18 | let className = "" |
19 | + | ||
20 | +// spawn("export DISPLAY=:7", { shell: true}) | ||
21 | + | ||
19 | /** | 22 | /** |
20 | - * | 23 | + * |
21 | * @param {*} id 课堂id | 24 | * @param {*} id 课堂id |
22 | */ | 25 | */ |
23 | class MediaCreat { | 26 | class MediaCreat { |
24 | - constructor() { } | ||
25 | - // 取出所有数据 | ||
26 | - async allData() { | ||
27 | - let fileConfig = await new MediaCreat().getConfigFileJson() | ||
28 | - if(!fileConfig) return false | ||
29 | - className = siteIds.shift() | ||
30 | - const { GETCLASSURL,GETCLASSURLPARAMETER } = JSON.parse(fileConfig) | ||
31 | - let page = 1 | ||
32 | - if (className) { | ||
33 | - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page) | ||
34 | - parentData[result.data.data.siteId] = new Set() | ||
35 | - for (let j = 0; j < result.data.data.list.length; j++) { | ||
36 | - classid.push(result.data.data.list[j]) | ||
37 | - parentData[result.data.data.siteId].add(result.data.data.list[j]['classId']) | ||
38 | - } | ||
39 | - const { siteId, list, totalPage } = result.data.data | ||
40 | - for (let i = page += 1; i <= totalPage; i++) { | ||
41 | - let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i) | ||
42 | - for (let j = 0; j < result.data.data.list.length; j++) { | ||
43 | - classid.push(result.data.data.list[j]) | ||
44 | - parentData[result.data.data.siteId].add(result.data.data.list[j]['classId']) | ||
45 | - } | ||
46 | - } | ||
47 | - parentData[result.data.data.siteId] = Array.from(parentData[result.data.data.siteId]) | ||
48 | - if (siteIds.length) { | ||
49 | - return await new MediaCreat().allData() | ||
50 | - } | ||
51 | - this.wrieLog("去重前的classId:------>" + JSON.stringify(classid)) | ||
52 | - this.wrieLog("httpData:------>" + JSON.stringify(result.data)) | ||
53 | - return true | ||
54 | - } else { | ||
55 | - return false | 27 | + constructor() { |
56 | } | 28 | } |
57 | - } | ||
58 | - wrieLog(text){ | ||
59 | - // 写入log | ||
60 | - let logFile = `./log/${dayTimeYMD().ymd}.txt` | ||
61 | - fs.appendFileSync(logFile,new Date().toLocaleString() + " " +text+'\r\n'); | ||
62 | - } | ||
63 | - async mediaCreat(id, siteId) { | ||
64 | - let fileConfig = await new MediaCreat().getConfigFileJson() | ||
65 | - if(!fileConfig) return false | ||
66 | - const { BACKMEDIACONFIG,PROJECTWINCATALOG,PROJECTCATALOG } = JSON.parse(fileConfig) | ||
67 | - | ||
68 | - let mediaDir = PROJECTCATALOG + "/media/" | ||
69 | - let classDir = PROJECTCATALOG + "/media/" + siteId | ||
70 | - let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + ymd | ||
71 | - if (!fs.existsSync(mediaDir)) { | ||
72 | - fs.mkdirSync(mediaDir); | ||
73 | - } | ||
74 | - if (!fs.existsSync(classDir)) { | ||
75 | - fs.mkdirSync(classDir); | ||
76 | - } | ||
77 | - if (!fs.existsSync(ymdDir)) { | ||
78 | - fs.mkdirSync(ymdDir); | ||
79 | - } | ||
80 | - let url = `web_capture_c -o=../media/${siteId}/${ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&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}` | ||
81 | - var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) | ||
82 | - // workerProcess.stdout.on('data', async function (data) { | ||
83 | - | ||
84 | - // }); | ||
85 | - | ||
86 | - workerProcess.on('close', async (code) => { | ||
87 | - let files = fs.readdirSync(ymdDir); | ||
88 | - if (files.indexOf(id + ".mp4") == -1) { | ||
89 | - //当前课堂没有写入到文件夹,进入重录 | ||
90 | - new MediaCreat().mediaCreat(id, siteId) | ||
91 | - return false | ||
92 | - } else { | ||
93 | - if (parentData[siteId].indexOf(id.toString()) != -1) { | ||
94 | - parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1) | ||
95 | - } | ||
96 | - if (parentData[siteId].length == 0) { | ||
97 | - // //全部录制完毕 | ||
98 | - this.wrieLog("录制结束:------>") | ||
99 | - fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
100 | - if (err) { | ||
101 | - console.log(err); | 29 | + |
30 | + // 取出所有数据 | ||
31 | + async allData() { | ||
32 | + const {startTime, endTime} = YesterdayTime() | ||
33 | + let fileConfig = await new MediaCreat().getConfigFileJson() | ||
34 | + if (!fileConfig) return false | ||
35 | + className = siteIds.shift() | ||
36 | + const {GETCLASSURL, GETCLASSURLPARAMETER} = JSON.parse(fileConfig) | ||
37 | + let page = 1 | ||
38 | + if (className) { | ||
39 | + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, page) | ||
40 | + parentData[result.data.data.siteId] = new Set() | ||
41 | + for (let j = 0; j < result.data.data.list.length; j++) { | ||
42 | + classid.push(result.data.data.list[j]) | ||
43 | + parentData[result.data.data.siteId].add(result.data.data.list[j]['classId']) | ||
102 | } | 44 | } |
103 | - }); | ||
104 | - } | ||
105 | - if (classid.length) { | ||
106 | - let shiftData = classid.shift() | ||
107 | - new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) | 45 | + const {siteId, list, totalPage} = result.data.data |
46 | + for (let i = page += 1; i <= totalPage; i++) { | ||
47 | + let result = await getRequestClassIds(GETCLASSURL, className, GETCLASSURLPARAMETER.key, startTime, endTime, i) | ||
48 | + for (let j = 0; j < result.data.data.list.length; j++) { | ||
49 | + classid.push(result.data.data.list[j]) | ||
50 | + parentData[result.data.data.siteId].add(result.data.data.list[j]['classId']) | ||
51 | + } | ||
52 | + } | ||
53 | + parentData[result.data.data.siteId] = Array.from(parentData[result.data.data.siteId]) | ||
54 | + if (siteIds.length) { | ||
55 | + return await new MediaCreat().allData() | ||
56 | + } | ||
57 | + this.wrieLog("去重前的classId:------>" + JSON.stringify(classid)) | ||
58 | + this.wrieLog("httpData:------>" + JSON.stringify(result.data)) | ||
59 | + return true | ||
60 | + } else { | ||
61 | + return false | ||
108 | } | 62 | } |
109 | - } | ||
110 | - }); | ||
111 | - } | ||
112 | - async recordingCreat(id, siteId) { | ||
113 | - let fileConfig = await new MediaCreat().getConfigFileJson() | ||
114 | - if(!fileConfig) return false | ||
115 | - const { BACKMEDIACONFIG,PROJECTWINCATALOG,PROJECTCATALOG } = JSON.parse(fileConfig) | ||
116 | - let mediaDir = PROJECTCATALOG + "/media/" | ||
117 | - let recordingDir = mediaDir + "recording/" | ||
118 | - let classDir = recordingDir + siteId +"/" | ||
119 | - let dateDir = classDir + dayTimeYMD().ymd | ||
120 | - if (!fs.existsSync(mediaDir)) { | ||
121 | - fs.mkdirSync(mediaDir); | ||
122 | - } | ||
123 | - if (!fs.existsSync(recordingDir)) { | ||
124 | - fs.mkdirSync(recordingDir); | ||
125 | - } | ||
126 | - if (!fs.existsSync(classDir)) { | ||
127 | - fs.mkdirSync(classDir); | ||
128 | } | 63 | } |
129 | - if (!fs.existsSync(dateDir)) { | ||
130 | - fs.mkdirSync(dateDir); | 64 | + |
65 | + wrieLog(text) { | ||
66 | + // 写入log | ||
67 | + let logFile = `./log/${dayTimeYMD().ymd}.txt` | ||
68 | + fs.appendFileSync(logFile, new Date().toLocaleString() + " " + text + '\r\n'); | ||
131 | } | 69 | } |
132 | - let url = `web_capture_c -o=../media/recording/${siteId}/${dayTimeYMD().ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&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}` | ||
133 | - | ||
134 | - var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) | ||
135 | - // workerProcess.stdout.on('data', async function (data) { | ||
136 | - | ||
137 | - // }); | ||
138 | - | ||
139 | - workerProcess.on('close', async (code) =>{ | ||
140 | - let files = fs.readdirSync(dateDir); | ||
141 | - if (files.indexOf(id + ".mp4") == -1) { | ||
142 | - //当前课堂没有写入到文件夹,进入重录 | ||
143 | - new MediaCreat().recordingCreat(id, siteId) | ||
144 | - return false | ||
145 | - } else { | ||
146 | - if (parentData[siteId].indexOf(id.toString()) != -1) { | ||
147 | - parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1) | 70 | + |
71 | + // async mediaCreat(id, siteId) { | ||
72 | + // const {ymd} = YesterdayTime() | ||
73 | + // let fileConfig = await new MediaCreat().getConfigFileJson() | ||
74 | + // if (!fileConfig) return false | ||
75 | + // const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig) | ||
76 | + // | ||
77 | + // let mediaDir = PROJECTCATALOG + "/media/" | ||
78 | + // let classDir = PROJECTCATALOG + "/media/" + siteId | ||
79 | + // let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + ymd | ||
80 | + // if (!fs.existsSync(mediaDir)) { | ||
81 | + // fs.mkdirSync(mediaDir); | ||
82 | + // } | ||
83 | + // if (!fs.existsSync(classDir)) { | ||
84 | + // fs.mkdirSync(classDir); | ||
85 | + // } | ||
86 | + // if (!fs.existsSync(ymdDir)) { | ||
87 | + // fs.mkdirSync(ymdDir); | ||
88 | + // } | ||
89 | + // let url = `"${PROJECTWINCATALOG} /web_capture_c" -o=../media/${siteId}/${ymd}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&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}` | ||
90 | + // var workerProcess = exec(url) // , {cwd: PROJECTWINCATALOG, shell: true} | ||
91 | + // // workerProcess.stdout.on('data', async function (data) { | ||
92 | + // | ||
93 | + // // }); | ||
94 | + // | ||
95 | + // workerProcess.on('close', async (code) => { | ||
96 | + // let files = fs.readdirSync(ymdDir); | ||
97 | + // if (files.indexOf(id + ".mp4") == -1) { | ||
98 | + // //当前课堂没有写入到文件夹,进入重录 | ||
99 | + // new MediaCreat().mediaCreat(id, siteId) | ||
100 | + // return false | ||
101 | + // } else { | ||
102 | + // if (parentData[siteId].indexOf(id.toString()) != -1) { | ||
103 | + // parentData[siteId].splice(parentData[siteId].indexOf(id.toString()), 1) | ||
104 | + // } | ||
105 | + // if (parentData[siteId].length == 0) { | ||
106 | + // // //全部录制完毕 | ||
107 | + // this.wrieLog("录制结束:------>") | ||
108 | + // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
109 | + // if (err) { | ||
110 | + // console.log(err); | ||
111 | + // } | ||
112 | + // }); | ||
113 | + // } | ||
114 | + // if (classid.length) { | ||
115 | + // let shiftData = classid.shift() | ||
116 | + // new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) | ||
117 | + // } | ||
118 | + // } | ||
119 | + // }); | ||
120 | + // } | ||
121 | + | ||
122 | + recordingCreat(id, siteId) { | ||
123 | + this.wrieLog(" 课堂录制开始:------>" + id) | ||
124 | + let fileConfig = this.getConfigFileJson() | ||
125 | + if (!fileConfig) return false | ||
126 | + const {BACKMEDIACONFIG, PROJECTWINCATALOG, PROJECTCATALOG} = JSON.parse(fileConfig) | ||
127 | + let mediaDir = PROJECTCATALOG + "/media/" | ||
128 | + let classDir = PROJECTCATALOG + "/media/" + siteId | ||
129 | + let ymdDir = PROJECTCATALOG + "/media/" + siteId + "/" + dayTimeYMD().ymd | ||
130 | + if (!fs.existsSync(mediaDir)) { | ||
131 | + fs.mkdirSync(mediaDir); | ||
148 | } | 132 | } |
149 | - if (parentData[siteId].length == 0) { | ||
150 | - // //全部录制完毕 | ||
151 | - this.wrieLog("录制结束:------>") | ||
152 | - fs.writeFile(dateDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
153 | - if (err) { | ||
154 | - console.log(err); | ||
155 | - } | ||
156 | - }); | 133 | + if (!fs.existsSync(classDir)) { |
134 | + fs.mkdirSync(classDir); | ||
157 | } | 135 | } |
158 | - if (classid.length) { | ||
159 | - let shiftData = classid.shift() | ||
160 | - new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | 136 | + if (!fs.existsSync(ymdDir)) { |
137 | + fs.mkdirSync(ymdDir); | ||
161 | } | 138 | } |
162 | - } | ||
163 | - }); | ||
164 | - } | ||
165 | - | ||
166 | - async getConfigFileJson(){ | ||
167 | - const buffer= fs.readFileSync(process.cwd()+"/config/config.json") | ||
168 | - return String(buffer) | ||
169 | - } | 139 | + // 目前url是linux的写法 win系统不支持 |
140 | + // export DISPLAY=:7 | ||
141 | + // let url = `${path.resolve(__dirname, PROJECTWINCATALOG+"/web_capture_c")} -o=${ymdDir}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&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}` | ||
142 | + // console.log("url", url) | ||
143 | + let url = `${PROJECTWINCATALOG}/web_capture_c -o=${ymdDir}/${id}.mp4 -u="${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&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} -k=0` | ||
144 | + // console.log("url", url) | ||
145 | + // console.log("PROJECTWINCATALOG", PROJECTWINCATALOG) | ||
146 | + exec(url, {maxBuffer:1073741824},(err, stdout, stderr) => { | ||
147 | + // setTimeout(()=>{ | ||
148 | + if (err != null) { | ||
149 | + this.wrieLog(" 错误" + id +":" + err) | ||
150 | + this.wrieLog(" 错误 stdout" + id +":" + stdout) | ||
151 | + this.wrieLog(" 错误 stderr" + id +":" + stderr) | ||
152 | + // if (files.indexOf(id + ".mp4") == -1) { | ||
153 | + // // //当前课堂没有写入到文件夹,进入重录 | ||
154 | + // this.wrieLog(" 课堂录制未发现该" + id + "课堂号") | ||
155 | + // this.recordingCreat(id, siteId) | ||
156 | + // // return false | ||
157 | + // } | ||
158 | + // if (classid.length) { | ||
159 | + // setTimeout(()=>{ | ||
160 | + // let shiftData = classid.shift() | ||
161 | + // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) | ||
162 | + // this.recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
163 | + // },20000) | ||
164 | + // // clearInterval(interValGetFile) | ||
165 | + // } | ||
166 | + return | ||
167 | + } | ||
168 | + let files = fs.readdirSync(ymdDir); | ||
169 | + // let interValGetFile = setInterval(()=>{ | ||
170 | + if (files.indexOf(id + ".mp4") == -1) { | ||
171 | + this.wrieLog(" 课堂录制未发现该" + id + "课堂号") | ||
172 | + }else{ | ||
173 | + if (classid.length) { | ||
174 | + setTimeout(()=>{ | ||
175 | + let shiftData = classid.shift() | ||
176 | + this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) | ||
177 | + this.recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
178 | + },60*1000*5) | ||
179 | + // clearInterval(interValGetFile) | ||
180 | + }else{ | ||
181 | + this.wrieLog("录制结束:------>") | ||
182 | + fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
183 | + if (err) { | ||
184 | + console.log(err); | ||
185 | + } | ||
186 | + }); | ||
187 | + // clearInterval(interValGetFile) | ||
188 | + } | ||
189 | + } | ||
190 | + // },3000) | ||
191 | + // if (files.indexOf(id + ".mp4") == -1) { | ||
192 | + // // //当前课堂没有写入到文件夹,进入重录 | ||
193 | + // this.wrieLog(" 课堂录制未发现该" + id + "课堂号") | ||
194 | + // this.recordingCreat(id, siteId) | ||
195 | + // // return false | ||
196 | + // } else { | ||
197 | + // if (classid.length) { | ||
198 | + // let shiftData = classid.shift() | ||
199 | + // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) | ||
200 | + // this.recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
201 | + // } else { | ||
202 | + // this.wrieLog("录制结束:------>") | ||
203 | + // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
204 | + // if (err) { | ||
205 | + // console.log(err); | ||
206 | + // } | ||
207 | + // }); | ||
208 | + // } | ||
209 | + // } | ||
210 | + // },20000) | ||
211 | + }) | ||
212 | + // console.log("/web_capture_c",path.resolve(__dirname, PROJECTWINCATALOG+"./web_capture_c")) | ||
213 | + // spawnSync(path.resolve(__dirname, PROJECTWINCATALOG+"./web_capture_c"),[ | ||
214 | + // "-o",`${ymdDir}/${id}.mp4`, | ||
215 | + // "-u",`${BACKMEDIACONFIG.url}?classId=${id}&recordMp4=${BACKMEDIACONFIG.recordMp4}&userId=${BACKMEDIACONFIG.userId}&userName=${BACKMEDIACONFIG.userName}&userRole=${BACKMEDIACONFIG.userRole}&portalIP=${BACKMEDIACONFIG.portalIP}&portalPort=${BACKMEDIACONFIG.portalPort}&channels=${BACKMEDIACONFIG.channels}&playRecord=${BACKMEDIACONFIG.playRecord}`, | ||
216 | + // "-d",`${BACKMEDIACONFIG.d}`, | ||
217 | + // "-s",`${BACKMEDIACONFIG.s}`, | ||
218 | + // "-fa",`${BACKMEDIACONFIG.fa}`, | ||
219 | + // "-k",`${BACKMEDIACONFIG.k}`, | ||
220 | + // "-w",`${BACKMEDIACONFIG.w}`, | ||
221 | + // "-h",`${BACKMEDIACONFIG.h}` | ||
222 | + // ]) | ||
223 | + // workerProcess = spawnSync(url,{shell: true})// {cwd: PROJECTWINCATALOG, shell: true} | ||
224 | + // console.log("workerProcess",workerProcess) | ||
225 | + // workerProcess.stdout.on('data', function (data) { | ||
226 | + // console.log("stdout",data) | ||
227 | + // }); | ||
228 | + // workerProcess.stderr.on('data', (data) => { | ||
229 | + // console.error(`stderr: ${data}`); | ||
230 | + // }); | ||
231 | + // | ||
232 | + // workerProcess.on('close', (code) => { | ||
233 | + // console.log("code", code) | ||
234 | + // if (code == 0) { | ||
235 | + // this.wrieLog(" 课堂录制结束:------>" + id) | ||
236 | + // let files = fs.readdirSync(ymdDir); | ||
237 | + // if (files.indexOf(id + ".mp4") == -1) { | ||
238 | + // // //当前课堂没有写入到文件夹,进入重录 | ||
239 | + // this.wrieLog(" 课堂录制未发现该" + id + "课堂号") | ||
240 | + // new MediaCreat().recordingCreat(id, siteId) | ||
241 | + // // return false | ||
242 | + // } else { | ||
243 | + // if (classid.length) { | ||
244 | + // let shiftData = classid.shift() | ||
245 | + // this.wrieLog(" 录制下一节课 课堂号:" + shiftData['classId']) | ||
246 | + // new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
247 | + // } else { | ||
248 | + // this.wrieLog("录制结束:------>") | ||
249 | + // fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { | ||
250 | + // if (err) { | ||
251 | + // console.log(err); | ||
252 | + // } | ||
253 | + // }); | ||
254 | + // } | ||
255 | + // } | ||
256 | + // } | ||
257 | + // }); | ||
258 | + } | ||
259 | + | ||
260 | + getConfigFileJson() { | ||
261 | + const buffer = fs.readFileSync(process.cwd() + "/config/config.json") | ||
262 | + return String(buffer) | ||
263 | + } | ||
170 | } | 264 | } |
171 | 265 | ||
172 | 266 | ||
173 | -router.get('/', async function (req, res, next) { | ||
174 | - new MediaCreat().wrieLog("录制开始:------>") | ||
175 | - let fileConfig = await new MediaCreat().getConfigFileJson() | ||
176 | - if(!fileConfig) return false | ||
177 | - | ||
178 | - const {GETCLASSURLPARAMETER} = JSON.parse(fileConfig) | ||
179 | - siteIds = GETCLASSURLPARAMETER.siteId | ||
180 | - | ||
181 | - let result = await new MediaCreat().allData() | ||
182 | - if (result) { | ||
183 | - // 去重 | ||
184 | - classobj = {} | ||
185 | - classid = classid.reduce(function (item, next) { | ||
186 | - classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next); | ||
187 | - return item; | ||
188 | - }, []); | ||
189 | - // 写入log | ||
190 | - new MediaCreat().wrieLog("去重后的classid:------>" + JSON.stringify(classid)) | ||
191 | - if (classid.length) { | ||
192 | - for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) { | ||
193 | - let shiftData = classid.shift() | ||
194 | - if (shiftData) { | ||
195 | - new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) | ||
196 | - } else { | ||
197 | - return false | ||
198 | - } | ||
199 | - } | ||
200 | - res.send({ code: "0" }); | ||
201 | - }else{ | ||
202 | - res.send({ code: "1" ,message:"无录制数据"}); | ||
203 | - } | ||
204 | - } | ||
205 | -}); | 267 | +// router.get('/', async function (req, res, next) { |
268 | +// new MediaCreat().wrieLog("录制开始:------>") | ||
269 | +// let fileConfig = await new MediaCreat().getConfigFileJson() | ||
270 | +// if (!fileConfig) return false | ||
271 | +// | ||
272 | +// const {GETCLASSURLPARAMETER} = JSON.parse(fileConfig) | ||
273 | +// siteIds = GETCLASSURLPARAMETER.siteId | ||
274 | +// | ||
275 | +// let result = await new MediaCreat().allData() | ||
276 | +// if (result) { | ||
277 | +// // 去重 | ||
278 | +// classobj = {} | ||
279 | +// classid = classid.reduce(function (item, next) { | ||
280 | +// classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next); | ||
281 | +// return item; | ||
282 | +// }, []); | ||
283 | +// // 写入log | ||
284 | +// new MediaCreat().wrieLog("去重后的classid:------>" + JSON.stringify(classid)) | ||
285 | +// if (classid.length) { | ||
286 | +// for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) { | ||
287 | +// let shiftData = classid.shift() | ||
288 | +// if (shiftData) { | ||
289 | +// // new MediaCreat().mediaCreat(shiftData['classId'], shiftData['siteId']) | ||
290 | +// } else { | ||
291 | +// return false | ||
292 | +// } | ||
293 | +// } | ||
294 | +// res.send({code: "0"}); | ||
295 | +// } else { | ||
296 | +// res.send({code: "1", message: "无录制数据"}); | ||
297 | +// } | ||
298 | +// } | ||
299 | +// }); | ||
206 | 300 | ||
207 | /** | 301 | /** |
208 | * { | 302 | * { |
@@ -210,32 +304,34 @@ router.get('/', async function (req, res, next) { | @@ -210,32 +304,34 @@ router.get('/', async function (req, res, next) { | ||
210 | * } | 304 | * } |
211 | */ | 305 | */ |
212 | router.post('/recording', async function (req, res, next) { | 306 | router.post('/recording', async function (req, res, next) { |
213 | - new MediaCreat().wrieLog("录制开始:------>") | ||
214 | - let fileConfig = await new MediaCreat().getConfigFileJson() | ||
215 | - if(!fileConfig) return false | ||
216 | - const { classId } = req.body | ||
217 | - if(classId && classId.length){ | ||
218 | - classid = classId | ||
219 | - const { PROJECTCATALOG,GETCLASSURLPARAMETER } = JSON.parse(fileConfig) | ||
220 | - for(let i=0;i<classId.length;i++){ | ||
221 | - if(!Array.isArray(parentData[classId[i].siteId])){ | ||
222 | - parentData[classId[i].siteId] = [] | ||
223 | - } | ||
224 | - parentData[classId[i].siteId].push(classId[i].classId) | 307 | + new MediaCreat().wrieLog("录制启动:------>") |
308 | + let fileConfig = new MediaCreat().getConfigFileJson() | ||
309 | + if (!fileConfig) return false | ||
310 | + let {classId, maxMedia} = req.body | ||
311 | + if (classid.length > 0) { | ||
312 | + // 有正在录制中的课堂,禁止重复 | ||
313 | + res.send({code: "1", message: "有正在录制中的课堂", data: classid}); | ||
314 | + return | ||
225 | } | 315 | } |
226 | - for(let i=0;i<GETCLASSURLPARAMETER.maxMedia;i++){ | ||
227 | - let shiftData = classid.shift() | ||
228 | - if (shiftData) { | ||
229 | - new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
230 | - } else { | ||
231 | - return false | ||
232 | - } | 316 | + if (classId && classId.length) { |
317 | + classid = classId | ||
318 | + if (!maxMedia || maxMedia == undefined) { | ||
319 | + maxMedia = 1 | ||
320 | + } | ||
321 | + console.log("maxMedia", maxMedia) | ||
322 | + for (let i = 0; i < maxMedia; i++) { | ||
323 | + let shiftData = classid.shift() | ||
324 | + if (shiftData) { | ||
325 | + new MediaCreat().recordingCreat(shiftData['classId'], shiftData['siteId']) | ||
326 | + } else { | ||
327 | + return false | ||
328 | + } | ||
329 | + } | ||
330 | + res.send({code: "0"}); | ||
331 | + } else { | ||
332 | + res.send({code: "1", message: "无录制数据"}); | ||
233 | } | 333 | } |
234 | - res.send({ code: "0" }); | ||
235 | - }else{ | ||
236 | - res.send({ code: "1" ,message:"无录制数据"}); | ||
237 | - } | ||
238 | - | 334 | + |
239 | }) | 335 | }) |
240 | 336 | ||
241 | 337 |
-
请 注册 或 登录 后发表评论