add upload alert and documentation

This commit is contained in:
Radon 2025-09-04 19:41:21 -05:00
parent 298265763f
commit f605bcea5a

View File

@ -1,3 +1,30 @@
/*
RadChat Frontend (static/app.js)
Overview:
- Single-page application handling UI, signaling (WebSocket), and media (WebRTC).
- Uses a central CONFIG object (frozen) to define defaults for output, media, and connection.
- Manages:
* WebSocket connection lifecycle (reconnect, pings, presence)
* WebRTC peer connections (offers/answers/ICE, track management)
* UI state: users list, chat pane, emoji picker, file uploads, audio controls
* Permissions and device selection (planned for settings UI)
Key Endpoints (see backend):
- /ws: signaling channel (JSON messages matching message.go)
- /files: POST uploads; /files/{id}: GET downloads
- /check-username and /user-count auxiliary endpoints
Configuration:
- Adjust CONFIG.CONN.RTC_CONFIGURATION.iceServers to set STUN/TURN.
- For relay-only networks, consider setting iceTransportPolicy to "relay".
Notes:
- Keep JSON envelope fields in sync with message.go to avoid wire format drift.
- Avoid heavy DOM queries in hot paths; use cached selectors where possible.
- Large file; consider future modularization by feature (chat, rtc, ui, files).
*/
// ==================== CONFIGURATION ==================== // ==================== CONFIGURATION ====================
// noinspection HtmlUnknownTarget // noinspection HtmlUnknownTarget
function Fz(obj) { function Fz(obj) {
@ -15,7 +42,7 @@ const CONFIG = Fz({
NOISE_SUPPRESSION: true, NOISE_SUPPRESSION: true,
LATENCY: 0.01, LATENCY: 0.01,
LATENCY_HINT: 'interactive', LATENCY_HINT: 'interactive',
SAMPLE_RATE: 64000, SAMPLE_RATE: 96000,
DEVICE_ID: 'default', DEVICE_ID: 'default',
SPEAKING_THRESHOLD: 10, SPEAKING_THRESHOLD: 10,
SPEAKING_TIMEOUT: 500, SPEAKING_TIMEOUT: 500,
@ -54,7 +81,7 @@ const CONFIG = Fz({
CONNECTED_USER_LIMIT: 10, CONNECTED_USER_LIMIT: 10,
SAVE_RATE_THROTTLE: 1000, SAVE_RATE_THROTTLE: 1000,
SYSTEM_MSG_DEFAULT_TIMEOUT: 5000, SYSTEM_MSG_DEFAULT_TIMEOUT: 5000,
FILE_UPLOAD_SIZE_LIMIT: 128 * (1024 * 1024), FILE_UPLOAD_SIZE_LIMIT: 256 * (1024 * 1024),
} }
}); });
@ -441,17 +468,24 @@ class UIManager {
formData.append('client_id', state.currentId) formData.append('client_id', state.currentId)
try { try {
// Uploading files system message
const alertMessage = ChatManager.addChatAlert('Uploading file(s)...', 'upload');
const response = await fetch('/files', { const response = await fetch('/files', {
method: 'POST', method: 'POST',
body: formData body: formData
}); });
if (response.ok) { if (response.ok) {
alertMessage.remove();
const data = await response.json(); const data = await response.json();
console.log('Upload successful:', data); console.log('Upload successful:', data);
} else { } else {
alertMessage.remove();
ChatManager.addChatAlert(`Upload failed: ${error}`, 'upload_failure', 3000);
console.error('Upload failed:', response.statusText); console.error('Upload failed:', response.statusText);
} }
} catch (error) { } catch (error) {
ChatManager.addChatAlert(`Upload failed: ${error}`, 'upload_failure', 3000);
console.error('Upload error:', error); console.error('Upload error:', error);
} }
}, { once: true }); }, { once: true });
@ -1634,7 +1668,7 @@ class ChatManager {
UIManager.scrollChatToBottom(); UIManager.scrollChatToBottom();
console.log('Added chat message from:', data.username, 'message:', message); console.log('Added chat message from:', data.username, 'message:', message);
} }
static addChatAlert(message, type, timeout) { static addChatAlert(message, type, timeout) {
const chatMessages = $id('chat-messages'); const chatMessages = $id('chat-messages');
if (!chatMessages) return; if (!chatMessages) return;
const alertEl = document.createElement('div'); const alertEl = document.createElement('div');
@ -1659,6 +1693,7 @@ class ChatManager {
chatMessages.appendChild(alertEl); chatMessages.appendChild(alertEl);
UIManager.scrollChatToBottom(); UIManager.scrollChatToBottom();
console.log('📢 Added chat alert:', message); console.log('📢 Added chat alert:', message);
return alertEl;
} }
static deleteMessage(messageId) { static deleteMessage(messageId) {