client: realtime socket and shared UI components
Add Socket.IO client wrapper (auto-reconnect, auth token), and reusable components: Layout (nav bar), Toast notifications, and Countdown timer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { io, type Socket } from 'socket.io-client';
|
||||
import { API_URL } from '../config';
|
||||
|
||||
let socket: Socket | null = null;
|
||||
|
||||
/** Connette il socket realtime (path /ws) autenticandosi con il JWT. */
|
||||
export function connectSocket(token: string): Socket {
|
||||
disconnectSocket();
|
||||
socket = io(API_URL, { path: '/ws', auth: { token } });
|
||||
return socket;
|
||||
}
|
||||
|
||||
export function getSocket(): Socket | null {
|
||||
return socket;
|
||||
}
|
||||
|
||||
export function disconnectSocket(): void {
|
||||
socket?.disconnect();
|
||||
socket = null;
|
||||
}
|
||||
Reference in New Issue
Block a user