feat: add Socket.IO heats_updated broadcast event
- Export getIO function from socket module - Broadcast heats_updated event when user updates their heats - Event includes userId, username, and updated heats array - Non-blocking broadcast (won't fail request if socket fails)
This commit is contained in:
@@ -5,8 +5,18 @@ const { prisma } = require('../utils/db');
|
||||
// Track active users in each event room
|
||||
const activeUsers = new Map(); // eventId -> Set of { socketId, userId, username, avatar }
|
||||
|
||||
// Global Socket.IO instance
|
||||
let io;
|
||||
|
||||
function getIO() {
|
||||
if (!io) {
|
||||
throw new Error('Socket.IO not initialized');
|
||||
}
|
||||
return io;
|
||||
}
|
||||
|
||||
function initializeSocket(httpServer) {
|
||||
const io = new Server(httpServer, {
|
||||
io = new Server(httpServer, {
|
||||
cors: {
|
||||
origin: process.env.CORS_ORIGIN || 'http://localhost:8080',
|
||||
credentials: true,
|
||||
@@ -348,4 +358,4 @@ function initializeSocket(httpServer) {
|
||||
return io;
|
||||
}
|
||||
|
||||
module.exports = { initializeSocket };
|
||||
module.exports = { initializeSocket, getIO };
|
||||
|
||||
Reference in New Issue
Block a user