Fix jwt-token
This commit is contained in:
@@ -1,33 +1,34 @@
|
|||||||
function initializeSocketHandlers(io) {
|
function initializeSocketHandlers(io) {
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log(`Client connected: ${socket.id}`);
|
const clientIP = socket.handshake.address || socket.request.connection.remoteAddress || 'unknown';
|
||||||
|
console.log(`Client connected: ${socket.id} from IP: ${clientIP}`);
|
||||||
|
|
||||||
// Join device-specific rooms for targeted updates
|
// Join device-specific rooms for targeted updates
|
||||||
socket.on('join_device_room', (deviceId) => {
|
socket.on('join_device_room', (deviceId) => {
|
||||||
socket.join(`device_${deviceId}`);
|
socket.join(`device_${deviceId}`);
|
||||||
console.log(`Client ${socket.id} joined device room: device_${deviceId}`);
|
console.log(`Client ${socket.id} (IP: ${clientIP}) joined device room: device_${deviceId}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Join dashboard room for general updates
|
// Join dashboard room for general updates
|
||||||
socket.on('join_dashboard', () => {
|
socket.on('join_dashboard', () => {
|
||||||
socket.join('dashboard');
|
socket.join('dashboard');
|
||||||
console.log(`Client ${socket.id} joined dashboard room`);
|
console.log(`Client ${socket.id} (IP: ${clientIP}) joined dashboard room`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Leave rooms
|
// Leave rooms
|
||||||
socket.on('leave_device_room', (deviceId) => {
|
socket.on('leave_device_room', (deviceId) => {
|
||||||
socket.leave(`device_${deviceId}`);
|
socket.leave(`device_${deviceId}`);
|
||||||
console.log(`Client ${socket.id} left device room: device_${deviceId}`);
|
console.log(`Client ${socket.id} (IP: ${clientIP}) left device room: device_${deviceId}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('leave_dashboard', () => {
|
socket.on('leave_dashboard', () => {
|
||||||
socket.leave('dashboard');
|
socket.leave('dashboard');
|
||||||
console.log(`Client ${socket.id} left dashboard room`);
|
console.log(`Client ${socket.id} (IP: ${clientIP}) left dashboard room`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle client disconnect
|
// Handle client disconnect
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log(`Client disconnected: ${socket.id}`);
|
console.log(`Client disconnected: ${socket.id} from IP: ${clientIP}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send current status on connect
|
// Send current status on connect
|
||||||
|
|||||||
Reference in New Issue
Block a user