Skip to main content
Version: v5

Incoming Call

Overview

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.

Image

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.

Usage

Integration

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

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

export default IncomingCallsDemo;

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;
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;
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;

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;

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
}
);

ccCallRejected?.unsubscribe();

ccCallAccepted?.unsubscribe();

ccCallEnded?.unsubscribe();

Customization

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:

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

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

export default IncomingCallsDemo;

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;

Below is a list of customizations along with corresponding code snippets

PropertyDescriptionCode
Custom soundSpecifies a custom sound to play for incoming calls.customSoundForCalls='Your Custom Sound For Calls'
Disable soundDisables the sound for incoming calls.disableSoundForCalls={true}
CallThe CometChat call object used to initialize and display the incoming call component.call={callObject}

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;

LeadingView

Property leadingView is a function that renders a JSX element to display the leading view.

The customized call interface is displayed below.

Image

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;

TitleView

Property titleView is a function that renders a JSX element to display the title view.

The customized call interface is displayed below.

Image

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;

TrailingView

Property trailingView is a function that renders a JSX element to display the trailing view.

The customized call interface is displayed below.

Image

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;

ItemView

Property itemView is a function that renders a JSX element to display the item view.

The customized call interface is displayed below.

Image

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;