@tencentcloud/sdk-mcp 1.3.4 → 1.3.5
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/chatuikit/android/features/theme.md +363 -0
- package/resource/doc/chatuikit/android/workflow.md +0 -0
- package/resource/doc/chatuikit/{android/client_api_android.md → faq/android_sdk/client-api.md} +0 -1
- package/resource/doc/chatuikit/faq/{native_sdk/faq.md → common/product.md} +8 -0
- package/resource/doc/chatuikit/faq/flutter_sdk/faq.md +54 -0
- package/resource/doc/chatuikit/faq/web_sdk/faq.md +1 -1
- package/resource/doc/chatuikit/flutter/features/theme.md +379 -0
- package/resource/doc/chatuikit/flutter/workflow.md +816 -0
- package/resource/doc/chatuikit/iOS/features/theme.md +416 -0
- package/resource/doc/chatuikit/iOS/workflow.md +0 -0
- package/resource/doc/chatuikit/react/components/chat-setting.md +124 -0
- package/resource/doc/chatuikit/react/components/contact-list.md +1331 -0
- package/resource/doc/chatuikit/react/components/search.md +885 -0
- package/resource/doc/chatuikit/vue/components/chat-setting.md +88 -0
- package/resource/doc/chatuikit/vue/components/contact-list.md +679 -0
- package/resource/doc/chatuikit/vue/components/search.md +1384 -0
- package/resource/doc/livekit/live/android/workflow.md +137 -4
- package/resource/doc/livekit/live/flutter/live-audience-list.md +337 -0
- package/resource/doc/livekit/live/flutter/live-audio-effect.md +739 -0
- package/resource/doc/livekit/live/flutter/live-barrage.md +578 -0
- package/resource/doc/livekit/live/flutter/live-base-beauty.md +484 -0
- package/resource/doc/livekit/live/flutter/live-co-guest-interaction.md +606 -0
- package/resource/doc/livekit/live/flutter/live-gift.md +812 -0
- package/resource/doc/livekit/live/flutter/live-host-interaction.md +1113 -0
- package/resource/doc/livekit/live/flutter/live-integration.md +1029 -0
- package/resource/doc/livekit/live/flutter/live-live-list.md +861 -0
- package/resource/doc/livekit/live/ios/live-audience-list.md +335 -0
- package/resource/doc/livekit/live/ios/live-audio-effect.md +373 -0
- package/resource/doc/livekit/live/ios/live-barrage.md +529 -0
- package/resource/doc/livekit/live/ios/live-base-beauty.md +237 -0
- package/resource/doc/livekit/live/ios/live-co-guest-interaction.md +483 -0
- package/resource/doc/livekit/live/ios/live-gift.md +785 -0
- package/resource/doc/livekit/live/ios/live-host-interaction.md +743 -0
- package/resource/doc/livekit/live/ios/live-integration.md +822 -0
- package/resource/doc/livekit/live/ios/live-live-list.md +535 -0
- package/resource/doc/livekit/live/ios/workflow.md +352 -0
- package/resource/doc/rtcengine/faq/web/web.md +2 -2
- package/resource/doc/rtcengine/web/how_to_integrated_web_sdk.md +2 -2
- package/resource/doc/rtcengine/web/plugin/20-advanced-customized-capture-rendering.md +84 -0
- package/resource/doc/rtcengine/web/plugin/21-advanced-auto-play-policy.md +86 -0
- package/resource/doc/rtcengine/web/plugin/22-advanced-audio-mixer.md +220 -0
- package/resource/doc/rtcengine/web/plugin/23-advanced-support-detection.md +217 -0
- package/resource/doc/rtcengine/web/plugin/24-advanced-network-quality.md +137 -0
- package/resource/doc/rtcengine/web/plugin/25-advanced-device-change.md +97 -0
- package/resource/doc/rtcengine/web/plugin/26-advanced-publish-cdn-stream.md +453 -0
- package/resource/doc/rtcengine/web/plugin/27-advanced-small-stream.md +180 -0
- package/resource/doc/rtcengine/web/plugin/28-advanced-beauty.md +349 -0
- package/resource/doc/rtcengine/web/plugin/29-advanced-water-mark.md +149 -0
- package/resource/doc/rtcengine/web/plugin/30-advanced-cross-room-link.md +96 -0
- package/resource/doc/rtcengine/web/plugin/31-advanced-plugins-overview.md +405 -0
- package/resource/doc/rtcengine/web/plugin/34-advanced-proxy.md +244 -0
- package/resource/doc/rtcengine/web/plugin/35-advanced-ai-denoiser.md +84 -0
- package/resource/doc/rtcengine/web/plugin/36-advanced-virtual-background.md +202 -0
- package/resource/doc/rtcengine/web/plugin/37-advanced-voice-changer.md +98 -0
- package/resource/doc/rtcengine/web/plugin/38-advanced-basic-beauty.md +95 -0
- package/resource/doc/rtcengine/web/plugin/39-advanced-video-decoder.md +33 -0
- package/resource/doc/rtcengine/web/plugin/40-advanced-video-mixer.md +380 -0
- package/resource/doc/rtcengine/web/plugin/41-advanced-small-stream-auto-switcher.md +91 -0
- package/resource/doc/rtcengine/web/plugin/42-advanced-realtime-transcriber.md +314 -0
- package/resource/doc/rtcengine/web/plugin/43-advanced-face-detection.md +180 -0
- package/tools/chat/get-native-chat-feature-detail.js +30 -0
- package/tools/chat/get-native-chat-feature-detail.js.map +1 -0
- package/tools/chat/get-native-chat-integration.js +30 -12
- package/tools/chat/get-native-chat-integration.js.map +1 -1
- package/tools/common/get-faq.js +2 -4
- package/tools/common/get-faq.js.map +1 -1
- package/tools/definitions/get_native_chat_feature_detail_def.js +32 -0
- package/tools/definitions/get_native_chat_feature_detail_def.js.map +1 -0
- package/tools/definitions/get_native_chat_uikit_integration_def.js +18 -6
- package/tools/definitions/get_native_chat_uikit_integration_def.js.map +1 -1
- package/tools/definitions/{get_native_live_extra_features_def.js → get_native_live_uikit_extra_features_def.js} +3 -3
- package/tools/definitions/get_native_live_uikit_extra_features_def.js.map +1 -0
- package/tools/definitions/{get_native_live_interaction_def.js → get_native_live_uikit_interaction_def.js} +3 -3
- package/tools/definitions/get_native_live_uikit_interaction_def.js.map +1 -0
- package/tools/definitions/get_web_chat_uikit_component_detail_def.js +46 -7
- package/tools/definitions/get_web_chat_uikit_component_detail_def.js.map +1 -1
- package/tools/index.js +6 -4
- package/tools/index.js.map +1 -1
- package/tools/live/{get_native_live_extra_features.js → get_native_live_uikit_extra_features.js} +4 -4
- package/tools/live/get_native_live_uikit_extra_features.js.map +1 -0
- package/tools/live/{get_native_live_interaction.js → get_native_live_uikit_interaction.js} +4 -4
- package/tools/live/get_native_live_uikit_interaction.js.map +1 -0
- package/tools/rtcengine/get-trtc-web-sdk-faq.js +1 -1
- package/tools/rtcengine/get-trtc-web-sdk-plugin.js +45 -0
- package/tools/rtcengine/get-trtc-web-sdk-plugin.js.map +1 -0
- package/utils/handle-component-name.js +0 -16
- package/utils/handle-component-name.js.map +1 -1
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
- package/resource/doc/chatuikit/android/integrate_tuichat_only_android.md +0 -382
- package/resource/doc/chatuikit/android/ui_api_android.md +0 -418
- package/resource/doc/chatuikit/iOS/integrate_tuichat_only_iOS.md +0 -993
- package/resource/doc/chatuikit/iOS/ui_api_iOS.md +0 -526
- package/tools/definitions/get_native_live_extra_features_def.js.map +0 -1
- package/tools/definitions/get_native_live_interaction_def.js.map +0 -1
- package/tools/live/get_native_live_extra_features.js.map +0 -1
- package/tools/live/get_native_live_interaction.js.map +0 -1
- /package/resource/doc/chatuikit/android/{integrate_tuikit_android.md → integration.md} +0 -0
- /package/resource/doc/chatuikit/{flutter/client_api_Flutter.md → faq/flutter_sdk/client-api.md} +0 -0
- /package/resource/doc/chatuikit/{iOS/client_api_iOS.md → faq/ios_sdk/client-api.md} +0 -0
- /package/resource/doc/chatuikit/flutter/{integrate_tuikit_Flutter.md → integration.md} +0 -0
- /package/resource/doc/chatuikit/iOS/{integrate_tuikit_iOS.md → integration.md} +0 -0
- /package/resource/doc/chatuikit/react/components/{chatheader.md → chat-header.md} +0 -0
- /package/resource/doc/chatuikit/vue/components/{chatheader.md → chat-header.md} +0 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
本文档将帮助您使用 **AtomicXCore SDK** 的核心组件 [LiveCoreWidget](https://tencent-rtc.github.io/TUIKit_Flutter/api_view_live_live_core_widget/api_view_live_live_core_widget-library.html),快速构建一个包含主播开播和观众观看功能的基础直播 App。
|
|
2
|
+
|
|
3
|
+
## 核心功能
|
|
4
|
+
|
|
5
|
+
**LiveCoreWidget** 是一个专为直播场景设计的轻量级 Widget 组件,是您构建直播场景的核心,它封装了所有复杂的底层直播技术(例如推拉流、连麦、音视频渲染)。您可以将 LiveCoreWidget 作为直播画面的"画布",专注于上层 UI 与交互的开发。
|
|
6
|
+
|
|
7
|
+
通过下方的视图层级示意图,您可以直观了解 **LiveCoreWidget** 在直播界面中的位置和作用:
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## 准备工作
|
|
13
|
+
|
|
14
|
+
### 步骤1:开通服务
|
|
15
|
+
|
|
16
|
+
请参见 [开通服务](https://write.woa.com/document/141302177829593088),获取体验版或付费版 SDK。
|
|
17
|
+
|
|
18
|
+
### 步骤2:在当前项目中导入 AtomicXCore
|
|
19
|
+
1. **安装组件**:请在您的 `pubspec.yaml` 文件中添加 `atomic_x_core` 依赖,然后执行 `flutter pub get`。
|
|
20
|
+
|
|
21
|
+
``` yaml
|
|
22
|
+
dependencies:
|
|
23
|
+
atomic_x_core: ^3.6.0
|
|
24
|
+
```
|
|
25
|
+
2. **配置工程权限:**Android 和 iOS 工程都需要配置权限。
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
【Android】
|
|
31
|
+
|
|
32
|
+
请在 `android/app/src/main/AndroidManifest.xml` 文件中添加相机和麦克风的使用权限说明。
|
|
33
|
+
``` xml
|
|
34
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
35
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
【iOS】
|
|
39
|
+
|
|
40
|
+
请在应用 `iOS` 目录的 **Podfile** 和 `ios/Runner` 目录的 `Info.plist` 文件中添加相机和麦克风的使用权限说明。
|
|
41
|
+
|
|
42
|
+
**Podfile**
|
|
43
|
+
``` ruby
|
|
44
|
+
post_install do |installer|
|
|
45
|
+
installer.pods_project.targets.each do |target|
|
|
46
|
+
flutter_additional_ios_build_settings(target)
|
|
47
|
+
target.build_configurations.each do |config|
|
|
48
|
+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
|
|
49
|
+
'$(inherited)',
|
|
50
|
+
'PERMISSION_MICROPHONE=1',
|
|
51
|
+
'PERMISSION_CAMERA=1',
|
|
52
|
+
]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Info.plist**
|
|
59
|
+
``` xml
|
|
60
|
+
<key>NSCameraUsageDescription</key>
|
|
61
|
+
<string>TUILiveKit需要访问你的相机权限,开启后录制的视频才会有画面</string>
|
|
62
|
+
<key>NSMicrophoneUsageDescription</key>
|
|
63
|
+
<string>TUILiveKit需要访问您的麦克风权限,开启后录制的视频才会有声音</string>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+

|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### 步骤3:实现登录逻辑
|
|
71
|
+
|
|
72
|
+
在您的项目中调用 `LoginStore.shared.login` 完成登录,**这是使用 AtomicXCore 所有功能的关键前提**。
|
|
73
|
+
|
|
74
|
+
> **重要:**
|
|
75
|
+
>
|
|
76
|
+
|
|
77
|
+
> 推荐在您 App 自身的用户账户登录成功后,再调用 LoginStore.shared.login,以确保登录业务逻辑的清晰和一致。
|
|
78
|
+
>
|
|
79
|
+
|
|
80
|
+
``` java
|
|
81
|
+
import 'package:flutter/material.dart';
|
|
82
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
83
|
+
|
|
84
|
+
void main() async {
|
|
85
|
+
WidgetsFlutterBinding.ensureInitialized();
|
|
86
|
+
|
|
87
|
+
final result = await LoginStore.shared.login(
|
|
88
|
+
sdkAppID: 1400000001, // 替换为您的 sdkAppID
|
|
89
|
+
userID: "test_001", // 替换为您的 userID
|
|
90
|
+
userSig: "xxxxxxxxxxx", // 替换为您的 userSig
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (result.isSuccess) {
|
|
94
|
+
debugPrint("login success");
|
|
95
|
+
} else {
|
|
96
|
+
debugPrint("login failed code: ${result.errorCode}, message: ${result.errorMessage}");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
runApp(const MyApp());
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**登录接口参数说明:**
|
|
104
|
+
<table>
|
|
105
|
+
<tr>
|
|
106
|
+
<td rowspan="1" colSpan="1" >**参数**</td>
|
|
107
|
+
|
|
108
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
109
|
+
|
|
110
|
+
<td rowspan="1" colSpan="1" >**说明**</td>
|
|
111
|
+
</tr>
|
|
112
|
+
|
|
113
|
+
<tr>
|
|
114
|
+
<td rowspan="1" colSpan="1" >`sdkAppID`</td>
|
|
115
|
+
|
|
116
|
+
<td rowspan="1" colSpan="1" >`int`</td>
|
|
117
|
+
|
|
118
|
+
<td rowspan="1" colSpan="1" >从 [控制台](https://console.cloud.tencent.com/trtc) 获取,通常是以 `140` 或 `160` 开头的 10 位整数。</td>
|
|
119
|
+
</tr>
|
|
120
|
+
|
|
121
|
+
<tr>
|
|
122
|
+
<td rowspan="1" colSpan="1" >`userID`</td>
|
|
123
|
+
|
|
124
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
125
|
+
|
|
126
|
+
<td rowspan="1" colSpan="1" >当前用户的唯一 ID,仅包含英文字母、数字、连字符和下划线。为避免多端登录冲突,**请勿使用**`1`、`123`**等简单 ID**。</td>
|
|
127
|
+
</tr>
|
|
128
|
+
|
|
129
|
+
<tr>
|
|
130
|
+
<td rowspan="1" colSpan="1" >`userSig`</td>
|
|
131
|
+
|
|
132
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
133
|
+
|
|
134
|
+
<td rowspan="1" colSpan="1" >用于腾讯云鉴权的票据。请注意:<br>- 开发环境:您可以采用本地 `GenerateTestUserSig.genTestSig` 函数生成 userSig 或者通过 [UserSig 辅助工具](https://console.cloud.tencent.com/im/tool-usersig) 生成临时的 UserSig。<br>- 生产环境:为了防止密钥泄露,请务必采用服务端生成 UserSig 的方式。详细信息请参考 [服务端生成 UserSig](https://cloud.tencent.com/document/product/647/17275)。<br>更多信息请参见 [如何计算及使用 UserSig](https://cloud.tencent.com/document/product/647/17275)。</td>
|
|
135
|
+
</tr>
|
|
136
|
+
</table>
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## 搭建基础直播间
|
|
140
|
+
|
|
141
|
+
### 步骤1:实现主播视频开播
|
|
142
|
+
|
|
143
|
+
主播开播流程如下,您只需执行以下几步操作,即可快速搭建主播视频直播。
|
|
144
|
+
|
|
145
|
+

|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
> **提示:**
|
|
149
|
+
>
|
|
150
|
+
|
|
151
|
+
> 主播开播推流的业务代码,您也可以参考 TUILiveKit 开源项目中的 [live_room_anchor_widget.dart](https://github.com/Tencent-RTC/TUIKit_Flutter/blob/main/live/livekit/lib/live_stream/features/live_room_anchor_widget.dart) 文件来了解完整的实现逻辑。
|
|
152
|
+
>
|
|
153
|
+
|
|
154
|
+
1. **初始化主播推流视图**
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
在您的主播页面中,创建一个 `LiveCoreWidget` 实例,并通过 `LiveCoreController` 控制直播行为。
|
|
158
|
+
|
|
159
|
+
``` java
|
|
160
|
+
import 'package:flutter/material.dart';
|
|
161
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
162
|
+
|
|
163
|
+
/// YourAnchorPage 代表您的主播开播页面
|
|
164
|
+
class YourAnchorPage extends StatefulWidget {
|
|
165
|
+
final String liveId;
|
|
166
|
+
|
|
167
|
+
const YourAnchorPage({super.key, required this.liveId});
|
|
168
|
+
|
|
169
|
+
@override
|
|
170
|
+
State<YourAnchorPage> createState() => _YourAnchorPageState();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
class _YourAnchorPageState extends State<YourAnchorPage> {
|
|
174
|
+
// 1. 创建 LiveCoreController 实例
|
|
175
|
+
late final LiveCoreController _controller;
|
|
176
|
+
|
|
177
|
+
@override
|
|
178
|
+
void initState() {
|
|
179
|
+
super.initState();
|
|
180
|
+
// 2. 初始化 controller
|
|
181
|
+
_controller = LiveCoreController.create();
|
|
182
|
+
// 3. 设置直播 ID
|
|
183
|
+
_controller.setLiveID(widget.liveId);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@override
|
|
187
|
+
Widget build(BuildContext context) {
|
|
188
|
+
return Scaffold(
|
|
189
|
+
body: Stack(
|
|
190
|
+
children: [
|
|
191
|
+
// 4. 将主播推流页面加载到您的视图上
|
|
192
|
+
LiveCoreWidget(controller: _controller),
|
|
193
|
+
// 您的其他 UI 组件
|
|
194
|
+
],
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
2. **打开摄像头和麦克风**
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
通过调用 **DeviceStore** 的 `openLocalCamera`、`openLocalMicrophone` 接口打开摄像头和麦克风,**您无需做额外操作,LiveCoreWidget 会自动预览当前摄像头的视频流**,示例代码如下:
|
|
204
|
+
|
|
205
|
+
``` java
|
|
206
|
+
import 'package:flutter/material.dart';
|
|
207
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
208
|
+
|
|
209
|
+
/// YourAnchorPage 代表您的主播开播页面
|
|
210
|
+
class YourAnchorPage extends StatefulWidget {
|
|
211
|
+
final String liveId;
|
|
212
|
+
|
|
213
|
+
const YourAnchorPage({super.key, required this.liveId});
|
|
214
|
+
|
|
215
|
+
@override
|
|
216
|
+
State<YourAnchorPage> createState() => _YourAnchorPageState();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
class _YourAnchorPageState extends State<YourAnchorPage> {
|
|
220
|
+
late final LiveCoreController _controller;
|
|
221
|
+
|
|
222
|
+
@override
|
|
223
|
+
void initState() {
|
|
224
|
+
super.initState();
|
|
225
|
+
_controller = LiveCoreController.create();
|
|
226
|
+
_controller.setLiveID(widget.liveId);
|
|
227
|
+
// 打开设备
|
|
228
|
+
_openDevices();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
void _openDevices() {
|
|
232
|
+
// 1. 打开前置摄像头
|
|
233
|
+
DeviceStore.shared.openLocalCamera(true);
|
|
234
|
+
// 2. 打开麦克风
|
|
235
|
+
DeviceStore.shared.openLocalMicrophone();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@override
|
|
239
|
+
Widget build(BuildContext context) {
|
|
240
|
+
return Scaffold(
|
|
241
|
+
body: Stack(
|
|
242
|
+
children: [
|
|
243
|
+
LiveCoreWidget(controller: _controller),
|
|
244
|
+
],
|
|
245
|
+
),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
3. **开始直播**
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
通过调用 **LiveListStore** 的 `createLive` 接口开始视频直播,完整示例代码如下:
|
|
254
|
+
|
|
255
|
+
``` java
|
|
256
|
+
import 'package:flutter/material.dart';
|
|
257
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
258
|
+
|
|
259
|
+
/// YourAnchorPage 代表您的主播开播页面
|
|
260
|
+
class YourAnchorPage extends StatefulWidget {
|
|
261
|
+
final String liveId;
|
|
262
|
+
|
|
263
|
+
const YourAnchorPage({super.key, required this.liveId});
|
|
264
|
+
|
|
265
|
+
@override
|
|
266
|
+
State<YourAnchorPage> createState() => _YourAnchorPageState();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
class _YourAnchorPageState extends State<YourAnchorPage> {
|
|
270
|
+
late final LiveCoreController _controller;
|
|
271
|
+
|
|
272
|
+
@override
|
|
273
|
+
void initState() {
|
|
274
|
+
super.initState();
|
|
275
|
+
_controller = LiveCoreController.create();
|
|
276
|
+
_controller.setLiveID(widget.liveId);
|
|
277
|
+
_openDevices();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
void _openDevices() {
|
|
281
|
+
DeviceStore.shared.openLocalCamera(true);
|
|
282
|
+
DeviceStore.shared.openLocalMicrophone();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 调用开播接口开始直播
|
|
286
|
+
Future<void> _startLive() async {
|
|
287
|
+
// 1. 准备 LiveInfo 对象
|
|
288
|
+
final liveInfo = LiveInfo(
|
|
289
|
+
// 设置直播的房间 id
|
|
290
|
+
liveID: widget.liveId,
|
|
291
|
+
// 设置直播的房间名称
|
|
292
|
+
liveName: "test 直播",
|
|
293
|
+
// 配置布局模板,默认:600 动态宫格布局
|
|
294
|
+
seatLayoutTemplateID: 600,
|
|
295
|
+
// 配置主播始终在麦位上
|
|
296
|
+
keepOwnerOnSeat: true,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// 2. 调用 LiveListStore.shared.createLive 开始直播
|
|
300
|
+
final result = await LiveListStore.shared.createLive(liveInfo);
|
|
301
|
+
|
|
302
|
+
if (result.isSuccess) {
|
|
303
|
+
debugPrint("startLive success");
|
|
304
|
+
} else {
|
|
305
|
+
debugPrint("startLive error: ${result.errorMessage}");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@override
|
|
310
|
+
Widget build(BuildContext context) {
|
|
311
|
+
return Scaffold(
|
|
312
|
+
body: Stack(
|
|
313
|
+
children: [
|
|
314
|
+
LiveCoreWidget(controller: _controller),
|
|
315
|
+
// 开播按钮
|
|
316
|
+
Positioned(
|
|
317
|
+
bottom: 50,
|
|
318
|
+
left: 0,
|
|
319
|
+
right: 0,
|
|
320
|
+
child: Center(
|
|
321
|
+
child: ElevatedButton(
|
|
322
|
+
onPressed: _startLive,
|
|
323
|
+
child: const Text('开始直播'),
|
|
324
|
+
),
|
|
325
|
+
),
|
|
326
|
+
),
|
|
327
|
+
],
|
|
328
|
+
),
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**LiveInfo 参数说明:**
|
|
335
|
+
|
|
336
|
+
<table>
|
|
337
|
+
<tr>
|
|
338
|
+
<td rowspan="1" colSpan="1" >**参数名**</td>
|
|
339
|
+
|
|
340
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
341
|
+
|
|
342
|
+
<td rowspan="1" colSpan="1" >**属性**</td>
|
|
343
|
+
|
|
344
|
+
<td rowspan="1" colSpan="1" >**描述**</td>
|
|
345
|
+
</tr>
|
|
346
|
+
|
|
347
|
+
<tr>
|
|
348
|
+
<td rowspan="1" colSpan="1" >`liveID`</td>
|
|
349
|
+
|
|
350
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
351
|
+
|
|
352
|
+
<td rowspan="1" colSpan="1" >必填</td>
|
|
353
|
+
|
|
354
|
+
<td rowspan="1" colSpan="1" >直播间的唯一标识符。</td>
|
|
355
|
+
</tr>
|
|
356
|
+
|
|
357
|
+
<tr>
|
|
358
|
+
<td rowspan="1" colSpan="1" >`liveName`</td>
|
|
359
|
+
|
|
360
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
361
|
+
|
|
362
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
363
|
+
|
|
364
|
+
<td rowspan="1" colSpan="1" >直播间的标题。</td>
|
|
365
|
+
</tr>
|
|
366
|
+
|
|
367
|
+
<tr>
|
|
368
|
+
<td rowspan="1" colSpan="1" >`notice`</td>
|
|
369
|
+
|
|
370
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
371
|
+
|
|
372
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
373
|
+
|
|
374
|
+
<td rowspan="1" colSpan="1" >直播间的公告信息。</td>
|
|
375
|
+
</tr>
|
|
376
|
+
|
|
377
|
+
<tr>
|
|
378
|
+
<td rowspan="1" colSpan="1" >`isMessageDisable`</td>
|
|
379
|
+
|
|
380
|
+
<td rowspan="1" colSpan="1" >`bool`</td>
|
|
381
|
+
|
|
382
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
383
|
+
|
|
384
|
+
<td rowspan="1" colSpan="1" >是否禁言(`true`:是,`false`:否)。</td>
|
|
385
|
+
</tr>
|
|
386
|
+
|
|
387
|
+
<tr>
|
|
388
|
+
<td rowspan="1" colSpan="1" >`isPublicVisible`</td>
|
|
389
|
+
|
|
390
|
+
<td rowspan="1" colSpan="1" >`bool`</td>
|
|
391
|
+
|
|
392
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
393
|
+
|
|
394
|
+
<td rowspan="1" colSpan="1" >是否公开可见(`true`:是,`false`:否)。</td>
|
|
395
|
+
</tr>
|
|
396
|
+
|
|
397
|
+
<tr>
|
|
398
|
+
<td rowspan="1" colSpan="1" >`isSeatEnabled`</td>
|
|
399
|
+
|
|
400
|
+
<td rowspan="1" colSpan="1" >`bool`</td>
|
|
401
|
+
|
|
402
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
403
|
+
|
|
404
|
+
<td rowspan="1" colSpan="1" >是否启用麦位功能(`true`:是,`false`:否)。</td>
|
|
405
|
+
</tr>
|
|
406
|
+
|
|
407
|
+
<tr>
|
|
408
|
+
<td rowspan="1" colSpan="1" >`keepOwnerOnSeat`</td>
|
|
409
|
+
|
|
410
|
+
<td rowspan="1" colSpan="1" >`bool`</td>
|
|
411
|
+
|
|
412
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
413
|
+
|
|
414
|
+
<td rowspan="1" colSpan="1" >是否保持房主在麦位上。</td>
|
|
415
|
+
</tr>
|
|
416
|
+
|
|
417
|
+
<tr>
|
|
418
|
+
<td rowspan="1" colSpan="1" >`maxSeatCount`</td>
|
|
419
|
+
|
|
420
|
+
<td rowspan="1" colSpan="1" >`int`</td>
|
|
421
|
+
|
|
422
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
423
|
+
|
|
424
|
+
<td rowspan="1" colSpan="1" >最大麦位数量。</td>
|
|
425
|
+
</tr>
|
|
426
|
+
|
|
427
|
+
<tr>
|
|
428
|
+
<td rowspan="1" colSpan="1" >`seatMode`</td>
|
|
429
|
+
|
|
430
|
+
<td rowspan="1" colSpan="1" >`TakeSeatMode`</td>
|
|
431
|
+
|
|
432
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
433
|
+
|
|
434
|
+
<td rowspan="1" colSpan="1" >上麦模式(`TakeSeatMode.free`:自由上麦,`TakeSeatMode.apply`:申请上麦)。</td>
|
|
435
|
+
</tr>
|
|
436
|
+
|
|
437
|
+
<tr>
|
|
438
|
+
<td rowspan="1" colSpan="1" >`seatLayoutTemplateID`</td>
|
|
439
|
+
|
|
440
|
+
<td rowspan="1" colSpan="1" >`int`</td>
|
|
441
|
+
|
|
442
|
+
<td rowspan="1" colSpan="1" >必填</td>
|
|
443
|
+
|
|
444
|
+
<td rowspan="1" colSpan="1" >麦位布局模板 ID。</td>
|
|
445
|
+
</tr>
|
|
446
|
+
|
|
447
|
+
<tr>
|
|
448
|
+
<td rowspan="1" colSpan="1" >`coverURL`</td>
|
|
449
|
+
|
|
450
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
451
|
+
|
|
452
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
453
|
+
|
|
454
|
+
<td rowspan="1" colSpan="1" >直播间的封面图片地址。</td>
|
|
455
|
+
</tr>
|
|
456
|
+
|
|
457
|
+
<tr>
|
|
458
|
+
<td rowspan="1" colSpan="1" >`backgroundURL`</td>
|
|
459
|
+
|
|
460
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
461
|
+
|
|
462
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
463
|
+
|
|
464
|
+
<td rowspan="1" colSpan="1" >直播间的背景图片地址。</td>
|
|
465
|
+
</tr>
|
|
466
|
+
|
|
467
|
+
<tr>
|
|
468
|
+
<td rowspan="1" colSpan="1" >`categoryList`</td>
|
|
469
|
+
|
|
470
|
+
<td rowspan="1" colSpan="1" >`List<int>`</td>
|
|
471
|
+
|
|
472
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
473
|
+
|
|
474
|
+
<td rowspan="1" colSpan="1" >直播间的分类标签列表。</td>
|
|
475
|
+
</tr>
|
|
476
|
+
|
|
477
|
+
<tr>
|
|
478
|
+
<td rowspan="1" colSpan="1" >`activityStatus`</td>
|
|
479
|
+
|
|
480
|
+
<td rowspan="1" colSpan="1" >`int`</td>
|
|
481
|
+
|
|
482
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
483
|
+
|
|
484
|
+
<td rowspan="1" colSpan="1" >直播活动状态。</td>
|
|
485
|
+
</tr>
|
|
486
|
+
|
|
487
|
+
<tr>
|
|
488
|
+
<td rowspan="1" colSpan="1" >`isGiftEnabled`</td>
|
|
489
|
+
|
|
490
|
+
<td rowspan="1" colSpan="1" >`bool`</td>
|
|
491
|
+
|
|
492
|
+
<td rowspan="1" colSpan="1" >选填</td>
|
|
493
|
+
|
|
494
|
+
<td rowspan="1" colSpan="1" >是否启用礼物功能(`true`:是,`false`:否)。</td>
|
|
495
|
+
</tr>
|
|
496
|
+
</table>
|
|
497
|
+
|
|
498
|
+
4. **结束直播**
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
直播结束后,主播可以调用 **LiveListStore** 的 `endLive` 接口结束直播。SDK 会处理停止推流和销毁房间的逻辑。
|
|
502
|
+
|
|
503
|
+
``` java
|
|
504
|
+
import 'package:flutter/material.dart';
|
|
505
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
506
|
+
|
|
507
|
+
/// YourAnchorPage 代表您的主播开播页面
|
|
508
|
+
class YourAnchorPage extends StatefulWidget {
|
|
509
|
+
final String liveId;
|
|
510
|
+
|
|
511
|
+
const YourAnchorPage({super.key, required this.liveId});
|
|
512
|
+
|
|
513
|
+
@override
|
|
514
|
+
State<YourAnchorPage> createState() => _YourAnchorPageState();
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
class _YourAnchorPageState extends State<YourAnchorPage> {
|
|
518
|
+
// ... 其他代码 ...
|
|
519
|
+
|
|
520
|
+
// 结束直播
|
|
521
|
+
Future<void> _stopLive() async {
|
|
522
|
+
final result = await LiveListStore.shared.endLive();
|
|
523
|
+
|
|
524
|
+
if (result.isSuccess) {
|
|
525
|
+
debugPrint("endLive success");
|
|
526
|
+
} else {
|
|
527
|
+
debugPrint("endLive error: ${result.errorMessage}");
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// ... 其他代码 ...
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### 步骤2:实现观众进房观看
|
|
536
|
+
|
|
537
|
+
观众观看流程如下,通过简单几步操作,即可实现观众观看直播。
|
|
538
|
+
|
|
539
|
+

|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
> **提示:**
|
|
543
|
+
>
|
|
544
|
+
|
|
545
|
+
> 观众进房拉流的业务代码,您也可以参考 TUILiveKit 开源项目中的 [audience_widget.dart](https://github.com/Tencent-RTC/TUIKit_Flutter/blob/main/live/livekit/lib/live_stream/features/audience/audience_widget.dart) 文件来了解完整的实现逻辑。
|
|
546
|
+
>
|
|
547
|
+
|
|
548
|
+
1. **实现观众拉流页面**
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
在您的观众页面中,创建 `LiveCoreWidget` 实例,并通过 `LiveCoreController` 控制直播行为。
|
|
552
|
+
|
|
553
|
+
``` java
|
|
554
|
+
import 'package:flutter/material.dart';
|
|
555
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
556
|
+
|
|
557
|
+
/// YourAudiencePage 代表您的观众观看页面
|
|
558
|
+
class YourAudiencePage extends StatefulWidget {
|
|
559
|
+
final String liveId;
|
|
560
|
+
|
|
561
|
+
const YourAudiencePage({super.key, required this.liveId});
|
|
562
|
+
|
|
563
|
+
@override
|
|
564
|
+
State<YourAudiencePage> createState() => _YourAudiencePageState();
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
class _YourAudiencePageState extends State<YourAudiencePage> {
|
|
568
|
+
// 1. 创建 LiveCoreController 实例
|
|
569
|
+
late final LiveCoreController _controller;
|
|
570
|
+
|
|
571
|
+
@override
|
|
572
|
+
void initState() {
|
|
573
|
+
super.initState();
|
|
574
|
+
// 2. 初始化 controller
|
|
575
|
+
_controller = LiveCoreController.create();
|
|
576
|
+
// 3. 绑定直播 id
|
|
577
|
+
_controller.setLiveID(widget.liveId);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
@override
|
|
581
|
+
Widget build(BuildContext context) {
|
|
582
|
+
return Scaffold(
|
|
583
|
+
body: Stack(
|
|
584
|
+
children: [
|
|
585
|
+
// 4. 将观众拉流页面加载到您的视图上
|
|
586
|
+
LiveCoreWidget(controller: _controller),
|
|
587
|
+
],
|
|
588
|
+
),
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
```
|
|
593
|
+
2. **进入直播间观看**
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
通过调用 **LiveListStore** 的 `joinLive` 接口加入直播,**您无需做额外操作,LiveCoreWidget 会自动播放当前房间的视频流**,完整示例代码如下:
|
|
597
|
+
|
|
598
|
+
``` java
|
|
599
|
+
import 'package:flutter/material.dart';
|
|
600
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
601
|
+
|
|
602
|
+
/// YourAudiencePage 代表您的观众观看页面
|
|
603
|
+
class YourAudiencePage extends StatefulWidget {
|
|
604
|
+
final String liveId;
|
|
605
|
+
|
|
606
|
+
const YourAudiencePage({super.key, required this.liveId});
|
|
607
|
+
|
|
608
|
+
@override
|
|
609
|
+
State<YourAudiencePage> createState() => _YourAudiencePageState();
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
class _YourAudiencePageState extends State<YourAudiencePage> {
|
|
613
|
+
late final LiveCoreController _controller;
|
|
614
|
+
|
|
615
|
+
@override
|
|
616
|
+
void initState() {
|
|
617
|
+
super.initState();
|
|
618
|
+
_controller = LiveCoreController.create();
|
|
619
|
+
_controller.setLiveID(widget.liveId);
|
|
620
|
+
// 进入直播间
|
|
621
|
+
_joinLive();
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
Future<void> _joinLive() async {
|
|
625
|
+
// 调用 LiveListStore.shared.joinLive 进入直播间
|
|
626
|
+
// - liveId: 与主播开播同样的 liveId
|
|
627
|
+
final result = await LiveListStore.shared.joinLive(widget.liveId);
|
|
628
|
+
|
|
629
|
+
if (result.isSuccess) {
|
|
630
|
+
debugPrint("joinLive success");
|
|
631
|
+
} else {
|
|
632
|
+
debugPrint("joinLive error: ${result.errorMessage}");
|
|
633
|
+
// 进房失败,也需要退出页面
|
|
634
|
+
// if (mounted) Navigator.of(context).pop();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
@override
|
|
639
|
+
Widget build(BuildContext context) {
|
|
640
|
+
return Scaffold(
|
|
641
|
+
body: Stack(
|
|
642
|
+
children: [
|
|
643
|
+
LiveCoreWidget(controller: _controller),
|
|
644
|
+
],
|
|
645
|
+
),
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
```
|
|
650
|
+
3. **退出直播**
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
观众退出直播间时,需要调用 **LiveListStore** 的 `leaveLive` 接口退出直播。SDK 会自动停止拉流并退出房间。
|
|
654
|
+
|
|
655
|
+
``` java
|
|
656
|
+
import 'package:flutter/material.dart';
|
|
657
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
658
|
+
|
|
659
|
+
/// YourAudiencePage 代表您的观众观看页面
|
|
660
|
+
class YourAudiencePage extends StatefulWidget {
|
|
661
|
+
final String liveId;
|
|
662
|
+
|
|
663
|
+
const YourAudiencePage({super.key, required this.liveId});
|
|
664
|
+
|
|
665
|
+
@override
|
|
666
|
+
State<YourAudiencePage> createState() => _YourAudiencePageState();
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
class _YourAudiencePageState extends State<YourAudiencePage> {
|
|
670
|
+
// ... 其他代码 ...
|
|
671
|
+
|
|
672
|
+
// 退出直播
|
|
673
|
+
Future<void> _leaveLive() async {
|
|
674
|
+
final result = await LiveListStore.shared.leaveLive();
|
|
675
|
+
|
|
676
|
+
if (result.isSuccess) {
|
|
677
|
+
debugPrint("leaveLive success");
|
|
678
|
+
} else {
|
|
679
|
+
debugPrint("leaveLive error: ${result.errorMessage}");
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// ... 其他代码 ...
|
|
684
|
+
}
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### 步骤3:监听直播事件
|
|
688
|
+
|
|
689
|
+
在观众加入直播间后,您还需要处理一些房间内的"被动"事件。例如,主播主动结束了直播,或者观众因为违规等原因被踢出房间。如果不监听这些事件,观众端 UI 可能会停留在黑屏页面,影响用户体验。
|
|
690
|
+
|
|
691
|
+
您可以通过 `LiveListListener` 来实现事件监听。
|
|
692
|
+
``` java
|
|
693
|
+
import 'package:flutter/material.dart';
|
|
694
|
+
import 'package:atomic_x_core/atomicxcore.dart';
|
|
695
|
+
|
|
696
|
+
/// YourAudiencePage 代表您的观众观看页面
|
|
697
|
+
class YourAudiencePage extends StatefulWidget {
|
|
698
|
+
final String liveId;
|
|
699
|
+
|
|
700
|
+
const YourAudiencePage({super.key, required this.liveId});
|
|
701
|
+
|
|
702
|
+
@override
|
|
703
|
+
State<YourAudiencePage> createState() => _YourAudiencePageState();
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
class _YourAudiencePageState extends State<YourAudiencePage> {
|
|
707
|
+
late final LiveCoreController _controller;
|
|
708
|
+
// 1. 定义 LiveListListener 来管理事件监听
|
|
709
|
+
late final LiveListListener _liveListListener;
|
|
710
|
+
|
|
711
|
+
@override
|
|
712
|
+
void initState() {
|
|
713
|
+
super.initState();
|
|
714
|
+
_controller = LiveCoreController.create();
|
|
715
|
+
_controller.setLiveID(widget.liveId);
|
|
716
|
+
// 2. 监听直播事件
|
|
717
|
+
_setupLiveEventListener();
|
|
718
|
+
// 3. 进入直播间
|
|
719
|
+
_joinLive();
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// 4. 新增一个方法来设置事件监听
|
|
723
|
+
void _setupLiveEventListener() {
|
|
724
|
+
_liveListListener = LiveListListener(
|
|
725
|
+
onLiveEnded: (liveID, reason, message) {
|
|
726
|
+
// 监听到直播结束
|
|
727
|
+
debugPrint("Live ended. liveID: $liveID, reason: ${reason.value}, message: $message");
|
|
728
|
+
// 在此处处理退出直播间的逻辑,例如关闭当前页面
|
|
729
|
+
// if (mounted) Navigator.of(context).pop();
|
|
730
|
+
},
|
|
731
|
+
onKickedOutOfLive: (liveID, reason, message) {
|
|
732
|
+
// 监听到被踢出直播
|
|
733
|
+
debugPrint("Kicked out of live. liveID: $liveID, reason: ${reason.value}, message: $message");
|
|
734
|
+
// 在此处处理退出直播间的逻辑
|
|
735
|
+
// if (mounted) Navigator.of(context).pop();
|
|
736
|
+
},
|
|
737
|
+
);
|
|
738
|
+
LiveListStore.shared.addLiveListListener(_liveListListener);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
Future<void> _joinLive() async {
|
|
742
|
+
final result = await LiveListStore.shared.joinLive(widget.liveId);
|
|
743
|
+
if (result.isSuccess) {
|
|
744
|
+
debugPrint("joinLive success");
|
|
745
|
+
} else {
|
|
746
|
+
debugPrint("joinLive error: ${result.errorMessage}");
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
Future<void> _leaveLive() async {
|
|
751
|
+
final result = await LiveListStore.shared.leaveLive();
|
|
752
|
+
if (result.isSuccess) {
|
|
753
|
+
debugPrint("leaveLive success");
|
|
754
|
+
} else {
|
|
755
|
+
debugPrint("leaveLive error: ${result.errorMessage}");
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
@override
|
|
760
|
+
void dispose() {
|
|
761
|
+
// 5. 移除事件监听
|
|
762
|
+
LiveListStore.shared.removeLiveListListener(_liveListListener);
|
|
763
|
+
super.dispose();
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
@override
|
|
767
|
+
Widget build(BuildContext context) {
|
|
768
|
+
return Scaffold(
|
|
769
|
+
body: Stack(
|
|
770
|
+
children: [
|
|
771
|
+
LiveCoreWidget(controller: _controller),
|
|
772
|
+
],
|
|
773
|
+
),
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
### 运行效果
|
|
780
|
+
|
|
781
|
+
集成 **LiveCoreWidget** 后,您将得到一个纯净的视频渲染视图,它已具备完整的直播业务能力,但没有任何交互 UI。您可以参考下一章节 [丰富直播场景](https://write.woa.com/#.E4.B8.B0.E5.AF.8C.E7.9B.B4.E6.92.AD.E5.9C.BA.E6.99.AF) 来完善直播场景。
|
|
782
|
+
<table>
|
|
783
|
+
<tr>
|
|
784
|
+
<td rowspan="1" colSpan="1" ></td>
|
|
785
|
+
|
|
786
|
+
<td rowspan="1" colSpan="1" >**动态宫格布局**</td>
|
|
787
|
+
|
|
788
|
+
<td rowspan="1" colSpan="1" >**浮动小窗布局**</td>
|
|
789
|
+
|
|
790
|
+
<td rowspan="1" colSpan="1" >**固定宫格布局**</td>
|
|
791
|
+
|
|
792
|
+
<td rowspan="1" colSpan="1" >**固定小窗布局**</td>
|
|
793
|
+
</tr>
|
|
794
|
+
|
|
795
|
+
<tr>
|
|
796
|
+
<td rowspan="1" colSpan="1" >**模板 ID**</td>
|
|
797
|
+
|
|
798
|
+
<td rowspan="1" colSpan="1" >600</td>
|
|
799
|
+
|
|
800
|
+
<td rowspan="1" colSpan="1" >601</td>
|
|
801
|
+
|
|
802
|
+
<td rowspan="1" colSpan="1" >800</td>
|
|
803
|
+
|
|
804
|
+
<td rowspan="1" colSpan="1" >801</td>
|
|
805
|
+
</tr>
|
|
806
|
+
|
|
807
|
+
<tr>
|
|
808
|
+
<td rowspan="1" colSpan="1" >**描述**</td>
|
|
809
|
+
|
|
810
|
+
<td rowspan="1" colSpan="1" >默认布局,可根据连麦人数动态调整宫格大小。</td>
|
|
811
|
+
|
|
812
|
+
<td rowspan="1" colSpan="1" >连麦嘉宾以浮动小窗形式显示。</td>
|
|
813
|
+
|
|
814
|
+
<td rowspan="1" colSpan="1" >连麦人数固定,每个嘉宾占据一个固定宫格。</td>
|
|
815
|
+
|
|
816
|
+
<td rowspan="1" colSpan="1" >连麦人数固定,嘉宾以固定小窗形式显示。</td>
|
|
817
|
+
</tr>
|
|
818
|
+
</table>
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
## 丰富直播场景
|
|
822
|
+
|
|
823
|
+
当您完成了基础的直播功能后,您可以参考以下功能指南来为直播添加丰富的互动玩法。
|
|
824
|
+
<table>
|
|
825
|
+
<tr>
|
|
826
|
+
<td rowspan="1" colSpan="1" >**直播功能**</td>
|
|
827
|
+
|
|
828
|
+
<td rowspan="1" colSpan="1" >**功能介绍**</td>
|
|
829
|
+
|
|
830
|
+
<td rowspan="1" colSpan="1" >**功能 Stores**</td>
|
|
831
|
+
|
|
832
|
+
<td rowspan="1" colSpan="1" >**实现指南**</td>
|
|
833
|
+
</tr>
|
|
834
|
+
|
|
835
|
+
<tr>
|
|
836
|
+
<td rowspan="1" colSpan="1" >**实现观众音视频连线**</td>
|
|
837
|
+
|
|
838
|
+
<td rowspan="1" colSpan="1" >观众申请上麦,与主播进行实时视频互动。</td>
|
|
839
|
+
|
|
840
|
+
<td rowspan="1" colSpan="1" >[CoGuestStore](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_co_guest_store/CoGuestStore-class.html)</td>
|
|
841
|
+
|
|
842
|
+
<td rowspan="1" colSpan="1" >[实现观众连线](https://write.woa.com/document/191126722261704704)</td>
|
|
843
|
+
</tr>
|
|
844
|
+
|
|
845
|
+
<tr>
|
|
846
|
+
<td rowspan="1" colSpan="1" >**实现主播跨房连线 PK**</td>
|
|
847
|
+
|
|
848
|
+
<td rowspan="1" colSpan="1" >两个不同房间的主播进行连线,实现互动或 PK。</td>
|
|
849
|
+
|
|
850
|
+
<td rowspan="1" colSpan="1" >[CoHostStore](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_co_host_store/CoHostStore-class.html) / [BattleStore](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_battle_store/BattleStore-class.html)</td>
|
|
851
|
+
|
|
852
|
+
<td rowspan="1" colSpan="1" >[实现主播连线 PK](https://write.woa.com/document/191126592718098432)</td>
|
|
853
|
+
</tr>
|
|
854
|
+
|
|
855
|
+
<tr>
|
|
856
|
+
<td rowspan="1" colSpan="1" >**添加弹幕聊天功能**</td>
|
|
857
|
+
|
|
858
|
+
<td rowspan="1" colSpan="1" >观众可以在直播间发送和接收实时文字消息。</td>
|
|
859
|
+
|
|
860
|
+
<td rowspan="1" colSpan="1" >[BarrageStore](https://tencent-rtc.github.io/TUIKit_Flutter/api_barrage_barrage_store/BarrageStore-class.html)</td>
|
|
861
|
+
|
|
862
|
+
<td rowspan="1" colSpan="1" >[实现弹幕功能](https://write.woa.com/document/191126817095999488)</td>
|
|
863
|
+
</tr>
|
|
864
|
+
|
|
865
|
+
<tr>
|
|
866
|
+
<td rowspan="1" colSpan="1" >**构建礼物赠送系统**</td>
|
|
867
|
+
|
|
868
|
+
<td rowspan="1" colSpan="1" >观众可以向主播赠送虚拟礼物,增加互动和趣味性。</td>
|
|
869
|
+
|
|
870
|
+
<td rowspan="1" colSpan="1" >[GiftStore](https://tencent-rtc.github.io/TUIKit_Flutter/api_gift_gift_store/GiftStore-class.html)</td>
|
|
871
|
+
|
|
872
|
+
<td rowspan="1" colSpan="1" >[实现礼物功能](https://write.woa.com/document/191127024797196288)</td>
|
|
873
|
+
</tr>
|
|
874
|
+
</table>
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
## API 文档
|
|
878
|
+
<table>
|
|
879
|
+
<tr>
|
|
880
|
+
<td rowspan="1" colSpan="1" >**Store/Component**</td>
|
|
881
|
+
|
|
882
|
+
<td rowspan="1" colSpan="1" >**功能描述**</td>
|
|
883
|
+
|
|
884
|
+
<td rowspan="1" colSpan="1" >**API 文档**</td>
|
|
885
|
+
</tr>
|
|
886
|
+
|
|
887
|
+
<tr>
|
|
888
|
+
<td rowspan="1" colSpan="1" >**LiveCoreWidget**</td>
|
|
889
|
+
|
|
890
|
+
<td rowspan="1" colSpan="1" >直播视频流展示与交互的核心视图组件:负责视频流渲染和视图挂件处理,支持主播直播、观众连麦、主播连线等场景。</td>
|
|
891
|
+
|
|
892
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_view_live_live_core_widget/LiveCoreWidget-class.html)</td>
|
|
893
|
+
</tr>
|
|
894
|
+
|
|
895
|
+
<tr>
|
|
896
|
+
<td rowspan="1" colSpan="1" >**LiveCoreController**</td>
|
|
897
|
+
|
|
898
|
+
<td rowspan="1" colSpan="1" >LiveCoreWidget 的控制器:用于设置直播 ID、控制预览等操作。</td>
|
|
899
|
+
|
|
900
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_view_live_live_core_widget/LiveCoreController-class.html)</td>
|
|
901
|
+
</tr>
|
|
902
|
+
|
|
903
|
+
<tr>
|
|
904
|
+
<td rowspan="1" colSpan="1" >**LiveListStore**</td>
|
|
905
|
+
|
|
906
|
+
<td rowspan="1" colSpan="1" >直播间全生命周期管理:创建 / 加入 / 离开 / 销毁房间,查询房间列表,修改直播信息(名称、公告等),监听直播状态(如被踢出、结束)。</td>
|
|
907
|
+
|
|
908
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_live_list_store/LiveListStore-class.html)</td>
|
|
909
|
+
</tr>
|
|
910
|
+
|
|
911
|
+
<tr>
|
|
912
|
+
<td rowspan="1" colSpan="1" >**DeviceStore**</td>
|
|
913
|
+
|
|
914
|
+
<td rowspan="1" colSpan="1" >音视频设备控制:麦克风(开关 / 音量)、摄像头(开关 / 切换 / 画质)、屏幕共享,设备状态实时监听。</td>
|
|
915
|
+
|
|
916
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_device_device_store/DeviceStore-class.html)</td>
|
|
917
|
+
</tr>
|
|
918
|
+
|
|
919
|
+
<tr>
|
|
920
|
+
<td rowspan="1" colSpan="1" >**CoGuestStore**</td>
|
|
921
|
+
|
|
922
|
+
<td rowspan="1" colSpan="1" >观众连麦管理:连麦申请 / 邀请 / 同意 / 拒绝,连麦成员权限控制(麦克风 / 摄像头),状态同步。</td>
|
|
923
|
+
|
|
924
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_co_guest_store/CoGuestStore-class.html)</td>
|
|
925
|
+
</tr>
|
|
926
|
+
|
|
927
|
+
<tr>
|
|
928
|
+
<td rowspan="1" colSpan="1" >**CoHostStore**</td>
|
|
929
|
+
|
|
930
|
+
<td rowspan="1" colSpan="1" >主播跨房连线:支持多布局模板(动态网格等),发起 / 接受 / 拒绝连线,连麦主播互动管理。</td>
|
|
931
|
+
|
|
932
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_co_host_store/CoHostStore-class.html)</td>
|
|
933
|
+
</tr>
|
|
934
|
+
|
|
935
|
+
<tr>
|
|
936
|
+
<td rowspan="1" colSpan="1" >**BattleStore**</td>
|
|
937
|
+
|
|
938
|
+
<td rowspan="1" colSpan="1" >主播 PK 对战:发起 PK(配置时长 / 对手),管理 PK 状态(开始 / 结束),同步分数,监听对战结果。</td>
|
|
939
|
+
|
|
940
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_battle_store/BattleStore-class.html)</td>
|
|
941
|
+
</tr>
|
|
942
|
+
|
|
943
|
+
<tr>
|
|
944
|
+
<td rowspan="1" colSpan="1" >**GiftStore**</td>
|
|
945
|
+
|
|
946
|
+
<td rowspan="1" colSpan="1" >礼物互动:获取礼物列表,发送 / 接收礼物,监听礼物事件(含发送者、礼物详情)。</td>
|
|
947
|
+
|
|
948
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_gift_gift_store/GiftStore-class.html)</td>
|
|
949
|
+
</tr>
|
|
950
|
+
|
|
951
|
+
<tr>
|
|
952
|
+
<td rowspan="1" colSpan="1" >**BarrageStore**</td>
|
|
953
|
+
|
|
954
|
+
<td rowspan="1" colSpan="1" >弹幕功能:发送文本 / 自定义弹幕,维护弹幕列表,实时监听弹幕状态。</td>
|
|
955
|
+
|
|
956
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_barrage_barrage_store/BarrageStore-class.html)</td>
|
|
957
|
+
</tr>
|
|
958
|
+
|
|
959
|
+
<tr>
|
|
960
|
+
<td rowspan="1" colSpan="1" >**LikeStore**</td>
|
|
961
|
+
|
|
962
|
+
<td rowspan="1" colSpan="1" >点赞互动:发送点赞,监听点赞事件,同步总点赞数。</td>
|
|
963
|
+
|
|
964
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_like_store/LikeStore-class.html)</td>
|
|
965
|
+
</tr>
|
|
966
|
+
|
|
967
|
+
<tr>
|
|
968
|
+
<td rowspan="1" colSpan="1" >**LiveAudienceStore**</td>
|
|
969
|
+
|
|
970
|
+
<td rowspan="1" colSpan="1" >观众管理:获取实时观众列表(ID / 名称 / 头像),统计观众数量,监听观众进出事件。</td>
|
|
971
|
+
|
|
972
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_live_live_audience_store/LiveAudienceStore-class.html)</td>
|
|
973
|
+
</tr>
|
|
974
|
+
|
|
975
|
+
<tr>
|
|
976
|
+
<td rowspan="1" colSpan="1" >**AudioEffectStore**</td>
|
|
977
|
+
|
|
978
|
+
<td rowspan="1" colSpan="1" >音频特效:变声(童声 / 男声)、混响(KTV 等)、耳返调节,实时切换特效。</td>
|
|
979
|
+
|
|
980
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_device_audio_effect_store/AudioEffectStore-class.html)</td>
|
|
981
|
+
</tr>
|
|
982
|
+
|
|
983
|
+
<tr>
|
|
984
|
+
<td rowspan="1" colSpan="1" >**BaseBeautyStore**</td>
|
|
985
|
+
|
|
986
|
+
<td rowspan="1" colSpan="1" >基础美颜:调节磨皮 / 美白 / 红润(0-100 级),重置美颜状态,同步效果参数。</td>
|
|
987
|
+
|
|
988
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Flutter/api_device_base_beauty_store/BaseBeautyStore-class.html)</td>
|
|
989
|
+
</tr>
|
|
990
|
+
</table>
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
## 常见问题
|
|
994
|
+
|
|
995
|
+
### 主播调用 createLive 或 观众调用 joinLive 后为什么画面是黑的,没有视频画面?
|
|
996
|
+
- **检查 setLiveID**:请确保在调用开播或观看接口前,已经为 `LiveCoreController` 实例设置了正确的 `liveID`。
|
|
997
|
+
|
|
998
|
+
- **检查设备权限**:请确保 App 已获得摄像头和麦克风的系统使用权限。
|
|
999
|
+
|
|
1000
|
+
- **检查主播端**:主播端是否正常调用 `DeviceStore.shared.openLocalCamera(true)` 打开了摄像头。
|
|
1001
|
+
|
|
1002
|
+
- **检查网络**:请检查设备网络连接是否正常。
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
### Flutter 项目如何请求权限?
|
|
1006
|
+
|
|
1007
|
+
您可以使用 `permission_handler` 插件来请求摄像头和麦克风权限:
|
|
1008
|
+
``` java
|
|
1009
|
+
import 'package:permission_handler/permission_handler.dart';
|
|
1010
|
+
|
|
1011
|
+
Future<void> requestPermissions() async {
|
|
1012
|
+
await [
|
|
1013
|
+
Permission.camera,
|
|
1014
|
+
Permission.microphone,
|
|
1015
|
+
].request();
|
|
1016
|
+
}
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
### 如何在 Flutter 中处理页面生命周期?
|
|
1020
|
+
|
|
1021
|
+
建议在 `dispose` 方法中清理资源,例如移除事件监听器:
|
|
1022
|
+
``` java
|
|
1023
|
+
@override
|
|
1024
|
+
void dispose() {
|
|
1025
|
+
LiveListStore.shared.removeLiveListListener(_liveListListener);
|
|
1026
|
+
super.dispose();
|
|
1027
|
+
}
|
|
1028
|
+
```
|
|
1029
|
+
|