From 22bab3477488d75ffd07f2636463490f0601630c Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Sat, 8 Apr 2017 02:01:12 +0000 Subject: [PATCH] Add improved child process handlers --- player.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/player.js b/player.js index 75433c3..2087b08 100644 --- a/player.js +++ b/player.js @@ -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;