diff --git a/src/static/rooms.js b/src/static/rooms.js index 13546db..a1a4b4a 100644 --- a/src/static/rooms.js +++ b/src/static/rooms.js @@ -25,7 +25,7 @@ function closePublicRoomsBrowser() { // Subscribe to live public rooms updates function subscribeToPublicRooms() { - if (typeof socket !== 'undefined' && socket.connected && !isSubscribedToRooms) { + if (typeof socket !== 'undefined' && socket !== null && socket.connected && !isSubscribedToRooms) { socket.emit('subscribe_public_rooms'); isSubscribedToRooms = true; console.log('Subscribed to public rooms updates'); @@ -34,7 +34,7 @@ function subscribeToPublicRooms() { // Unsubscribe from public rooms updates function unsubscribeFromPublicRooms() { - if (typeof socket !== 'undefined' && socket.connected && isSubscribedToRooms) { + if (typeof socket !== 'undefined' && socket !== null && socket.connected && isSubscribedToRooms) { socket.emit('unsubscribe_public_rooms'); isSubscribedToRooms = false; console.log('Unsubscribed from public rooms updates'); @@ -49,7 +49,7 @@ function loadPublicRoomsWebSocket() { currentSortBy = document.getElementById('roomsSortSelect').value; currentMinUsers = document.getElementById('minUsersFilter').value || 0; - if (typeof socket !== 'undefined' && socket.connected) { + if (typeof socket !== 'undefined' && socket !== null && socket.connected) { socket.emit('request_public_rooms', { sort: currentSortBy, min_users: currentMinUsers, @@ -106,29 +106,39 @@ function refreshPublicRooms() { // Update stats display function updateStatsDisplay(stats) { const statsElement = document.getElementById('roomsStats'); - statsElement.textContent = `${stats.public_rooms} public rooms • ${stats.total_users} users online`; + if (statsElement) { + statsElement.textContent = `${stats.public_rooms} public rooms • ${stats.total_users} users online`; + } } // Show loading state function showLoadingState() { - document.getElementById('roomsLoading').style.display = 'flex'; - document.getElementById('roomsList').style.display = 'none'; - document.getElementById('roomsEmpty').style.display = 'none'; + const loadingElement = document.getElementById('roomsLoading'); + const listElement = document.getElementById('roomsList'); + const emptyElement = document.getElementById('roomsEmpty'); + + if (loadingElement) loadingElement.style.display = 'flex'; + if (listElement) listElement.style.display = 'none'; + if (emptyElement) emptyElement.style.display = 'none'; } // Show error state function showErrorState() { - document.getElementById('roomsLoading').style.display = 'none'; - document.getElementById('roomsList').style.display = 'none'; - document.getElementById('roomsEmpty').style.display = 'flex'; - + const loadingElement = document.getElementById('roomsLoading'); + const listElement = document.getElementById('roomsList'); const emptyElement = document.getElementById('roomsEmpty'); - emptyElement.innerHTML = ` -
Unable to connect to the server. Please try again.
- - `; + + if (loadingElement) loadingElement.style.display = 'none'; + if (listElement) listElement.style.display = 'none'; + if (emptyElement) { + emptyElement.style.display = 'flex'; + emptyElement.innerHTML = ` +Unable to connect to the server. Please try again.
+ + `; + } } // Display rooms @@ -137,18 +147,19 @@ function displayRooms() { const roomsLoading = document.getElementById('roomsLoading'); const roomsEmpty = document.getElementById('roomsEmpty'); - roomsLoading.style.display = 'none'; + if (roomsLoading) roomsLoading.style.display = 'none'; if (publicRoomsData.length === 0) { - roomsEmpty.style.display = 'flex'; - roomsList.style.display = 'none'; + if (roomsEmpty) roomsEmpty.style.display = 'flex'; + if (roomsList) roomsList.style.display = 'none'; return; } - roomsEmpty.style.display = 'none'; - roomsList.style.display = 'block'; - - roomsList.innerHTML = publicRoomsData.map(room => createRoomCard(room)).join(''); + if (roomsEmpty) roomsEmpty.style.display = 'none'; + if (roomsList) { + roomsList.style.display = 'block'; + roomsList.innerHTML = publicRoomsData.map(room => createRoomCard(room)).join(''); + } } // Create room card HTML @@ -221,10 +232,16 @@ function joinPublicRoom(roomId) { closePublicRoomsBrowser(); // Fill in the room input with the selected room - document.getElementById('roomInput').value = roomId; + const roomInput = document.getElementById('roomInput'); + if (roomInput) { + roomInput.value = roomId; + } // Clear password field since these are public rooms - document.getElementById('roomPasswordInput').value = ''; + const roomPasswordInput = document.getElementById('roomPasswordInput'); + if (roomPasswordInput) { + roomPasswordInput.value = ''; + } // Trigger your existing join room functionality const joinButton = document.getElementById('joinRoomBtn'); @@ -233,29 +250,9 @@ function joinPublicRoom(roomId) { } } -// Event listeners for controls -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('roomsSortSelect').addEventListener('change', refreshPublicRooms); - document.getElementById('minUsersFilter').addEventListener('change', refreshPublicRooms); -}); - -// Close on escape key -document.addEventListener('keydown', function(e) { - if (e.key === 'Escape' && document.getElementById('publicRoomsBrowser').style.display === 'block') { - closePublicRoomsBrowser(); - } -}); - -// Close on backdrop click -document.getElementById('publicRoomsBrowser').addEventListener('click', function(e) { - if (e.target === this) { - closePublicRoomsBrowser(); - } -}); - // WebSocket event handlers for real-time updates function setupPublicRoomsWebSocketHandlers() { - if (typeof socket === 'undefined') { + if (typeof socket === 'undefined' || socket === null) { console.log('Socket not available, using HTTP fallback'); return; } @@ -277,7 +274,8 @@ function setupPublicRoomsWebSocketHandlers() { console.log('Received live public rooms update:', data); // Only update if the browser is currently open and we're subscribed - if (document.getElementById('publicRoomsBrowser').style.display === 'block' && isSubscribedToRooms) { + const browserElement = document.getElementById('publicRoomsBrowser'); + if (browserElement && browserElement.style.display === 'block' && isSubscribedToRooms) { publicRoomsData = data.rooms || []; if (data.stats) { @@ -299,21 +297,55 @@ function setupPublicRoomsWebSocketHandlers() { // Auto-setup WebSocket handlers when page loads function waitForSocketAndSetupHandlers() { - if (typeof socket !== 'undefined' && socket.connected) { + if (typeof socket !== 'undefined' && socket !== null && socket.connected) { setupPublicRoomsWebSocketHandlers(); } else { setTimeout(waitForSocketAndSetupHandlers, 100); } } -// Start the setup process +// Event listeners for controls document.addEventListener('DOMContentLoaded', function() { + // Add null checks for DOM elements + const sortSelect = document.getElementById('roomsSortSelect'); + const minUsersFilter = document.getElementById('minUsersFilter'); + + if (sortSelect) { + sortSelect.addEventListener('change', refreshPublicRooms); + } + + if (minUsersFilter) { + minUsersFilter.addEventListener('change', refreshPublicRooms); + } + + // Start the WebSocket setup process waitForSocketAndSetupHandlers(); // Auto-refresh every 30 seconds when browser is open setInterval(function() { - if (document.getElementById('publicRoomsBrowser').style.display === 'block') { + const browserElement = document.getElementById('publicRoomsBrowser'); + if (browserElement && browserElement.style.display === 'block') { refreshPublicRooms(); } }, 30000); }); + +// Close on escape key +document.addEventListener('keydown', function(e) { + const browserElement = document.getElementById('publicRoomsBrowser'); + if (e.key === 'Escape' && browserElement && browserElement.style.display === 'block') { + closePublicRoomsBrowser(); + } +}); + +// Close on backdrop click +document.addEventListener('DOMContentLoaded', function() { + const browserElement = document.getElementById('publicRoomsBrowser'); + if (browserElement) { + browserElement.addEventListener('click', function(e) { + if (e.target === this) { + closePublicRoomsBrowser(); + } + }); + } +}); \ No newline at end of file diff --git a/src/templates/chat.html b/src/templates/chat.html index 1188b7e..6a83da1 100644 --- a/src/templates/chat.html +++ b/src/templates/chat.html @@ -9,10 +9,6 @@ - - - -- If you are coming from the "ngrok" link. Then you probably saw the warning page. That this Page may be maillicious. + If you are coming from the "ngrok" link. Then you probably saw the warning page. That this Page may be malicious. We are focused on privacy and encrypted messaging. We do not serve any harmful code. We are - OSS + OSS
For a better experience, consider downloading our desktop application. It offers enhanced performance - trough native Encryption (instead of Browser-Reliant Encryption). Click the button below to download the latest version. + through native Encryption (instead of Browser-Reliant Encryption). Click the button below to download the latest version.
@@ -118,6 +113,7 @@