Browse Source

Filter out @F messages from mpg321

master
Annika Backstrom 4 years ago
parent
commit
2ec67288e4
  1. 13
      bin/mpg321-dummy
  2. 2
      config.json.vagrant
  3. 18
      jukebox/child-process.js
  4. 3
      jukebox/media-player.js
  5. 8
      player.js

13
bin/mpg321-dummy

@ -1,5 +1,10 @@
#!/bin/bash
var i = 1;
while read line ; do
echo "running $line"
done
setInterval(function() {
i += 1;
process.stderr.write(`@F ${i} 2 3 4\n`);
}, 100);
process.stdin.on('data', function(data) {
process.stdout.write(`GOT MESSAGE ${data}`);
});

2
config.json.vagrant

@ -2,5 +2,5 @@
"port": "8080",
"tag_reader": ["./bin/tag-reader-dummy"],
"mpg321": ["./bin/mpg321-dummy"]
"mpg321": ["node", "./bin/mpg321-dummy"]
}

18
jukebox/child-process.js

@ -11,6 +11,7 @@ module.exports.ChildProcessEmitter = class ChildProcessEmitter extends EventEmit
super();
this.logger = logger;
this.stderrFilters = [];
var cmd = command[0],
args = command.slice(1);
@ -26,14 +27,21 @@ module.exports.ChildProcessEmitter = class ChildProcessEmitter extends EventEmit
});
this.childProcess.stdout.on('data', (data) => {
var s = data.toString(), lines = s.split(/\n/g);
for (var i = 0, l = lines.length; i < l; i++) {
this.emit('message', lines[i]);
}
var lines = data.toString().split(/\n/g);
lines.map(line => line.trim())
.filter(line => line.length)
.map(line => this.emit('message', line));
});
this.childProcess.stderr.on('data', (data) => {
this.logger.error('process stderr', { class: this.constructor.name, stderr: String(data).trim()});
var line = data.toString().trim();
var filtered = this.stderrFilters.reduce((filter, filtered) => {
return filtered || filter(line);
}, false);
if (filtered) {
return;
}
this.logger.error('process stderr', { class: this.constructor.name, stderr: line});
});
}

3
jukebox/media-player.js

@ -5,6 +5,9 @@ const ChildProcessEmitter = require('./child-process').ChildProcessEmitter;
class MediaPlayer extends ChildProcessEmitter {
constructor(config, logger) {
super(config.mpg321, logger);
this.stderrFilters.push(line => {
return line.substr(0, 3) == '@F '
});
}
}

8
player.js

@ -45,13 +45,13 @@ function exitHandler(options, err) {
process.on('exit', exitHandler.bind(null));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
TagReader.on('message', (data) => {
TagReader.on('message', data => {
processLine(data);
});
if (config.debug) {
MediaPlayer.on('message', (data) => {
logger.debug("mediaplayer send message", { line: data });
MediaPlayer.on('message', line => {
logger.debug("mediaplayer sent message", { line: line });
});
}
@ -66,7 +66,7 @@ function lookup(tag, cb) {
return cb('PAUSE', 2);
}
glob('media/' + tag + ' - *.mp3', function(er, files) {
glob('media/' + tag + ' - *.mp3', (er, files) => {
if (files.length > 0) {
appendLog(files[0]);
return cb("LOAD " + files[0], 5);

Loading…
Cancel
Save