CometChat React UI Kit

repository·v7·Indexed 21 days ago

https://github.com/cometchat/cometchat-uikit-react

A library of ready-to-use, customizable UI components for integrating real-time messaging, voice and video calling, and AI-powered features into React applications. Version 7.1.0 supports conversations, rich message lists, AI assistants, and full visual customization via CSS custom properties. It requires Node.js >= 18 and React >= 18.

Tokens
42.4K
Snippets
151
Records
240
Agent score
71%

What's inside @cometchat/chat-uikit-react

  1. Overview of CometChat UI Kit Features

    v7

    The CometChat React UI Kit provides pre-built, customizable components including:

    • Conversations: List and manage one-on-one and group chats.
    • Messages: Rich message lists with support for reactions, threads, and read receipts.
    • Calling: Voice and video calling capabilities with call logs.
    • AI Features: AI-powered assistant chat and smart replies.
    • Theming: Full visual customization via CSS custom properties.
    • Localization: Built-in multi-language support.
  2. Run Unit Tests with Vitest

    v7

    Unit tests cover individual components, hooks, and utilities. They are located alongside source files as *.spec.ts or *.spec.tsx and do not require a browser or running server.

    # Run all unit tests
    npm test
    
    # Run with coverage
    npm run test:coverage
  3. Configure E2E Fixtures for Error States

    v7

    To test rejected upload states (file size exceeded or unsupported MIME types), you must provide specific fixtures in sample-app/e2e/fixtures/.

    1. File Size Exceeded (e2e-oversize.*)

    Place any file larger than 100 MB in e2e/fixtures/. Example generation:

    head -c 150000000 /dev/urandom > e2e/fixtures/e2e-oversize.txt

    2. Unsupported MIME Type (e2e-blocked-mime.*)

    This requires two components:

    1. A fixture: A file in e2e/fixtures/ named e2e-blocked-mime.* (extension must NOT be png, mp4, mp3, or pdf).
    2. Environment Variable: Set E2E_BLOCKED_MIME_TYPE in .env.e2e to the exact MIME type denied in your CometChat Dashboard (e.g., E2E_BLOCKED_MIME_TYPE=image/svg+xml).

    Note: The restriction must be set on the Strategy group → Scope permissions → Admin role in the dashboard.

    # Generate an oversize file (~150 MB)
    head -c 150000000 /dev/urandom > e2e/fixtures/e2e-oversize.txt
  4. Set up the React Sample App

    v7

    The React Sample App is a reference implementation of CometChat's React UI Kit v7 using React 19 and Vite. It demonstrates real-time messaging, voice/video calling, and AI-powered chat features.

    Prerequisites

    • Node.js >= 18
    • npm >= 9
    • A CometChat account with an App ID, Region, and Auth Key.

    Installation Steps

    1. Clone the repository and checkout the v7 branch:
      git clone https://github.com/cometchat/cometchat-uikit-react.git
      cd cometchat-uikit-react
      git checkout v7
    2. Navigate to the sample app directory:
      cd sample-app
    3. Install dependencies:
      npm install
    4. Configure your credentials (see Configuration section).
    5. Start the development server:
      npm run dev
    git clone https://github.com/cometchat/cometchat-uikit-react.git
    git checkout v7
    cd cometchat-uikit-react/sample-app
    npm install
    npm run dev
  5. Install the CometChat React UI Kit

    v7

    To integrate real-time messaging and calling into your React application, install the @cometchat/chat-uikit-react package via npm.

    Prerequisites

    • Node.js >= 18
    • npm >= 9
    • React >= 18

    Setup Steps

    1. Register at the CometChat Dashboard to create an account.
    2. Create a new app to obtain your App ID, Region, and Auth Key.
    npm install @cometchat/chat-uikit-react
  6. Set up E2E Tests with Playwright

    v7

    End-to-end tests are located in sample-app/e2e/ and run against the live sample app.

    1. Dashboard Configuration

    Create a CometChat app and note the App ID, Region, Auth Key, and REST API Key. Enable the following extensions in the Dashboard:

    • Stickers
    • Calling
    • Conversation & Advanced Search
    • Polls
    • Collaborative Document
    • Collaborative Whiteboard

    2. Create AI Agent User

    In the Dashboard → BYO Agents, create a user with:

    • UID: ai-agent-e2e
    • Name: AI Agent E2E
    • Role: @agentic

    3. Environment Configuration

    Configure the .env.e2e file in the sample-app directory:

    COMETCHAT_APP_ID=your-app-id
    COMETCHAT_REGION=us
    COMETCHAT_AUTH_KEY=your-auth-key
    COMETCHAT_API_KEY=your-rest-api-key
    E2E_USER_UID=e2e-user-1
    AI_AGENT_UID=ai-agent-e2e

    4. Installation and Execution

    # Install Playwright browsers
    npx playwright install
    
    # Seed test data (one-time)
    cd sample-app
    npm run e2e:seed
    
    # Start dev server (in a separate terminal)
    npm run dev
    
    # Run tests
    npm run e2e
  7. Report a security vulnerability to CometChat

    v7

    If you discover a security vulnerability in CometChat, please follow the Responsible Disclosure Policy. To prevent putting the community at risk, keep potential vulnerabilities confidential until they are confirmed and fixed by the CometChat team.

    To report a security-related issue, send an email directly to the CometChat security team.

    Email: security@cometchat.com
  8. Understand AI Assistant Stream Events

    v7

    The AI assistant uses a stream of events to provide real-time updates (text streaming, tool calls, etc.). These events follow the CometChatAIStreamEvent interface.

    Event Types (CometChatAIStreamEventType):

    • run_started: The AI run has begun.
    • text_message_start / text_message_content / text_message_end: Lifecycle of text streaming.
    • tool_call_start / tool_call_end / tool_call_args / tool_call_result: Lifecycle of tool/function execution.
    • run_finished: The AI run is complete.

    Event Data Structure:

    • type: The event type.
    • content: The text chunk (for text_message_content).
    • toolCallId: The ID of the tool being called.
    • toolName: The name of the tool (for tool_call_start).
    • toolArgs: The arguments chunk (for tool_call_args).
    • toolResult: The result of the tool execution (for tool_call_result).
  9. How CometChatConversations state and actions work

    v7

    The CometChatConversations component system is built around a central context (CometChatConversationsContextValue) that manages the lifecycle of the conversation list.

    State Management:

    • Fetching: The component manages fetchState (loading, error, etc.) and hasMore to handle pagination via fetchNext.
    • Selection: It supports multiple selection modes (none, single, multiple). It tracks selectedConversationIds and a selectedConversationsMap to ensure selected items persist even during searches.
    • Search: The searchText state drives the filtering of the list. When setSearchText is called, it triggers a re-fetch of the conversation list.
    • Typing Indicators: Real-time typing status is maintained in a typingIndicatorMap keyed by user UID or group GUID.

    Interaction Flow:

    1. Initialization: The Root component initializes the fetch process using the provided conversationsRequestBuilder.
    2. User Interaction: Clicking an item (handleItemClick) updates the activeConversationId and handles selection logic based on the selectionMode.
    3. Deletion: Deleting a conversation involves deleteConversation (immediate) or setConversationToBeDeleted (which prepares the state for a confirmation UI).
  10. Configure presence subscriptions

    v7

    You can control which users' presence (online/offline status) the UIKit subscribes to using the UIKitSettingsBuilder. There are three modes:

    1. All Users: Subscribes to presence for all users (subscribePresenceForAllUsers()).
    2. Friends: Subscribes to presence for users in the current user's friend list (subscribePresenceForFriends()).
    3. Roles: Subscribes to presence for users belonging to specific roles (subscribePresenceForRoles(roles: string[])).
    // Subscribe to presence for specific roles
    const settings = new UIKitSettingsBuilder()
      .setAppId('YOUR_APP_ID')
      .setRegion('us')
      .subscribePresenceForRoles(['admin', 'moderator'])
      .build();