mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
io.in logger
This commit is contained in:
@@ -175,11 +175,12 @@ var opts = {
|
|||||||
/*
|
/*
|
||||||
* Go through all of the currently established sockets & hook their .emit/.on
|
* 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;
|
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) {
|
clients.forEach(function(client) {
|
||||||
Logger.io_one(client, client.uid);
|
Logger.io_one(client, client.uid);
|
||||||
@@ -190,9 +191,6 @@ var opts = {
|
|||||||
/*
|
/*
|
||||||
* This function replaces a socket's .emit/.on functions in order to intercept events
|
* 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) {
|
function override(method, name, errorMsg) {
|
||||||
return function() {
|
return function() {
|
||||||
if(opts.streams.log.f) {
|
if(opts.streams.log.f) {
|
||||||
@@ -207,6 +205,7 @@ var opts = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (socket && meta.config.loggerIOStatus > 0) {
|
||||||
// courtesy of: http://stackoverflow.com/a/9674248
|
// courtesy of: http://stackoverflow.com/a/9674248
|
||||||
socket.oEmit = socket.emit;
|
socket.oEmit = socket.emit;
|
||||||
var emit = socket.emit;
|
var emit = socket.emit;
|
||||||
@@ -215,8 +214,6 @@ var opts = {
|
|||||||
socket.$oEmit = socket.$emit;
|
socket.$oEmit = socket.$emit;
|
||||||
var $emit = socket.$emit;
|
var $emit = socket.$emit;
|
||||||
socket.$emit = override($emit, 'on', 'Logger.io_one: $emit.apply: Failed');
|
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) {
|
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) {
|
SocketAdmin.themes.getInstalled = function(socket, data, callback) {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ function onDisconnect(socket, data) {
|
|||||||
// see https://github.com/Automattic/socket.io/issues/1814
|
// see https://github.com/Automattic/socket.io/issues/1814
|
||||||
data.rooms.forEach(function(roomName) {
|
data.rooms.forEach(function(roomName) {
|
||||||
if (roomName.startsWith('topic')) {
|
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) {
|
Sockets.logoutUser = function(uid) {
|
||||||
io.sockets.in('uid_' + uid).emit('event:disconnect');
|
io.in('uid_' + uid).emit('event:disconnect');
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.in = function(room) {
|
Sockets.in = function(room) {
|
||||||
return io.sockets.in(room);
|
return io.in(room);
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.getSocketCount = function() {
|
Sockets.getSocketCount = function() {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ SocketMeta.reconnected = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
emitter.on('nodebb:ready', function() {
|
emitter.on('nodebb:ready', function() {
|
||||||
websockets.server.sockets.emit('event:nodebb.ready', {
|
websockets.server.emit('event:nodebb.ready', {
|
||||||
'cache-buster': meta.config['cache-buster']
|
'cache-buster': meta.config['cache-buster']
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ module.exports = function(SocketUser) {
|
|||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
status: status
|
status: status
|
||||||
};
|
};
|
||||||
websockets.server.sockets.emit('event:user_status_change', data);
|
websockets.server.emit('event:user_status_change', data);
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user