Skip to main content
Version: v4

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-avatarThis component component displays an image or user's avatar with fallback to the first two letters of the username

Usage

Integration

import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
/>
)}
</>
);
}

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 { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const onAcceptHandler = (message: CometChat.BaseMessage) => {
//code
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
onAccept={onAcceptHandler}
/>
)}
</>
);
}
2. onDecline

onDecline is triggered when you click the Decline button of the Incoming Call component. This action does not have a predefined behavior. You can override this action using the following code snippet.

import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const onDeclineHandler = (call) => {
setCallReceived(false);
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={onDeclineHandler}
/>
)}
</>
);
}
3. onError

This action doesn't change the behavior of the component but rather listens for any errors that occur in the Banned Members component.

import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const onErrorHandler = (error: CometChat.CometChatException) => {
//code
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
onError={onErrorHandler}
/>
)}
</>
);
}

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of ChatSDK.

The Incoming Call component does not have any exposed filters.

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.
ccCallFailledThis event is triggered when an error occurs during the intiated call.
import { CometChatUIEventHandler } from "@cometchat/chat-uikit-react-native";

CometChatUIEventHandler.addCallListener("CALL_LISTENER_ID", {
ccCallRejected: ({ call }) => {
//code
},
});

CometChatUIEventHandler.addCallListener("CALL_LISTENER_ID", {
ccCallAccepted: ({ call }) => {
//code
},
});

CometChatUIEventHandler.addCallListener("CALL_LISTENER_ID", {
ccCallEnded: ({ call }) => {
//code
},
});

CometChatUIEventHandler.addCallListener("CALL_LISTENER_ID", {
ccCallFailled: ({ call }) => {
//code
},
});

import { CometChatUIEventHandler } from "@cometchat/chat-uikit-react-native";

CometChatUIEventHandler.removeCallListener("CALL_LISTENER_ID");

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 Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

1. IncomingCall Style

To customize the appearance, you can assign a IncomingCallStyle object to the Incoming Call component.

In this example, we are employing the IncomingCallStyle.

Image
import { CometChat } from "@cometchat/chat-sdk-react-native";
import {
CometChatIncomingCall,
IncomingCallStyleInterface,
} from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const incomingCallStyle: IncomingCallStyleInterface = {
declineButtonTextColor: "red",
acceptButtonTextColor: "#6851D6",
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
incomingCallStyle={incomingCallStyle}
/>
)}
</>
);
}

The following properties are exposed by IncomingCallStyle:

PropertyDescriptionCode
borderUsed to set borderborder?: BorderStyleInterface,
borderRadiusUsed to set border radiusborderRadius?: number;
backgroundColorUsed to set background colourbackground?: string;
heightUsed to set heightheight?: number | string;
widthUsed to set widthwidth?: number | string;
titleFontUsed to customise the font of the title in the app bartitleFont?: FontStyleInterface;
titleColorUsed to customise the color of the title in the app bartitleColor?: string;
subtitleColorUsed to set the color for group item subtitlesubtitleColor?: string;
subtitleFontUsed to set the font style for group item subtitlesubtitle Font?: FontStyleInterface;
onlineStatusColorUsed to set online status coloronlineStatusColor?: string;
acceptButtonTextColorUsed to set accept button text coloracceptButtonTextColor?: string;
acceptButtonTextFontUsed to set accept button text fontacceptButtonTextFont?: FontStyleInterface;
acceptButtonBackgroundColorUsed to set accept button background coloracceptButtonBackgroundColor?: string;
acceptButtonBorderUsed to set accept button borderacceptButtonBorder?: BorderStyleInterface;
declineButtonTextColorUsed to set decline button text colordeclineButtonTextColor?: string;
declineButtonTextFontUsed to set decline button text fontdeclineButtonTextFont?: FontStyleInterface;
declineButtonBackgroundColorUsed to set decline button background colordeclineButtonBackgroundColor?: string;
declineButtonBorderUsed to set decline button borderdeclineButtonBorder?: BorderStyleInterface;
2. Avatar Style

If you want to apply customized styles to the Avatar component within the Incoming Call Component, you can use the following code snippet. For more information you can refer Avatar Styles.

import { CometChat } from "@cometchat/chat-sdk-react-native";
import {
CometChatIncomingCall,
AvatarStyleInterface,
BorderStyleInterface,
} from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const borderStyle: BorderStyleInterface = {
borderWidth: 10,
borderStyle: "solid",
borderColor: "#cc5e95",
};

const avatarStyle: AvatarStyleInterface = {
outerViewSpacing: 5,
outerView: {
borderWidth: 2,
borderStyle: "dotted",
borderColor: "blue",
},
border: borderStyle,
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
avatarStyle={avatarStyle}
/>
)}
</>
);
}
3. OngoingCallScreen Style

You can use this style property to apply customized styles to the OngoingCallScreen component within the Incoming Call Component.


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 { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
acceptButtonText="Answer"
declineButtonText="Reject"
disableSoundForCalls={true}
/>
)}
</>
);
}
Image

Below is a list of customizations along with corresponding code snippets

PropertyDescriptionCode
titleUsed to set titletitle?: string
acceptButtonTextUsed to set custom accept button textacceptButtonText?: string
declineButtonTextUsed to set custom decline button textdeclineButtonText?: string
customSoundForCallsUsed to set custom sound for incoming callscustomSoundForCalls?: string
disableSoundForCallsUsed to disable/enable the sound of incoming calls, by default it is set to falsedisableSoundForCalls?: string
callCometChat call object consumed by the component to launch itselfdisableSoundForMessages={true}

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

By using the SubtitleView property, you can modify the SubtitleView to meet your specific needs.

Image
import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatIncomingCall } from "@cometchat/chat-uikit-react-native";

function App(): React.JSX.Element {
const incomingCall = useRef(null);
const [callReceived, setCallReceived] = useState(false);
const listnerID = "UNIQUE_LISTENER_ID";

useEffect(() => {
//code
CometChat.addCallListener(
listnerID,
new CometChat.CallListener({
onIncomingCallReceived: (call) => {
incomingCall.current = call;
setCallReceived(true);
},
onOutgoingCallRejected: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
onIncomingCallCancelled: (call) => {
incomingCall.current = null;
setCallReceived(false);
},
})
);
});

const getSubtitleView = (call: CometChat.Call | CometChat.CustomMessage) => {
return (
<Text
style={{
fontSize: 15,
color: "red",
shadowColor: "red",
}}
>
Custom Subtitle
</Text>
);
};

return (
<>
{callReceived && (
<CometChatIncomingCall
call={incomingCall.current!}
onDecline={(call) => {
setCallReceived(false);
}}
SubtitleView={getSubtitleView}
/>
)}
</>
);
}