fix(assist): fixed getSessions
This commit is contained in:
parent
22efd5709b
commit
81d55a7699
2 changed files with 11 additions and 6 deletions
|
|
@ -144,6 +144,7 @@ const socketsLiveByProject = async function (req, res) {
|
|||
let filters = await extractPayloadFromRequest(req);
|
||||
let withFilters = hasFilters(filters);
|
||||
let liveSessions = new Set();
|
||||
const sessIDs = new Set();
|
||||
let rooms = await getAvailableRooms(io);
|
||||
for (let roomId of rooms.keys()) {
|
||||
let {projectKey, sessionId} = extractPeerId(roomId);
|
||||
|
|
@ -152,11 +153,17 @@ const socketsLiveByProject = async function (req, res) {
|
|||
for (let item of connected_sockets) {
|
||||
if (item.handshake.query.identity === IDENTITIES.session) {
|
||||
if (withFilters) {
|
||||
if (item.handshake.query.sessionInfo && isValidSession(item.handshake.query.sessionInfo, filters.filter)) {
|
||||
if (item.handshake.query.sessionInfo &&
|
||||
isValidSession(item.handshake.query.sessionInfo, filters.filter) &&
|
||||
!sessIDs.has(item.handshake.query.sessionInfo.sessionId)
|
||||
) {
|
||||
liveSessions.add(item.handshake.query.sessionInfo);
|
||||
sessIDs.set(item.handshake.query.sessionInfo.sessionId);
|
||||
}
|
||||
} else {
|
||||
liveSessions.add(item.handshake.query.sessionInfo);
|
||||
if (!sessIDs.has(item.handshake.query.sessionInfo.sessionId)) {
|
||||
liveSessions.add(item.handshake.query.sessionInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -164,9 +171,7 @@ const socketsLiveByProject = async function (req, res) {
|
|||
}
|
||||
let sessions = Array.from(liveSessions);
|
||||
console.log("sessions: ", sessions);
|
||||
respond(res, _sessionId === undefined ? sortPaginate(sessions, filters)
|
||||
: sessions.length > 0 ? sessions[0]
|
||||
: null);
|
||||
respond(res, _sessionId === undefined ? sortPaginate(sessions, filters) : sessions.length > 0 ? sessions[0] : null);
|
||||
}
|
||||
|
||||
const autocomplete = async function (req, res) {
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ const sortPaginate = function (list, filters) {
|
|||
list.sort((a, b) => {
|
||||
const tA = getValue(a, "timestamp");
|
||||
const tB = getValue(b, "timestamp");
|
||||
return tA < tB ? 1 : tA > tB ? -1 : 0;
|
||||
return tA < tB ? 1 : tA > tB ? -1 : 0; // b - a
|
||||
});
|
||||
if (filters.sort.order) {
|
||||
list.reverse();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue