- apps/Backend/src/queue/: connection, queues, workers, processors - apps/Frontend/src/hooks/use-job-status.ts: WebSocket job progress hook - apps/Frontend/src/lib/socket.ts: shared Socket.IO singleton Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
636 B
TypeScript
25 lines
636 B
TypeScript
/**
|
|
* Shared Socket.IO client singleton.
|
|
*
|
|
* Import `socket` anywhere in the frontend to use the shared connection.
|
|
* The socket connects lazily — the first import triggers the connection.
|
|
*/
|
|
import { io, Socket } from "socket.io-client";
|
|
|
|
const SOCKET_URL =
|
|
import.meta.env.VITE_API_BASE_URL_BACKEND ||
|
|
(typeof window !== "undefined" ? window.location.origin : "");
|
|
|
|
export const socket: Socket = io(SOCKET_URL, {
|
|
withCredentials: true,
|
|
autoConnect: true,
|
|
});
|
|
|
|
socket.on("connect", () => {
|
|
console.log("[socket] connected:", socket.id);
|
|
});
|
|
|
|
socket.on("disconnect", () => {
|
|
console.log("[socket] disconnected");
|
|
});
|