Quick start
The smallest working chat, a fully configured example, and complete Vite and Next.js setups.
Minimum working chat
After installing and adding the CSS import and config file:
tsx
"use client"; // Next.js only - required on any file that imports chat import ChatMain from "@realtimexsco/live-chat";import { chatConfig } from "@/configs/chat.config"; export default function ChatPage() { return ( <div className="h-dvh min-h-0 overflow-hidden"> <ChatMain clientId={chatConfig.clientId} accessToken={chatConfig.accessToken} loggedUserDetails={chatConfig.loggedUserDetails} apiUrl={chatConfig.apiUrl} socketUrl={chatConfig.socketUrl} themeColor={chatConfig.themeColor} /> </div> );}Container height
A height is required. ChatMain includes a built-in viewport (chat-package-viewport):
viewportHeight="screen"- full pageviewportHeight="calc(100dvh - 4rem)"- below a fixed header- or wrap it in
h-dvh min-h-0 overflow-hiddenand keep the defaultviewportHeight="full"
Complete ChatMain example
All the common props: theme, locale, layout, customization, calls and alerts.
tsx
"use client"; import { useState } from "react";import ChatMain, { type ChatColorMode, type ChatComponents, type ChatClassNames, type ChatFeatures, type AvatarSlotProps, defaultChatLayoutConfig,} from "@realtimexsco/live-chat";import { chatConfig } from "@/configs/chat.config"; const MyAvatar = ({ src, name, size }: AvatarSlotProps) => ( <img src={src || undefined} alt={name} className={`rounded-full object-cover avatar--${size}`} style={{ width: 36, height: 36 }} />); const components: ChatComponents = { Avatar: MyAvatar, // ChatLayout: MyFullCustomUI, // Case 1 - replace the entire UI // MessageItem: MyMessageBubble, // Case 2 - a single slot}; const classNames: ChatClassNames = { sidebar: "bg-slate-950", channelHeader: "border-b-2 border-indigo-500", messageBubbleSender: "rounded-3xl shadow-md", messageBubbleReceiver: "rounded-3xl",}; const features: ChatFeatures = { showPhoneCall: true, showVideoCall: true,}; export default function ChatPage() { const [colorMode, setColorMode] = useState<ChatColorMode>("light"); const [error, setError] = useState<string | null>(null); return ( <div className="h-dvh min-h-0 overflow-hidden"> <ChatMain {...chatConfig} colorMode={colorMode} onColorModeChange={setColorMode} showColorModeToggle={false} locale="en-US" timeZone="Asia/Kolkata" hour12={false} showDateTimeSettings layout={{ ...defaultChatLayoutConfig }} components={components} classNames={classNames} features={features} error={error} onErrorDismiss={() => setError(null)} /> </div> );}React (Vite) - full setup
shell
npm create vite@latest -- my-chat-app --template react-tscd my-chat-appnpm install @realtimexsco/live-chat react react-domnpm install -D @vitejs/plugin-reactshell
src/├── main.tsx├── App.tsx├── index.css ← CSS import (see Project setup)└── configs/ └── chat.config.tssrc/main.tsx
tsx
import { createRoot } from "react-dom/client";import "./index.css";import App from "./App"; createRoot(document.getElementById("root")!).render(<App />);src/App.tsx
tsx
import ChatMain from "@realtimexsco/live-chat";import { chatConfig } from "./configs/chat.config"; export default function App() { return ( <div className="h-dvh min-h-0 overflow-hidden"> <ChatMain {...chatConfig} /> </div> );}Run npm run dev.
Next.js - full setup
shell
npm create next-app@latest -- my-chat-app --typescript --tailwind --app --src-dircd my-chat-appnpm install @realtimexsco/live-chatsrc/app/chat/page.tsx
tsx
"use client"; // Next.js only - required on any file that imports chat import ChatMain from "@realtimexsco/live-chat";import { chatConfig } from "@/configs/chat.config"; export default function ChatPage() { return ( <div className="h-dvh min-h-0 overflow-hidden"> <ChatMain clientId={chatConfig.clientId} accessToken={chatConfig.accessToken} loggedUserDetails={chatConfig.loggedUserDetails} apiUrl={chatConfig.apiUrl} socketUrl={chatConfig.socketUrl} themeColor={chatConfig.themeColor} /> </div> );}Run npm run dev and open http://localhost:3000/chat. Remember transpilePackages in next.config.ts.