Add improved child process handlers

This commit is contained in:
Annika Backstrom 2017-04-08 02:01:12 +00:00
parent e5c4923609
commit 22bab34774

View File

@ -19,6 +19,19 @@ var template = pug.compileFile(__dirname + '/source/templates/homepage.pug'),
var play_log = [];
function exitHandler(options, err) {
console.log('[player] closing children');
if (err) console.log(err.stack);
tag_reader.kill();
player.kill();
if (options.exit) {
process.exit();
}
}
process.on('exit', exitHandler.bind(null));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
tag_reader.on('error', function(err) {
console.log(`[tag_reader:error] ${err}`);
});
@ -27,6 +40,14 @@ player.on('error', function(err) {
console.log(`[player:error] ${err}`);
});
tag_reader.on('close', function(code, signal) {
console.log(`[tag_reader] process closed:code=${code} signal=${signal}`);
});
player.on('close', function(code, signal) {
console.log(`[mpg321] process closed:code=${code} signal=${signal}`);
});
// player.stdin.write("GAIN 100");
var last_tag = null;