[mirotalk] - #331: fix peer count inflation when room password is set

This commit is contained in:
Miroslav Pejic
2026-03-19 09:09:23 +01:00
parent 672b32f6d0
commit 5f883a51f1
8 changed files with 26 additions and 28 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# ====================================================
# MiroTalk P2P v.1.7.55 - Environment Configuration
# MiroTalk P2P v.1.7.56 - Environment Configuration
# ====================================================
# App environment
+4 -2
View File
@@ -21,12 +21,13 @@ module.exports = class ServerApi {
}
getStats(peers, timestamp = new Date().toISOString()) {
const metaKeys = new Set(['lock', 'password']);
let totalRooms = 0;
let totalPeers = 0;
for (const room_id in peers) {
totalRooms++; // Increment room count
totalPeers += Object.keys(peers[room_id]).length; // Count the number of peers in the room
totalPeers += Object.keys(peers[room_id]).filter((k) => !metaKeys.has(k)).length;
}
return {
@@ -37,9 +38,10 @@ module.exports = class ServerApi {
}
getActiveRooms(roomList) {
const metaKeys = new Set(['lock', 'password']);
return Object.entries(roomList).map(([roomId, room]) => ({
id: roomId,
peers: room && typeof room === 'object' ? Object.keys(room).length : 0,
peers: room && typeof room === 'object' ? Object.keys(room).filter((k) => !metaKeys.has(k)).length : 0,
join: this.getProtocol() + this._host + '/' + roomId,
}));
}
+1 -1
View File
@@ -2,7 +2,7 @@
/**
* ==============================================
* MiroTalk P2P v.1.7.55 - Configuration File
* MiroTalk P2P v.1.7.56 - Configuration File
* ==============================================
*
* This file is the central configuration source.
+14 -18
View File
@@ -45,7 +45,7 @@ dependencies: {
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.7.55
* @version 1.7.56
*
*/
@@ -379,6 +379,13 @@ const sockets = {}; // collect sockets
const peers = {}; // collect peers info grp by channels
const presenters = {}; // collect presenters grp by channels
const roomMetaKeys = new Set(['lock', 'password']);
function getPeerCount(roomId) {
if (!peers[roomId]) return 0;
return Object.keys(peers[roomId]).filter((k) => !roomMetaKeys.has(k)).length;
}
app.set('trust proxy', trustProxy); // Enables trust for proxy headers (e.g., X-Forwarded-For) based on the trustProxy setting
app.use(helmet.noSniff()); // Enable content type sniffing prevention
@@ -1442,7 +1449,7 @@ io.sockets.on('connect', async (socket) => {
channels[channel][socket.id] = socket;
socket.channels[channel] = channel;
const peerCounts = Object.keys(peers[channel]).length;
const peerCounts = getPeerCount(channel);
// Send some server info to joined peer
await sendToPeer(socket.id, sockets, 'serverInfo', {
@@ -1996,21 +2003,10 @@ io.sockets.on('connect', async (socket) => {
delete channels[channel][socket.id];
delete peers[channel][socket.id]; // delete peer data from the room
switch (Object.keys(peers[channel]).length) {
case 0: // last peer disconnected from the room without room lock & password set
delete peers[channel];
delete presenters[channel];
delete channels[channel]; // Clean up channels to prevent memory leak
break;
case 2: // last peer disconnected from the room having room lock & password set
if (peers[channel]['lock'] && peers[channel]['password']) {
delete peers[channel]; // clean lock and password value from the room
delete presenters[channel]; // clean the presenter from the channel
delete channels[channel]; // Clean up channels to prevent memory leak
}
break;
default:
break;
if (getPeerCount(channel) === 0) {
delete peers[channel];
delete presenters[channel];
delete channels[channel]; // Clean up channels to prevent memory leak
}
} catch (err) {
log.error('Remove Peer', toJson(err));
@@ -2245,7 +2241,7 @@ function getActiveRooms() {
for (const roomId in peers) {
if (peers.hasOwnProperty(roomId)) {
// Get the count of peers in the current room
const peersCount = Object.keys(peers[roomId]).length;
const peersCount = getPeerCount(roomId);
roomPeersArray.push({
roomId: roomId,
peersCount: peersCount,
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "mirotalk",
"version": "1.7.55",
"version": "1.7.56",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mirotalk",
"version": "1.7.55",
"version": "1.7.56",
"license": "AGPL-3.0",
"dependencies": {
"@mattermost/client": "11.4.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.7.55",
"version": "1.7.56",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
+1 -1
View File
@@ -107,7 +107,7 @@ let brand = {
},
about: {
imageUrl: '../images/mirotalk-logo.gif',
title: 'WebRTC P2P v1.7.55',
title: 'WebRTC P2P v1.7.56',
html: `
<button
id="support-button"
+2 -2
View File
@@ -15,7 +15,7 @@
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.7.55
* @version 1.7.56
*
*/
@@ -13738,7 +13738,7 @@ function showAbout() {
Swal.fire({
background: swBg,
position: 'center',
title: brand.about?.title && brand.about.title.trim() !== '' ? brand.about.title : 'WebRTC P2P v1.7.55',
title: brand.about?.title && brand.about.title.trim() !== '' ? brand.about.title : 'WebRTC P2P v1.7.56',
imageUrl: brand.about?.imageUrl && brand.about.imageUrl.trim() !== '' ? brand.about.imageUrl : images.about,
customClass: { image: 'img-about' },
html: `