799967501@qq.com

完整版

1 node_modules 1 node_modules
2 -.idea  
  2 +.idea
  3 +log
1 { 1 {
2 "GETCLASSURL":"http://139.196.126.156:8081/getLogs/recordClassList", 2 "GETCLASSURL":"http://139.196.126.156:8081/getLogs/recordClassList",
3 "GETCLASSURLPARAMETER":{ 3 "GETCLASSURLPARAMETER":{
4 - "siteId":["BuzzKID","kuaikuenglish"], 4 + "siteId":["beidatest"],
5 "key":"xdymp4record20191225", 5 "key":"xdymp4record20191225",
6 "page":1, 6 "page":1,
7 "maxMedia":1 7 "maxMedia":1
8 }, 8 },
9 - "PROJECTWINCATALOG":"E:/project/web_capture_release/win-x64",  
10 - "PROJECTCATALOG":"E:/project/web_capture_release", 9 + "PROJECTWINCATALOG":"F:/project/web_capture_release/win-x64",
  10 + "PROJECTCATALOG":"F:/project/web_capture_release",
11 "BACKMEDIACONFIG":{ 11 "BACKMEDIACONFIG":{
12 "url" : "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html", 12 "url" : "https://pclive.xuedianyun.com/pcBase/pclive2/dev/index.html",
  13 + "recordMp4":true,
13 "classId":"", 14 "classId":"",
14 "userId":0, 15 "userId":0,
15 "userName":"", 16 "userName":"",
@@ -9,10 +9,16 @@ const methods = { @@ -9,10 +9,16 @@ const methods = {
9 let date = YesterdayTimeDate.getDate() 9 let date = YesterdayTimeDate.getDate()
10 let startTime = new Date(year + "-" + month + "-" + date + " 5:30:00").getTime() 10 let startTime = new Date(year + "-" + month + "-" + date + " 5:30:00").getTime()
11 let endTime = new Date(year + "-" + month + "-" + date + " 23:59:00").getTime() 11 let endTime = new Date(year + "-" + month + "-" + date + " 23:59:00").getTime()
  12 + if(month < 10){
  13 + month = '0' + month
  14 + }
  15 + if(date < 10){
  16 + date = '0' + date
  17 + }
12 return { 18 return {
13 startTime, 19 startTime,
14 endTime, 20 endTime,
15 - ymd:year + "-" + month + "-" + date 21 + ymd:year+month+date
16 } 22 }
17 }, 23 },
18 dayTimeYMD() { 24 dayTimeYMD() {
@@ -20,6 +26,12 @@ const methods = { @@ -20,6 +26,12 @@ const methods = {
20 let year = dayTimeDate.getFullYear() 26 let year = dayTimeDate.getFullYear()
21 let month = dayTimeDate.getMonth() + 1 27 let month = dayTimeDate.getMonth() + 1
22 let date = dayTimeDate.getDate() 28 let date = dayTimeDate.getDate()
  29 + if(month < 10){
  30 + month = '0' + month
  31 + }
  32 + if(date < 10){
  33 + date = '0' + date
  34 + }
23 return { 35 return {
24 ymd:year + "-" + month + "-" + date 36 ymd:year + "-" + month + "-" + date
25 } 37 }
@@ -3,7 +3,8 @@ @@ -3,7 +3,8 @@
3 "version": "0.0.0", 3 "version": "0.0.0",
4 "private": true, 4 "private": true,
5 "scripts": { 5 "scripts": {
6 - "start": "nodemon ./bin/www" 6 + "start": "nodemon ./bin/www",
  7 + "pm2": "pm2 start ./bin/www --name webScreen"
7 }, 8 },
8 "dependencies": { 9 "dependencies": {
9 "axios": "^0.19.0", 10 "axios": "^0.19.0",
@@ -48,11 +48,18 @@ class MediaCreat { @@ -48,11 +48,18 @@ class MediaCreat {
48 if (siteIds.length) { 48 if (siteIds.length) {
49 return await new MediaCreat().allData() 49 return await new MediaCreat().allData()
50 } 50 }
  51 + this.wrieLog("去重前的classId:------>" + JSON.stringify(classid))
  52 + this.wrieLog("httpData:------>" + JSON.stringify(result.data))
51 return true 53 return true
52 } else { 54 } else {
53 return false 55 return false
54 } 56 }
55 } 57 }
  58 + wrieLog(text){
  59 + // 写入log
  60 + let logFile = `./log/${dayTimeYMD().ymd}.txt`
  61 + fs.appendFileSync(logFile,new Date().toLocaleString() + " " +text+'\r\n');
  62 + }
56 async mediaCreat(id, siteId) { 63 async mediaCreat(id, siteId) {
57 let fileConfig = await new MediaCreat().getConfigFileJson() 64 let fileConfig = await new MediaCreat().getConfigFileJson()
58 if(!fileConfig) return false 65 if(!fileConfig) return false
@@ -70,13 +77,13 @@ class MediaCreat { @@ -70,13 +77,13 @@ class MediaCreat {
70 if (!fs.existsSync(ymdDir)) { 77 if (!fs.existsSync(ymdDir)) {
71 fs.mkdirSync(ymdDir); 78 fs.mkdirSync(ymdDir);
72 } 79 }
73 - let url = `web_capture_c -o=../media/${siteId}/${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}` 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}`
74 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) 81 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
75 // workerProcess.stdout.on('data', async function (data) { 82 // workerProcess.stdout.on('data', async function (data) {
76 83
77 // }); 84 // });
78 85
79 - workerProcess.on('close', async function (code) { 86 + workerProcess.on('close', async (code) => {
80 let files = fs.readdirSync(ymdDir); 87 let files = fs.readdirSync(ymdDir);
81 if (files.indexOf(id + ".mp4") == -1) { 88 if (files.indexOf(id + ".mp4") == -1) {
82 //当前课堂没有写入到文件夹,进入重录 89 //当前课堂没有写入到文件夹,进入重录
@@ -88,6 +95,7 @@ class MediaCreat { @@ -88,6 +95,7 @@ class MediaCreat {
88 } 95 }
89 if (parentData[siteId].length == 0) { 96 if (parentData[siteId].length == 0) {
90 // //全部录制完毕 97 // //全部录制完毕
  98 + this.wrieLog("录制结束:------>")
91 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { 99 fs.writeFile(ymdDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
92 if (err) { 100 if (err) {
93 console.log(err); 101 console.log(err);
@@ -121,13 +129,14 @@ class MediaCreat { @@ -121,13 +129,14 @@ class MediaCreat {
121 if (!fs.existsSync(dateDir)) { 129 if (!fs.existsSync(dateDir)) {
122 fs.mkdirSync(dateDir); 130 fs.mkdirSync(dateDir);
123 } 131 }
124 - 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}` 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 +
125 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true }) 134 var workerProcess = spawn(url, { cwd: PROJECTWINCATALOG, shell: true })
126 // workerProcess.stdout.on('data', async function (data) { 135 // workerProcess.stdout.on('data', async function (data) {
127 136
128 // }); 137 // });
129 138
130 - workerProcess.on('close', async function (code) { 139 + workerProcess.on('close', async (code) =>{
131 let files = fs.readdirSync(dateDir); 140 let files = fs.readdirSync(dateDir);
132 if (files.indexOf(id + ".mp4") == -1) { 141 if (files.indexOf(id + ".mp4") == -1) {
133 //当前课堂没有写入到文件夹,进入重录 142 //当前课堂没有写入到文件夹,进入重录
@@ -139,6 +148,7 @@ class MediaCreat { @@ -139,6 +148,7 @@ class MediaCreat {
139 } 148 }
140 if (parentData[siteId].length == 0) { 149 if (parentData[siteId].length == 0) {
141 // //全部录制完毕 150 // //全部录制完毕
  151 + this.wrieLog("录制结束:------>")
142 fs.writeFile(dateDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) { 152 fs.writeFile(dateDir + "/download.json", `{ "code": "0", "success": "ok"}`, function (err) {
143 if (err) { 153 if (err) {
144 console.log(err); 154 console.log(err);
@@ -161,6 +171,7 @@ class MediaCreat { @@ -161,6 +171,7 @@ class MediaCreat {
161 171
162 172
163 router.get('/', async function (req, res, next) { 173 router.get('/', async function (req, res, next) {
  174 + new MediaCreat().wrieLog("录制开始:------>")
164 let fileConfig = await new MediaCreat().getConfigFileJson() 175 let fileConfig = await new MediaCreat().getConfigFileJson()
165 if(!fileConfig) return false 176 if(!fileConfig) return false
166 177
@@ -170,10 +181,13 @@ router.get('/', async function (req, res, next) { @@ -170,10 +181,13 @@ router.get('/', async function (req, res, next) {
170 let result = await new MediaCreat().allData() 181 let result = await new MediaCreat().allData()
171 if (result) { 182 if (result) {
172 // 去重 183 // 去重
  184 + classobj = {}
173 classid = classid.reduce(function (item, next) { 185 classid = classid.reduce(function (item, next) {
174 classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next); 186 classobj[next.classId] ? '' : classobj[next.classId] = true && item.push(next);
175 return item; 187 return item;
176 }, []); 188 }, []);
  189 + // 写入log
  190 + new MediaCreat().wrieLog("去重后的classid:------>" + JSON.stringify(classid))
177 if (classid.length) { 191 if (classid.length) {
178 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) { 192 for (let i = 0; i < GETCLASSURLPARAMETER.maxMedia; i++) {
179 let shiftData = classid.shift() 193 let shiftData = classid.shift()
@@ -183,8 +197,10 @@ router.get('/', async function (req, res, next) { @@ -183,8 +197,10 @@ router.get('/', async function (req, res, next) {
183 return false 197 return false
184 } 198 }
185 } 199 }
  200 + res.send({ code: "0" });
  201 + }else{
  202 + res.send({ code: "1" ,message:"无录制数据"});
186 } 203 }
187 - res.send({ code: "0" });  
188 } 204 }
189 }); 205 });
190 206
@@ -194,6 +210,7 @@ router.get('/', async function (req, res, next) { @@ -194,6 +210,7 @@ router.get('/', async function (req, res, next) {
194 * } 210 * }
195 */ 211 */
196 router.post('/recording', async function (req, res, next) { 212 router.post('/recording', async function (req, res, next) {
  213 + new MediaCreat().wrieLog("录制开始:------>")
197 let fileConfig = await new MediaCreat().getConfigFileJson() 214 let fileConfig = await new MediaCreat().getConfigFileJson()
198 if(!fileConfig) return false 215 if(!fileConfig) return false
199 const { classId } = req.body 216 const { classId } = req.body
@@ -214,8 +231,11 @@ router.post('/recording', async function (req, res, next) { @@ -214,8 +231,11 @@ router.post('/recording', async function (req, res, next) {
214 return false 231 return false
215 } 232 }
216 } 233 }
  234 + res.send({ code: "0" });
  235 + }else{
  236 + res.send({ code: "1" ,message:"无录制数据"});
217 } 237 }
218 - res.send({ code: "0" }); 238 +
219 }) 239 })
220 240
221 241