diff --git a/player.js b/player.js index be56e4b..f8a5432 100644 --- a/player.js +++ b/player.js @@ -85,20 +85,32 @@ function appendLog(message) { wss.broadcast(JSON.stringify(data)); } -tag_reader.stdout.on('data', (data) => { +function processLine(data) { if (Date.now() / 1000 < debounce_until) { return; } + last_tag = String(data).trim(); console.log("[tag] " + last_tag); + + // min 1 sec debounce + debounce_until = Date.now() / 1000 + 1; + lookup(last_tag, function(action, wait_sec) { wait_sec = wait_sec || 1; + debounce_until = Date.now() / 1000 + wait_sec; if (action) { - debounce_until = Date.now() / 1000 + wait_sec; console.log(`[action] [${action}] for [${last_tag}]`); player.stdin.write(action + "\n"); } }); +} + +tag_reader.stdout.on('data', (data) => { + var s = data.toString(), lines = s.split(/\n/g); + for (var i = 0, l = lines.length; i < l; i++) { + processLine(lines[i]); + } }); tag_reader.stderr.on('data', (data) => {