Quick Reference for AI Agents & Developers// Install: npm install @cometchat/calls-sdk-javascript
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
// Initialize Calls SDK (after Chat SDK init)
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(APP_ID)
.setRegion(REGION)
.build();
await CometChatCalls.init(callAppSettings);
// For dedicated deployments, add: .setHost("https://your-custom-url.cometchat.io")
Set up the CometChat Calls SDK to add voice and video calling capabilities to your web application.
Prerequisites
Before you begin:
- Create a CometChat account and app
- Note your App ID, Auth Key, and Region from the Dashboard credentials section
- Complete the Chat SDK Setup (unless using Standalone Calling)
Installation
npm install @cometchat/calls-sdk-javascript
yarn add @cometchat/calls-sdk-javascript
pnpm add @cometchat/calls-sdk-javascript
Import
Import the CometChatCalls class in your application:
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
Initialize
Initialize the Calls SDK before using any calling features. Call init() on app startup, typically in your main entry file.
JavaScript
TypeScript
Async/Await
const appId = "YOUR_APP_ID";
const region = "YOUR_REGION"; // e.g., "us", "eu"
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.build();
CometChatCalls.init(callAppSettings).then(
() => {
console.log("CometChatCalls initialized successfully");
},
(error) => {
console.log("CometChatCalls initialization failed:", error);
}
);
const appId: string = "YOUR_APP_ID";
const region: string = "YOUR_REGION";
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.build();
CometChatCalls.init(callAppSettings).then(
(): void => {
console.log("CometChatCalls initialized successfully");
},
(error: any): void => {
console.log("CometChatCalls initialization failed:", error);
}
);
const initCallsSDK = async () => {
try {
const appId = "YOUR_APP_ID";
const region = "YOUR_REGION"; // e.g., "us", "eu"
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.build();
await CometChatCalls.init(callAppSettings);
console.log("CometChatCalls initialized successfully");
} catch (error) {
console.log("CometChatCalls initialization failed:", error);
}
};
Replace YOUR_APP_ID and YOUR_REGION with your actual CometChat credentials from the Dashboard.
Configuration Options
The CallAppSettingsBuilder provides these configuration methods:
| Method | Description | Required |
|---|
setAppId(appId) | Your CometChat App ID | Yes |
setRegion(region) | Region where your app was created (us, eu, etc.) | Yes |
setHost(host) | Custom client URL for dedicated deployments | No |
Dedicated Deployment
For dedicated CometChat deployments, use setHost() to specify your custom URL:
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.setHost("https://your-custom-url.cometchat.io")
.build();
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.setHost("https://your-custom-url.cometchat.io")
.build();
Complete Setup Example
Here’s a complete initialization flow with both Chat and Calls SDKs:
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
const appId = "YOUR_APP_ID";
const region = "YOUR_REGION";
async function initializeCometChat() {
try {
// Initialize Chat SDK
const appSettings = new CometChat.AppSettingsBuilder()
.subscribePresenceForAllUsers()
.setRegion(region)
.autoEstablishSocketConnection(true)
.build();
await CometChat.init(appId, appSettings);
console.log("Chat SDK initialized");
// Initialize Calls SDK
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.build();
await CometChatCalls.init(callAppSettings);
console.log("Calls SDK initialized");
return true;
} catch (error) {
console.error("Initialization failed:", error);
return false;
}
}
// Call on app startup
initializeCometChat();
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatCalls } from "@cometchat/calls-sdk-javascript";
const appId: string = "YOUR_APP_ID";
const region: string = "YOUR_REGION";
async function initializeCometChat(): Promise<boolean> {
try {
// Initialize Chat SDK
const appSettings = new CometChat.AppSettingsBuilder()
.subscribePresenceForAllUsers()
.setRegion(region)
.autoEstablishSocketConnection(true)
.build();
await CometChat.init(appId, appSettings);
console.log("Chat SDK initialized");
// Initialize Calls SDK
const callAppSettings = new CometChatCalls.CallAppSettingsBuilder()
.setAppId(appId)
.setRegion(region)
.build();
await CometChatCalls.init(callAppSettings);
console.log("Calls SDK initialized");
return true;
} catch (error) {
console.error("Initialization failed:", error);
return false;
}
}
// Call on app startup
initializeCometChat();
Next Steps