Migrating app version from v3 to v4 ?Skip the create new app step. Your existing v3 app can be migrated to v4.Follow steps mentioned in Add the CometChat dependency section below to upgrade to latest version of v4
Get your Application Keys
Signup for CometChat and then:- Create a new app
- Head over to the API & Auth Keys section and note the Auth Key, App ID & Region
Add the CometChat Dependency
NPM
- JavaScript
Initialization
Theinit() method initializes the SDK and must be called before any other CometChat method. Call it once at app startup, typically in your entry file (index.js, main.js, or App.js).
- TypeScript
- JavaScript
APP_ID and APP_REGION with your credentials from the Dashboard.
Parameters
| Parameter | Type | Description |
|---|---|---|
| appID | string | Your CometChat App ID |
| appSetting | AppSettings | Configuration object built with AppSettingsBuilder |
AppSettings Options
| Method | Description | Default |
|---|---|---|
setRegion(region) | Region where your app was created (us, eu, in) | Required |
subscribePresenceForAllUsers() | Subscribe to presence events for all users | — |
subscribePresenceForRoles(roles) | Subscribe to presence for specific roles | — |
subscribePresenceForFriends() | Subscribe to presence for friends only | — |
autoEstablishSocketConnection(bool) | Let SDK manage WebSocket connections | true |
overrideAdminHost(adminHost) | Custom admin URL (dedicated deployment) | — |
overrideClientHost(clientHost) | Custom client URL (dedicated deployment) | — |
setStorageMode(storageMode) | Local storage mode (CometChat.StorageMode.SESSION for session storage) | — |
Presence Subscription
Choose how to subscribe to user presence (online/offline status):WebSocket Connection
By default, the SDK manages WebSocket connections automatically. To manage them manually:Session Storage
Use session storage instead of local storage (data clears when browser closes):SSR Compatibility
The CometChat SDK requires browser APIs (window, WebSocket) and cannot run on the server. For SSR frameworks, initialize the SDK only on the client side.
- Next.js
- NuxtJS
- Ionic/Cordova
Import the SDK dynamically in
useEffect:Next Steps
Authentication
Log in users with Auth Key or Auth Token
Send Messages
Send your first message