Skip to main content
Render the incoming call UI with accept and decline actions.

When to use this

  • You need to handle incoming audio/video calls.
  • You want a default accept/decline screen.
  • You need to customize call handling.

Prerequisites

  • CometChat React UI Kit v6 installed: @cometchat/chat-uikit-react.
  • @cometchat/calls-sdk-javascript installed.
  • CometChatUIKit.init() and CometChatUIKit.login() complete before rendering.

Quick start

  1. Add the component to your UI.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";

<CometChatIncomingCall />;
What this does: Renders the minimal version of the component.
  1. Verify the component renders after init() and login().

Core concepts

  • Mount CometChatIncomingCall at the app root.
  • Use onAccept and onDecline to customize behavior.

Implementation

  • Package: @cometchat/chat-uikit-react
  • Import: import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
  • Minimal JSX: <CometChatIncomingCall /> — auto-detects incoming calls when mounted at app root
  • Required setup: CometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID") + @cometchat/calls-sdk-javascript installed
  • Key props: onAccept (callback), onDecline (callback), call (CometChat.Call), disableSoundForCalls (boolean), callSettingsBuilder (function)
  • CSS class: .cometchat-incoming-call
  • Events: ccCallRejected, ccCallAccepted, ccCallEnded

Overview

What you’re changing: Overview. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. The Incoming call is a Component that serves as a visual representation when the user receives an incoming call, such as a voice call or video call, providing options to answer or decline the call.
The Incoming Call is comprised of the following base components:
ComponentsDescription
cometchat-list-itemThis component’s view consists of avatar, status indicator , title, and subtitle. The fields are then mapped with the SDK’s user, group class.
cometchat-buttonThis component represents a button with optional icon and text.
cometchat-avatarThis component component displays an image or user’s avatar with fallback to the first two letters of the username.
Before using this component: Ensure CometChatUIKit.init(UIKitSettings) has completed and the user is logged in via CometChatUIKit.login("UID"). See React.js Integration.

Usage

What you’re changing: Usage. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below.

Integration

import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  return <CometChatIncomingCall />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
1. onAccept
onAccept is triggered when you click the accept button of the Incoming Call component. You can override this action using the following code snippet.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const handleOnAccept = () => {
    console.log("custom on accept action");
  };

  return <CometChatIncomingCall onAccept={handleOnAccept} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
2. onDecline
onDecline is triggered when you click the Decline button of the Incoming Call component. You can override this action using the following code snippet.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const handleOnDecline = () => {
    console.log("your custom on decline action");
  };

  return <CometChatIncomingCall onDecline={handleOnDecline} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
3. onError
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the Incoming Call component.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const handleOnError = (error: CometChat.CometChatException) => {
    console.log("your custom on error action", error);
  };

  return <CometChatIncomingCall onError={handleOnError} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.

Filters

You can set CallSettingsBuilder in the Incoming Call Component to customise the calling experience. To know more about the filters available please refer to CallSettingsBuilder.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getCallSettingsBuilder = (call: CometChat.Call) => {
    return new CometChatCalls.CallSettingsBuilder()
      .setIsAudioOnlyCall(
        call?.getType() === CometChatUIKitConstants.MessageTypes.audio
          ? true
          : false
      )
      .build();
  };

  return <CometChatIncomingCall callSettingsBuilder={getCallSettingsBuilder} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. The list of events emitted by the Incoming Call component is as follows.
EventDescription
ccCallRejectedThis event is triggered when the initiated call is rejected by the receiver.
ccCallAcceptedThis event is triggered when the initiated call is accepted by the receiver.
ccCallEndedThis event is triggered when the initiated call successfully ends.
const ccCallRejected = CometChatCallEvents.ccCallRejected.subscribe(
  (call: CometChat.Call) => {
    //Your Code
  }
);

const ccCallAccepted = CometChatCallEvents.ccCallAccepted.subscribe(
  (call: CometChat.Call) => {
    //Your Code
  }
);

const ccCallEnded = CometChatCallEvents.ccCallEnded.subscribe(
  (call: CometChat.Call) => {
    //Your Code
  }
);
What this does: Shows the code for this step.

ccCallRejected?.unsubscribe();

ccCallAccepted?.unsubscribe();

ccCallEnded?.unsubscribe();
What this does: Shows the code for this step.

Customization

