2012-02-25 16:44:37 +01:00
|
|
|
var log4js = require('log4js');
|
2012-02-25 17:23:44 +01:00
|
|
|
var socketio = require('socket.io');
|
|
|
|
var settings = require('../../utils/Settings');
|
|
|
|
var socketIORouter = require("../../handler/SocketIORouter");
|
2012-03-01 19:00:58 +01:00
|
|
|
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
2012-02-25 16:44:37 +01:00
|
|
|
|
2012-02-25 17:23:44 +01:00
|
|
|
var padMessageHandler = require("../../handler/PadMessageHandler");
|
2012-02-25 16:44:37 +01:00
|
|
|
|
2012-04-19 14:25:12 +02:00
|
|
|
var connect = require('connect');
|
|
|
|
|
2012-02-25 16:44:37 +01:00
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
|
|
|
//init socket.io and redirect all requests to the MessageHandler
|
|
|
|
var io = socketio.listen(args.app);
|
|
|
|
|
2012-04-19 14:25:12 +02:00
|
|
|
/* Require an express session cookie to be present, and load the
|
|
|
|
* session. See http://www.danielbaulig.de/socket-ioexpress for more
|
|
|
|
* info */
|
|
|
|
io.set('authorization', function (data, accept) {
|
|
|
|
if (!data.headers.cookie) return accept('No session cookie transmitted.', false);
|
|
|
|
data.cookie = connect.utils.parseCookie(data.headers.cookie);
|
|
|
|
data.sessionID = data.cookie.express_sid;
|
|
|
|
args.app.sessionStore.get(data.sessionID, function (err, session) {
|
|
|
|
if (err || !session) return accept('Bad session / session has expired', false);
|
|
|
|
data.session = new connect.middleware.session.Session(data, session);
|
|
|
|
accept(null, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-25 16:44:37 +01:00
|
|
|
//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
|
2012-08-16 01:00:36 +02:00
|
|
|
io.set('transports', ['htmlfile','xhr-polling']);
|
2012-02-25 16:44:37 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
hooks.callAll("socketio", {"app": args.app, "io": io});
|
|
|
|
}
|