RealTimeX
Sign inStart for free
RealTimeXWeb Package
IntroductionPrerequisitesInstallationProject setupQuick start
Package structureConfigurationComponentsHooksAPI integrationSocket events
OverviewReplace entire UIReplace componentsStyle with classNamesThemes & localePhone & video callingIn-call control barFeatures
Unread badgeRich-text messagesPins, stars & datesMessage threadsMentionsCanvas & draftsNotificationsAdmin permissionsServer refusalsSession & token refresh
Host app integrationTroubleshootingFAQVersion historyBest practicesSupport & contact
Web packageGetting started

Project setup

One CSS import, a couple of bundler settings and a config file.

CSS setup

Add these lines to your global CSS file (for example src/index.css or app/globals.css) - once:

css
1@tailwind base;2@tailwind components;3@tailwind utilities;4@import "@realtimexsco/live-chat/styles.css";

That's everything chat needs. styles.cssis pre-compiled, so there's no @source, no @theme and no chat-specific Tailwind config. The @tailwindlines are only for your own app - leave them out if you don't use Tailwind. Set the brand color with the themeColor prop.

Warning

Import it once, globally - not inside a CSS module scoped to one component. Chat modals portal to document.body and need the global styles. See Host app integration for import order and z-index.

Vite - vite.config.ts

Only the chat-related parts - merge them into your existing config:

typescript
1import path from "path";2import { defineConfig } from "vite";3import react from "@vitejs/plugin-react";4 5export default defineConfig({6  plugins: [react()],7  resolve: {8    alias: { "@": path.join(__dirname, "src") },9    // Keep a single copy so the chat shares your app's React, store and socket.10    dedupe: ["react", "react-dom", "@realtimexsco/live-chat"],11  },12  optimizeDeps: {13    exclude: ["@realtimexsco/live-chat"],14    // live-chat stays excluded, but Vite must still pre-bundle its nested15    // deps (CJS interop, needed under pnpm). Nested `>` paths mean you do16    // NOT add these to your own package.json.17    include: [18      "@realtimexsco/live-chat > socket.io-client",19      "@realtimexsco/live-chat > zustand",20      "@realtimexsco/live-chat > @videosdk.live/react-sdk",21    ],22  },23  server: {24    proxy: {25      // Optional local-dev proxy for the chat REST API (avoids CORS).26      // Point `apiUrl` at "/chat-api" when running locally.27      "/chat-api": {28        target: "https://realtimex.softwareco.com",29        changeOrigin: true,30        secure: true,31        rewrite: (p) => p.replace(/^\/chat-api/, "/api/v1"),32      },33    },34  },35});

Next.js - next.config.ts

typescript
1import type { NextConfig } from "next";2 3const nextConfig: NextConfig = {4  transpilePackages: ["@realtimexsco/live-chat"],5};6 7export default nextConfig;

Add "use client" at the top of any file that imports chat.

Project config file

Create src/configs/chat.config.ts:

typescript
1/** Optional: read _id from the JWT so it always matches the token */2function userIdFromToken(token: string): string | undefined {3  try {4    const payload = JSON.parse(5      atob(token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"))6    );7    return payload._id || payload.id;8  } catch {9    return undefined;10  }11}12 13const accessToken = "YOUR_JWT_ACCESS_TOKEN";14 15export const chatConfig = {16  clientId: "YOUR_CLIENT_ID",17  accessToken,18  loggedUserDetails: {19    _id: userIdFromToken(accessToken) ?? "YOUR_USER_ID",20    name: "Your Name",21    email: "you@example.com",22  },23  apiUrl: "https://realtimex.softwareco.com/api/v1",24  socketUrl: "https://realtimex.softwareco.com", // optional - derived from apiUrl25  themeColor: "#6366f1",26} as const;

Environment variables

Optional - read them in chat.config.ts:

shell
1# .env.local (Next.js) or .env (Vite, with the VITE_ prefix)2NEXT_PUBLIC_CHAT_CLIENT_ID=your-client-id3NEXT_PUBLIC_API_V1_BASE_URL=https://realtimex.softwareco.com/api/v14NEXT_PUBLIC_SOCKET_URL=https://realtimex.softwareco.com
typescript
1export const chatConfig = {2  clientId: process.env.NEXT_PUBLIC_CHAT_CLIENT_ID ?? "",3  accessToken: "YOUR_JWT_ACCESS_TOKEN",4  apiUrl: process.env.NEXT_PUBLIC_API_V1_BASE_URL ?? "",5  socketUrl:6    process.env.NEXT_PUBLIC_SOCKET_URL ??7    (process.env.NEXT_PUBLIC_API_V1_BASE_URL ?? "").replace(/\/api\/v1\/?$/, ""),8  // ...9};

Vite uses import.meta.env.VITE_* instead of NEXT_PUBLIC_*.

Dev proxy (CORS)

If the API blocks browser requests during local development, proxy them through your dev server (Vite):

typescript
1server: {2  proxy: {3    "/chat-api": {4      target: "https://YOUR_API_HOST",5      changeOrigin: true,6      rewrite: (path) => path.replace(/^\/chat-api/, "/api/v1"),7    },8  },9},

Then set apiUrl: "/chat-api" in chat.config.ts for local development.

PreviousInstallationNextQuick start

On this page

CSS setupVite - vite.config.tsNext.js - next.config.tsProject config fileEnvironment variablesDev proxy (CORS)
Back to top