What you’re changing: Customization. Where to change it: Component props or CSS as shown below. Default behavior: UI Kit defaults. Override: Use the examples in this section. Verify: The UI reflects the change shown below. To fit your app’s design requirements, you can customize the appearance of the Incoming Call component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using CSS you can customize the look and feel of the component in your app like the color, size, shape, and fonts. Example:
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  return <CometChatIncomingCall />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements. Here is a code snippet demonstrating how you can customize the functionality of the Incoming Call component.
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  return (
    <CometChatIncomingCall
      disableSoundForCalls={true}
    />
  );
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
Below is a list of customizations along with corresponding code snippets
PropertyDescriptionCode
CallThe CometChat call object used to initialize and display the incoming call component.call={callObject}
Disable soundDisables the sound for incoming calls.disableSoundForCalls={true}
Custom soundSpecifies a custom sound to play for incoming calls.customSoundForCalls='Your Custom Sound For Calls'

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.
SubtitleView
Property subtitleView is a function that renders a JSX element to display the subtitle view.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getSubtitleView = (call: CometChat.Call): JSX.Element => {
    /** Return custom subtitle view */
  };

  return <CometChatIncomingCall subtitleView={getSubtitleView} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
LeadingView
Property leadingView is a function that renders a JSX element to display the leading view. The customized call interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAvatar, CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getLeadingView = (call: CometChat.Call) => {
        return (
            <div>
                <CometChatAvatar name={call?.getCallInitiator()?.getName()} image={call?.getCallInitiator()?.getAvatar()} />
            </div>
        )
    };

  return <CometChatIncomingCall leadingView={getLeadingView} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
TitleView
Property titleView is a function that renders a JSX element to display the title view. The customized call interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getTitleView = (call: CometChat.Call) => {
        return (
            <div className="incoming-call__title-wrapper">
                {call?.getCallInitiator()?.getName()}
                <div className="incoming-call__tag">
                    <div className="incoming-call__tag-icon" />
                    {call.getCallInitiator()?.getRole()}
                </div>
            </div>
        )
    };

  return <CometChatIncomingCall titleView={getTitleView} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
TrailingView
Property trailingView is a function that renders a JSX element to display the trailing view. The customized call interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getTrailingView = (call: CometChat.Call) => {
        return (
            <div className="incoming-call__avatar">
                <div className="incoming-call__avatar-icon" />
                {call.getCallInitiator()?.getRole()}
            </div>
        )
    };

  return <CometChatIncomingCall trailingView={getTrailingView} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
ItemView
Property itemView is a function that renders a JSX element to display the item view. The customized call interface is displayed below.
Use the following code to achieve the customization shown above.
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAvatar, CometChatIncomingCall } from "@cometchat/chat-uikit-react";
import React from "react";

const IncomingCallsDemo = () => {
  const getItemView = (call: CometChat.Call) => {
        return (
            <div className="incoming-call__itemview">
                <CometChatAvatar name={call?.getCallInitiator()?.getName()} image={call?.getCallInitiator()?.getAvatar()} />
                <div>
                    <div className="incoming-call__itemview-title">
                        {call?.getCallInitiator()?.getName()}
                    </div>
                    <div className="incoming-call__itemview-subtitle">
                        {"Incoming " + call.getType() + " call"}
                    </div>
                </div>
            </div>
        )
    };

  return <CometChatIncomingCall itemView={getItemView} />;
};

export default IncomingCallsDemo;
What this does: Shows the code for this step.
SymptomCauseFix
Component doesn’t renderCometChatUIKit.init() not called or not awaitedEnsure init completes before rendering. See Methods
Component renders but no incoming call shownUser not logged in or no active incoming callCall CometChatUIKit.login("UID") after init. The component auto-detects incoming calls.
Callback not firingWrong prop name or signatureCheck the Actions section for exact prop name and parameter types
Custom view not appearingReturning null or undefined from view propEnsure view function returns valid JSX
No ringtone playingdisableSoundForCalls set to true or custom sound path invalidSet disableSoundForCalls={false} and verify custom sound file path
SSR hydration errorComponent uses browser APIs on serverWrap in useEffect or dynamic import with ssr: false. See Next.js Integration

Customization matrix

What you want to changeWhereProperty/APIExample
Handle acceptCometChatIncomingCallonAcceptonAccept={() => ...}
Handle declineCometChatIncomingCallonDeclineonDecline={() => ...}
Disable soundsCometChatIncomingCalldisableSoundForCallsdisableSoundForCalls={true}

Common pitfalls and fixes

SymptomCauseFix
Incoming UI not shownComponent not mountedRender CometChatIncomingCall at root
Calls not availableCalls SDK missingInstall @cometchat/calls-sdk-javascript
Init/login missingSDK not initializedCall CometChatUIKit.init() and login()

FAQ

Where should I mount it? At the app root so it can listen globally. Can I customize accept/decline? Yes. Use onAccept and onDecline.

Next steps