mirror of
https://github.com/temetro/temetro.git
synced 2026-07-26 20:08:14 +00:00
730e07fcfc
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>
19 lines
539 B
TypeScript
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;
|
|
}
|