This commit is contained in:
Your Name 2017-04-14 10:49:49 +12:00
commit 191978bd4f
3 changed files with 27 additions and 11 deletions

View file

@ -8,7 +8,7 @@
"name": "Unconfigured",
"master": "http://data.protagon.space:8080",
"ffmpegPath": "ffmpeg",
"ssh-user": "root",
"ssh-user": "ssh",
"ssh-local-user": "alarm",
"ssh-port": 22,
"customOutputOptions": "",

34
main.js
View file

@ -57,7 +57,7 @@ let status = {
}
let errors = ['Camera Disconnected', 'YoutTube Disconnected', 'Wrong ffmpeg executable.'];
let cmd, sshpid;
let cmd;
let spawn = function() {
source = 'rtsp://' + config.camIP + ':' + config.camPort + '/' + config.camProfile;
@ -203,14 +203,25 @@ function isReachable(host, port, callback) {
});
}
function stopFFMPEG() {
if(!cmd)
return;
cmd.kill('SIGINT');
setTimeout(() => {
logger.log(importance[3], "Force Stop!");
cmd.kill();
}, 30);
}
var commandHandlers = function commandHandlers(command, cb) {
var handlers = {
startStop: function() {
if (status.running !== 2)
if (status.running === 0) {
logger.log(importance[1], "Stop Command!");
mustBe = true
cmd.kill();
mustBe = true;
stopFFMPEG();
socket.emit('data', {
type: 'message',
data: {
@ -285,7 +296,7 @@ var commandHandlers = function commandHandlers(command, cb) {
config: command.data
}
});
cmd.kill();
stopFFMPEG();
spawn();
} else {
socket.disconnect();
@ -300,7 +311,7 @@ var commandHandlers = function commandHandlers(command, cb) {
logger.log(importance[1], "Restart Command!");
mustBe = true;
restart = true;
cmd.kill();
stopFFMPEG();
} else {
logger.log(importance[1], "Start Command!");
spawn();
@ -396,10 +407,9 @@ function init() {
}
let d = false;
function initSSH(cb) {
status.ssh = {
// that Could come from the Master server!
user: config['ssh-user'],
localUser: config['ssh-local-user'],
masterPort: config['ssh-port']
@ -431,7 +441,14 @@ function connectSSH(cb = function() {
cwd: __dirname
});
ssh.on('error', (err) => {
throw err;
socket.emit('data', {
type: 'message',
data: {
title: 'Error',
type: 'error',
text: 'Could not start SSH tunnels!'
}
}, command.sender);
});
cb();
});
@ -476,7 +493,6 @@ function initSocket() {
});
socket.on('disconnect', function() {
d = true;
socket.disconnect();
init();
});

View file

@ -4,7 +4,7 @@ const fs = require('fs');
let pid;
let config = JSON.parse(fs.readFileSync('./config.js'));
let p = spawn(`ssh -oStrictHostKeyChecking=no -p ${config['ssh-port']} -f -N -R ${process.argv[2]}:localhost:22 -f -N -R 0.0.0.0:${process.argv[3]}:${config.camIP}:${process.argv[4]} ${config['ssh-user']}@${config.master.replace(/((http|https)\:\/{2}|\:[0-9]+)/g, '')} && pidof ssh`, {
let p = spawn(`ssh -oStrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -p ${config['ssh-port']} -f -N -R ${process.argv[2]}:localhost:22 -f -N -R 0.0.0.0:${process.argv[3]}:${config.camIP}:${process.argv[4]} ${config['ssh-user']}@${config.master.replace(/((http|https)\:\/{2}|\:[0-9]+)/g, '')} && pidof ssh`, {
shell: true,
detached: false
})