|
|
|
|
@ -4,6 +4,8 @@ const express = require('express');
|
|
|
|
|
const app = express();
|
|
|
|
|
const fileUpload = require('express-fileupload');
|
|
|
|
|
|
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(fileUpload());
|
|
|
|
|
|
|
|
|
|
@ -68,27 +70,40 @@ app.get('/videos', (req, res) => {
|
|
|
|
|
let process = null;
|
|
|
|
|
let mayRestart = false;
|
|
|
|
|
|
|
|
|
|
// if (fs.existsSync('/tmp/video')) {
|
|
|
|
|
// const initialVideo = fs.readFileSync('/tmp/video');
|
|
|
|
|
// startVideo(initialVideo);
|
|
|
|
|
// }
|
|
|
|
|
if (fs.existsSync('/selectedvideo')) {
|
|
|
|
|
const initialVideo = fs.readFileSync('/selectedvideo');
|
|
|
|
|
startVideo(initialVideo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startVideo(path) {
|
|
|
|
|
process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]);
|
|
|
|
|
|
|
|
|
|
process.stdout.on('data', (data) => {
|
|
|
|
|
console.log(`stdout: ${data}`);
|
|
|
|
|
});
|
|
|
|
|
const newProcess = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-an', '-loglevel', 'error', path]);
|
|
|
|
|
|
|
|
|
|
process.stderr.on('data', (data) => {
|
|
|
|
|
console.error(`stderr: ${data}`);
|
|
|
|
|
});
|
|
|
|
|
// process.stdout.on('data', (data) => {
|
|
|
|
|
// console.log(`stdout: ${data}`);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// process.stderr.on('data', (data) => {
|
|
|
|
|
// console.error(`stderr: ${data}`);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
process.on("exit", () => {
|
|
|
|
|
if (!mayRestart) {
|
|
|
|
|
startVideo(path);
|
|
|
|
|
// newProcess.on("exit", (code) => {
|
|
|
|
|
// if (!mayRestart && code !== 0) {
|
|
|
|
|
// startVideo(path);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (process) {
|
|
|
|
|
process.kill();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// newProcess.on("exit", (code) => {
|
|
|
|
|
// if (!mayRestart && code !== 0 && process === newProcess) {
|
|
|
|
|
// startVideo(path);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
process = newProcess;
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.mkdirSync('/video', { recursive: true });
|
|
|
|
|
@ -109,13 +124,64 @@ app.post('/play', (req, res) => {
|
|
|
|
|
video = path.join('/video/', path.basename(video))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync('/tmp/video', video);
|
|
|
|
|
fs.writeFileSync('/selectedvideo', video);
|
|
|
|
|
|
|
|
|
|
startVideo(video);
|
|
|
|
|
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post("/select", (req, res) => {
|
|
|
|
|
let video = req.query.video;
|
|
|
|
|
fs.writeFileSync('/overlayvideo', video);
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post("/playoverlay", (req, res) => {
|
|
|
|
|
const p = require('child_process').spawn('/home/pi/video-player/play-overlay.sh');
|
|
|
|
|
// p.stdout.on('data', (data) => {
|
|
|
|
|
// console.log(`stdout: ${data}`);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// p.stderr.on('data', (data) => {
|
|
|
|
|
// console.error(`stderr: ${data}`);
|
|
|
|
|
// });
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post("/startprojector", (req, res) => {
|
|
|
|
|
require('child_process').spawn('sudo', ['/home/pi/video-player/start-projector.sh']);
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post("/stopprojector", (req, res) => {
|
|
|
|
|
require('child_process').spawn('sudo', ['/home/pi/video-player/stop-projector.sh']);
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function projectorNumberToText(number) {
|
|
|
|
|
switch (number) {
|
|
|
|
|
case '01':
|
|
|
|
|
return 'On';
|
|
|
|
|
case '02':
|
|
|
|
|
return 'Starting/Stopping';
|
|
|
|
|
case '03':
|
|
|
|
|
return 'Starting/Stopping';
|
|
|
|
|
case '04':
|
|
|
|
|
return 'Off';
|
|
|
|
|
default:
|
|
|
|
|
return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.get("/projectorstatus", async (req, res) => {
|
|
|
|
|
const res1 = await fetch('http://192.168.1.93/api/v01/control/escvp21?cmd=PWR?');
|
|
|
|
|
const status1 = projectorNumberToText(await res1.text());
|
|
|
|
|
const res2 = await fetch('http://192.168.1.67/api/v01/control/escvp21?cmd=PWR?');
|
|
|
|
|
const status2 = projectorNumberToText(await res2.text());
|
|
|
|
|
res.json({ status1, status2 });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post('/upload', function (req, res) {
|
|
|
|
|
|
|
|
|
|
if (!req.files || Object.keys(req.files).length === 0) {
|
|
|
|
|
@ -123,19 +189,40 @@ app.post('/upload', function (req, res) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
|
|
|
|
|
const uploadPath = path.join(__dirname, '/public/videos/');
|
|
|
|
|
// const uploadPath = path.join(__dirname, '/public/videos/');
|
|
|
|
|
const uploadPath = "/video";
|
|
|
|
|
|
|
|
|
|
console.log(req.files.file);
|
|
|
|
|
|
|
|
|
|
req.files.file.mv(uploadPath + "video.mp4", function (err) {
|
|
|
|
|
req.files.file.mv(path.join(uploadPath, req.files.file.name), function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return res.status(500);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
require('child_process').spawn('sudo', ['systemctl', 'restart', 'video-player2.service']);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
res.redirect('/');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post("/delete", async (req, res) => {
|
|
|
|
|
let video = req.query.video;
|
|
|
|
|
await fs.rm(video);
|
|
|
|
|
res.json({ status: 'ok' });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get("/selectedvideo", (req, res) => {
|
|
|
|
|
if (fs.existsSync('/selectedvideo')) {
|
|
|
|
|
res.send(fs.readFileSync('/selectedvideo').toString());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
res.json("");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.redirect('/');
|
|
|
|
|
});
|
|
|
|
|
app.get("/overlayvideo", (req, res) => {
|
|
|
|
|
if (fs.existsSync('/overlayvideo')) {
|
|
|
|
|
res.send(fs.readFileSync('/overlayvideo').toString());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
res.json("");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|