CometChat Calls SDK v5 — Setup
Overview
Install and initialize the CometChat Calls SDK v5 in a web project. Covers npm installation, CometChatCalls.init(), authentication with login() or loginWithAuthToken(), and browser permissions.
Key Imports
import { CometChatCalls } from '@cometchat/calls-sdk-javascript';
Implementation
1. Install the Package
npm install @cometchat/calls-sdk-javascript@latest
2. Initialize the SDK
const appSettings = {
appId: 'YOUR_APP_ID',
region: 'us', // 'us' | 'eu' | 'in'
};
const result = await CometChatCalls.init(appSettings);
if (result.success) {
console.log('Calls SDK initialized');
} else {
console.error('Init failed:', result.error.message);
}
3. Login with UID + Auth Key (Development Only)
try {
const user = await CometChatCalls.login('USER_UID', 'AUTH_KEY');
console.log('Logged in:', user.name);
} catch (error) {
console.error('Login failed:', error.errorDescription);
}
4. Login with Auth Token (Production)
try {
const user = await CometChatCalls.loginWithAuthToken('AUTH_TOKEN');
console.log('Logged in:', user.name);
} catch (error) {
console.error('Login failed:', error.errorDescription);
}
5. Check Login State
const user = CometChatCalls.getLoggedInUser();
if (user) {
console.log('Already logged in as:', user.name);
}
// Or check boolean
if (CometChatCalls.isUserLoggedIn()) {
// ready to join sessions
}
6. Logout
await CometChatCalls.logout();
7. Browser Permissions (Optional)
The SDK automatically requests camera and microphone permissions when joining a session. You can optionally pre-request them to avoid the permission prompt during the call:
await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
8. Login Listeners (Optional)
CometChatCalls.addLoginListener('my-listener', {
onLoginSuccess: (user) => console.log('Login success:', user.name),
onLoginFailure: (error) => console.error('Login failed:', error.errorDescription),
onLogoutSuccess: () => console.log('Logged out'),
onLogoutFailure: (error) => console.error('Logout failed:', error.errorDescription),
});
// Remove when done
CometChatCalls.removeLoginListener('my-listener');
Gotchas
- Call
init()before any other SDK method init()returns{ success, error }— it does not throwlogin()andloginWithAuthToken()throw on failure — use try/catch- Auth Key login is for development only — use Auth Token in production
- The SDK persists login state in
localStorage— users stay logged in across page reloads - If using both Chat SDK and Calls SDK, initialize and login to both separately
regionaccepts both lowercase ('us') and uppercase ('US')
Sample App Reference
sample-apps/cometchat-calls-sample-app-react/— React sample with init + login flowsample-apps/cometchat-calls-sample-app-vue/— Vue samplesample-apps/cometchat-calls-sample-app-angular/— Angular samplesample-apps/cometchat-calls-sample-app-svelte/— Svelte samplesample-apps/cometchat-calls-sample-app-ionic/— Ionic sample