From 395c024642e35a4a5b1d3e8a26b809e58c47308d Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 19 Sep 2012 10:36:57 -0400 Subject: [PATCH] Start of playout commands includes `loadBg`, `load` and `play` related to #1 --- index.js | 2 ++ lib/playout.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/playout.js diff --git a/index.js b/index.js index 02a421d..daf8308 100644 --- a/index.js +++ b/index.js @@ -21,3 +21,5 @@ util.inherits(ccg, events.EventEmitter); require("./lib/connection")(ccg); // query commands require("./lib/query")(ccg); +// query commands +require("./lib/playout")(ccg); diff --git a/lib/playout.js b/lib/playout.js new file mode 100644 index 0000000..44fc8b7 --- /dev/null +++ b/lib/playout.js @@ -0,0 +1,56 @@ +module.exports = function (ccg) { + var sendPlayoutCommand = function (self, cmd, channel, file, options, cb) { + cmd += " " + channel; + cmd += " " + file.replace("\\", "\\\\"); + + if (!cb) { + cb = options; + options = {}; + } + + if (options.loop) cmd += " LOOP"; + + // this should be validated + if (options.transition) cmd += " " + options.transition; + + if (options.seek && parseInt(options.seek, 10) > 0) cmd += " SEEK " + options.seek; + + if (options.length && parseInt(options.seek, 10) > 0) cmd += " SEEK " + options.length; + + if (options.filter) cmd += " " + options.filter; + + if (options.auto) cmd += " AUTO"; + + self.sendCommand(cmd, function (err, data) { + cb(err, data); + }); + }; + + // --- + // ccg.load + // --- + // Load media file + // [LOAD](http://casparcg.com/wiki/CasparCG_2.0_AMCP_Protocol#LOAD) + ccg.prototype.load = function (channel, file, options, cb) { + sendPlayoutCommand(this, "LOAD", channel, file, options, cb); + }; + + // --- + // ccg.loadBg + // --- + // Load media file into background + // [LOADBG](http://casparcg.com/wiki/CasparCG_2.0_AMCP_Protocol#LOADBG) + ccg.prototype.loadBg = function (channel, file, options, cb) { + sendPlayoutCommand(this, "LOADBG", channel, file, options, cb); + }; + + // --- + // ccg.play + // --- + // Play media file + // [PLAY](http://casparcg.com/wiki/CasparCG_2.0_AMCP_Protocol#PLAY) + ccg.prototype.play = function (channel, file, options, cb) { + sendPlayoutCommand(this, "PLAY", channel, file, options, cb); + }; + +}; \ No newline at end of file