diff --git a/app/src/Server.js b/app/src/Server.js index 34fd76f6..4f19ba51 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -345,7 +345,6 @@ function getMeetCount(roomList) { }} }); - return meetings; } @@ -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 => ` - -
-

Room ID: ${room.roomId}

- Bees: ${room.peerCount} -
-
- `).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 ` + +
+

Room ID: ${room.roomId}

+ Bees: ${room.peerCount || 0} +
+
+ `; + }) + .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); } }); @@ -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; diff --git a/app/src/ServerApi.js b/app/src/ServerApi.js index 539d98ee..bd4166fd 100644 --- a/app/src/ServerApi.js +++ b/app/src/ServerApi.js @@ -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) {