### Android Configuration Example Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Example of Android-specific configuration, including additional permissions and foreground service settings. ```json { "android": { "additionalPermissions": [ "android.permission.CALL_PHONE", "android.permission.READ_PHONE_NUMBERS", ], "foregroundService": { "channelId": "com.example.myapp", "channelName": "My App Calls", "notificationTitle": "My App is handling calls", "notificationIcon": "mipmap/ic_launcher", }, } } ``` -------------------------------- ### One-Time Setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/README.md Call the setup() method once early in the application's lifecycle, typically during startup, rather than on a per-call basis. ```dart void main() async { await callKeep.setup(...); // Once at startup runApp(MyApp()); } ``` -------------------------------- ### FlutterCallkeep Setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/INDEX.md Initializes the FlutterCallkeep plugin. This method should be called once when your application starts. ```APIDOC ## setup() ### Description Initializes the FlutterCallkeep plugin. This is a crucial first step before using any other plugin functionalities. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters None ### Request Example ```dart await FlutterCallkeep.setup(); ``` ### Response None ``` -------------------------------- ### Production Setup with All Features Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md This setup includes all features for production, such as permission handling, foreground service configuration, and additional Android permissions. ```dart await callKeep.setup( showAlertDialog: _showPermissionAlert, options: { 'ios': { 'appName': 'MyApp', }, 'android': { 'additionalPermissions': [ 'android.permission.CALL_PHONE', 'android.permission.READ_PHONE_NUMBERS', 'android.permission.CAMERA', ], 'foregroundService': { 'channelId': 'com.mycompany.myapp.voip', 'channelName': 'VoIP Calls', 'notificationTitle': 'My App - Incoming call', 'notificationIcon': 'mipmap/ic_notification_icon', }, }, }, ); ``` -------------------------------- ### Complete CallKeep Setup with iOS and Android Options Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md A comprehensive example demonstrating the setup of CallKeep with both iOS and Android configurations, including additional permissions and foreground service settings for Android. ```dart await callKeep.setup( showAlertDialog: () async { return await showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return AlertDialog( title: const Text('Permissions Required'), content: const Text( 'This application needs to access your phone accounts', ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: const Text('OK'), ), ], ); }, ) ?? false; }, options: { 'ios': { 'appName': 'CallKeepDemo', }, 'android': { 'additionalPermissions': [ 'android.permission.CALL_PHONE', 'android.permission.READ_PHONE_NUMBERS', ], 'foregroundService': { 'channelId': 'com.company.my', 'channelName': 'Foreground service for my app', 'notificationTitle': 'My app is running on background', 'notificationIcon': 'mipmap/ic_notification_launcher', }, }, }, ); ``` -------------------------------- ### Minimal Setup for Development Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Use this minimal setup for development purposes. It configures basic iOS app name settings. ```dart await callKeep.setup( options: { 'ios': {'appName': 'DevApp'}, 'android': {}, }, ); ``` -------------------------------- ### Setup Callkeep with Permissions Dialog Source: https://github.com/flutter-webrtc/callkeep/blob/master/README.md Configure Callkeep with a custom dialog to request necessary permissions. This setup should be called when your application starts. The dialog appears if permissions are not yet granted. ```dart callKeep.setup( showAlertDialog: () async { final BuildContext context = navigatorKey.currentContext!; return await showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return AlertDialog( title: const Text('Permissions Required'), content: const Text( 'This application needs to access your phone accounts'), actions: [ TextButton( child: const Text('Cancel'), onPressed: () => Navigator.of(context).pop(false), ), TextButton( child: const Text('OK'), onPressed: () => Navigator.of(context).pop(true), ), ], ); }, ) ?? false; }, options:{ 'ios': { 'appName': 'CallKeepDemo', }, 'android': { 'additionalPermissions': [ 'android.permission.CALL_PHONE', 'android.permission.READ_PHONE_NUMBERS' ], // Required to get audio in background when using Android 11 'foregroundService': { 'channelId': 'com.company.my', 'channelName': 'Foreground service for my app', 'notificationTitle': 'My app is running on background', 'notificationIcon': 'mipmap/ic_notification_launcher', }, }, }); ``` -------------------------------- ### setup() Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Initializes CallKeep with platform-specific options and an optional alert dialog handler. This method must be called before any other methods in the class. ```APIDOC ## setup() ### Description Initializes CallKeep with platform-specific options and an optional alert dialog handler. Must be called before using other methods. ### Method Signature ```dart Future setup({ Future Function()? showAlertDialog, required Map options, bool backgroundMode = false, }) ``` ### Parameters #### Optional Parameters - **showAlertDialog** (`Future Function()?`) - Callback function that displays a permission alert dialog. Must return `true` if user approves, `false` otherwise. - **backgroundMode** (`bool`) - If `true`, skips permission requests on Android setup. #### Required Parameters - **options** (`Map`) - Platform-specific configuration with keys `'ios'` and `'android'`. ### Returns `Future` — completes when setup is finished. ### Throws `Exception` if iOS options lack required `'appName'` key or if `'appName'` is not a string. ### Example ```dart await callKeep.setup( showAlertDialog: () async { return await showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: const Text('Permissions Required'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: const Text('OK'), ), ], ); }, ) ?? false; }, options: { 'ios': { 'appName': 'MyApp', }, 'android': { 'additionalPermissions': ['android.permission.CALL_PHONE'], 'foregroundService': { 'channelId': 'com.example.my', 'channelName': 'Foreground service for my app', 'notificationTitle': 'My app is running', 'notificationIcon': 'mipmap/ic_notification_launcher', }, }, }, ); ``` ``` -------------------------------- ### Complete CallKeep Event Subscription Example Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md A comprehensive example demonstrating how to subscribe to various CallKeep events, including call actions, mute/hold toggles, audio session lifecycle, and PushKit tokens. ```dart import 'package:callkeep/callkeep.dart'; void initState() { super.initState(); final callKeep = FlutterCallkeep(); // Answer action callKeep.on((event) { _handleAnswerCall(event.callData.callUUID!); }); // End call action callKeep.on((event) { _handleEndCall(event.callUUID!); }); // Mute action callKeep.on((event) { _handleMuteToggle(event.callUUID!, event.muted!); }); // Hold action callKeep.on((event) { _handleHoldToggle(event.callUUID!, event.hold!); }); // Audio session lifecycle callKeep.on((event) { _setupAudioRouting(); }); callKeep.on((event) { _cleanupAudioRouting(); }); // PushKit token (iOS) callKeep.on((event) { _sendTokenToBackend(event.token!); }); } @override void dispose() { super.dispose(); // Unsubscribe if needed final callKeep = FlutterCallkeep(); // Listeners are typically kept for the app lifetime } ``` -------------------------------- ### Setup FlutterCallkeep Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Initialize the FlutterCallkeep plugin. This method requires platform-specific options and can optionally skip permission requests. ```dart Future setup({ Future Function()? showAlertDialog, required Map options, bool backgroundMode = false, }) async ``` -------------------------------- ### Cross-Platform Method: setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md Initializes the CallKeep module. Works on both iOS and Android. ```dart setup() ``` -------------------------------- ### setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Initializes the FlutterCallkeep plugin. This method must be called before any other methods. It allows for platform-specific configuration and optionally skips permission requests. ```APIDOC ## setup() ### Description Initializes the FlutterCallkeep plugin with platform-specific options and optional permission dialog handling. ### Method Future ### Parameters #### Optional Parameters - **showAlertDialog** (Future Function()?) - A callback function that returns a Future to control the display of permission dialogs. - **backgroundMode** (bool) - If true, skips permission requests. Defaults to false. #### Required Parameters - **options** (Map) - A map containing platform-specific configuration for 'ios' and 'android'. ``` -------------------------------- ### Setup FlutterCallkeep in Background Handler Source: https://github.com/flutter-webrtc/callkeep/blob/master/README.md Initializes FlutterCallkeep and sets up call handling within a Firebase Cloud Messaging background handler. Ensure setup is called only once. ```dart final FlutterCallkeep _callKeep = FlutterCallkeep(); bool _callKeepStarted = false; Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { await Firebase.initializeApp(); if (!_callKeepStarted) { try { await _callKeep.setup(callSetup); _callKeepStarted = true; } catch (e) { print(e); } } // then process your remote message looking for some call uuid // and display any incoming call } ``` -------------------------------- ### Start Call Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/INDEX.md Initiates a new outgoing call. This method is used when the user starts a call from within the application. ```APIDOC ## startCall(CallData callData) ### Description Initiates a new outgoing call. This method requires `CallData` to provide details about the call, such as the number to dial. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **callData** (CallData) - Required - Object containing details of the outgoing call. ### Request Example ```dart final callData = CallData(number: '+1987654321'); await FlutterCallkeep.startCall(callData); ``` ### Response None ``` -------------------------------- ### Enable Background Mode for CallKeep Setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Set `backgroundMode` to `true` when calling `setup` from background message handlers (like FCM) on Android. This skips the usual permission and phone account setup prompts. ```dart // In background message handler await callKeep.setup( options: androidOptions, backgroundMode: true, ); ``` -------------------------------- ### Setup CallKeep with Basic Options Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Initialize CallKeep with platform-specific configuration options. The `showAlertDialog` callback is optional but useful for permission requests. ```dart await callKeep.setup( showAlertDialog: () async { /* ... */ }, options: { 'ios': { /* iOS-specific options */ }, 'android': { /* Android-specific options */ }, }, ); ``` -------------------------------- ### Example CallData Instantiation Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/calldata-class.md Demonstrates creating a CallData object with sample values for a call. This includes a UUID, handle, name, video capability, PushKit origin, and additional data. ```dart final callData = CallData( 'uuid-12345-abcdef-67890', '+1234567890', 'John Doe', false, true, {'messageId': 'msg123', 'priority': 'high'}, ); ``` -------------------------------- ### Platform-Specific Configuration Example Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Demonstrates setting up CallKeep with platform-specific options for both iOS and Android, including foreground service settings and additional permissions. ```dart final options = { 'ios': { 'appName': 'TestApp', }, 'android': { 'additionalPermissions': [ 'android.permission.CALL_PHONE', ], 'foregroundService': { 'channelId': 'com.test.app', 'channelName': 'Test App Calls', 'notificationTitle': 'Test App calling', 'notificationIcon': 'mipmap/ic_launcher', }, }, }; await callKeep.setup( options: options, ); ``` -------------------------------- ### Complete Event Handler Setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-manager.md Set up handlers for various call-related events including answering, ending, muting, and audio session lifecycle events. ```dart void _setupCallHandlers() { final callKeep = FlutterCallkeep(); // Answer handler callKeep.on((event) { final uuid = event.callData.callUUID; if (uuid != null) { _answerCall(uuid); } }); // End call handler callKeep.on((event) { if (event.callUUID != null) { _terminateCall(event.callUUID!); } }); // Mute handler callKeep.on((event) { if (event.callUUID != null && event.muted != null) { _updateMute(event.callUUID!, event.muted!); } }); // Audio session lifecycle callKeep.on((event) { _initializeAudio(); }); callKeep.on((event) { _cleanupAudio(); }); } ``` -------------------------------- ### Incoming Call Payload Example Source: https://github.com/flutter-webrtc/callkeep/blob/master/README.md An example JSON payload structure for incoming call data, including caller information and call details. ```json { "uuid": "xxxxx-xxxxx-xxxxx-xxxxx", "caller_id": "+0123456789", "caller_name": "Draco", "caller_id_type": "number", "has_video": "false" } ``` -------------------------------- ### Report Started Call (Android) Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Reports that a call has started. This method is specific to Android and has no effect on iOS. ```dart Future reportStartedCallWithUUID(String uuid) async ``` -------------------------------- ### Initialize CallKeep Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/quick-start.md Set up CallKeep with platform-specific options and a permission dialog handler. Ensure Flutter binding is initialized before setup. ```dart import 'package:callkeep/callkeep.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); final callKeep = FlutterCallkeep(); // Setup CallKeep await callKeep.setup( showAlertDialog: _showPermissionDialog, options: { 'ios': { 'appName': 'MyApp', }, 'android': { 'additionalPermissions': [ 'android.permission.CALL_PHONE', ], 'foregroundService': { 'channelId': 'com.example.myapp', 'channelName': 'My App Calls', 'notificationTitle': 'My App is handling calls', 'notificationIcon': 'mipmap/ic_launcher', }, }, }, ); runApp(const MyApp()); } Future _showPermissionDialog() async { final context = navigatorKey.currentContext; if (context == null) return false; return await showDialog( context: context, barrierDismissible: false, builder: (context) => AlertDialog( title: const Text('Permissions'), content: const Text('This app needs phone permissions'), actions: [ TextButton( onPressed: () => Navigator.pop(context, false), child: const Text('Cancel'), ), TextButton( onPressed: () => Navigator.pop(context, true), child: const Text('OK'), ), ], ), ) ?? false; } ``` -------------------------------- ### Setup FlutterCallkeep with Options Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Initializes CallKeep with platform-specific configurations and an optional custom dialog for permission requests. This must be called before other methods. Ensure 'appName' is provided in iOS options. ```dart await callKeep.setup( showAlertDialog: () async { return await showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: const Text('Permissions Required'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: const Text('OK'), ), ], ); }, ) ?? false; }, options: { 'ios': { 'appName': 'MyApp', }, 'android': { 'additionalPermissions': ['android.permission.CALL_PHONE'], 'foregroundService': { 'channelId': 'com.example.my', 'channelName': 'Foreground service for my app', 'notificationTitle': 'My app is running', 'notificationIcon': 'mipmap/ic_notification_launcher', }, }, }, ); ``` -------------------------------- ### startCall Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Initiates a new outgoing call. This method is used to start a call to a specified contact or number. ```APIDOC ## startCall() ### Description Initiates a new outgoing call with specified caller and recipient details. ### Method Future ### Parameters #### Required Parameters - **uuid** (String) - The unique identifier for the call. - **handle** (String) - The phone number or identifier to call. - **callerName** (String) - The name of the caller. #### Optional Parameters - **handleType** (String) - The type of the handle (e.g., 'number', 'email'). Defaults to 'number'. - **hasVideo** (bool) - Indicates if the call has video. Defaults to false. - **additionalData** (Map) - A map for any additional data associated with the call. Defaults to an empty map. ``` -------------------------------- ### Video Call Setup Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Configure CallKeep for video calls by including camera and audio permissions, along with specific foreground service settings for video calls. ```dart await callKeep.setup( options: { 'ios': {'appName': 'VideoApp'}, 'android': { 'additionalPermissions': [ 'android.permission.CAMERA', 'android.permission.RECORD_AUDIO', ], 'foregroundService': { 'channelId': 'com.example.video', 'channelName': 'Video Calls', 'notificationTitle': 'Video call in progress', 'notificationIcon': 'mipmap/ic_video_launcher', }, }, }, ); ``` -------------------------------- ### CallKeepDidReceiveStartCallAction Constructor Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Represents the action to start a new call. It includes call data necessary for initiating the call. ```dart // All of these have a fromMap factory constructor: class CallKeepDidReceiveStartCallAction { factory fromMap(Map arguments) final CallData callData; } ``` -------------------------------- ### Incoming Call Display Example Data Flow Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md Walks through the sequence of events for displaying an incoming call, from FCM message to the Flutter listener receiving the answer event. ```text FCM message received → App calls displayIncomingCall(uuid, handle, name, hasVideo, additionalData) → Sent to native via MethodChannel → iOS/Android displays call UI → User sees call notification → User taps answer button → Native sends 'CallKeepPerformAnswerCallAction' event back → eventListener() receives it → Emits CallKeepPerformAnswerCallAction event → App's listener receives event and answers the actual call ``` -------------------------------- ### CallKeepDidReceiveStartCallAction Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md Fired when a call should be started, typically from external activation like native UI. It carries call data necessary to initiate the call. ```APIDOC ## CallKeepDidReceiveStartCallAction ### Description Fired when a call should be started (typically from external activation like native UI). ### Event Data #### callData (`CallData`) - `callUUID` (string) - The unique identifier for the call. - `handle` (string) - The caller's handle or number. - `name` (string) - The caller's name. - `video` (boolean) - Indicates if the call is a video call. ### Example ```dart callKeep.on((event) => { final uuid = event.callData.callUUID; final callerHandle = event.callData.handle; print('Start call from: $callerHandle'); }); ``` ``` -------------------------------- ### Set App Available for Calls (Android) Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Indicates to the Android dialer that the app is ready to handle outgoing calls. Call after setup. ```dart await callKeep.setAvailable(available: true); ``` -------------------------------- ### Subscribe to CallKeep Events Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md Use the on() method to subscribe to specific event types. This example shows how to listen for the CallKeepPerformAnswerCallAction event. ```dart callKeep.on((event) { print('Answer call: ${event.callData.callUUID}'); }); ``` -------------------------------- ### Start Outgoing Call Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Initiates an outgoing call. Use this when starting a call from within the app. Requires a unique UUID, callee's handle, and caller's name. Optionally supports video and custom data. ```dart Future startCall({ required String uuid, required String handle, required String callerName, String handleType = 'number', bool hasVideo = false, Map additionalData = const {}, }) ``` ```dart await callKeep.startCall( uuid: 'uuid-outgoing-123', handle: '+9876543210', callerName: 'Jane Smith', hasVideo: true, ); ``` -------------------------------- ### Listen for CallKeepDidReceiveStartCallAction Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md Fired when a call should be started, typically from external activation like native UI. Use this to initiate a new call within your application. ```dart callKeep.on((event) { final uuid = event.callData.callUUID; final callerHandle = event.callData.handle; print('Start call from: $callerHandle'); }); ``` -------------------------------- ### Initiate Outgoing Call Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/quick-start.md Start an outgoing call with specified details including UUID, handle, and caller name. ```dart final callKeep = FlutterCallkeep(); await callKeep.startCall( uuid: 'outgoing-uuid-456', handle: '+9876543210', callerName: 'My App', hasVideo: false, ); ``` -------------------------------- ### Register Android Events (Android) Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Initializes native event handling for Android-specific events. Usually called during setup. ```dart await callKeep.registerAndroidEvents(); ``` -------------------------------- ### Displaying an Incoming Call Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/README.md Provides an example of how to display an incoming call notification on both iOS and Android using the same API. ```dart // Same code works on both platforms await callKeep.displayIncomingCall( uuid: 'uuid-123', handle: '+1234567890', callerName: 'John', ); ``` -------------------------------- ### Handling Platform Differences in CallKeep Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Use Platform.isIOS and Platform.isAndroid to conditionally execute CallKeep methods based on the operating system. This example shows reporting an outgoing call on iOS and registering a phone account on Android. ```dart import 'dart:io'; final callKeep = FlutterCallkeep(); if (Platform.isIOS) { // iOS-specific logic await callKeep.reportConnectingOutgoingCallWithUUID(uuid); } else if (Platform.isAndroid) { // Android-specific logic await callKeep.registerPhoneAccount(); await callKeep.setAvailable(available: true); } ``` -------------------------------- ### Display Custom Permission Alert Dialog Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Provide a custom asynchronous callback to display a permission alert dialog to the user. This is shown on Android when phone account setup is needed. The callback should return `true` if the user approves the permission, and `false` otherwise. If not provided, permission requests may silently fail on Android. ```dart showAlertDialog: () async { final result = await showDialog( context: navigatorKey.currentContext!, barrierDismissible: false, builder: (BuildContext context) { return AlertDialog( title: const Text('Permissions Required'), content: const Text('This app needs phone permissions'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: const Text('Allow'), ), ], ); }, ); return result ?? false; } ``` -------------------------------- ### Listen for Audio Session Activation Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md This snippet demonstrates how to listen for the CallKeepDidActivateAudioSession event, which is fired when the audio session is activated, typically at the start of a call. It is useful for setting up audio configurations. ```dart callKeep.on((event) { print('Audio session activated'); _setupAudio(); }); ``` -------------------------------- ### Enabling Verbose Logging in Native Code Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md To see MethodChannel calls, enable verbose logging in your native Android (Kotlin) or iOS (Swift) implementation. The exact method depends on your specific native setup. ```plaintext // In native code (Kotlin/Swift), enable verbose logging // This depends on your native implementation ``` -------------------------------- ### Prepare Go Modules Source: https://github.com/flutter-webrtc/callkeep/blob/master/tool/README.md Navigate to the tools directory and run 'go mod tidy' to ensure all Go modules are correctly managed before running the tool. ```bash cd tools && go mod tidy ``` -------------------------------- ### CallKeepDidActivateAudioSession Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-types.md Fired when the audio session is activated, typically at the start of a call. ```APIDOC ## CallKeepDidActivateAudioSession ### Description Fired when the audio session is activated (typically at call start). ### Event Type `CallKeepDidActivateAudioSession` ### Parameters This event does not have any parameters. ``` -------------------------------- ### Creating CallData Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/calldata-class.md Demonstrates the direct constructor usage for creating CallData objects programmatically, typically for initiating outgoing calls. It also shows how to use this CallData object with the callKeep.startCall method. ```APIDOC ## Creating CallData ### Description Used for programmatic creation of call data, typically for outgoing calls. ### Method Direct constructor ### Parameters - **callUUID** (string) - Required - Unique identifier for the call. - **handle** (string) - Required - The phone number or identifier for the call. - **name** (string) - Optional - The display name of the caller. - **hasVideo** (bool) - Optional - Indicates if the call involves video. - **isConnecting** (bool) - Optional - Indicates if the call is currently connecting. - **customData** (Map) - Optional - Additional custom data associated with the call. ### Usage Example ```dart final outgoingCall = CallData( 'uuid-out-123', '+9876543210', 'Jane Smith', false, false, {'initiatedBy': 'user_action'}, ); await callKeep.startCall( uuid: outgoingCall.callUUID!, handle: outgoingCall.handle!, callerName: outgoingCall.name ?? '', hasVideo: outgoingCall.hasVideo ?? false, ); ``` ``` -------------------------------- ### reportStartedCallWithUUID Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Reports that a call has started for a given UUID. This method is specific to Android and has no effect on iOS. ```APIDOC ## reportStartedCallWithUUID ### Description Reports that a call has started for a given UUID. This method is specific to Android and has no effect on iOS. ### Method Future ### Parameters #### Path Parameters - **uuid** (String) - Required - The unique identifier of the call. ### Platform Android only; no-op on iOS ``` -------------------------------- ### Main Package Entry Point Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md This code exports all public APIs from the main package entry point, making them available for use. ```dart export 'src/actions.dart'; export 'src/api.dart'; export 'src/call.dart'; export 'src/event.dart'; ``` -------------------------------- ### Use ConnectionService Features Conditionally Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Example of conditionally using ConnectionService features based on API level support. ```dart import 'package:callkeep/callkeep.dart'; if (supportConnectionService) { // Can use ConnectionService features } ``` -------------------------------- ### backToForeground Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Brings the application to the foreground. Returns false on iOS. ```APIDOC ## backToForeground ### Description Brings the application to the foreground. ### Method Future ### Platform Android; returns false on iOS ``` -------------------------------- ### Initialize CallKeep Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/README.md Sets up the CallKeep plugin with platform-specific options. Ensure you provide necessary permissions and foreground service configurations for Android. ```dart final callKeep = FlutterCallkeep(); await callKeep.setup( showAlertDialog: _showPermissionDialog, options: { 'ios': {'appName': 'MyApp'}, 'android': { 'additionalPermissions': ['android.permission.CALL_PHONE'], 'foregroundService': { 'channelId': 'com.example.myapp', 'channelName': 'My App Calls', 'notificationTitle': 'Call in progress', 'notificationIcon': 'mipmap/ic_launcher', }, }, }, ); ``` -------------------------------- ### Run iOS APNS Test Source: https://github.com/flutter-webrtc/callkeep/blob/master/tool/README.md Execute the Go tool to send a push notification to an iOS device via APNS. Replace placeholders with your actual device token. ```bash go run cmd/main.go -i +8618612345678 -p apns -d $ios_device_token ``` -------------------------------- ### System Events Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Constructors for system-related events. ```APIDOC ## System Events ### CallKeepProviderReset #### Description Represents the reset of the CallKeep provider. #### Constructor `CallKeepProviderReset()` ### CallKeepCheckReachability #### Description Represents a check for reachability. #### Constructor `CallKeepCheckReachability()` ### CallKeepDidLoadWithEvents #### Description Represents the event that CallKeep has loaded with events. #### Constructor `CallKeepDidLoadWithEvents()` ### CallKeepPushKitToken #### Description Represents the PushKit token. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `token` (String?) - The PushKit token. ``` -------------------------------- ### iOS Configuration Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Configuration options required for iOS integration. ```APIDOC ## iOS Configuration ### Required Option ```dart 'ios': { 'appName': 'MyApp', // Required - shown in CallKit UI } ``` ``` -------------------------------- ### Get Active Calls Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Retrieves a list of UUIDs for all currently active calls. Returns an empty list if no calls are active. ```dart Future> activeCalls() ``` ```dart final activeUUIDs = await callKeep.activeCalls(); print('Active calls: $activeUUIDs'); ``` -------------------------------- ### Get List of Active Calls Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Retrieves a list of UUIDs for all currently active calls. Returns a future list of strings. ```dart Future> activeCalls() async ``` -------------------------------- ### Cross-Platform Method: startCall Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md Initiates a new outgoing call. Works on both iOS and Android. ```dart startCall() ``` -------------------------------- ### Using Helper Getters for Platform Checks Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Leverage helper getters like isIOS and supportConnectionService for cleaner conditional logic when handling platform-specific CallKeep features. This is an alternative to direct Platform checks. ```dart if (isIOS) { // iOS only } else if (supportConnectionService) { // Android 6.0+ } else { // Unsupported Android version } ``` -------------------------------- ### on() Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-manager.md Subscribes to events of a particular type with a strongly-typed callback. Multiple listeners can be registered for the same event type, and they are invoked in the order they were added. ```APIDOC ## on() ### Description Subscribes to events of a particular type with a strongly-typed callback. Multiple listeners can be registered for the same event type, and they are invoked in the order they were added. ### Method Signature ```dart void on(ValueChanged listener) ``` ### Parameters #### Listener - **listener** (`ValueChanged`) - Required - Callback function that receives the event of type `T`. Signature: `void listener(T event)` ### Type Parameters - **T** — Must extend `EventType`. Determines which event type this listener subscribes to. ### Returns `void` — no return value ### Behavior - If the same listener is registered twice, the previous registration is removed and the new one is added. - Multiple listeners of the same type can be registered. - Listeners are invoked in the order they were added when an event is emitted. ### Example ```dart // Simple subscription callKeep.on((event) { print('Answer: ${event.callData.callUUID}'); }); // Type inference void handleAnswer(CallKeepPerformAnswerCallAction event) { print('Handling answer action'); } callKeep.on(handleAnswer); ``` ``` -------------------------------- ### FlutterCallkeep Singleton Factory Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md Demonstrates the singleton pattern implementation for FlutterCallkeep, ensuring a single instance is used throughout the application. This is achieved using a private constructor and a factory method. ```dart factory FlutterCallkeep() { return _instance; } static final FlutterCallkeep _instance = FlutterCallkeep._internal(); ``` -------------------------------- ### Action Events Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Constructors for various action-related events, each with a `fromMap` factory constructor. ```APIDOC ## Action Events All of these have a `fromMap` factory constructor. ### CallKeepDidReceiveStartCallAction #### Description Represents an action to start a call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callData` (CallData) - The data associated with the call. ### CallKeepPerformAnswerCallAction #### Description Represents an action to answer a call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callData` (CallData) - The data associated with the call. ### CallKeepShowIncomingCallAction #### Description Represents an action to show an incoming call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callData` (CallData) - The data associated with the call. ### CallKeepPerformEndCallAction #### Description Represents an action to end a call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callUUID` (String?) - The UUID of the call to end. ### CallKeepPerformRejectCallAction #### Description Represents an action to reject a call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callUUID` (String?) - The UUID of the call to reject. ### CallKeepDidChangeAudioAction #### Description Represents a change in the audio state of a call. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callUUID` (String?) - The UUID of the call. - `audioRoute` (int?) - The new audio route. ### CallKeepDidReceiveFailedCallAction #### Description Represents a failed call that was received. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callData` (CallData) - The data associated with the failed call. ### CallKeepDidFailCallAction #### Description Represents a call that failed. #### Factory Constructor `factory fromMap(Map arguments)` #### Fields - `callUUID` (String?) - The UUID of the failed call. - `action` (String?) - The action that led to the failure. ``` -------------------------------- ### Handle Audio Session Activation Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/platform-guide.md Listens for the CallKeepDidActivateAudioSession event, indicating that the audio session has been activated and a call is starting. Used for setting up audio routing. ```dart callKeep.on((event) { _setupAudioRouting(); }); ``` -------------------------------- ### backToForeground() Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Brings the application back to the foreground. This is particularly useful for resuming call-related activities when the app has been backgrounded. ```APIDOC ## backToForeground() ### Description Brings the app back to the foreground. This is useful for resuming call UI or activities. ### Method Future ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```dart final success = await callKeep.backToForeground(); ``` ### Response #### Success Response - **success** (bool) - `true` on Android if successful, `false` on iOS ### Platform Android; iOS returns `false` ``` -------------------------------- ### Initialize CallKeep in main() Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/configuration.md Initializes CallKeep early in the application lifecycle, typically in the main function or a splash screen, to ensure it's ready before the app starts. ```dart void main() async { WidgetsFlutterBinding.ensureInitialized(); final callKeep = FlutterCallkeep(); await callKeep.setup( showAlertDialog: _showPermissionDialog, options: _callKeepOptions, ); runApp(MyApp()); } ``` -------------------------------- ### Platform Helper Getters Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Provides helper getters to check the platform and support for connection services. ```dart bool get isIOS => Platform.isIOS; bool get supportConnectionService => !isIOS && int.parse(Platform.version) >= 23; ``` -------------------------------- ### Get FlutterCallkeep Singleton Instance Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Obtain the singleton instance of FlutterCallkeep. This method ensures that only one instance of the class is active throughout the application's lifecycle. ```dart final callKeep = FlutterCallkeep(); ``` -------------------------------- ### Run Android FCM Test Source: https://github.com/flutter-webrtc/callkeep/blob/master/tool/README.md Execute the Go tool to send a push notification to an Android device via FCM. Replace placeholders with your actual FCM token. ```bash go run cmd/main.go -i +8618612345678 -p fcm -d $android_fcm_token ``` -------------------------------- ### Integrate with FCM for Background Calls Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/README.md Handles incoming calls received via Firebase Cloud Messaging when the app is in the background. Requires CallKeep setup within the background handler. ```dart @pragma('vm:entry-point') Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { final callKeep = FlutterCallkeep(); if (!_initialized) { await callKeep.setup( options: _options, backgroundMode: true, ); _initialized = true; } final uuid = message.data['uuid']; final handle = message.data['handle']; await callKeep.displayIncomingCall( uuid: uuid, handle: handle, ); } ``` -------------------------------- ### Helper Getters Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md Utility getters to check platform-specific features. ```APIDOC ## Helper Getters ### Description Provides information about the current platform and its capabilities. ### Getters: - `isIOS` (`bool`): `true` if the platform is iOS. - `supportConnectionService` (`bool`): `true` if Android 23+ (ConnectionService supported). ### Source `src/api.dart` ``` -------------------------------- ### Initialize Logger Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/event-manager.md Instantiate the default logger for debug output. You can replace this with a custom logger instance. ```dart Logger logger = Logger(); ``` -------------------------------- ### Create Custom Event Extending EventType Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/types.md Example of creating a custom event class by extending `EventType`. Override `sanityCheck()` to implement custom validation logic before the event is emitted. ```dart class CustomCallEvent extends EventType { const CustomCallEvent(this.message); final String message; @override void sanityCheck() { if (message.isEmpty) { throw Exception('Message cannot be empty'); } } } ``` -------------------------------- ### Handle Call Actions Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/quick-start.md Listen for and respond to user actions on the call UI, such as answering, ending, muting, or holding calls. This should be set up in `initState`. ```dart @override void initState() { super.initState(); final callKeep = FlutterCallkeep(); // User answers call callKeep.on((event) { _answerCall(event.callData.callUUID!); }); // User hangs up callKeep.on((event) { _endCall(event.callUUID!); }); // User mutes callKeep.on((event) { _setMute(event.callUUID!, event.muted!); }); // User puts on hold callKeep.on((event) { _setHold(event.callUUID!, event.hold!); }); } ``` -------------------------------- ### Create CallData for Outgoing Call Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/calldata-class.md Use the direct constructor to create a CallData object for an outgoing call initiated by the application. This object is then used to start the call via the CallKeep API. ```dart // Direct constructor for app-created calls final outgoingCall = CallData( 'uuid-out-123', '+9876543210', 'Jane Smith', false, false, {'initiatedBy': 'user_action'}, ); await callKeep.startCall( uuid: outgoingCall.callUUID!, handle: outgoingCall.handle!, callerName: outgoingCall.name ?? '', hasVideo: outgoingCall.hasVideo ?? false, ); ``` -------------------------------- ### Helper Functions/Getters Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Provides helper functions and getters, such as checking if the platform is iOS and determining support for the connection service based on the platform and version. ```APIDOC ## Helper Functions/Getters ```dart bool get isIOS => Platform.isIOS; bool get supportConnectionService => !isIOS && int.parse(Platform.version) >= 23; ``` ``` -------------------------------- ### Android-Only Method: setForegroundServiceSettings Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/module-summary.md This method is specific to Android and is a no-op on iOS. ```dart setForegroundServiceSettings() ``` -------------------------------- ### Handling Incoming Call Events Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/README.md Shows how to listen for and handle the `CallKeepPerformAnswerCallAction` event, which is triggered when a user answers a call. ```dart callKeep.on((event) { print('User answered: ${event.callData.callUUID}'); }); ``` -------------------------------- ### Receiving CallData Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/calldata-class.md Illustrates how CallData objects are constructed when received from native events, using a factory constructor (fromMap) implicitly via event handlers like `callKeep.on`. ```APIDOC ## Receiving CallData ### Description Handles the construction of CallData objects when received from native events, such as incoming calls. ### Method Factory constructor (implicitly used via event listeners) ### Event Handling Example ```dart callKeep.on((event) { final incomingCall = event.callData; // Constructed via fromMap() print('Incoming: ${incomingCall.name}'); }); ``` ``` -------------------------------- ### displayIncomingCall() Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/flutter-callkeep-class.md Displays an incoming call UI on the native platform, providing details about the caller and call type. ```APIDOC ## displayIncomingCall() ### Description Displays an incoming call UI on the native platform. ### Method Signature ```dart Future displayIncomingCall({ required String uuid, required String handle, String callerName = '', String handleType = 'number', bool hasVideo = false, Map additionalData = const {}, }) ``` ### Parameters #### Optional Parameters - **callerName** (`String`) - Display name of the caller. - **handleType** (`String`) - Type of handle; typically `'number'` or `'email'`. - **hasVideo** (`bool`) - Whether the call includes video. - **additionalData** (`Map`) - Custom metadata to pass through the call system. #### Required Parameters - **uuid** (`String`) - Unique identifier for this call (must be a valid UUID). - **handle** (`String`) - Phone number or identifier of the caller. ### Returns `Future` — completes when the incoming call is displayed. ### Example ```dart await callKeep.displayIncomingCall( uuid: 'uuid-12345-abcdef', handle: '+1234567890', callerName: 'John Doe', handleType: 'number', hasVideo: false, additionalData: {'messageId': 'msg123'}, ); ``` ``` -------------------------------- ### CallData Constructor Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/calldata-class.md Creates a CallData instance with all call information. This constructor is used to initialize a CallData object with details about a specific call. ```APIDOC ## const CallData() ### Description Creates a `CallData` instance with all call information. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```dart const CallData( this.callUUID, this.handle, this.name, this.hasVideo, this.fromPushKit, this.additionalData, ) ``` ### Parameters - **callUUID** (String?) - Unique identifier for the call (typically a UUID v4) - **handle** (String?) - Phone number, SIP URI, or other identifier of the remote party - **name** (String?) - Display name of the remote party - **hasVideo** (bool?) - Whether the call includes video capability - **fromPushKit** (bool?) - Whether this call originated from a PushKit notification (iOS) - **additionalData** (Map?) - Custom metadata and context for the call ### Returns `CallData` instance ### Example ```dart final callData = CallData( 'uuid-12345-abcdef-67890', '+1234567890', 'John Doe', false, true, {'messageId': 'msg123', 'priority': 'high'}, ); ``` ``` -------------------------------- ### CallKeepPushKitToken Constructor Source: https://github.com/flutter-webrtc/callkeep/blob/master/_autodocs/api-reference/method-signatures.md Represents the PushKit token for receiving push notifications. It includes the token string. ```dart class CallKeepPushKitToken { factory fromMap(Map arguments) final String? token; } ```