cometchat_calls_sdk 5.1.0
cometchat_calls_sdk: ^5.1.0 copied to clipboard
Integrate voice & video calling into your Flutter app with CometChat's Calls SDK. Create real-time communication for better user engagement.
CometChat Calls SDK for Flutter #
The CometChat Calls SDK enables real-time voice and video calling capabilities in your Flutter application. Built on top of WebRTC, it provides a complete calling solution with built-in UI components and extensive customization options.
Features #
- 1:1 and group voice/video calls
- Built-in calling UI with customizable themes
- Screen sharing
- Call recording
- Active speaker detection
Installation #
Add the dependency to your pubspec.yaml:
dependencies:
cometchat_calls_sdk: ^5.1.0
Then run:
flutter pub get
Android setup #
-
minSdkVersion26 or later,compileSdk36, and Android Gradle Plugin 8.9.1 or later. -
Add the camera and microphone permissions your calls use, and ask for them at runtime before joining:
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> -
To keep a call running in the background with an ongoing call notification, declare the plugin's service in your app's
AndroidManifest.xml, inside<application>, with the foreground service types your app can justify on Google Play:<service android:name="com.cometchatcalls.cometchatcalls_plugin.services.OngoingCallService" android:exported="false" android:foregroundServiceType="microphone|camera" />Without it, calls work only while the app is in the foreground: when the app goes to the background, Android stops the microphone and camera, so the other participants hear and see nothing.
iOS setup #
The plugin builds with Swift Package Manager only: the native Calls SDK 5.1 is published as a Swift package, not on the CocoaPods trunk. Swift Package Manager is on by default from Flutter 3.44; on an older Flutter, or if your app turned it off, run:
flutter config --enable-swift-package-manager
Apps can still use CocoaPods for their other plugins. If Swift Package Manager
is off, pod install stops with these steps.
- The minimum iOS version is 15.1, and the app builds with Xcode 26.1.1 or later:
connectivity_plus7.1 and later, which the plugin depends on, use the iOS 26 SDK. An app that must build with Xcode 16 can holdconnectivity_plusat 7.0.x in its ownpubspec.yaml(connectivity_plus: '>=7.0.0 <7.1.0'). - Add
NSCameraUsageDescriptionandNSMicrophoneUsageDescriptionto yourInfo.plist. - Apps that also use the Chat SDK v4 need
CometChatSDK4.1.3 or later.
Example #
example/ initialises the SDK, logs a user in and joins a call
session.
Call lifecycle #
On Android and iOS every call below runs the native Calls SDK method of the
same name, so a call behaves as it does in a native app. Call init and
login first.
// Place a call. The receiver is told it is ringing, and the session starts
// preparing so the join is near-instant once the call is accepted.
CometChatCalls.initiateCall(
receiver: 'user-2',
options: InitiateCallOptions(type: CallType.video),
onSuccess: (InitiatedCall call) { /* show the outgoing call screen */ },
onError: (CometChatCallsException e) {},
);
// Prepare a session without joining it: signalling only, no media or UI.
CometChatCalls.connect(
sessionId: sessionId,
sessionSettings: SessionSettingsBuilder().setPeerCall(true).build(),
onSuccess: (CallSession session) {},
onError: (CometChatCallsException e) {},
);
// Join. A session prepared by connect() or initiateCall() is taken over.
CometChatCalls.joinSession(
sessionId: sessionId,
sessionSettings: settings,
onSuccess: (Widget? callView) { /* show it until the call ends */ },
onError: (CometChatCallsException e) {},
);
// End a call before it is joined: decline, cancel, busy or unanswered.
CometChatCalls.endCall(
sessionId: sessionId,
status: EndCallStatus.rejected,
onSuccess: () {},
onError: (CometChatCallsException e) {},
);
joinSessioncompletes once the native SDK has joined, and hands you the call view. Keep that widget mounted until the call ends: the view holds the running call, and removing it ends it.- A session prepared with
connectkeeps the settings it was prepared with; the settings passed to the join that takes it over are not used. getActiveSession()andgetSessionState()report the session in progress.CallSessionaddsgetSessionId(),getCallToken(),getPrepareStatus(),getPrepareError(),isSessionActive()andisSessionJoined().CallSession.leave()leaves the session, or cancels a prepare still in flight.leaveSession()is deprecated in its favour.addIncomingCallListenerdelivers incoming calls handed to the SDK withinjectIncomingCall, which the push notifications SDK does for pushes. The end reasons it reports differ between Android and iOS.setCallKitAudioEnabled(true)(iOS) lets CallKit own the audio session, for apps that report their calls to CallKit.
On web, connect, joinSession, getActiveSession, getSessionState and
the CallSession methods above run on the web SDK; getCallToken() reports
null there, since the web SDK keeps the token to itself. initiateCall,
endCall and the incoming call APIs are Android and iOS only.
Web Support #
The SDK supports Flutter web out of the box. During plugin registration it
automatically injects everything it needs — the CometChat Calls JavaScript
SDK, its stylesheet, and the JS bridge — so no changes to your
web/index.html are required. The calling API is identical to mobile.
1. Enable web for your app #
flutter config --enable-web
# If your project has no web/ folder yet:
flutter create . --platforms=web
2. Use the SDK #
Initialize, log in, then join a session and render the widget returned by
joinSession into your widget tree.
import 'package:cometchat_calls_sdk/cometchat_calls_sdk.dart';
// 1. Initialize
final appSettings = (CallAppSettingBuilder()
..appId = '<APP_ID>'
..region = '<REGION>') // 'us', 'eu' or 'in'
.build();
CometChatCalls.init(
appSettings,
onSuccess: (String message) { /* SDK initialized */ },
onError: (CometChatCallsException e) { /* handle error */ },
);
// 2. Log in
CometChatCalls.login(
uid: '<UID>',
authKey: '<AUTH_KEY>',
onSuccess: (User? user) { /* logged in */ },
onError: (CometChatCallsException e) { /* handle error */ },
);
// 3. Join a session and render the returned widget
final sessionSettings = (SessionSettingsBuilder()
.setTitle('My Meeting')
.startAudioMuted(false)
.startVideoPaused(false))
.build();
CometChatCalls.joinSession(
sessionId: '<SESSION_ID>',
sessionSettings: sessionSettings,
onSuccess: (Widget? callWidget) {
// Add callWidget to your widget tree, e.g.:
// body: SizedBox.expand(child: callWidget)
},
onError: (CometChatCallsException e) { /* handle error */ },
);
3. Run it #
flutter run -d chrome # run during development
flutter build web # production build (serve build/web over HTTPS)
Notes & requirements #
- Internet access — the CometChat Calls JS SDK is loaded from a CDN
(
unpkg.com) at runtime, so the page needs network access on first load. - Secure context — browsers only grant camera/microphone access over
HTTPS or on
localhost. Serve your production web build over HTTPS. - Permissions — the browser prompts for camera/mic on the first call; no Flutter permission plugin is required on web.
- Browsers — any modern WebRTC-capable browser (Chromium-based, Firefox, Safari).
Help and Support #
For issues running the project or integrating with our UI Kits, consult our documentation or create a support ticket or seek real-time support via the CometChat Dashboard.