diff --git a/app.js b/app.js index a23b0d3..1862717 100644 --- a/app.js +++ b/app.js @@ -72,6 +72,14 @@ var pushNavData = function() { }; var navTimer = setInterval(pushNavData, 100); +// Prepare dependency map for plugins +var deps = { + server: server + , app: app + , io: io + , client: client +}; + // Load the plugins var dir = path.join(__dirname, 'plugins'); @@ -79,7 +87,7 @@ config.plugins.forEach(function (plugin) { console.log("Loading " + plugin + " plugin."); // Load the backend code - require(path.join(dir, plugin))(plugin, app, io, client); + require(path.join(dir, plugin))(plugin, deps); // Add the public assets to a static route if (fs.existsSync(assets = path.join(dir, plugin, 'public'))) { diff --git a/plugins/hud/index.js b/plugins/hud/index.js index 140dd23..8a33557 100644 --- a/plugins/hud/index.js +++ b/plugins/hud/index.js @@ -1,4 +1,4 @@ -function hud(name, app, io, client) { +function hud(name, deps) { // Nothing special on the backend for now }; diff --git a/plugins/pilot/index.js b/plugins/pilot/index.js index aa792a8..247683d 100644 --- a/plugins/pilot/index.js +++ b/plugins/pilot/index.js @@ -1,14 +1,14 @@ -function pilot(iname, app, io, client) { - io.sockets.on('connection', function (socket) { +function pilot(name, deps) { + deps.io.sockets.on('connection', function (socket) { socket.on('/pilot/move', function (cmd) { var _name; console.log("move", cmd); - return typeof client[_name = cmd.action] === "function" ? client[_name](cmd.speed) : void 0; + return typeof deps.client[_name = cmd.action] === "function" ? deps.client[_name](cmd.speed) : void 0; }); socket.on('/pilot/drone', function (cmd) { var _name; console.log("drone", cmd); - return typeof client[_name = cmd.action] === "function" ? client[_name]() : void 0; + return typeof deps.client[_name = cmd.action] === "function" ? deps.client[_name]() : void 0; }); }); }; diff --git a/plugins/video-png/index.js b/plugins/video-png/index.js index e5595b0..d4e60e0 100644 --- a/plugins/video-png/index.js +++ b/plugins/video-png/index.js @@ -1,11 +1,11 @@ var arDrone = require('ar-drone'); -function video(name, app, io, client) { +function video(name, deps) { var latestImage; // Add a new route to fetch camera image - app.get('/camera/:id', function(req, res) { + deps.app.get('/camera/:id', function(req, res) { if (!latestImage) { res.writeHead(301, {"Location": "/plugin/" + name + "/images/nofeed.jpg"}); res.end();