RealTimeX
Start For Free

RealTimeX

Package Documentation

IntroductionPrerequisitesInstallationProject setupQuick start
Package structureConfigurationComponentsHooksAPI integrationSocket events
OverviewReplace entire UIReplace componentsStyle with classNamesThemes & localePhone & video callingIn-call control barFeatures
TroubleshootingFAQVersion historyBest practicesSupport & contact

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.

Note

queryParams / queryParamsByApi from API Integration apply to REST requests only — they do not modify the socket connection query string.

Connection lifecycle

  1. ChatMain performs client-user login and receives a JWT used for subsequent API and socket auth.
  2. The socket client connects to socketUrl (or apiUrl with /api/v1 stripped) at the /connection namespace.
  3. onSocketConnected fires once the handshake succeeds.
  4. onSocketError fires if the connection cannot be established or drops unexpectedly.
  5. ChatSocketStatus (a replaceable component slot) reflects the live connection state in the UI.

Message send flow (optimistic UI)

  1. The composer calls a store send action (for example emitDmSend).
  2. The message is inserted into the store immediately and rendered — this is the optimistic step.
  3. The socket emits the send event to the backend.
  4. On server acknowledgment, the optimistic message reconciles with the persisted message (id, timestamps, status).
  5. 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.

CategoryWhat it coversTypical UI effect
ConnectionConnect, disconnect, reconnect, auth handshakeChatSocketStatus, alert banners
ConversationNew DM/group, participant changes, group info updatesChannel list refresh, header title/avatar updates
MessageSend, edit, delete, pin, star, reactions, attachmentsMessage list inserts/updates, optimistic reconciliation
ReceiptsDelivered / read acknowledgmentsMessageStatus ticks
Presence / typingTyping start/stop, online indicators where enabledTyping 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.

tsx
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();

Warning

Emitting raw socket events outside the store can desync optimistic UI. Prefer documented store actions whenever possible.
PreviousAPI integrationNextOverview

On this page

OverviewConnection lifecycleMessage send flow (optimistic UI)Event categoriesAccessing socket state and actions directly