Add improved child process handlers
This commit is contained in:
parent
e5c4923609
commit
22bab34774
21
player.js
21
player.js
@ -19,6 +19,19 @@ var template = pug.compileFile(__dirname + '/source/templates/homepage.pug'),
|
|||||||
|
|
||||||
var play_log = [];
|
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) {
|
tag_reader.on('error', function(err) {
|
||||||
console.log(`[tag_reader:error] ${err}`);
|
console.log(`[tag_reader:error] ${err}`);
|
||||||
});
|
});
|
||||||
@ -27,6 +40,14 @@ player.on('error', function(err) {
|
|||||||
console.log(`[player:error] ${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");
|
// player.stdin.write("GAIN 100");
|
||||||
|
|
||||||
var last_tag = null;
|
var last_tag = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user