Files
temetro/frontend/lib/socket.ts
T
Khalid Abdi 403e0e38e9 frontend: runtime backend URL (LAN), voice dictation, version + update UI
Resolve the backend URL from the current host at runtime (lib/backend-url.ts)
so one build works on localhost and any clinic LAN IP without a rebuild; used
by the API client, auth client, and socket. Wire the AI-chat mic to the Web
Speech API with graceful fallback. Add a Settings "About & updates" panel
(current/latest version, update command, shareable network address) and an
optional dismissible update banner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 21:34:30 +03:00

20 lines
630 B
TypeScript

import { io, type Socket } from "socket.io-client";
import { resolveBackendUrl } from "@/lib/backend-url";
// A single shared Socket.io connection to the backend, authenticated by the
// Better Auth session cookie (withCredentials). Used by messaging and
// notifications. Created lazily on first use in the browser.
let socket: Socket | null = null;
export function getSocket(): Socket {
if (!socket) {
// Resolved lazily in the browser so it targets the host actually in use.
socket = io(resolveBackendUrl(), {
withCredentials: true,
transports: ["websocket", "polling"],
});
}
return socket;
}