Package Reference
Package Structure
Recommended project folder structure
For production integrations — especially inside admin templates such as Elstar or Metronic — RealtimeX recommends separating credentials, UI overrides, and layout toggles into their own config files. That keeps secrets out of layout code and makes customization reviewable in isolation.
src/
|-- configs/
| |-- chat.config.ts # credentials only
| |-- chat.customization.config.ts # components + classNames
| |-- chat.layout.config.ts # layout section toggles
|-- components/chat/custom/
| |-- ElstarMembersDrawer.tsx # custom drawer example
| |-- ElstarChatAvatar.tsx
| |-- index.ts
|-- views/Chat.tsx # wires up ChatMainWiring it together
Import the three config modules into your chat page and spread them onto ChatMain. Layout and customization stay optional — start with credentials alone, then layer overrides as your design requires.
import ChatMain from "@realtimexsco/live-chat";
import { chatConfig } from "@/configs/chat.config";
import { chatCustomization } from "@/configs/chat.customization.config";
import { chatLayoutConfig } from "@/configs/chat.layout.config";
export default function ChatPage() {
return (
<ChatMain
{...chatConfig}
layout={chatLayoutConfig}
components={chatCustomization.components}
classNames={chatCustomization.classNames}
features={chatCustomization.features}
viewportHeight="calc(100dvh - 4rem)"
/>
);
}Components exported by the package
High-level exports you will import most often. The full slot map — including drawers, message parts, and call buttons — is documented in Components.
| Export | Role |
|---|---|
| ChatMain | Default entry — credentials, providers, and UI in one component |
| Chat / ChatLayout / DefaultChatLayout | Composable shell pieces for advanced layouts |
| Channel / ChannelList / ChannelHeader | Conversation sidebar and active-channel chrome |
| MessageList / MessageInput / MessageItem | Thread rendering and composer |
| ChatThemeProvider / ChatLocaleProvider / ChatAlertsProvider / ChatCustomizationProvider | Context providers used internally; rarely needed directly |
| ChatAvatar / ChannelListItem / HeaderCallActions / packageDefaultComponents | Building blocks and the default component map for overrides |
Hooks exported by the package
Prefer these hooks inside custom slots and layouts. Full signatures and examples are on the Hooks page.
useChatStore— Zustand store for messages, conversations, and socket actionsuseChatController— state and handlers for building a custom ChatLayoutuseChatContext— low-level chat provider contextuseChatCustomization/useChatCustomizationOptional— current components and classNamesuseChatFeatures/useChatFeaturesOptional— phone/video flags and callbacksuseChatTheme— themeColor, isDark, and CSS variablesuseChatLocale— date/time formatting helpers using the active localeuseChatAlerts— error/info alert state
Utilities exported by the package
Helpers for layout/customization merges, imperative credential setup, and query-param configuration. See Configuration and API Integration for how they map to ChatMain props.
import {
mergeChatLayoutConfig,
defaultChatLayoutConfig,
} from "@realtimexsco/live-chat";
export const chatLayoutConfig = mergeChatLayoutConfig({
...defaultChatLayoutConfig,
sidebar: true,
input: true,
});mergeChatLayoutConfig,defaultChatLayoutConfig— layout section helpersmergeChatCustomization,defaultChatClassNames,defaultChatComponents,defaultChatFeaturessetChatClientId,setChatAccessToken,setChatBaseURL,setChatSocketUrl— imperative API setupsetChatQueryParams/getChatQueryParams,setChatQueryParamApis/getChatQueryParamApis,setChatQueryParamsByApi/getChatQueryParamsByApiCHAT_API_KEYS,CHAT_GET_API_KEYS,resolveChatApiKeysocketService,getSocketConfigshowNotification,downloadFile