diff --git a/kitchenradio/app/helper.js b/kitchenradio/app/helper.js index 9286c90..249810b 100644 --- a/kitchenradio/app/helper.js +++ b/kitchenradio/app/helper.js @@ -11,7 +11,8 @@ var os = require('os') , dns = require('dns') , Log = require('./logging') , Crypto = require('crypto') -, interfaceAddresses = require('interface-addresses'); +, interfaceAddresses = require('interface-addresses'), +, spawn = require('child_process').spawn; var app = null; @@ -26,8 +27,11 @@ exports.init = function(express) { return this; } +exports.shspawn = function(command) { + spawn('sh', ['-c', command], { stdio: 'inherit' }); +} -exports.timeSince = function timeSince(date) { +exports.timeSince = function(date) { var seconds = Math.floor((new Date() - date) / 1000); diff --git a/kitchenradio/app/radio.js b/kitchenradio/app/radio.js index 6ef2659..23d6689 100644 --- a/kitchenradio/app/radio.js +++ b/kitchenradio/app/radio.js @@ -80,54 +80,9 @@ exports.play = function(idx) { } - /*grep('http://', m3u, function(list){ - Log.inspect('Radio: grep', list); - });*/ - - - /*try { - var parsers = require('playlist-parser'); - var M3U = parsers.M3U; - - var playlist = M3U.parse(fs.readFileSync(m3u, { encoding: 'utf8' })); - Log.inspect('Radio: playlist', playlist); - - if(Helper.isDefinedAndNotNull(playlist[0])) { - stream2play = playlist[0].file; - } else { - - } - } catch(e) { - Log.error(e); - }*/ - - /*var Child = spawn( - App.get('tools_root')+'action.sh', - ['play'] - );*/ - - child = exec(App.get('tools_root')+'action.sh play', - function (error, stdout, stderr) { - console.log('stdout: ' + stdout); - console.log('stderr: ' + stderr); - if (error !== null) { - console.log('exec error: ' + error); - } - }); - - // listen for any response from the child - Child.stdout.on('data', function(chunk) { - Log.log('Radio: stdout: ' + chunk); - }); - - // listen for any errors - Child.stderr.on('data', function (chunk) { - Log.error('Radio: stderr: ' + chunk); - }); - - /*Child.on('exit', function (code){ - Log.log('Radio: Child process exited with exit code ' + code); - });*/ + Child.stdin.pause(); + Child.kill(); + Helper.shspawn(App.get('tools_root')+'action.sh play'); }); download.on('error', function(err) { diff --git a/kitchenradio/bin/stop_radio.sh b/kitchenradio/bin/stop_radio.sh new file mode 100755 index 0000000..1ecf18e --- /dev/null +++ b/kitchenradio/bin/stop_radio.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# V0.1 + + +### DEFINITIONS + +MY_PATH="$(pwd)" +. $MY_PATH/bin/_inc/def_text_coloring.sh + + +### PRORGAM + +echo +echo "${BGre}Stop playing ...${RCol}" +echo