* feat(assist): removed cache for solo-node assist mode * feat(assist): try to fetch from global io object * feat(assist): small changes * feat(assist): added cache per request instead of cache per room * feat(assist): fixed await call in global scope * feat(assist): try to fix circular structure issue * feat(assist): use preprocessor for sockets list * feat(assist): check the theory about fetchSockets data set * feat(assist): try to keep everything inside handshake.query object
40 lines
No EOL
835 B
JavaScript
40 lines
No EOL
835 B
JavaScript
const _io = require("socket.io");
|
|
const {getCompressionConfig} = require("./helper");
|
|
|
|
let io;
|
|
|
|
const getServer = function () {
|
|
return io;
|
|
}
|
|
|
|
const fetchSockets = async function (roomID) {
|
|
if (!io) {
|
|
return [];
|
|
}
|
|
if (!roomID) {
|
|
return await io.fetchSockets();
|
|
}
|
|
return await io.in(roomID).fetchSockets();
|
|
}
|
|
|
|
const createSocketIOServer = function (server, prefix) {
|
|
if (io) {
|
|
return io;
|
|
}
|
|
io = _io(server, {
|
|
maxHttpBufferSize: (parseFloat(process.env.maxHttpBufferSize) || 5) * 1e6,
|
|
cors: {
|
|
origin: "*",
|
|
methods: ["GET", "POST", "PUT"]
|
|
},
|
|
path: (prefix ? prefix : '') + '/socket',
|
|
...getCompressionConfig()
|
|
});
|
|
return io;
|
|
}
|
|
|
|
module.exports = {
|
|
createSocketIOServer,
|
|
getServer,
|
|
fetchSockets,
|
|
} |