Files
temetro/frontend/lib/socket.ts
T
Khalid Abdi 730e07fcfc feat: real-time staff messaging over Socket.io
Add conversations/participants/messages tables, a participant-scoped REST
API (/api/conversations) and a Socket.io server (session-authenticated
handshake; per-user + per-conversation rooms) sharing the HTTP port. New
messages broadcast live and create per-recipient notifications. Also lands
the notifications table + service + routes (used by the message flow). The
Messages page is rewritten: live threads, unread state, and a compose
dialog to start a conversation with a clinic member.

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

19 lines
539 B
TypeScript

import { io, type Socket } from "socket.io-client";
import { API_BASE_URL } from "@/lib/api-client";
// 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) {
socket = io(API_BASE_URL, {
withCredentials: true,
transports: ["websocket", "polling"],
});
}
return socket;
}