Update socket.io to version 1.4.0

This commit is contained in:
calzoneman 2016-01-06 21:42:48 -08:00
parent 1ac69709ee
commit eeaffe1f61
7 changed files with 35 additions and 7 deletions

View file

@ -50,7 +50,8 @@ var defaults = {
io: {
domain: "http://localhost",
"default-port": 1337,
"ip-connection-limit": 10
"ip-connection-limit": 10,
"per-message-deflate": false
},
mail: {
enabled: false,

View file

@ -25,11 +25,20 @@ Socket.prototype.packet = function () {
exports.add('socket.io:packet');
};
function getConnectedSockets() {
var sockets = io.instance.sockets.sockets;
if (typeof sockets.length === 'number') {
return sockets.length;
} else {
return Object.keys(sockets).length;
}
}
setInterval(function () {
try {
counters['memory:rss'] = process.memoryUsage().rss / 1048576;
counters['load:1min'] = os.loadavg()[0];
counters['socket.io:count'] = io.instance.sockets.sockets.length;
counters['socket.io:count'] = getConnectedSockets();
counterLog.log(JSON.stringify(counters));
} catch (e) {
Logger.errlog.log(e.stack);

View file

@ -583,7 +583,7 @@ module.exports.loadAnnouncement = function () {
var sv = Server.getServer();
sv.announcement = announcement;
for (var id in sv.ioServers) {
sv.ioServers[id].sockets.emit("announcement", announcement);
sv.ioServers[id].emit("announcement", announcement);
}
});
};

View file

@ -242,6 +242,9 @@ function handleConnection(sock) {
module.exports = {
init: function (srv, webConfig) {
var bound = {};
const ioOptions = {
perMessageDeflate: Config.get("io.per-message-deflate")
};
var io = sio.instance = sio();
io.use(handleAuth);
@ -259,7 +262,7 @@ module.exports = {
}
if (id in srv.servers) {
io.attach(srv.servers[id]);
io.attach(srv.servers[id], ioOptions);
} else {
var server = require("http").createServer().listen(bind.port, bind.ip);
server.on("clientError", function (err, socket) {
@ -268,7 +271,7 @@ module.exports = {
} catch (e) {
}
});
io.attach(server);
io.attach(server, ioOptions);
}
bound[id] = null;