This guide walks you through installing the CometChat Calls SDK and initializing it in your web application.
Install the SDK
Install the CometChat Calls SDK using npm or yarn:
npm install @cometchat/calls-sdk-javascript
yarn add @cometchat/calls-sdk-javascript
Import the SDK
Import the CometChatCalls class in your JavaScript or TypeScript file:
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
Initialize CometChat Calls
The init() method initializes the SDK with your app credentials. Call this method once when your application starts.
CallAppSettings
The initialization requires a configuration object with the following properties:
| Parameter | Type | Required | Description |
|---|
appId | String | Yes | Your CometChat App ID |
region | String | Yes | Your app region (us, eu, or in) |
const appId = "APP_ID"; // Replace with your App ID
const region = "REGION"; // Replace with your Region ("us", "eu", or "in")
const callAppSettings = {
appId: appId,
region: region,
};
const result = await CometChatCalls.init(callAppSettings);
if (result.success) {
console.log("CometChat Calls SDK initialized successfully");
} else {
console.error("CometChat Calls SDK initialization failed:", result.error);
}
The init() method returns an object with:
| Property | Type | Description |
|---|
success | Boolean | true if initialization succeeded |
error | Object | null | Error details if initialization failed |
Browser Requirements
The Calls SDK requires a modern browser with WebRTC support:
| Browser | Minimum Version |
|---|
| Chrome | 72+ |
| Firefox | 68+ |
| Safari | 12.1+ |
| Edge | 79+ |
HTTPS is required for camera and microphone access in production. Localhost is exempt from this requirement during development.
Permissions
The browser will prompt users for camera and microphone permissions when joining a call. Ensure your application handles permission denials gracefully.
// Check if permissions are granted
async function checkMediaPermissions() {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
});
stream.getTracks().forEach(track => track.stop());
return true;
} catch (error) {
console.error("Media permissions denied:", error);
return false;
}
}