speakmore-2.0/static/js/online_detection.js
Olai bc9fcda6aa Updated online detection and fixed bugs
Updated online detection and fixed bugs
2024-06-25 23:27:34 +02:00

20 lines
764 B
JavaScript

document.addEventListener('DOMContentLoaded', (event) => {
const socket = io();
// Handle user online/offline status
socket.on('user_online', function(data) {
const statusIndicator = document.querySelector(`.status-indicator[data-username="${data.username}"]`);
if (statusIndicator) {
statusIndicator.classList.remove('offline');
statusIndicator.classList.add('online');
}
});
socket.on('user_offline', function(data) {
const statusIndicator = document.querySelector(`.status-indicator[data-username="${data.username}"]`);
if (statusIndicator) {
statusIndicator.classList.remove('online');
statusIndicator.classList.add('offline');
}
});
});