io.in logger

v1.18.x
barisusakli 9 years ago
parent e0c6acd163
commit 4a06750ae2

@ -175,11 +175,12 @@ var opts = {
/*
* Go through all of the currently established sockets & hook their .emit/.on
*/
if(!socket && !socket.io.sockets) {
if (!socket || !socket.io || !socket.io.sockets || !Array.isArray(socket.io.sockets.sockets)) {
return;
}
var clients = []; //socket.io.sockets.clients(); doesn't work in socket.io 1.x
var clients = socket.io.sockets.sockets;
clients.forEach(function(client) {
Logger.io_one(client, client.uid);
@ -190,33 +191,29 @@ var opts = {
/*
* This function replaces a socket's .emit/.on functions in order to intercept events
*/
if(socket && meta.config.loggerIOStatus > 0) {
(function() {
function override(method, name, errorMsg) {
return function() {
if(opts.streams.log.f) {
opts.streams.log.f.write(Logger.prepare_io_string(name, uid, arguments));
}
try {
method.apply(socket, arguments);
} catch(err) {
winston.info(errorMsg, err);
}
};
function override(method, name, errorMsg) {
return function() {
if(opts.streams.log.f) {
opts.streams.log.f.write(Logger.prepare_io_string(name, uid, arguments));
}
// courtesy of: http://stackoverflow.com/a/9674248
socket.oEmit = socket.emit;
var emit = socket.emit;
socket.emit = override(emit, 'emit', 'Logger.io_one: emit.apply: Failed');
try {
method.apply(socket, arguments);
} catch(err) {
winston.info(errorMsg, err);
}
};
}
socket.$oEmit = socket.$emit;
var $emit = socket.$emit;
socket.$emit = override($emit, 'on', 'Logger.io_one: $emit.apply: Failed');
if (socket && meta.config.loggerIOStatus > 0) {
// courtesy of: http://stackoverflow.com/a/9674248
socket.oEmit = socket.emit;
var emit = socket.emit;
socket.emit = override(emit, 'emit', 'Logger.io_one: emit.apply: Failed');
})();
socket.$oEmit = socket.$emit;
var $emit = socket.$emit;
socket.$emit = override($emit, 'on', 'Logger.io_one: $emit.apply: Failed');
}
};

@ -76,7 +76,7 @@ SocketAdmin.restart = function(socket, data, callback) {
};
SocketAdmin.fireEvent = function(socket, data, callback) {
index.server.sockets.emit(data.name, data.payload || {});
index.server.emit(data.name, data.payload || {});
};
SocketAdmin.themes.getInstalled = function(socket, data, callback) {

@ -93,7 +93,7 @@ function onDisconnect(socket, data) {
// see https://github.com/Automattic/socket.io/issues/1814
data.rooms.forEach(function(roomName) {
if (roomName.startsWith('topic')) {
io.sockets.in(roomName).emit('event:user_leave', socket.uid);
io.in(roomName).emit('event:user_leave', socket.uid);
}
});
}
@ -210,11 +210,11 @@ function callMethod(method, socket, params, callback) {
}
Sockets.logoutUser = function(uid) {
io.sockets.in('uid_' + uid).emit('event:disconnect');
io.in('uid_' + uid).emit('event:disconnect');
};
Sockets.in = function(room) {
return io.sockets.in(room);
return io.in(room);
};
Sockets.getSocketCount = function() {

@ -28,7 +28,7 @@ SocketMeta.reconnected = function(socket, data, callback) {
};
emitter.on('nodebb:ready', function() {
websockets.server.sockets.emit('event:nodebb.ready', {
websockets.server.emit('event:nodebb.ready', {
'cache-buster': meta.config['cache-buster']
});
});

@ -38,7 +38,7 @@ module.exports = function(SocketUser) {
uid: socket.uid,
status: status
};
websockets.server.sockets.emit('event:user_status_change', data);
websockets.server.emit('event:user_status_change', data);
callback(null, data);
});
};

Loading…
Cancel
Save