Update to socket.io 1.0

This commit is contained in:
calzoneman 2014-08-19 22:57:28 -05:00
parent daec397015
commit db86d3918f
4 changed files with 21 additions and 42 deletions

View File

@ -609,9 +609,7 @@ Channel.prototype.handleReadLog = function (user) {
};
Channel.prototype._broadcast = function (msg, data, ns) {
sio.ioServers.forEach(function (io) {
io.sockets.in(ns).emit(msg, data);
});
sio.instance.in(ns).emit(msg, data);
};
Channel.prototype.broadcastAll = function (msg, data) {

View File

@ -26,14 +26,16 @@ var ipCount = {};
/**
* Called before an incoming socket.io connection is accepted.
*/
function handleAuth(data, accept) {
data.user = false;
function handleAuth(socket, accept) {
var data = socket.request;
socket.user = false;
if (data.headers.cookie) {
cookieParser(data, null, function () {
var auth = data.cookies.auth;
db.users.verifyAuth(auth, function (err, user) {
if (!err) {
data.user = {
socket.user = {
name: user.name,
global_rank: user.global_rank
};
@ -158,10 +160,10 @@ function handleConnection(sock) {
addTypecheckedFunctions(sock);
var user = new User(sock);
if (sock.handshake.user) {
if (sock.user) {
user.setFlag(Flags.U_REGISTERED);
user.clearFlag(Flags.U_READY);
user.refreshAccount({ name: sock.handshake.user.name },
user.refreshAccount({ name: sock.user.name },
function (err, account) {
if (err) {
user.clearFlag(Flags.U_REGISTERED);
@ -189,44 +191,30 @@ function handleConnection(sock) {
module.exports = {
init: function (srv) {
var bound = {};
var io = sio.instance = sio();
io.use(handleAuth);
io.on("connection", handleConnection);
Config.get("listen").forEach(function (bind) {
if (!bind.io) {
return;
}
var id = bind.ip + ":" + bind.port;
if (id in srv.ioServers) {
if (id in bound) {
Logger.syslog.log("[WARN] Ignoring duplicate listen address " + id);
return;
}
var io = null;
if (id in srv.servers) {
io = srv.ioServers[id] = sio.listen(srv.servers[id]);
io.attach(srv.servers[id]);
} else {
if (net.isIPv6(bind.ip) || bind.ip === "::") {
/**
* Socket.IO won't bind to a v6 address natively.
* Instead, we have to create a node HTTP server, bind it
* to the desired address, then have socket.io listen on it
*/
io = srv.ioServers[id] = sio.listen(
require("http").createServer().listen(bind.port, bind.ip)
);
} else {
io = srv.ioServers[id] = sio.listen(bind.port, bind.ip);
}
io.attach(require("http").createServer().listen(bind.port, bind.ip));
}
if (io) {
io.set("log level", 1);
io.set("authorization", handleAuth);
io.on("connection", handleConnection);
}
bound[id] = null;
});
sio.ioServers = Object.keys(srv.ioServers)
.filter(Object.hasOwnProperty.bind(srv.ioServers))
.map(function (k) { return srv.ioServers[k] });
}
};

View File

@ -20,7 +20,7 @@
"oauth": "^0.9.12",
"q": "^1.0.1",
"serve-static": "^1.5.3",
"socket.io": "~0.9.16",
"socket.io": "^1.0.6",
"yamljs": "^0.1.5"
}
}

View File

@ -1095,17 +1095,10 @@ try {
throw false;
}
if (NO_WEBSOCKETS || USEROPTS.altsocket) {
var i = io.transports.indexOf("websocket");
if (i >= 0) {
io.transports.splice(i, 1);
}
}
if (IO_URL === IO_URLS["ipv4-ssl"] || IO_URL === IO_URLS["ipv6-ssl"]) {
socket = io.connect(IO_URL, { secure: true });
socket = io(IO_URL, { secure: true });
} else {
socket = io.connect(IO_URL);
socket = io(IO_URL);
}
setupCallbacks();
} catch (e) {