diff --git a/node/server.js b/node/server.js index c0bf49b1e..bf2b1030e 100644 --- a/node/server.js +++ b/node/server.js @@ -103,49 +103,6 @@ async.waterfall([ app.listen(settings.port, settings.ip); console.log("Server is listening at " + settings.ip + ":" + settings.port); - - - - //init socket.io and redirect all requests to the MessageHandler - var io = socketio.listen(app); - - //this is only a workaround to ensure it works with all browers behind a proxy - //we should remove this when the new socket.io version is more stable - io.set('transports', ['xhr-polling']); - - var socketIOLogger = log4js.getLogger("socket.io"); - io.set('logger', { - debug: function (str) - { - socketIOLogger.debug.apply(socketIOLogger, arguments); - }, - info: function (str) - { - socketIOLogger.info.apply(socketIOLogger, arguments); - }, - warn: function (str) - { - socketIOLogger.warn.apply(socketIOLogger, arguments); - }, - error: function (str) - { - socketIOLogger.error.apply(socketIOLogger, arguments); - }, - }); - - //minify socket.io javascript - if(settings.minify) - io.enable('browser client minification'); - - var padMessageHandler = require("./handler/PadMessageHandler"); - var timesliderMessageHandler = require("./handler/TimesliderMessageHandler"); - - //Initalize the Socket.IO Router - socketIORouter = require("./handler/SocketIORouter"); - socketIORouter.setSocketIO(io); - socketIORouter.addComponent("pad", padMessageHandler); - socketIORouter.addComponent("timeslider", timesliderMessageHandler); - callback(null); } ]); diff --git a/node/socketio.js b/node/socketio.js new file mode 100644 index 000000000..e6a4f95c3 --- /dev/null +++ b/node/socketio.js @@ -0,0 +1,49 @@ +var settings = require('./utils/Settings'); +var socketio = require('socket.io'); +var socketIORouter = require("./handler/SocketIORouter"); +var log4js = require('log4js'); +var hooks = require("./pluginfw/hooks"); + +var padMessageHandler = require("./handler/PadMessageHandler"); +var timesliderMessageHandler = require("./handler/TimesliderMessageHandler"); + + +exports.expressCreateServer = function (hook_name, args, cb) { + //init socket.io and redirect all requests to the MessageHandler + var io = socketio.listen(args.app); + + //this is only a workaround to ensure it works with all browers behind a proxy + //we should remove this when the new socket.io version is more stable + io.set('transports', ['xhr-polling']); + + var socketIOLogger = log4js.getLogger("socket.io"); + io.set('logger', { + debug: function (str) + { + socketIOLogger.debug.apply(socketIOLogger, arguments); + }, + info: function (str) + { + socketIOLogger.info.apply(socketIOLogger, arguments); + }, + warn: function (str) + { + socketIOLogger.warn.apply(socketIOLogger, arguments); + }, + error: function (str) + { + socketIOLogger.error.apply(socketIOLogger, arguments); + }, + }); + + //minify socket.io javascript + if(settings.minify) + io.enable('browser client minification'); + + //Initalize the Socket.IO Router + socketIORouter.setSocketIO(io); + socketIORouter.addComponent("pad", padMessageHandler); + socketIORouter.addComponent("timeslider", timesliderMessageHandler); + + hooks.callAll("socketio", {"app": args.app, "io": io}); +} diff --git a/pluginomatic.json b/pluginomatic.json index bb2e0473b..04b61c313 100644 --- a/pluginomatic.json +++ b/pluginomatic.json @@ -8,7 +8,8 @@ { "name": "webaccess", "hooks": { "expressConfigure": "../webaccess:expressConfigure" } }, { "name": "apicalls", "hooks": { "expressCreateServer": "../apicalls:expressCreateServer" } }, { "name": "importexport", "hooks": { "expressCreateServer": "../importexport:expressCreateServer" } }, - { "name": "errorhandling", "hooks": { "expressCreateServer": "../errorhandling:expressCreateServer" } } + { "name": "errorhandling", "hooks": { "expressCreateServer": "../errorhandling:expressCreateServer" } }, + { "name": "socketio", "hooks": { "expressCreateServer": "../socketio:expressCreateServer" } } ] }