"use strict"; const throttle = require('throttle-debounce/throttle'); const ChildProcessEmitter = require('./child-process').ChildProcessEmitter; const DEFAULT_PAUSE_THROTTLE = 2000; const DEFAULT_PLAY_THROTTLE = 5000; class MediaPlayer extends ChildProcessEmitter { constructor(config, logger) { super(config.mpg321, logger); this.stderrFilters.push(line => { return line.substr(0, 3) == '@F ' }); this.pauseThrottled = throttle(config.pause_throttle || DEFAULT_PAUSE_THROTTLE, () => { this._pause(); }); this.playFileThrottled = throttle(config.play_throttle || DEFAULT_PLAY_THROTTLE, (path) => { this._playFile(path); }); // default to unthrottled this.pause = this._pauseFile; this.playFile = this._playFile; } throttle() { this.pause = this.pauseThrottled; this.playFile = this.playFileThrottled; } stop() { this.send('STOP'); } _pause() { this.send('PAUSE'); } _playFile(path) { this.send("LOAD " + path); } } module.exports = function(config, logger) { return new MediaPlayer(config, logger); }; // vim:set ts=2 sw=2 et: