Package Reference
Socket Events
Overview
The bundled Socket.IO client connects to socketUrl at the /connection namespace after ChatMain completes client-user login. Incoming events update the Zustand store; components that select from useChatStore re-render automatically.
In typical integrations you do not register socket listeners yourself. Use store actions (for example emitDmSend) and let the package reconcile optimistic UI with server acknowledgments.
Connection lifecycle
ChatMainperforms client-user login and receives a JWT used for subsequent API and socket auth.- The socket client connects to
socketUrl(orapiUrlwith/api/v1stripped) at the/connectionnamespace. onSocketConnectedfires once the handshake succeeds.onSocketErrorfires if the connection cannot be established or drops unexpectedly.ChatSocketStatus(a replaceable component slot) reflects the live connection state in the UI.
Message send flow (optimistic UI)
- The composer calls a store send action (for example
emitDmSend). - The message is inserted into the store immediately and rendered — this is the optimistic step.
- The socket emits the send event to the backend.
- On server acknowledgment, the optimistic message reconciles with the persisted message (id, timestamps, status).
- Read receipts (sent / delivered / read) update status as further socket events arrive.
Event categories
Exact event names are owned by the RealtimeX backend and may evolve. Treat the categories below as the mental model for what the client listens for and emits through the store layer.
| Category | What it covers | Typical UI effect |
|---|---|---|
| Connection | Connect, disconnect, reconnect, auth handshake | ChatSocketStatus, alert banners |
| Conversation | New DM/group, participant changes, group info updates | Channel list refresh, header title/avatar updates |
| Message | Send, edit, delete, pin, star, reactions, attachments | Message list inserts/updates, optimistic reconciliation |
| Receipts | Delivered / read acknowledgments | MessageStatus ticks |
| Presence / typing | Typing start/stop, online indicators where enabled | Typing indicator under the channel header |
For REST endpoint coverage that complements these realtime flows, see API Integration and the full API documentation.
Accessing socket state and actions directly
Prefer store selectors and actions. Reach for low-level socket helpers only when diagnosing connection issues.
import {
socketService,
getSocketConfig,
useChatStore,
} from "@realtimexsco/live-chat";
// Store actions that emit socket events
const emitDmSend = useChatStore((s) => s.emitDmSend);
// Low-level access — advanced diagnostics only
const config = getSocketConfig();