feat: enhance estimated wait time display and handle token expiration in event page

This commit is contained in:
2025-09-19 19:31:18 +02:00
parent 9d1428fde0
commit ff0625ea76
2 changed files with 60 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ function broadcastUpdate(eventId, io) {
io.to(sid).emit("queue_update", {
activeCount: ev.sockets.size,
position: pos === -1 ? null : pos + 1,
estimatedWait: pos === -1 ? null : pos * TOKEN_TTL_SECONDS,
estimatedWait: pos === -1 ? null : (ev.active.size + pos) * TOKEN_TTL_SECONDS,
})
}
}
@@ -84,6 +84,34 @@ async function evaluateQueue(eventId, io) {
io.to(next).emit("granted", { token, expiresAt: expiresAt.toISOString() })
}
// Check for expired tokens in database and notify clients
if (connection) {
try {
const [expiredSessions] = await connection.execute(
'SELECT socket_id FROM active_sessions WHERE event_id = ? AND expires_at < NOW()',
[eventId]
)
for (const session of expiredSessions) {
const sid = session.socket_id
if (ev.active.has(sid)) {
ev.active.delete(sid)
io.to(sid).emit("token_expired")
}
}
// Clean up expired sessions from database
if (expiredSessions.length > 0) {
await connection.execute(
'DELETE FROM active_sessions WHERE event_id = ? AND expires_at < NOW()',
[eventId]
)
}
} catch (error) {
console.error('DB error checking expired tokens:', error)
}
}
// If too many active (rare), revoke oldest
if (ev.active.size > CONCURRENT_ACTIVE) {
const toRevoke = Array.from(ev.active).slice(CONCURRENT_ACTIVE)
@@ -135,6 +163,13 @@ export async function GET(req) {
global.io = io
// Periodikus token ellenőrzés minden 5 másodpercben
setInterval(async () => {
for (const eventId of Object.keys(events)) {
await evaluateQueue(eventId, io)
}
}, 5000)
io.on("connection", (socket) => {
console.log("Csatlakozott:", socket.id)
@@ -226,7 +261,7 @@ export async function GET(req) {
io.to(socket.id).emit("queue_update", {
activeCount: ev.sockets.size,
position: pos === -1 ? null : pos + 1,
estimatedWait: pos === -1 ? null : pos * TOKEN_TTL_SECONDS,
estimatedWait: pos === -1 ? null : (ev.active.size + pos) * TOKEN_TTL_SECONDS,
})
})