@tencent-rtc/mcp 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resource/doc/callkit/core-sdk/android/answer-call.md +852 -0
- package/resource/doc/callkit/core-sdk/android/make-call.md +954 -0
- package/resource/doc/callkit/core-sdk/android/offline-push.md +361 -0
- package/resource/doc/callkit/core-sdk/flutter/answer-call.md +1160 -0
- package/resource/doc/callkit/core-sdk/flutter/make-call.md +1205 -0
- package/resource/doc/callkit/core-sdk/flutter/offline-push.md +398 -0
- package/resource/doc/callkit/core-sdk/ios/answer-call.md +1090 -0
- package/resource/doc/callkit/core-sdk/ios/make-call.md +1248 -0
- package/resource/doc/callkit/core-sdk/ios/offline-push.md +485 -0
- package/resource/doc/callkit/core-sdk/uni-app/answer-call.md +950 -0
- package/resource/doc/callkit/core-sdk/uni-app/make-call.md +1052 -0
- package/resource/doc/callkit/preset/android/integration.md +1 -1
- package/resource/doc/callkit/preset/flutter/integration.md +1 -1
- package/resource/doc/callkit/preset/ios/integration.md +1 -1
- package/resource/doc/callkit/preset/react/api.md +1 -1
- package/resource/doc/callkit/preset/vue/api.md +1 -1
- package/server.js +1 -1
- package/tools/call/get_native_callkit_core_integration.js +67 -0
- package/tools/call/get_native_callkit_core_integration.js.map +1 -0
- package/tools/common/present_framework_choice.js +1 -1
- package/tools/common/present_framework_choice.js.map +1 -1
- package/tools/common/record_skill_session.js +17 -6
- package/tools/common/record_skill_session.js.map +1 -1
- package/tools/definitions/get_native_call_uikit_integration_def.js +9 -3
- package/tools/definitions/get_native_call_uikit_integration_def.js.map +1 -1
- package/tools/definitions/get_native_callkit_core_integration_def.js +63 -0
- package/tools/definitions/get_native_callkit_core_integration_def.js.map +1 -0
- package/tools/index.js +2 -0
- package/tools/index.js.map +1 -1
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
- package/utils/report-runtime-error-cls-client.js +91 -0
- package/utils/report-runtime-error-cls-client.js.map +1 -0
|
@@ -0,0 +1,1160 @@
|
|
|
1
|
+
This document will guide you through integrating the **AtomicXCore SDK** components — **DeviceStore**, **CallStore**, and the core widget **CallCoreView** — to quickly implement call answering functionality.
|
|
2
|
+
|
|
3
|
+
## Core Features
|
|
4
|
+
|
|
5
|
+
To build multi-party audio/video call scenarios with **AtomicXCore**, use these three core modules:
|
|
6
|
+
|
|
7
|
+
| **Module** | **Description** |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [CallCoreView](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreView-class.html) | Core call view widget. Automatically listens to CallStore data and renders the call UI, with automatic layout switching for 1-on-1 and group calls. |
|
|
10
|
+
| [CallStore](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallStore-class.html) | Manages the call lifecycle, including dialing, answering, rejecting, and hanging up. Provides real-time participant audio/video status, call duration, call history, and other data. |
|
|
11
|
+
| [DeviceStore](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_device_device_store/DeviceStore-class.html) | Controls audio/video devices: microphone (toggle/volume), camera (toggle/switch/quality), screen sharing, and real-time device status monitoring. |
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
### Step 1: Activate the Service
|
|
16
|
+
|
|
17
|
+
Follow the **Activate the Service** guide to obtain either a trial or paid version of the SDK.
|
|
18
|
+
|
|
19
|
+
### Step 2: Integrate the SDK
|
|
20
|
+
|
|
21
|
+
**Install the package:** In your project root, run the following command to install the `atomic_x_core` plugin.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
flutter pub add atomic_x_core
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Step 3: Initialization and Login
|
|
28
|
+
|
|
29
|
+
#### Android Configuration
|
|
30
|
+
|
|
31
|
+
1. Because the SDK uses Java reflection internally, you must add certain SDK classes to your ProGuard keep list.
|
|
32
|
+
|
|
33
|
+
Edit your project's `build.gradle.kts` (or `build.gradle`) in the `android/app/` directory to enable ProGuard rules:
|
|
34
|
+
|
|
35
|
+
**build.gradle.kts:**
|
|
36
|
+
|
|
37
|
+
```kotlin
|
|
38
|
+
android {
|
|
39
|
+
buildTypes {
|
|
40
|
+
release {
|
|
41
|
+
isMinifyEnabled = true
|
|
42
|
+
proguardFiles(
|
|
43
|
+
getDefaultProguardFile("proguard-android.txt"),
|
|
44
|
+
"proguard-rules.pro"
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**build.gradle:**
|
|
52
|
+
|
|
53
|
+
```groovy
|
|
54
|
+
android {
|
|
55
|
+
buildTypes {
|
|
56
|
+
release {
|
|
57
|
+
minifyEnabled true
|
|
58
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Create a `proguard-rules.pro` file in your `android/app` directory and add:
|
|
65
|
+
|
|
66
|
+
```proguard
|
|
67
|
+
-keep class com.tencent.** { *; }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
2. (Optional) To use CallKit's floating window feature outside the app, enable system Picture-in-Picture.
|
|
71
|
+
|
|
72
|
+
In your `AndroidManifest.xml`, set `android:supportsPictureInPicture="true"` for `MainActivity`:
|
|
73
|
+
|
|
74
|
+
```xml
|
|
75
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
76
|
+
<application>
|
|
77
|
+
<activity
|
|
78
|
+
android:name=".MainActivity"
|
|
79
|
+
android:supportsPictureInPicture="true"
|
|
80
|
+
</activity>
|
|
81
|
+
</application>
|
|
82
|
+
</manifest>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### iOS Configuration
|
|
86
|
+
|
|
87
|
+
Since `tencent_rtc_sdk` uses Flutter FFI, Xcode's symbol stripping during Release builds may remove TRTC C symbols, causing `symbol not found` errors. To fix:
|
|
88
|
+
|
|
89
|
+
1. In Xcode **Build Settings**, set **Deployment Postprocessing** to **Yes**.
|
|
90
|
+
2. Set **Strip Style** for **Release** to **Non-Global Symbols**.
|
|
91
|
+
|
|
92
|
+
#### Initialize and Log in
|
|
93
|
+
|
|
94
|
+
Before you can answer calls, complete these steps in order:
|
|
95
|
+
|
|
96
|
+
1. **Create `CallStore`:** `CallStore.shared` initializes the call data layer.
|
|
97
|
+
2. **Log in the user:** call `LoginStore.shared.login(sdkAppId, userId, userSig)` to complete IM login.
|
|
98
|
+
3. **Initialize the call engine:** call `TUICallEngine.instance.init(sdkAppId, userId, userSig)` to initialize the TRTC call signaling engine (**required**; omitting this may prevent calls from being placed or received correctly).
|
|
99
|
+
|
|
100
|
+
Example:
|
|
101
|
+
|
|
102
|
+
```dart
|
|
103
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
104
|
+
import 'package:rtc_room_engine/api/call/tui_call_engine.dart';
|
|
105
|
+
|
|
106
|
+
Future<void> _login() async {
|
|
107
|
+
int sdkAppId = 1400000001; // Replace with your SDKAppID
|
|
108
|
+
String userId = 'test_001'; // Replace with your UserID
|
|
109
|
+
String userSig = 'xxxxxxxxxxx'; // Use a temporary userSig during development; when MCP is configured with sdkAppId and sdkSecretKey, the tool can issue it for you
|
|
110
|
+
|
|
111
|
+
CallStore.shared;
|
|
112
|
+
final result = await LoginStore.shared.login(sdkAppId, userId, userSig);
|
|
113
|
+
TUICallEngine.instance.init(sdkAppId, userId, userSig);
|
|
114
|
+
if (result.isSuccess) {
|
|
115
|
+
// Login successful
|
|
116
|
+
debugPrint('login success');
|
|
117
|
+
} else {
|
|
118
|
+
// Login failed
|
|
119
|
+
debugPrint('login failed, code: ${result.code}, message: ${result.message}');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
| **Parameter** | **Type** | **Description** |
|
|
125
|
+
| --- | --- | --- |
|
|
126
|
+
| `userId` | String | Unique user ID, up to **32 bytes**, with **no special characters**; use letters and digits. Avoid simple IDs like `1` or `123` to reduce multi-device conflicts. |
|
|
127
|
+
| `sdkAppId` | int | Obtain from the console. Usually a 10-digit integer starting with `140` or `160`. |
|
|
128
|
+
| `userSig` | String | Authentication token for TRTC. For development, generate `userSig` locally using [GenerateTestUserSig.genTestUserSig](https://github.com/Tencent-RTC/TUIKit_Flutter/blob/main/call/example/lib/debug/generate_test_user_sig.dart) for temporary use. When the **Tencent RTC MCP Server** is configured with `sdkAppId` and `sdkSecretKey`, the tool can auto-issue a `userSig` for you. For production, always generate `userSig` on your server to protect your secret key. |
|
|
129
|
+
|
|
130
|
+
## Implement Call Answering
|
|
131
|
+
|
|
132
|
+
**You must be logged in before you can answer a call.** Follow these six steps to implement the call answering feature.
|
|
133
|
+
|
|
134
|
+
### Step 1: Create the Call Page
|
|
135
|
+
|
|
136
|
+
Create a call page that is shown when an incoming call arrives.
|
|
137
|
+
|
|
138
|
+
1. **Create the call page:** Implement a `StatefulWidget` to host the call page and manage navigation for incoming calls.
|
|
139
|
+
|
|
140
|
+
2. **Add CallCoreView widget to the call page:** The core call UI requires a controller and automatically listens to CallStore data. It will render the UI and adapt layouts for both 1-on-1 and group calls.
|
|
141
|
+
|
|
142
|
+
```dart
|
|
143
|
+
import 'package:flutter/material.dart';
|
|
144
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
145
|
+
|
|
146
|
+
// 1. Create Call Page Widget
|
|
147
|
+
class CallPage extends StatefulWidget {
|
|
148
|
+
const CallPage({super.key});
|
|
149
|
+
|
|
150
|
+
@override
|
|
151
|
+
State<CallPage> createState() => _CallPageState();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
class _CallPageState extends State<CallPage> {
|
|
155
|
+
late CallCoreController controller;
|
|
156
|
+
|
|
157
|
+
@override
|
|
158
|
+
void initState() {
|
|
159
|
+
super.initState();
|
|
160
|
+
controller = CallCoreController.create();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@override
|
|
164
|
+
Widget build(BuildContext context) {
|
|
165
|
+
// 2. Add CallCoreView widget to Call Page
|
|
166
|
+
return CallCoreView(controller: controller);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**CallCoreView Widget Feature Overview:**
|
|
172
|
+
|
|
173
|
+
| **Feature** | **Description** | **Reference** |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| Set layout mode | Supports flexible layout mode switching. If unset, layout automatically adapts based on participant count. | Switch Layout Mode |
|
|
176
|
+
| Set avatar | Supports custom avatars for specific users via resource path. | Customize Default Avatar |
|
|
177
|
+
| Set volume indicator icon | Supports custom volume indicator icons for different volume levels. | Customize Volume Indicator Icon |
|
|
178
|
+
| Set network indicator icon | Supports real-time network quality indicator icons. | Customize Network Indicator Icon |
|
|
179
|
+
| Set waiting animation | In group calls, supports GIF animation for users in waiting state. | Customize Loading Animation |
|
|
180
|
+
|
|
181
|
+
### Step 2: Add Answer and Reject Buttons
|
|
182
|
+
|
|
183
|
+
Use the APIs from [DeviceStore](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_device_device_store/DeviceStore-class.html) and [CallStore](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallStore-class.html) to customize your buttons.
|
|
184
|
+
|
|
185
|
+
- **DeviceStore overview:** Microphone (toggle/volume), camera (toggle/switch/quality), screen sharing, and real-time device monitoring. Bind method calls to button taps and listen for device state changes to update button UI dynamically.
|
|
186
|
+
- **CallStore overview:** Core call controls (answer, hang up, reject). Bind method calls to button taps and listen for call state changes to sync button display with call status.
|
|
187
|
+
- **Icon resource download:** Button icons are available on [GitHub](https://github.com/Tencent-RTC/TUIKit_Flutter/tree/main/atomic-x/call_assets). These icons are custom-designed for TUICallKit and are free to use.
|
|
188
|
+
|
|
189
|
+
**Available Icon Resources:**
|
|
190
|
+
|
|
191
|
+
| **Resource** | **Description** | **Download** |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
| `callview_ic_dialing.png` | Answer/accept call icon. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_dialing.png) |
|
|
194
|
+
| `callview_ic_hangup.png` | Hang up / reject call icon. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_hangup.png) |
|
|
195
|
+
| `callview_ic_handsfree_enable.png` | Hands-free enabled icon. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_handsfree_enable.png) |
|
|
196
|
+
| `callview_ic_handsfree_disable.png` | Hands-free disabled icon. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_handsfree_disable.png) |
|
|
197
|
+
|
|
198
|
+
1. **Add Answer and Reject Buttons:** Create a button bar at the bottom and add **Answer** and **Reject** buttons. Bind their tap events to the [accept](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallStore/accept.html) and [reject](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallStore/reject.html) methods.
|
|
199
|
+
|
|
200
|
+
```dart
|
|
201
|
+
import 'package:flutter/material.dart';
|
|
202
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
203
|
+
|
|
204
|
+
// Answer and Reject Buttons Widget
|
|
205
|
+
class AcceptRejectButtons extends StatelessWidget {
|
|
206
|
+
const AcceptRejectButtons({super.key});
|
|
207
|
+
|
|
208
|
+
@override
|
|
209
|
+
Widget build(BuildContext context) {
|
|
210
|
+
return Row(
|
|
211
|
+
children: [
|
|
212
|
+
// Answer Button
|
|
213
|
+
_buildAcceptButton(),
|
|
214
|
+
// Reject Button
|
|
215
|
+
_buildRejectButton(),
|
|
216
|
+
],
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Answer Button
|
|
221
|
+
Widget _buildAcceptButton() {
|
|
222
|
+
return GestureDetector(
|
|
223
|
+
onTap: () {
|
|
224
|
+
// Call accept API to answer the call
|
|
225
|
+
CallStore.shared.accept();
|
|
226
|
+
},
|
|
227
|
+
child: Container(
|
|
228
|
+
width: 60,
|
|
229
|
+
height: 60,
|
|
230
|
+
decoration: const BoxDecoration(
|
|
231
|
+
color: Colors.green,
|
|
232
|
+
shape: BoxShape.circle,
|
|
233
|
+
),
|
|
234
|
+
child: const Icon(
|
|
235
|
+
Icons.call,
|
|
236
|
+
color: Colors.white,
|
|
237
|
+
size: 30,
|
|
238
|
+
),
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Reject Button
|
|
244
|
+
Widget _buildRejectButton() {
|
|
245
|
+
return GestureDetector(
|
|
246
|
+
onTap: () {
|
|
247
|
+
// Call reject API to reject the call
|
|
248
|
+
CallStore.shared.reject();
|
|
249
|
+
},
|
|
250
|
+
child: Container(
|
|
251
|
+
width: 60,
|
|
252
|
+
height: 60,
|
|
253
|
+
decoration: const BoxDecoration(
|
|
254
|
+
color: Colors.red,
|
|
255
|
+
shape: BoxShape.circle,
|
|
256
|
+
),
|
|
257
|
+
child: const Icon(
|
|
258
|
+
Icons.call_end,
|
|
259
|
+
color: Colors.white,
|
|
260
|
+
size: 30,
|
|
261
|
+
),
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
2. **Destroy the UI when the caller cancels or the callee rejects:** When the caller cancels the call or the callee rejects, the [onCallEnded](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallEventListener/onCallEnded.html) event fires. Listen for this event and close the call UI when the call ends.
|
|
269
|
+
|
|
270
|
+
```dart
|
|
271
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
272
|
+
import 'package:flutter/cupertino.dart';
|
|
273
|
+
|
|
274
|
+
void addListener() {
|
|
275
|
+
CallEventListener listener = CallEventListener(
|
|
276
|
+
onCallEnded: (callId, mediaType, reason, userId) {
|
|
277
|
+
Navigator.of(context).pop();
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
CallStore.shared.addListener(listener);
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**onCallEnded Event Parameter Details:**
|
|
285
|
+
|
|
286
|
+
| **Parameter** | **Type** | **Description** |
|
|
287
|
+
| --- | --- | --- |
|
|
288
|
+
| `callId` | String | Unique identifier for this call. |
|
|
289
|
+
| `mediaType` | CallMediaType | Type of call, either audio or video. `CallMediaType.video`: Video call. `CallMediaType.audio`: Audio call. |
|
|
290
|
+
| `reason` | CallEndReason | Reason for call ending. Possible values: `unknown`, `hangup`, `reject`, `noResponse`, `offline`, `lineBusy`, `canceled`, `otherDeviceAccepted`, `otherDeviceReject`, `endByServer`. |
|
|
291
|
+
| `userId` | String | User ID responsible for ending the call. |
|
|
292
|
+
|
|
293
|
+
### Step 3: Request Microphone and Camera Permissions
|
|
294
|
+
|
|
295
|
+
Check audio/video permissions before answering a call. If anything is missing, guide the user to grant it at runtime.
|
|
296
|
+
|
|
297
|
+
1. **Android permission declaration:**
|
|
298
|
+
|
|
299
|
+
Declare microphone and camera permissions in `AndroidManifest.xml`.
|
|
300
|
+
|
|
301
|
+
```xml
|
|
302
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
303
|
+
<!-- Microphone permission -->
|
|
304
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
305
|
+
<!-- Camera permission -->
|
|
306
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
307
|
+
</manifest>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
2. **iOS permission declaration:**
|
|
311
|
+
|
|
312
|
+
Under the root `<dict>` in your iOS app's `Info.plist`, add:
|
|
313
|
+
|
|
314
|
+
```xml
|
|
315
|
+
<key>NSCameraUsageDescription</key>
|
|
316
|
+
<string>CallingApp needs access to your camera to record video with visuals</string>
|
|
317
|
+
<key>NSMicrophoneUsageDescription</key>
|
|
318
|
+
<string>CallingApp needs access to your microphone to record video with audio</string>
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
3. **Dynamic permission requests:** We recommend the `permission_handler` plugin:
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
flutter pub add permission_handler
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
4. **iOS Podfile configuration (required):**
|
|
328
|
+
|
|
329
|
+
On iOS, `permission_handler` uses preprocessor macros per permission type; by default macros are **0** (off). You **must** enable the ones you need in `ios/Podfile` inside `post_install`, or permission requests may return **`denied`** immediately without showing the system dialog.
|
|
330
|
+
|
|
331
|
+
Edit `post_install`:
|
|
332
|
+
|
|
333
|
+
```ruby
|
|
334
|
+
post_install do |installer|
|
|
335
|
+
installer.pods_project.targets.each do |target|
|
|
336
|
+
flutter_additional_ios_build_settings(target)
|
|
337
|
+
target.build_configurations.each do |config|
|
|
338
|
+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
|
|
339
|
+
'$(inherited)',
|
|
340
|
+
'PERMISSION_CAMERA=1',
|
|
341
|
+
'PERMISSION_MICROPHONE=1',
|
|
342
|
+
]
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
> **Note:** After changing `Podfile`, run `cd ios && pod install` again so the change takes effect.
|
|
349
|
+
|
|
350
|
+
5. **Request at runtime:** Before answering a call, call:
|
|
351
|
+
|
|
352
|
+
```dart
|
|
353
|
+
import 'package:permission_handler/permission_handler.dart';
|
|
354
|
+
|
|
355
|
+
// Request audio/video permissions
|
|
356
|
+
Future<bool> requestCallPermissions() async {
|
|
357
|
+
// Request microphone and camera permissions
|
|
358
|
+
Map<Permission, PermissionStatus> statuses = await [
|
|
359
|
+
Permission.microphone,
|
|
360
|
+
Permission.camera,
|
|
361
|
+
].request();
|
|
362
|
+
|
|
363
|
+
// Check permission status
|
|
364
|
+
bool micGranted = statuses[Permission.microphone]?.isGranted ?? false;
|
|
365
|
+
bool cameraGranted = statuses[Permission.camera]?.isGranted ?? false;
|
|
366
|
+
|
|
367
|
+
if (micGranted && cameraGranted) {
|
|
368
|
+
// Permissions granted
|
|
369
|
+
return true;
|
|
370
|
+
} else {
|
|
371
|
+
// Some permissions denied, prompt user to enable
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Step 4: Handle Incoming Call Notifications
|
|
378
|
+
|
|
379
|
+
Listen to the current user's call status and play a ringtone or vibrate on incoming calls. Stop notifications after the call is answered or hung up.
|
|
380
|
+
|
|
381
|
+
1. **Data Layer Subscription:** Subscribe to `CallStore.shared.state.selfInfo` to reactively track the logged-in user's info.
|
|
382
|
+
|
|
383
|
+
2. **Play or Stop Notifications:** If `selfInfo.status` is `CallParticipantStatus.waiting`, play ringtone/vibration; if `CallParticipantStatus.accept`, stop the notification.
|
|
384
|
+
|
|
385
|
+
```dart
|
|
386
|
+
CallStore.shared.state.selfInfo.addListener(() {
|
|
387
|
+
CallParticipantInfo info = CallStore.shared.state.selfInfo.value;
|
|
388
|
+
if (info.status == CallParticipantStatus.accept || info.status == CallParticipantStatus.none) {
|
|
389
|
+
// Stop ringtone
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (info.status == CallParticipantStatus.waiting) {
|
|
393
|
+
// Play ringtone
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Step 5: Open Media Devices for Incoming Calls
|
|
399
|
+
|
|
400
|
+
When an incoming call arrives, get the media type from [onCallReceived](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallEventListener/onCallReceived.html). For a smoother experience, pre-open relevant media devices when showing the call UI.
|
|
401
|
+
|
|
402
|
+
1. **Listen to Incoming Call Event:** Subscribe to the `onCallReceived` event.
|
|
403
|
+
|
|
404
|
+
2. **Open Devices According to Media Type:** For audio calls, open only the microphone; for video calls, open both microphone and camera.
|
|
405
|
+
|
|
406
|
+
```dart
|
|
407
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
408
|
+
|
|
409
|
+
CallEventListener? callListener;
|
|
410
|
+
|
|
411
|
+
void initCallListener() {
|
|
412
|
+
// 1. Listen for incoming call event
|
|
413
|
+
callListener = CallEventListener(
|
|
414
|
+
onCallReceived: (callId, mediaType, userData) {
|
|
415
|
+
// 2. Open devices based on media type
|
|
416
|
+
openDeviceForMediaType(mediaType);
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
if (callListener != null) {
|
|
420
|
+
CallStore.shared.addListener(callListener!);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
void openDeviceForMediaType(CallMediaType? mediaType) {
|
|
425
|
+
if (mediaType == null) return;
|
|
426
|
+
DeviceStore.shared.openLocalMicrophone();
|
|
427
|
+
if (mediaType == CallMediaType.video) {
|
|
428
|
+
final isFrontCamera = DeviceStore.shared.state.isFrontCamera.value;
|
|
429
|
+
DeviceStore.shared.openLocalCamera(isFrontCamera);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**onCallReceived Event Details:**
|
|
435
|
+
|
|
436
|
+
| **Parameter** | **Type** | **Description** |
|
|
437
|
+
| --- | --- | --- |
|
|
438
|
+
| `callId` | String | Unique identifier for this call. |
|
|
439
|
+
| `mediaType` | CallMediaType | Call type: audio or video. `CallMediaType.video`: Video call. `CallMediaType.audio`: Audio call. |
|
|
440
|
+
|
|
441
|
+
**openLocalCamera API Parameter Details:**
|
|
442
|
+
|
|
443
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
444
|
+
| --- | --- | --- | --- |
|
|
445
|
+
| `isFront` | bool | Yes | Whether to open the front camera. `true`: Open front camera. `false`: Open rear camera. |
|
|
446
|
+
| `completion` | CompletionHandler | No | Completion callback for camera open result. Returns error code and message if opening fails. |
|
|
447
|
+
|
|
448
|
+
**openLocalMicrophone API Parameter Details:**
|
|
449
|
+
|
|
450
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
451
|
+
| --- | --- | --- | --- |
|
|
452
|
+
| `completion` | CompletionHandler | No | Completion callback for microphone open result. Returns error code and message if opening fails. |
|
|
453
|
+
|
|
454
|
+
### Step 6: Launch Call UI on Incoming Call
|
|
455
|
+
|
|
456
|
+
After subscribing to the [onCallReceived](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallEventListener/onCallReceived.html) event, launch the call page:
|
|
457
|
+
|
|
458
|
+
```dart
|
|
459
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
460
|
+
import 'package:flutter/material.dart';
|
|
461
|
+
|
|
462
|
+
CallEventListener? callListener;
|
|
463
|
+
|
|
464
|
+
void addListener(BuildContext context) {
|
|
465
|
+
callListener = CallEventListener(
|
|
466
|
+
onCallReceived: (callId, mediaType, userData) {
|
|
467
|
+
// Launch call page (using Navigator)
|
|
468
|
+
Navigator.push(
|
|
469
|
+
context,
|
|
470
|
+
MaterialPageRoute(builder: (context) => const CallPage()),
|
|
471
|
+
);
|
|
472
|
+
},
|
|
473
|
+
);
|
|
474
|
+
if (callListener != null) {
|
|
475
|
+
CallStore.shared.addListener(callListener!);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
## Integrate Offline Push
|
|
481
|
+
|
|
482
|
+
To receive call invitations while the app is offline, follow the dedicated **Integration Offline Push** guide for Flutter.
|
|
483
|
+
|
|
484
|
+
## Customize the UI
|
|
485
|
+
|
|
486
|
+
`CallCoreView` supports extensive UI customization. You can freely replace avatar and volume indicator icons. For fast integration, download these icons from [GitHub](https://github.com/Tencent-RTC/TUIKit_Flutter/tree/main/atomic-x/call_assets). All icons are custom-designed for TUICallKit and are copyright-free.
|
|
487
|
+
|
|
488
|
+
### Custom Volume Indicator Icons
|
|
489
|
+
|
|
490
|
+
Use the [volumeIcons](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreView/volumeIcons.html) parameter in `CallCoreView` to set icons for various volume levels.
|
|
491
|
+
|
|
492
|
+
**Sample Code:**
|
|
493
|
+
|
|
494
|
+
```dart
|
|
495
|
+
Widget _buildCallCoreView() {
|
|
496
|
+
Map<VolumeLevel, Image> volumeIcons = {
|
|
497
|
+
VolumeLevel.mute: Image.asset(''), // Icon for each volume level
|
|
498
|
+
};
|
|
499
|
+
return CallCoreView(
|
|
500
|
+
controller: CallCoreController.create(),
|
|
501
|
+
volumeIcons: volumeIcons,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**volumeIcons Parameter Details:**
|
|
507
|
+
|
|
508
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
509
|
+
| --- | --- | --- | --- |
|
|
510
|
+
| `volumeIcons` | Map | No | Maps volume levels to icon resources. Keys: `VolumeLevel.mute` (muted), `VolumeLevel.low` (0-25], `VolumeLevel.medium` (25-50], `VolumeLevel.high` (50-75], `VolumeLevel.peak` (75-100]. Values: icons for each level. |
|
|
511
|
+
|
|
512
|
+
**Volume Indicator Icons:**
|
|
513
|
+
|
|
514
|
+
| **Resource** | **Description** | **Download** |
|
|
515
|
+
| --- | --- | --- |
|
|
516
|
+
| `callview_ic_audio_input.png` | Volume indicator. Recommended for `VolumeLevel.low` or `VolumeLevel.medium`. Display when user volume exceeds this level. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_audio_input.png) |
|
|
517
|
+
| `callview_ic_self_mute.png` | Mute icon. Recommended for `VolumeLevel.mute`. Display when user is muted. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_self_mute.png) |
|
|
518
|
+
|
|
519
|
+
### Custom Network Indicator Icons
|
|
520
|
+
|
|
521
|
+
Use the [networkQualityIcons](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreView/networkQualityIcons.html) parameter to set icons for different network states.
|
|
522
|
+
|
|
523
|
+
**Sample Code:**
|
|
524
|
+
|
|
525
|
+
```dart
|
|
526
|
+
Widget _buildCallCoreView() {
|
|
527
|
+
Map<NetworkQuality, Image> networkQualityIcons = {
|
|
528
|
+
NetworkQuality.bad: Image.asset(''), // Icon for each network quality level
|
|
529
|
+
};
|
|
530
|
+
return CallCoreView(
|
|
531
|
+
controller: CallCoreController.create(),
|
|
532
|
+
networkQualityIcons: networkQualityIcons,
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
**networkQualityIcons Parameter Details:**
|
|
538
|
+
|
|
539
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
540
|
+
| --- | --- | --- | --- |
|
|
541
|
+
| `networkQualityIcons` | Map | No | Maps network quality levels to icon resources. Keys: `NetworkQuality.unknown`, `NetworkQuality.excellent`, `NetworkQuality.good`, `NetworkQuality.poor`, `NetworkQuality.bad`, `NetworkQuality.veryBad`, `NetworkQuality.down`. Values: icons for each state. |
|
|
542
|
+
|
|
543
|
+
**Poor Network Indicator Icon:**
|
|
544
|
+
|
|
545
|
+
| **Resource** | **Description** | **Download** |
|
|
546
|
+
| --- | --- | --- |
|
|
547
|
+
| `callview_ic_network_bad.png` | Poor network indicator. Recommended for `NetworkQuality.bad`, `NetworkQuality.veryBad`, or `NetworkQuality.down`. Display when connection is poor. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_network_bad.png) |
|
|
548
|
+
|
|
549
|
+
### Custom Default Avatar
|
|
550
|
+
|
|
551
|
+
Use the [defaultAvatar](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreView/defaultAvatar.html) parameter to set a default avatar for users. Listen to [allParticipants](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallState/allParticipants.html) for participant avatars. If unavailable or loading fails, show the default avatar.
|
|
552
|
+
|
|
553
|
+
**Sample Code:**
|
|
554
|
+
|
|
555
|
+
```dart
|
|
556
|
+
Widget _buildCallCoreView() {
|
|
557
|
+
Image defaultAvatarImage = Image.asset(''); // Default user avatar image
|
|
558
|
+
return CallCoreView(
|
|
559
|
+
controller: CallCoreController.create(),
|
|
560
|
+
defaultAvatar: defaultAvatarImage,
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**defaultAvatar Parameter Details:**
|
|
566
|
+
|
|
567
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
568
|
+
| --- | --- | --- | --- |
|
|
569
|
+
| `defaultAvatar` | Image | No | Default user avatar. |
|
|
570
|
+
|
|
571
|
+
**Default Avatar Resource:**
|
|
572
|
+
|
|
573
|
+
| **Resource** | **Description** | **Download** |
|
|
574
|
+
| --- | --- | --- |
|
|
575
|
+
| `callview_ic_avatar.png` | Default avatar. Recommended when loading fails or no avatar is set. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_avatar.png) |
|
|
576
|
+
|
|
577
|
+
### Custom Loading Animation
|
|
578
|
+
|
|
579
|
+
Use the [loadingAnimation](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreView/loadingAnimation.html) parameter to set a waiting animation for users in pending state.
|
|
580
|
+
|
|
581
|
+
**Sample Code:**
|
|
582
|
+
|
|
583
|
+
```dart
|
|
584
|
+
Widget _buildCallCoreView() {
|
|
585
|
+
Image loading = Image.asset(''); // Default loading animation resource
|
|
586
|
+
return CallCoreView(
|
|
587
|
+
controller: CallCoreController.create(),
|
|
588
|
+
loadingAnimation: loading,
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**loadingAnimation Parameter Details:**
|
|
594
|
+
|
|
595
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
596
|
+
| --- | --- | --- | --- |
|
|
597
|
+
| `loadingAnimation` | Image | No | GIF image resource. |
|
|
598
|
+
|
|
599
|
+
**Waiting Animation:**
|
|
600
|
+
|
|
601
|
+
| **Resource** | **Description** | **Download** |
|
|
602
|
+
| --- | --- | --- |
|
|
603
|
+
| `callview_ic_loading.gif` | Waiting animation for users. Recommended for group calls; display when user status is `waiting`. | [GitHub](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/atomic_x/src/main/res-callview/drawable-xxhdpi/callview_ic_loading.gif) |
|
|
604
|
+
|
|
605
|
+
### Add Call Duration Indicator
|
|
606
|
+
|
|
607
|
+
Call duration updates in real time via [activeCall](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallState/activeCall.html) `duration`. To display call duration:
|
|
608
|
+
|
|
609
|
+
1. **Subscribe to Data:** Listen to `CallStore.shared.state.activeCall` for the current active call.
|
|
610
|
+
2. **Bind Call Duration:** Bind the `activeCall.duration` field to a UI widget. This is reactive and auto-updates the UI — no manual timer needed.
|
|
611
|
+
|
|
612
|
+
```dart
|
|
613
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
614
|
+
import 'package:flutter/material.dart';
|
|
615
|
+
|
|
616
|
+
class TimerWidget extends StatelessWidget {
|
|
617
|
+
final double? fontSize;
|
|
618
|
+
final FontWeight? fontWeight;
|
|
619
|
+
|
|
620
|
+
const TimerWidget({
|
|
621
|
+
super.key,
|
|
622
|
+
this.fontSize,
|
|
623
|
+
this.fontWeight,
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
@override
|
|
627
|
+
Widget build(BuildContext context) {
|
|
628
|
+
return ValueListenableBuilder(
|
|
629
|
+
valueListenable: CallStore.shared.state.selfInfo,
|
|
630
|
+
builder: (context, info, child) {
|
|
631
|
+
if (info.status == CallParticipantStatus.accept) {
|
|
632
|
+
return ValueListenableBuilder(
|
|
633
|
+
valueListenable: CallStore.shared.state.activeCall,
|
|
634
|
+
builder: (context, activeCall, child) {
|
|
635
|
+
return Text(
|
|
636
|
+
formatDuration(activeCall.duration.toInt()),
|
|
637
|
+
style: TextStyle(
|
|
638
|
+
fontSize: fontSize,
|
|
639
|
+
fontWeight: fontWeight,
|
|
640
|
+
),
|
|
641
|
+
);
|
|
642
|
+
},
|
|
643
|
+
);
|
|
644
|
+
} else {
|
|
645
|
+
return Container();
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
String formatDuration(int timeCount) {
|
|
652
|
+
int hour = timeCount ~/ 3600;
|
|
653
|
+
int minute = (timeCount % 3600) ~/ 60;
|
|
654
|
+
String minuteShow = minute <= 9 ? "0$minute" : "$minute";
|
|
655
|
+
int second = timeCount % 60;
|
|
656
|
+
String secondShow = second <= 9 ? "0$second" : "$second";
|
|
657
|
+
|
|
658
|
+
if (hour > 0) {
|
|
659
|
+
String hourShow = hour <= 9 ? "0$hour" : "$hour";
|
|
660
|
+
return '$hourShow:$minuteShow:$secondShow';
|
|
661
|
+
} else {
|
|
662
|
+
return '$minuteShow:$secondShow';
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
> **Note:**
|
|
669
|
+
>
|
|
670
|
+
> For more reactive call state data, see [CallState](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallState-class.html).
|
|
671
|
+
|
|
672
|
+
## More Features
|
|
673
|
+
|
|
674
|
+
### Set Avatar and Nickname
|
|
675
|
+
|
|
676
|
+
Before the call starts, use [setSelfInfo](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_login_login_store/LoginStore/setSelfInfo.html) to set your nickname and avatar.
|
|
677
|
+
|
|
678
|
+
**Sample Code:**
|
|
679
|
+
|
|
680
|
+
```dart
|
|
681
|
+
UserProfile profile = UserProfile(
|
|
682
|
+
userID: "", // Your UserId
|
|
683
|
+
avatarURL: "", // Avatar URL
|
|
684
|
+
nickname: "", // Nickname to set
|
|
685
|
+
);
|
|
686
|
+
CompletionHandler result = await LoginStore.shared.setSelfInfo(userInfo: profile);
|
|
687
|
+
if (result.errorCode == 0) {
|
|
688
|
+
print("setSelfInfo success");
|
|
689
|
+
} else {
|
|
690
|
+
print("setSelfInfo failed");
|
|
691
|
+
}
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
**setSelfInfo API Parameter Details:**
|
|
695
|
+
|
|
696
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
697
|
+
| --- | --- | --- | --- |
|
|
698
|
+
| `userProfile` | [UserProfile](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_login_login_store/UserProfile-class.html) | Yes | User info struct: `userID` (String), `avatarURL` (String), `nickname` (String). |
|
|
699
|
+
| `completion` | CompletionHandler | No | Completion callback for result. |
|
|
700
|
+
|
|
701
|
+
### Switch Layout Modes
|
|
702
|
+
|
|
703
|
+
Use [setLayoutTemplate](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_view_call_call_core_view/CallCoreController/setLayoutTemplate.html) for flexible layout switching. If unset, `CallCoreView` adapts automatically: 1-on-1 calls use `Float` mode, group calls use `Grid` mode.
|
|
704
|
+
|
|
705
|
+
| **Mode** | **Layout** | **Interaction** |
|
|
706
|
+
| --- | --- | --- |
|
|
707
|
+
| Float | Full-screen self-view while waiting; after connecting, full-screen remote view with self-view as a floating window. | Floating window supports drag and click-to-swap with the main view. |
|
|
708
|
+
| Grid | Grid layout for all participants, suitable for 2+ users. Supports click-to-enlarge. | Click any participant's view to enlarge. |
|
|
709
|
+
| PIP | 1v1 shows fixed remote view; multi-party uses active-speaker strategy with full screen for the current speaker. | Waiting state shows self-view; after connecting, call duration is displayed. |
|
|
710
|
+
|
|
711
|
+
**Sample Code:**
|
|
712
|
+
|
|
713
|
+
```dart
|
|
714
|
+
CallCoreController controller = CallCoreController.create();
|
|
715
|
+
CallLayoutTemplate template = CallLayoutTemplate.float;
|
|
716
|
+
controller.setLayoutTemplate(template);
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
**setLayoutTemplate API Parameter Details:**
|
|
720
|
+
|
|
721
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
722
|
+
| --- | --- | --- | --- |
|
|
723
|
+
| `template` | CallLayoutTemplate | Yes | Layout mode for CallCoreView: `CallLayoutTemplate.float`, `CallLayoutTemplate.grid`, `CallLayoutTemplate.pip`. |
|
|
724
|
+
|
|
725
|
+
### Set Default Call Timeout
|
|
726
|
+
|
|
727
|
+
When making a call via [calls](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallStore/calls.html), specify the timeout using [CallParams](https://liteav.sdk.qcloud.com/doc/product/tuikit/atomic-x/flutter/v1.0/en/api_call_call_store/CallParams-class.html) `timeout`.
|
|
728
|
+
|
|
729
|
+
```dart
|
|
730
|
+
void startCall(List<String> userIdList, CallMediaType mediaType) {
|
|
731
|
+
CallParams params = CallParams(
|
|
732
|
+
timeout: 30, // Set call waiting timeout (seconds)
|
|
733
|
+
);
|
|
734
|
+
CallStore.shared.calls(userIdList, mediaType, params);
|
|
735
|
+
}
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
**calls API Parameter Details:**
|
|
739
|
+
|
|
740
|
+
| **Parameter** | **Type** | **Required** | **Description** |
|
|
741
|
+
| --- | --- | --- | --- |
|
|
742
|
+
| `userIdList` | List<String> | Yes | List of target user IDs. |
|
|
743
|
+
| `mediaType` | CallMediaType | Yes | Call type: audio or video. `CallMediaType.video` / `CallMediaType.audio`. |
|
|
744
|
+
| `params` | CallParams | No | Call extension parameters: `roomId` (String, optional, auto-assigned if unset), `timeout` (int, seconds), `userData` (String, custom data), `chatGroupId` (String, group ID for group calls), `isEphemeralCall` (bool, encrypted call with no call record). |
|
|
745
|
+
|
|
746
|
+
### Implement In-App Floating Window
|
|
747
|
+
|
|
748
|
+
If the call UI is covered (e.g., user navigates away), create a draggable floating window in the app. This window should show key call status (such as duration and remote info) and allow users to quickly return to the full call UI, enhancing multitasking.
|
|
749
|
+
|
|
750
|
+
```dart
|
|
751
|
+
_buildPipWindowWidget() {
|
|
752
|
+
final pipWidth = MediaQuery.of(context).size.width;
|
|
753
|
+
final pipHeight = MediaQuery.of(context).size.height;
|
|
754
|
+
final scale = pipWidth / originWidth;
|
|
755
|
+
CallCoreController controller = CallCoreController.create();
|
|
756
|
+
controller.setLayoutTemplate(CallLayoutTemplate.pip);
|
|
757
|
+
return Scaffold(
|
|
758
|
+
body: SizedBox(
|
|
759
|
+
width: pipWidth,
|
|
760
|
+
height: pipHeight,
|
|
761
|
+
child: Container(
|
|
762
|
+
width: pipWidth,
|
|
763
|
+
height: pipHeight,
|
|
764
|
+
decoration: const BoxDecoration(color: Colors.transparent),
|
|
765
|
+
child: MediaQuery(
|
|
766
|
+
data: MediaQuery.of(context).copyWith(
|
|
767
|
+
size: Size(originWidth ?? pipWidth, originHeight ?? pipHeight)
|
|
768
|
+
),
|
|
769
|
+
child: ClipRect(
|
|
770
|
+
child: Transform.scale(
|
|
771
|
+
scale: scale,
|
|
772
|
+
alignment: Alignment.center,
|
|
773
|
+
child: OverflowBox(
|
|
774
|
+
maxWidth: originWidth,
|
|
775
|
+
maxHeight: originHeight,
|
|
776
|
+
alignment: Alignment.center,
|
|
777
|
+
child: CallCoreView(
|
|
778
|
+
controller: controller,
|
|
779
|
+
),
|
|
780
|
+
),
|
|
781
|
+
),
|
|
782
|
+
),
|
|
783
|
+
),
|
|
784
|
+
),
|
|
785
|
+
),
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
### Implement Android Picture-in-Picture Outside App
|
|
791
|
+
|
|
792
|
+
Picture-in-Picture requires Android 8.0 (API 26) or later.
|
|
793
|
+
|
|
794
|
+
1. **MainActivity Configuration**
|
|
795
|
+
|
|
796
|
+
Listen for the `MainActivity` lifecycle. When `enablePictureInPicture` is `true`, automatically enter PiP when the app goes to background.
|
|
797
|
+
|
|
798
|
+
```kotlin
|
|
799
|
+
import android.app.PictureInPictureParams
|
|
800
|
+
import android.content.pm.PackageManager
|
|
801
|
+
import android.os.Build
|
|
802
|
+
import android.util.Log
|
|
803
|
+
import android.util.Rational
|
|
804
|
+
import io.flutter.embedding.android.FlutterActivity
|
|
805
|
+
import io.flutter.embedding.engine.FlutterEngine
|
|
806
|
+
import io.flutter.plugin.common.MethodChannel
|
|
807
|
+
|
|
808
|
+
class MainActivity : FlutterActivity() {
|
|
809
|
+
companion object {
|
|
810
|
+
private const val TAG = "MainActivity"
|
|
811
|
+
private const val CHANNEL = "atomic_x/pip"
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
private var enablePictureInPicture = false
|
|
815
|
+
|
|
816
|
+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
|
817
|
+
super.configureFlutterEngine(flutterEngine)
|
|
818
|
+
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
|
819
|
+
when (call.method) {
|
|
820
|
+
"enablePictureInPicture" -> {
|
|
821
|
+
val enable = call.argument<Boolean>("enable") ?: false
|
|
822
|
+
val success = enablePIP(enable)
|
|
823
|
+
result.success(success)
|
|
824
|
+
}
|
|
825
|
+
"enterPictureInPicture" -> {
|
|
826
|
+
val success = enterPIP()
|
|
827
|
+
result.success(success)
|
|
828
|
+
}
|
|
829
|
+
else -> result.notImplemented()
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
override fun onUserLeaveHint() {
|
|
835
|
+
super.onUserLeaveHint()
|
|
836
|
+
// Automatically enter PiP when user presses Home
|
|
837
|
+
if (enablePictureInPicture) {
|
|
838
|
+
enterPIP()
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
private fun enablePIP(enable: Boolean): Boolean {
|
|
843
|
+
Log.i(TAG, "enablePictureInPicture: $enable")
|
|
844
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
|
845
|
+
packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
|
846
|
+
enablePictureInPicture = enable
|
|
847
|
+
return true
|
|
848
|
+
}
|
|
849
|
+
return false
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
private fun enterPIP(): Boolean {
|
|
853
|
+
if (!enablePictureInPicture) return false
|
|
854
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
855
|
+
try {
|
|
856
|
+
val aspectRatio = Rational(9, 16)
|
|
857
|
+
val params = PictureInPictureParams.Builder()
|
|
858
|
+
.setAspectRatio(aspectRatio)
|
|
859
|
+
.build()
|
|
860
|
+
return enterPictureInPictureMode(params)
|
|
861
|
+
} catch (e: Exception) {
|
|
862
|
+
Log.e(TAG, "enterPIP failed: ${e.message}")
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return false
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
2. **AndroidManifest Configuration**
|
|
871
|
+
|
|
872
|
+
Add PiP support to `MainActivity`:
|
|
873
|
+
|
|
874
|
+
```xml
|
|
875
|
+
<activity
|
|
876
|
+
android:name=".MainActivity"
|
|
877
|
+
android:exported="true"
|
|
878
|
+
android:launchMode="singleTop"
|
|
879
|
+
android:taskAffinity=""
|
|
880
|
+
android:theme="@style/LaunchTheme"
|
|
881
|
+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
|
882
|
+
android:hardwareAccelerated="true"
|
|
883
|
+
android:windowSoftInputMode="adjustResize"
|
|
884
|
+
android:supportsPictureInPicture="true">
|
|
885
|
+
<meta-data
|
|
886
|
+
android:name="io.flutter.embedding.android.NormalTheme"
|
|
887
|
+
android:resource="@style/NormalTheme"
|
|
888
|
+
/>
|
|
889
|
+
<intent-filter>
|
|
890
|
+
<action android:name="android.intent.action.MAIN"/>
|
|
891
|
+
<category android:name="android.intent.category.LAUNCHER"/>
|
|
892
|
+
</intent-filter>
|
|
893
|
+
</activity>
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
3. **Dart Layer Configuration**
|
|
897
|
+
|
|
898
|
+
```dart
|
|
899
|
+
import 'package:flutter/services.dart';
|
|
900
|
+
|
|
901
|
+
class PipManager {
|
|
902
|
+
static const MethodChannel _channel = MethodChannel('atomic_x/pip');
|
|
903
|
+
|
|
904
|
+
/// Enable/disable PiP
|
|
905
|
+
static Future<bool> enablePictureInPicture(bool enable) async {
|
|
906
|
+
try {
|
|
907
|
+
final result = await _channel.invokeMethod<bool>('enablePictureInPicture', {'enable': enable});
|
|
908
|
+
return result ?? false;
|
|
909
|
+
} catch (e) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/// Enter PiP mode immediately
|
|
915
|
+
static Future<bool> enterPictureInPicture() async {
|
|
916
|
+
try {
|
|
917
|
+
final result = await _channel.invokeMethod<bool>('enterPictureInPicture');
|
|
918
|
+
return result ?? false;
|
|
919
|
+
} catch (e) {
|
|
920
|
+
return false;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
Enable PiP before the call starts; disable PiP after the call ends.
|
|
927
|
+
|
|
928
|
+
### Implement iOS Picture-in-Picture Outside App
|
|
929
|
+
|
|
930
|
+
iOS supports system PiP with the underlying TRTC engine. When the app goes to background, the call view floats above other apps as a PiP window, letting users multitask.
|
|
931
|
+
|
|
932
|
+
> **Note:**
|
|
933
|
+
>
|
|
934
|
+
> - Add `Background Modes` in Xcode's `Signing & Capabilities` and check `Audio, AirPlay, and Picture in Picture`.
|
|
935
|
+
> - Requires iOS 15.0 or later.
|
|
936
|
+
|
|
937
|
+
1. **Enable PiP**
|
|
938
|
+
|
|
939
|
+
```dart
|
|
940
|
+
import 'package:tencent_rtc_sdk/trtc_cloud.dart';
|
|
941
|
+
|
|
942
|
+
TRTCCloud.sharedInstance().then((trtcCloud) {
|
|
943
|
+
trtcCloud.callExperimentalAPI('''
|
|
944
|
+
{
|
|
945
|
+
"api": "configPictureInPicture",
|
|
946
|
+
"params": {
|
|
947
|
+
"enable": true,
|
|
948
|
+
"cameraBackgroundCapture": true,
|
|
949
|
+
"canvas": {
|
|
950
|
+
"width": 720,
|
|
951
|
+
"height": 1280,
|
|
952
|
+
"backgroundColor": "#111111"
|
|
953
|
+
},
|
|
954
|
+
"regions": [
|
|
955
|
+
{
|
|
956
|
+
"userId": "remoteUserId",
|
|
957
|
+
"userName": "",
|
|
958
|
+
"width": 1.0,
|
|
959
|
+
"height": 1.0,
|
|
960
|
+
"x": 0.0,
|
|
961
|
+
"y": 0.0,
|
|
962
|
+
"fillMode": 0,
|
|
963
|
+
"streamType": "high",
|
|
964
|
+
"backgroundColor": "#111111",
|
|
965
|
+
"backgroundImage": "file:///path/to/avatar.png"
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
"userId": "localUserId",
|
|
969
|
+
"userName": "",
|
|
970
|
+
"width": 0.333,
|
|
971
|
+
"height": 0.333,
|
|
972
|
+
"x": 0.65,
|
|
973
|
+
"y": 0.05,
|
|
974
|
+
"fillMode": 0,
|
|
975
|
+
"streamType": "high",
|
|
976
|
+
"backgroundColor": "#111111"
|
|
977
|
+
}
|
|
978
|
+
]
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
''');
|
|
982
|
+
});
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
2. **Disable PiP**
|
|
986
|
+
|
|
987
|
+
```dart
|
|
988
|
+
import 'package:tencent_rtc_sdk/trtc_cloud.dart';
|
|
989
|
+
|
|
990
|
+
TRTCCloud.sharedInstance().then((trtcCloud) {
|
|
991
|
+
trtcCloud.callExperimentalAPI('''
|
|
992
|
+
{
|
|
993
|
+
"api": "configPictureInPicture",
|
|
994
|
+
"params": {
|
|
995
|
+
"enable": false
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
''');
|
|
999
|
+
});
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
### Enable Background Audio/Video Capture
|
|
1003
|
+
|
|
1004
|
+
To ensure your app can capture audio/video while in the background (e.g., screen lock or app switch), configure Android and iOS as follows:
|
|
1005
|
+
|
|
1006
|
+
#### Android Configuration
|
|
1007
|
+
|
|
1008
|
+
1. **Permissions and Service (`AndroidManifest.xml`):** Android 9.0+ requires foreground service permissions; Android 14+ requires explicit service type for microphone/camera.
|
|
1009
|
+
|
|
1010
|
+
```xml
|
|
1011
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
1012
|
+
|
|
1013
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
1014
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
|
|
1015
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
|
1016
|
+
|
|
1017
|
+
<application>
|
|
1018
|
+
<service
|
|
1019
|
+
android:name=".CallForegroundService"
|
|
1020
|
+
android:enabled="true"
|
|
1021
|
+
android:exported="false"
|
|
1022
|
+
android:foregroundServiceType="camera|microphone" />
|
|
1023
|
+
</application>
|
|
1024
|
+
</manifest>
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
2. **Create Foreground Service Class (`CallForegroundService`):**
|
|
1028
|
+
|
|
1029
|
+
```kotlin
|
|
1030
|
+
import android.app.Notification
|
|
1031
|
+
import android.app.NotificationChannel
|
|
1032
|
+
import android.app.NotificationManager
|
|
1033
|
+
import android.app.Service
|
|
1034
|
+
import android.content.Context
|
|
1035
|
+
import android.content.Intent
|
|
1036
|
+
import android.os.Build
|
|
1037
|
+
import android.os.IBinder
|
|
1038
|
+
import androidx.core.app.NotificationCompat
|
|
1039
|
+
|
|
1040
|
+
class CallForegroundService : Service() {
|
|
1041
|
+
companion object {
|
|
1042
|
+
private const val NOTIFICATION_ID = 1001
|
|
1043
|
+
private const val CHANNEL_ID = "call_foreground_channel"
|
|
1044
|
+
fun start(context: Context) {
|
|
1045
|
+
val intent = Intent(context, CallForegroundService::class.java)
|
|
1046
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
1047
|
+
context.startForegroundService(intent)
|
|
1048
|
+
} else {
|
|
1049
|
+
context.startService(intent)
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
fun stop(context: Context) {
|
|
1054
|
+
val intent = Intent(context, CallForegroundService::class.java)
|
|
1055
|
+
context.stopService(intent)
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
override fun onCreate() {
|
|
1060
|
+
super.onCreate()
|
|
1061
|
+
createNotificationChannel()
|
|
1062
|
+
// Start foreground notification to ensure background capture permission
|
|
1063
|
+
startForeground(NOTIFICATION_ID, createNotification())
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
override fun onBind(intent: Intent?): IBinder? = null
|
|
1067
|
+
|
|
1068
|
+
private fun createNotification(): Notification {
|
|
1069
|
+
return NotificationCompat.Builder(this, CHANNEL_ID)
|
|
1070
|
+
.setContentTitle("In Call")
|
|
1071
|
+
.setContentText("App is running in background to maintain call")
|
|
1072
|
+
.setSmallIcon(android.R.drawable.ic_menu_call) // Replace with your app icon
|
|
1073
|
+
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
1074
|
+
.build()
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
private fun createNotificationChannel() {
|
|
1078
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
1079
|
+
val channel = NotificationChannel(
|
|
1080
|
+
CHANNEL_ID,
|
|
1081
|
+
"Call Keep-Alive Service",
|
|
1082
|
+
NotificationManager.IMPORTANCE_HIGH
|
|
1083
|
+
)
|
|
1084
|
+
val manager = getSystemService(NotificationManager::class.java)
|
|
1085
|
+
manager.createNotificationChannel(channel)
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
#### iOS Configuration
|
|
1092
|
+
|
|
1093
|
+
In Xcode:
|
|
1094
|
+
|
|
1095
|
+
1. Select your project `Target` → `Signing & Capabilities`.
|
|
1096
|
+
2. Click `+ Capability`.
|
|
1097
|
+
3. Add `Background Modes`.
|
|
1098
|
+
4. Check:
|
|
1099
|
+
- `Audio, AirPlay, and Picture in Picture` (for audio and PiP)
|
|
1100
|
+
- `Voice over IP` (for VoIP)
|
|
1101
|
+
- `Remote notifications` (optional, for offline push)
|
|
1102
|
+
|
|
1103
|
+
Your `Info.plist` will automatically include:
|
|
1104
|
+
|
|
1105
|
+
```xml
|
|
1106
|
+
<key>UIBackgroundModes</key>
|
|
1107
|
+
<array>
|
|
1108
|
+
<string>audio</string>
|
|
1109
|
+
<string>voip</string>
|
|
1110
|
+
<string>remote-notification</string>
|
|
1111
|
+
</array>
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
**Configure Audio Session (AVAudioSession):**
|
|
1115
|
+
|
|
1116
|
+
Set up the audio session before the call starts — ideally in the call UI's `viewDidLoad`, before dialing, or before answering.
|
|
1117
|
+
|
|
1118
|
+
```swift
|
|
1119
|
+
import AVFoundation
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Configure audio session for background audio capture.
|
|
1123
|
+
*
|
|
1124
|
+
* Recommended scenarios:
|
|
1125
|
+
* 1. In call UI's viewDidLoad
|
|
1126
|
+
* 2. Before making a call (calls)
|
|
1127
|
+
* 3. Before answering a call (accept)
|
|
1128
|
+
*/
|
|
1129
|
+
private func start() {
|
|
1130
|
+
let audioSession = AVAudioSession.sharedInstance()
|
|
1131
|
+
do {
|
|
1132
|
+
// Set audio session category to play and record
|
|
1133
|
+
// .allowBluetooth: Supports Bluetooth headset
|
|
1134
|
+
// .allowBluetoothA2DP: Supports high-quality Bluetooth audio (A2DP)
|
|
1135
|
+
try audioSession.setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP])
|
|
1136
|
+
// Activate audio session
|
|
1137
|
+
try audioSession.setActive(true)
|
|
1138
|
+
} catch {
|
|
1139
|
+
// Audio session configuration failed
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
> **Note:**
|
|
1145
|
+
>
|
|
1146
|
+
> Call `start()` via MethodChannel at the appropriate time in your app to enable background keep-alive.
|
|
1147
|
+
|
|
1148
|
+
## FAQ
|
|
1149
|
+
|
|
1150
|
+
### iOS Release Build [symbol not found] Error?
|
|
1151
|
+
|
|
1152
|
+
Since `tencent_rtc_sdk` uses Flutter FFI, Xcode's symbol stripping during Release builds may remove TRTC C symbols and cause `symbol not found` errors. To resolve:
|
|
1153
|
+
|
|
1154
|
+
1. In **Build Settings**, set **Deployment Postprocessing** to **Yes**.
|
|
1155
|
+
2. Set **Strip Style** for **Release** to **Non-Global Symbols**.
|
|
1156
|
+
|
|
1157
|
+
### If the callee goes offline and then comes online within the call invitation timeout, will they receive the incoming call event?
|
|
1158
|
+
|
|
1159
|
+
- **For single calls:** If the callee comes online within the timeout, they will receive the call invitation.
|
|
1160
|
+
- **For group calls:** If the callee comes online within the timeout, up to 20 unprocessed group messages will be pulled; if there is a call invitation, the incoming call event is triggered.
|