var restify = require('restify'); var bunyan = require('bunyan'); var Q = require("q"); var FS = require("q-io/fs"); // CONNECTIONS AND STUFF var fifoPath = '/home/daddel9/.mpv-fifo'; var log = bunyan.createLogger({name: 'MpvRemote'}); // SETUP var server = restify.createServer(); server.pre(restify.pre.sanitizePath()); // Serve static files server.get(/\/client\/?.*/, restify.serveStatic({ directory: __dirname })); // Mockup Methods // /seek/:time — seeks relative // /seek/:time/:mode — seeks with mode, modes [relative|absolute|absolute-percent|relative-percent|exact|keyframes] // /seek-chapter/:where — seeks to prev (where=-x) or next (where=+x) chapter // /volume/:amount — increases (amount=+x) or decreases (amount=-x) volume // /progress — show osd progress // /playpause — toggles playing // /muteunmute — toggles muting // server.get('/seek/:time', function (req, res, next) { // log.info("Seeking "+req.params['time']+" now."); // return FS.write( fifoPath, '{ "command": ["seek", "10"] }\n' ) // .then(function () { // log.info("wrote seek 10 to "+fifoPath); // res.send({'success':true}); // return next(false); // }, function(reason) { // log.info("failed because "+reason); // }); // log.info("after then"); // }); server.get('/seek/:time/:mode', function (req, res, next) { log.info("Seeking "+req.params['time']+" with mode "+req.params['mode']+" now."); res.send({'success':true}); return; }); server.listen(8080, function() { console.log('%s listening at %s', server.name, server.url); });