add user count and limit frontend
This commit is contained in:
parent
7fe2bfa95a
commit
d4ee12e33a
@ -51,6 +51,7 @@ const CONFIG = Fz({
|
||||
}
|
||||
},
|
||||
APP: {
|
||||
CONNECTED_USER_LIMIT: 10,
|
||||
SAVE_RATE_THROTTLE: 1000,
|
||||
SYSTEM_MSG_DEFAULT_TIMEOUT: 5000,
|
||||
FILE_UPLOAD_SIZE_LIMIT: 128 * (1024 * 1024),
|
||||
@ -260,7 +261,23 @@ class AppState {
|
||||
}
|
||||
const state = new AppState();
|
||||
// ==================== UTILITY FUNCTIONS ====================
|
||||
// noinspection HtmlUnknownTarget
|
||||
class Utils {
|
||||
static sleep(ms) {
|
||||
setTimeout(() => {}, ms);
|
||||
}
|
||||
static async getUserCount() {
|
||||
try {
|
||||
const response = await fetch('/user-count', {
|
||||
method: 'GET',
|
||||
});
|
||||
const data = await response.json();
|
||||
return { userCount: data.userCount };
|
||||
} catch (error) {
|
||||
console.error('Error checking user count:', error);
|
||||
return { userCount: 0 }; // Fallback to allowing attempt
|
||||
}
|
||||
}
|
||||
static playSound(filepath, volume) {
|
||||
const audio = new Audio(filepath);
|
||||
const defaultVolume = 0.5;
|
||||
@ -286,7 +303,7 @@ class Utils {
|
||||
}
|
||||
static processMediaEmbeds(text) {
|
||||
// Images (including GIFs)
|
||||
text = text.replace(/(https?:\/\/\S+\.(?:jpg|svg|jpeg|png|gif|webp|svg|bmp|tiff|ico|avif|jfif)(?:\?\S*)?)/gi,
|
||||
text = text.replace(/(https?:\/\/\S+\.(?:jpg|jpeg|png|gif|webp|svg|bmp|tiff|ico|avif|jfif)(?:\?\S*)?)/gi,
|
||||
'<img src="$1" alt="Image" class="embedded-image" loading="lazy">');
|
||||
// Videos
|
||||
text = text.replace(/(https?:\/\/\S+\.(?:mp4|webm|ogg|avi|mov|wmv|flv|mkv|m4v|3gp)(?:\?\S*)?)/gi,
|
||||
@ -412,6 +429,9 @@ class UIManager {
|
||||
files.forEach((file, index) => {
|
||||
if (file.size <= CONFIG.APP.FILE_UPLOAD_SIZE_LIMIT) {
|
||||
formData.append(`file_${index}`, file);
|
||||
} else {
|
||||
console.log(`File: ${file} is too large to upload`);
|
||||
alert(`File: ${file} is too large to upload`);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1895,6 +1915,17 @@ class ModalManager {
|
||||
// ==================== VOICE CHAT MANAGER ====================
|
||||
class VoiceChatManager {
|
||||
static async joinVoiceChat() {
|
||||
|
||||
const userCountData = await Utils.getUserCount();
|
||||
const userCount = userCountData.userCount;
|
||||
console.log("Users connected:", userCount)
|
||||
const userLimit = CONFIG.APP.CONNECTED_USER_LIMIT;
|
||||
|
||||
if (userCount >= userLimit) {
|
||||
alert(`The server has reached maximum capacity ${userLimit}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const usernameInput = $id('username-input');
|
||||
const username = usernameInput.value.trim();
|
||||
state.intentionalDisconnect = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user