Skip to content

Commit

Permalink
fix hidden rooms getMeetings endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bitkarrot committed Nov 5, 2024
1 parent 92f4958 commit 4b5b966
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 50 deletions.
46 changes: 26 additions & 20 deletions app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ function getMeetCount(roomList) {

}}
});

return meetings;
}

Expand Down Expand Up @@ -450,30 +449,36 @@ function startServer() {
let roomsHtml = '0';
try {
let meetings = getMeetCount(roomList);
//console.log("meetings", meetings)
//console.log("meetings length", meetings.length)

if (meetings?.length) {
// Create HTML for room data matching the client-side structure
// console.log("meetings available")
roomsHtml = meetings.map(room => `
<a href="/join/${room.roomId}" target="_blank">
<div class="feature text-center button-like">
<h4 class="room-id">Room ID: ${room.roomId}</h4>
<b class="peers">Bees: ${room.peerCount}</b>
</div>
</a>
`).join('');
// console.log("roomsHtml", roomsHtml)
// Replace room data placeholder
// Filter out undefined elements
meetings = Array.isArray(meetings) ? meetings.filter(room => room !== undefined) : [];
// console.log("meetings after filter:", meetings);

if (meetings.length) {
roomsHtml = meetings
.map(room => {
if (!room || !room.roomId) return '';

return `
<a href="/join/${room.roomId}" target="_blank">
<div class="feature text-center button-like">
<h4 class="room-id">Room ID: ${room.roomId}</h4>
<b class="peers">Bees: ${room.peerCount || 0}</b>
</div>
</a>
`;
})
.filter(html => html !== '')
.join('');

// roomsHtml will contain only the HTML for the valid room '58248RedPhoto'
activeHtml = activeHtml.replace('{{activeMeetings}}', roomsHtml);
}
else {
activeHtml = activeHtml.replace('{{activeMeetings}}', '');
} else {
activeHtml = activeHtml.replace('{{activeMeetings}}', '');
}
res.send(activeHtml);
} catch (err) {
console.log("error in active meetings", err)
activeHtml = activeHtml.replace('{{activeMeetings}}', '');
res.send(activeHtml);
}
});
Expand Down Expand Up @@ -1013,6 +1018,7 @@ function startServer() {
// Get meetings
try {
const meetings = api.getMeetings(roomList);
console.log('meetinfo --> ', meetings);
meetings.forEach((room) => {
// Replace the "peers" array with its length
room.peers = room.peers.length;
Expand Down
92 changes: 62 additions & 30 deletions app/src/ServerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,69 @@ module.exports = class ServerApi {
}

getMeetings(roomList) {
// Check if roomList is empty
if (roomList.size === 0) {
return []; // Return an empty array if there are no rooms
// Check if roomList exists
if (!roomList || roomList.size === 0) {
return [];
}

try {
const meetings = Array.from(roomList.entries())
.map(([id, room]) => {
// Skip if room is locked or invalid
if (!room || room._isLocked) {
return null;
}

try {
// Ensure room.peers exists and is valid
const peers = Array.from(room.peers?.values() || [])
.map(peer => {
try {
const {
peer_info: {
peer_name = '',
peer_presenter = false,
peer_npub = '',
peer_pubkey = '',
peer_lnaddress = '',
} = {},
} = peer || {};

return {
name: peer_name,
presenter: peer_presenter,
npub: peer_npub,
pubkey: peer_pubkey,
lnaddress: peer_lnaddress,
};
} catch (peerError) {
console.error('Error processing peer:', peerError);
return null;
}
})
.filter(peer => peer !== null); // Remove any failed peer entries

return {
roomId: id,
peers: peers,
};
} catch (roomError) {
console.error('Error processing room:', roomError);
return null;
}
})
.filter(meeting => {
// Remove null entries and ensure meeting has required properties
return meeting !== null &&
meeting.roomId !== undefined &&
Array.isArray(meeting.peers);
});

return meetings;
} catch (error) {
console.error('Error in getMeetings:', error);
return [];
}
const meetings = Array.from(roomList.entries()).map(([id, room]) => {
// hide room if locked
if (!room._isLocked) {
const peers = Array.from(room.peers.values()).map(
({
peer_info: {
peer_name,
peer_presenter,
peer_npub,
peer_pubkey,
peer_lnaddress,
},
}) => ({
name: peer_name,
presenter: peer_presenter,
npub: peer_npub,
pubkey: peer_pubkey,
lnaddress: peer_lnaddress,
}),
);
return {
roomId: id,
peers: peers,
};
}
});
return meetings;
}

getMeetingURL(name) {
Expand Down

0 comments on commit 4b5b966

Please sign in to comment.