@tencentcloud/sdk-mcp 1.3.8 → 1.3.9
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/integration.md +466 -484
- package/resource/doc/chatuikit/android/workflow.md +713 -0
- package/resource/doc/livekit/live/flutter/live-integration.md +208 -167
- package/resource/doc/livekit/voice/android/voice-audience-list.md +335 -0
- package/resource/doc/livekit/voice/android/voice-audio-effect.md +384 -0
- package/resource/doc/livekit/voice/android/voice-barrage.md +569 -0
- package/resource/doc/livekit/voice/android/voice-co-guest-interaction.md +748 -0
- package/resource/doc/livekit/voice/android/voice-gift.md +833 -0
- package/resource/doc/livekit/voice/android/voice-host-interaction.md +728 -0
- package/resource/doc/livekit/voice/android/voice-integration.md +886 -0
- package/resource/doc/livekit/voice/android/voice-room-list.md +493 -0
- package/resource/doc/livekit/voice/android/workflow.md +333 -0
- package/resource/doc/livekit/voice/flutter/voice-audience-list.md +337 -0
- package/resource/doc/livekit/voice/flutter/voice-audio-effect.md +739 -0
- package/resource/doc/livekit/voice/flutter/voice-barrage.md +578 -0
- package/resource/doc/livekit/voice/flutter/voice-co-guest-interaction.md +673 -0
- package/resource/doc/livekit/voice/flutter/voice-gift.md +812 -0
- package/resource/doc/livekit/voice/flutter/voice-integration.md +925 -0
- package/resource/doc/livekit/voice/flutter/voice-room-list.md +842 -0
- package/resource/doc/livekit/voice/flutter/workflow.md +359 -0
- package/resource/doc/livekit/voice/ios/voice-audience-list.md +335 -0
- package/resource/doc/livekit/voice/ios/voice-audio-effect.md +373 -0
- package/resource/doc/livekit/voice/ios/voice-barrage.md +529 -0
- package/resource/doc/livekit/voice/ios/voice-co-guest-interaction.md +701 -0
- package/resource/doc/livekit/voice/ios/voice-gift.md +785 -0
- package/resource/doc/livekit/voice/ios/voice-host-interaction.md +820 -0
- package/resource/doc/livekit/voice/ios/voice-integration.md +853 -0
- package/resource/doc/livekit/voice/ios/voice-room-list.md +467 -0
- package/resource/doc/livekit/voice/ios/workflow.md +358 -0
- package/resource/doc/livekit/voice/uni-app/voice-audience-list.md +264 -0
- package/resource/doc/livekit/voice/uni-app/voice-audio-effect.md +332 -0
- package/resource/doc/livekit/voice/uni-app/voice-barrage.md +482 -0
- package/resource/doc/livekit/voice/uni-app/voice-co-guest-interaction.md +944 -0
- package/resource/doc/livekit/voice/uni-app/voice-gift.md +716 -0
- package/resource/doc/livekit/voice/uni-app/voice-integration.md +613 -0
- package/resource/doc/livekit/voice/uni-app/voice-room-list.md +562 -0
- package/resource/doc/livekit/voice/uni-app/workflow.md +369 -0
- package/resource/doc/roomkit/vue/integration.md +119 -224
- package/resource/doc/roomkit/vue/workflow.md +472 -226
- package/resource/doc/tuicallkit/android/integration.md +675 -90
- package/resource/doc/tuicallkit/android/workflow.md +432 -0
- package/tools/common/present-scenario-choice.js +16 -0
- package/tools/common/present-scenario-choice.js.map +1 -0
- package/tools/definitions/get_native_call_uikit_integration_def.js +18 -2
- package/tools/definitions/get_native_call_uikit_integration_def.js.map +1 -1
- package/tools/definitions/get_native_chat_uikit_integration_def.js +29 -7
- package/tools/definitions/get_native_chat_uikit_integration_def.js.map +1 -1
- package/tools/definitions/get_native_live_uikit_integration_def.js +65 -40
- package/tools/definitions/get_native_live_uikit_integration_def.js.map +1 -1
- package/tools/definitions/get_native_live_uikit_interaction_def.js +42 -94
- package/tools/definitions/get_native_live_uikit_interaction_def.js.map +1 -1
- package/tools/definitions/get_web_room_feature_detail_def.js +29 -32
- package/tools/definitions/get_web_room_feature_detail_def.js.map +1 -1
- package/tools/definitions/get_web_room_uikit_integration_def.js +25 -9
- package/tools/definitions/get_web_room_uikit_integration_def.js.map +1 -1
- package/tools/definitions/present_scenario_choice_def.js +53 -0
- package/tools/definitions/present_scenario_choice_def.js.map +1 -0
- package/tools/definitions/record_prompt_def.js +6 -1
- package/tools/definitions/record_prompt_def.js.map +1 -1
- package/tools/definitions/record_result_def.js +20 -4
- package/tools/definitions/record_result_def.js.map +1 -1
- package/tools/index.js +2 -0
- package/tools/index.js.map +1 -1
- package/tools/live/get-native-live-uikit-integration.js +110 -34
- package/tools/live/get-native-live-uikit-integration.js.map +1 -1
- package/tools/live/get_native_live_uikit_interaction.js +128 -35
- package/tools/live/get_native_live_uikit_interaction.js.map +1 -1
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
`GiftStore` 是 `AtomicXCore` 中专门负责管理直播间礼物功能的模块。通过它,您可以为您的直播应用构建一套完整的礼物系统,实现丰富的营收和互动场景。
|
|
2
|
+
<table>
|
|
3
|
+
<tr>
|
|
4
|
+
<td rowspan="1" colSpan="1" >礼物面板</td>
|
|
5
|
+
|
|
6
|
+
<td rowspan="1" colSpan="1" >弹幕礼物</td>
|
|
7
|
+
|
|
8
|
+
<td rowspan="1" colSpan="1" >全屏礼物</td>
|
|
9
|
+
</tr>
|
|
10
|
+
|
|
11
|
+
<tr>
|
|
12
|
+
<td rowspan="1" colSpan="1" ></td>
|
|
13
|
+
|
|
14
|
+
<td rowspan="1" colSpan="1" ></td>
|
|
15
|
+
|
|
16
|
+
<td rowspan="1" colSpan="1" ></td>
|
|
17
|
+
</tr>
|
|
18
|
+
</table>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 核心功能
|
|
22
|
+
- **礼物列表获取**:从服务端拉取礼物面板所需的数据,包括礼物分类和礼物详情。
|
|
23
|
+
|
|
24
|
+
- **发送礼物**:观众可以向主播发送选定的礼物,并附带数量。
|
|
25
|
+
|
|
26
|
+
- **礼物事件广播**:实时接收房间内发生的礼物赠送事件,用于展示礼物动画和弹幕通知。
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 核心概念
|
|
30
|
+
|
|
31
|
+
在开始集成之前,我们先通过下表了解一下 `GiftStore` 相关的几个核心概念:
|
|
32
|
+
<table>
|
|
33
|
+
<tr>
|
|
34
|
+
<td rowspan="1" colSpan="1" >**核心概念**</td>
|
|
35
|
+
|
|
36
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
37
|
+
|
|
38
|
+
<td rowspan="1" colSpan="1" >**核心职责与描述**</td>
|
|
39
|
+
</tr>
|
|
40
|
+
|
|
41
|
+
<tr>
|
|
42
|
+
<td rowspan="1" colSpan="1" >`Gift`</td>
|
|
43
|
+
|
|
44
|
+
<td rowspan="1" colSpan="1" >`data class`</td>
|
|
45
|
+
|
|
46
|
+
<td rowspan="1" colSpan="1" >代表一个具体的礼物数据模型。包含了礼物的 ID、名称、图标地址、动画资源地址 (resourceURL) 和价格 (coins) 等。</td>
|
|
47
|
+
</tr>
|
|
48
|
+
|
|
49
|
+
<tr>
|
|
50
|
+
<td rowspan="1" colSpan="1" >`GiftCategory`</td>
|
|
51
|
+
|
|
52
|
+
<td rowspan="1" colSpan="1" >`data class`</td>
|
|
53
|
+
|
|
54
|
+
<td rowspan="1" colSpan="1" >代表一个礼物分类,例如“热门”、“豪华”等。它包含了分类的名称以及该分类下的 **Gift** 列表。</td>
|
|
55
|
+
</tr>
|
|
56
|
+
|
|
57
|
+
<tr>
|
|
58
|
+
<td rowspan="1" colSpan="1" >`GiftState`</td>
|
|
59
|
+
|
|
60
|
+
<td rowspan="1" colSpan="1" >`data class`</td>
|
|
61
|
+
|
|
62
|
+
<td rowspan="1" colSpan="1" >代表礼物模块的当前状态。其核心属性 usableGifts 是一个 `StateFlow`,存储了从服务端拉取到的完整礼物列表。</td>
|
|
63
|
+
</tr>
|
|
64
|
+
|
|
65
|
+
<tr>
|
|
66
|
+
<td rowspan="1" colSpan="1" >`GiftEvent`</td>
|
|
67
|
+
|
|
68
|
+
<td rowspan="1" colSpan="1" >`abstract class`</td>
|
|
69
|
+
|
|
70
|
+
<td rowspan="1" colSpan="1" >代表直播间内发生的礼物事件监听器。目前只有 onReceiveGift,当有任何人(包括自己)发送礼物时,房间内所有人都会收到此事件。</td>
|
|
71
|
+
</tr>
|
|
72
|
+
|
|
73
|
+
<tr>
|
|
74
|
+
<td rowspan="1" colSpan="1" >`GiftStore`</td>
|
|
75
|
+
|
|
76
|
+
<td rowspan="1" colSpan="1" >`abstract class`</td>
|
|
77
|
+
|
|
78
|
+
<td rowspan="1" colSpan="1" >这是与礼物功能交互的核心管理类。通过它,您可以拉取礼物列表、发送礼物,并通过添加监听器来接收礼物事件。</td>
|
|
79
|
+
</tr>
|
|
80
|
+
</table>
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## 实现步骤
|
|
84
|
+
|
|
85
|
+
### 步骤1:组件集成
|
|
86
|
+
|
|
87
|
+
> **说明:**
|
|
88
|
+
>
|
|
89
|
+
|
|
90
|
+
> 使用**礼物系统**要求开通TUILiveKit **多人连麦版**、**大规模直播版**,不同套餐中可配置的礼物数量有所不同,详细参见 [功能与计费说明](https://write.woa.com/document/141302177829593088) 中的**礼物系统**说明。
|
|
91
|
+
>
|
|
92
|
+
|
|
93
|
+
- **视频直播**:请参考 [快速接入](https://write.woa.com/document/191126372105478144) 集成 **AtomicXCore**,完成接入。
|
|
94
|
+
|
|
95
|
+
- **语聊房**:请参考 [快速接入](https://write.woa.com/document/192834878686547968) 集成 **AtomicXCore**,完成接入。
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### 步骤2:初始化并监听礼物事件
|
|
99
|
+
|
|
100
|
+
获取 GiftStore 实例,并设置监听器以接收礼物事件和礼物列表更新。
|
|
101
|
+
|
|
102
|
+
#### 实现方式:
|
|
103
|
+
1. **获取实例**:使用 `GiftStore.create(liveID)` 获取与当前直播间绑定的 `GiftStore` 实例。
|
|
104
|
+
|
|
105
|
+
2. **添加监听器**:添加 `GiftListener` 以接收 `onReceiveGift` 事件。
|
|
106
|
+
|
|
107
|
+
3. **订阅状态**:订阅 `giftStore.giftState.usableGifts` 以获取礼物列表。
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
#### 代码示例:
|
|
111
|
+
``` kotlin
|
|
112
|
+
import io.trtc.tuikit.atomicxcore.api.gift.Gift
|
|
113
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftCategory
|
|
114
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftListener
|
|
115
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftStore
|
|
116
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveUserInfo
|
|
117
|
+
import kotlinx.coroutines.flow.StateFlow
|
|
118
|
+
import kotlinx.coroutines.flow.MutableStateFlow
|
|
119
|
+
import kotlinx.coroutines.flow.asStateFlow
|
|
120
|
+
import kotlinx.coroutines.CoroutineScope
|
|
121
|
+
import kotlinx.coroutines.Dispatchers
|
|
122
|
+
import kotlinx.coroutines.launch
|
|
123
|
+
|
|
124
|
+
class GiftManager(
|
|
125
|
+
private val liveId: String
|
|
126
|
+
) {
|
|
127
|
+
private val giftStore: GiftStore = GiftStore.create(liveId)
|
|
128
|
+
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
|
129
|
+
// 对外暴露礼物列表
|
|
130
|
+
private val _giftList = MutableStateFlow<List<GiftCategory>>(emptyList())
|
|
131
|
+
val giftList: StateFlow<List<GiftCategory>> = _giftList.asStateFlow()
|
|
132
|
+
|
|
133
|
+
init {
|
|
134
|
+
setupGiftListener()
|
|
135
|
+
subscribeToGiftState()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/// 2. 订阅礼物事件
|
|
139
|
+
private fun setupGiftListener() {
|
|
140
|
+
giftStore.addGiftListener(object : GiftListener() {
|
|
141
|
+
override fun onReceiveGift(liveID: String, gift: Gift, count: Int, sender: LiveUserInfo) {
|
|
142
|
+
// 收到事件后,将其转发给UI层处理
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// 3. 订阅礼物列表状态
|
|
148
|
+
private fun subscribeToGiftState() {
|
|
149
|
+
coroutineScope.launch(Dispatchers.Main) {
|
|
150
|
+
giftStore.giftState.usableGifts.collect { giftList ->
|
|
151
|
+
// 仅在列表内容变化时才更新
|
|
152
|
+
_giftList.value = giftList
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 礼物列表结构体参数
|
|
160
|
+
- `GiftCategory`**参数说明**
|
|
161
|
+
|
|
162
|
+
<table>
|
|
163
|
+
<tr>
|
|
164
|
+
<td rowspan="1" colSpan="1" >**参数**</td>
|
|
165
|
+
|
|
166
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
167
|
+
|
|
168
|
+
<td rowspan="1" colSpan="1" >**描述**</td>
|
|
169
|
+
</tr>
|
|
170
|
+
|
|
171
|
+
<tr>
|
|
172
|
+
<td rowspan="1" colSpan="1" >`categoryID`</td>
|
|
173
|
+
|
|
174
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
175
|
+
|
|
176
|
+
<td rowspan="1" colSpan="1" >礼物分类的唯一 ID。</td>
|
|
177
|
+
</tr>
|
|
178
|
+
|
|
179
|
+
<tr>
|
|
180
|
+
<td rowspan="1" colSpan="1" >`name`</td>
|
|
181
|
+
|
|
182
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
183
|
+
|
|
184
|
+
<td rowspan="1" colSpan="1" >礼物分类的显示名称。</td>
|
|
185
|
+
</tr>
|
|
186
|
+
|
|
187
|
+
<tr>
|
|
188
|
+
<td rowspan="1" colSpan="1" >`desc`</td>
|
|
189
|
+
|
|
190
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
191
|
+
|
|
192
|
+
<td rowspan="1" colSpan="1" >礼物分类的描述信息。</td>
|
|
193
|
+
</tr>
|
|
194
|
+
|
|
195
|
+
<tr>
|
|
196
|
+
<td rowspan="1" colSpan="1" >`extensionInfo`</td>
|
|
197
|
+
|
|
198
|
+
<td rowspan="1" colSpan="1" >`Map<String, String>`</td>
|
|
199
|
+
|
|
200
|
+
<td rowspan="1" colSpan="1" >扩展信息字段。</td>
|
|
201
|
+
</tr>
|
|
202
|
+
|
|
203
|
+
<tr>
|
|
204
|
+
<td rowspan="1" colSpan="1" >`giftList`</td>
|
|
205
|
+
|
|
206
|
+
<td rowspan="1" colSpan="1" >`List`</td>
|
|
207
|
+
|
|
208
|
+
<td rowspan="1" colSpan="1" >该分类下包含的 Gift 礼物对象数组。</td>
|
|
209
|
+
</tr>
|
|
210
|
+
</table>
|
|
211
|
+
|
|
212
|
+
- `Gift`** 参数说明**
|
|
213
|
+
|
|
214
|
+
<table>
|
|
215
|
+
<tr>
|
|
216
|
+
<td rowspan="1" colSpan="1" >**参数**</td>
|
|
217
|
+
|
|
218
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
219
|
+
|
|
220
|
+
<td rowspan="1" colSpan="1" >**描述**</td>
|
|
221
|
+
</tr>
|
|
222
|
+
|
|
223
|
+
<tr>
|
|
224
|
+
<td rowspan="1" colSpan="1" >`giftID`</td>
|
|
225
|
+
|
|
226
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
227
|
+
|
|
228
|
+
<td rowspan="1" colSpan="1" > 礼物的唯一 ID。</td>
|
|
229
|
+
</tr>
|
|
230
|
+
|
|
231
|
+
<tr>
|
|
232
|
+
<td rowspan="1" colSpan="1" >`name`</td>
|
|
233
|
+
|
|
234
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
235
|
+
|
|
236
|
+
<td rowspan="1" colSpan="1" > 礼物的显示名称。</td>
|
|
237
|
+
</tr>
|
|
238
|
+
|
|
239
|
+
<tr>
|
|
240
|
+
<td rowspan="1" colSpan="1" >`desc`</td>
|
|
241
|
+
|
|
242
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
243
|
+
|
|
244
|
+
<td rowspan="1" colSpan="1" > 礼物的描述信息。</td>
|
|
245
|
+
</tr>
|
|
246
|
+
|
|
247
|
+
<tr>
|
|
248
|
+
<td rowspan="1" colSpan="1" >`iconURL`</td>
|
|
249
|
+
|
|
250
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
251
|
+
|
|
252
|
+
<td rowspan="1" colSpan="1" > 礼物图标 URL。</td>
|
|
253
|
+
</tr>
|
|
254
|
+
|
|
255
|
+
<tr>
|
|
256
|
+
<td rowspan="1" colSpan="1" >`resourceURL`</td>
|
|
257
|
+
|
|
258
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
259
|
+
|
|
260
|
+
<td rowspan="1" colSpan="1" > 礼物动画资源 URL。</td>
|
|
261
|
+
</tr>
|
|
262
|
+
|
|
263
|
+
<tr>
|
|
264
|
+
<td rowspan="1" colSpan="1" >`level`</td>
|
|
265
|
+
|
|
266
|
+
<td rowspan="1" colSpan="1" >`Long`</td>
|
|
267
|
+
|
|
268
|
+
<td rowspan="1" colSpan="1" > 礼物等级。</td>
|
|
269
|
+
</tr>
|
|
270
|
+
|
|
271
|
+
<tr>
|
|
272
|
+
<td rowspan="1" colSpan="1" >`coins`</td>
|
|
273
|
+
|
|
274
|
+
<td rowspan="1" colSpan="1" >`Long`</td>
|
|
275
|
+
|
|
276
|
+
<td rowspan="1" colSpan="1" > 礼物价格。</td>
|
|
277
|
+
</tr>
|
|
278
|
+
|
|
279
|
+
<tr>
|
|
280
|
+
<td rowspan="1" colSpan="1" >`extensionInfo`</td>
|
|
281
|
+
|
|
282
|
+
<td rowspan="1" colSpan="1" >`Map<String, String>`</td>
|
|
283
|
+
|
|
284
|
+
<td rowspan="1" colSpan="1" > 扩展信息字段。</td>
|
|
285
|
+
</tr>
|
|
286
|
+
</table>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
### 步骤3:获取礼物列表
|
|
290
|
+
|
|
291
|
+
调用 `refreshUsableGifts` 方法,从服务端拉取礼物数据。
|
|
292
|
+
|
|
293
|
+
#### 实现方式:
|
|
294
|
+
1. **调用接口**:在合适的时机(如进入直播间后)调用 `giftStore.refreshUsableGifts()`。
|
|
295
|
+
|
|
296
|
+
2. **处理回调**:可选地处理 completion 回调以获知拉取结果。
|
|
297
|
+
|
|
298
|
+
3. **接收数据**:拉取成功后,通过步骤2中对 giftStore.giftState.usableGifts 的订阅,自动接收到更新后的 usableGifts 列表。
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
#### 代码示例:
|
|
302
|
+
``` kotlin
|
|
303
|
+
class GiftManager(
|
|
304
|
+
private val liveId: String
|
|
305
|
+
) {
|
|
306
|
+
private val giftStore: GiftStore = GiftStore.create(liveId)
|
|
307
|
+
|
|
308
|
+
/// 从服务端刷新礼物列表
|
|
309
|
+
fun fetchGiftList() {
|
|
310
|
+
giftStore.refreshUsableGifts(object : CompletionHandler {
|
|
311
|
+
override fun onSuccess() {
|
|
312
|
+
println("礼物列表拉取成功")
|
|
313
|
+
// 成功后,数据会通过 giftState 订阅通道自动更新
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
override fun onFailure(code: Int, desc: String) {
|
|
317
|
+
println("礼物列表拉取失败: $desc")
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 步骤4:发送礼物
|
|
325
|
+
|
|
326
|
+
当用户在礼物面板选择一个礼物并点击发送时,调用 `sendGift` 接口将礼物发送出去。
|
|
327
|
+
|
|
328
|
+
#### 实现方式:
|
|
329
|
+
1. **获取参数**:从UI获取用户选择的 giftID 和发送数量 count。
|
|
330
|
+
|
|
331
|
+
2. **调用接口**:调用 `giftStore.sendGift(giftID, count, completion)`。
|
|
332
|
+
|
|
333
|
+
3. **处理回调**:在 `completion` 回调中处理发送失败的情况(例如余额不足提示);发送成功后的 UI 更新(动画、弹幕)应由 `onReceiveGift` 事件驱动。
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
#### 代码示例:
|
|
337
|
+
``` kotlin
|
|
338
|
+
class GiftManager(
|
|
339
|
+
private val liveId: String
|
|
340
|
+
) {
|
|
341
|
+
private val giftStore: GiftStore = GiftStore.create(liveId)
|
|
342
|
+
|
|
343
|
+
/// 用户发送一个礼物
|
|
344
|
+
fun sendGift(giftID: String, count: Int) {
|
|
345
|
+
giftStore.sendGift(giftID, count, object : CompletionHandler {
|
|
346
|
+
override fun onSuccess() {
|
|
347
|
+
println("礼物 $giftID 发送成功")
|
|
348
|
+
// 发送成功后,包括发送者在内的所有人都会收到 onReceiveGift 事件
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
override fun onFailure(code: Int, desc: String) {
|
|
352
|
+
println("礼物发送失败: $desc")
|
|
353
|
+
// 可以在此提示用户,例如"余额不足"或"网络错误"
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### `sendGift`接口参数
|
|
361
|
+
<table>
|
|
362
|
+
<tr>
|
|
363
|
+
<td rowspan="1" colSpan="1" >**参数名**</td>
|
|
364
|
+
|
|
365
|
+
<td rowspan="1" colSpan="1" >**类型**</td>
|
|
366
|
+
|
|
367
|
+
<td rowspan="1" colSpan="1" >**描述**</td>
|
|
368
|
+
</tr>
|
|
369
|
+
|
|
370
|
+
<tr>
|
|
371
|
+
<td rowspan="1" colSpan="1" >`giftID`</td>
|
|
372
|
+
|
|
373
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
374
|
+
|
|
375
|
+
<td rowspan="1" colSpan="1" >要发送的礼物的唯一 ID。</td>
|
|
376
|
+
</tr>
|
|
377
|
+
|
|
378
|
+
<tr>
|
|
379
|
+
<td rowspan="1" colSpan="1" >`count`</td>
|
|
380
|
+
|
|
381
|
+
<td rowspan="1" colSpan="1" >`Int`</td>
|
|
382
|
+
|
|
383
|
+
<td rowspan="1" colSpan="1" >发送的数量。</td>
|
|
384
|
+
</tr>
|
|
385
|
+
|
|
386
|
+
<tr>
|
|
387
|
+
<td rowspan="1" colSpan="1" >`completion`</td>
|
|
388
|
+
|
|
389
|
+
<td rowspan="1" colSpan="1" >`CompletionHandler?`</td>
|
|
390
|
+
|
|
391
|
+
<td rowspan="1" colSpan="1" >发送完成后的回调。</td>
|
|
392
|
+
</tr>
|
|
393
|
+
</table>
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
## 功能进阶
|
|
397
|
+
|
|
398
|
+
`GiftStore` 的功能高度依赖于您的业务后台服务。本章将指导您如何通过服务端配置和客户端实现,构建功能丰富、体验卓越的礼物互动系统。
|
|
399
|
+
|
|
400
|
+
### **礼物素材配置**
|
|
401
|
+
|
|
402
|
+
您需要自定义直播间可用的礼物种类、分类、名称、图标、价格以及动画效果,以满足运营需求和品牌特色。
|
|
403
|
+
|
|
404
|
+
#### 实现方式
|
|
405
|
+
1. **服务端配置**:使用 LiveKit 服务端 REST API 管理礼物信息、分类、多语言等。请参考 [礼物配置指引文档](https://cloud.tencent.com/document/product/647/121321)。
|
|
406
|
+
|
|
407
|
+
2. **客户端拉取**:在客户端调用 `refreshUsableGifts` 获取配置数据。
|
|
408
|
+
|
|
409
|
+
3. **UI 展示**:使用拉取到的 `List<GiftCategory>` 数据填充礼物面板。
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
#### **配置时序图**
|
|
413
|
+
|
|
414
|
+

|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
#### **涉及 REST API 接口一览**
|
|
418
|
+
<table>
|
|
419
|
+
<tr>
|
|
420
|
+
<td rowspan="1" colSpan="1" >接口分类</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="3" colSpan="1" >礼物管理</td>
|
|
429
|
+
|
|
430
|
+
<td rowspan="1" colSpan="1" >添加礼物信息</td>
|
|
431
|
+
|
|
432
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341527570997248)</td>
|
|
433
|
+
</tr>
|
|
434
|
+
|
|
435
|
+
<tr>
|
|
436
|
+
<td rowspan="1" colSpan="1" >删除礼物信息</td>
|
|
437
|
+
|
|
438
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341544133693440)</td>
|
|
439
|
+
</tr>
|
|
440
|
+
|
|
441
|
+
<tr>
|
|
442
|
+
<td rowspan="1" colSpan="1" >查询礼物信息</td>
|
|
443
|
+
|
|
444
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341539054186496)</td>
|
|
445
|
+
</tr>
|
|
446
|
+
|
|
447
|
+
<tr>
|
|
448
|
+
<td rowspan="3" colSpan="1" >礼物分类管理</td>
|
|
449
|
+
|
|
450
|
+
<td rowspan="1" colSpan="1" >添加礼物分类信息</td>
|
|
451
|
+
|
|
452
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180807825764642816)</td>
|
|
453
|
+
</tr>
|
|
454
|
+
|
|
455
|
+
<tr>
|
|
456
|
+
<td rowspan="1" colSpan="1" >删除指定礼物分类信息</td>
|
|
457
|
+
|
|
458
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180807830209925120)</td>
|
|
459
|
+
</tr>
|
|
460
|
+
|
|
461
|
+
<tr>
|
|
462
|
+
<td rowspan="1" colSpan="1" >获取指定礼物分类信息</td>
|
|
463
|
+
|
|
464
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180807827909746688)</td>
|
|
465
|
+
</tr>
|
|
466
|
+
|
|
467
|
+
<tr>
|
|
468
|
+
<td rowspan="3" colSpan="1" >礼物关系管理</td>
|
|
469
|
+
|
|
470
|
+
<td rowspan="1" colSpan="1" >添加指定礼物分类和礼物间的关系</td>
|
|
471
|
+
|
|
472
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341551420928000)</td>
|
|
473
|
+
</tr>
|
|
474
|
+
|
|
475
|
+
<tr>
|
|
476
|
+
<td rowspan="1" colSpan="1" >删除指定礼物分类和礼物间的关系</td>
|
|
477
|
+
|
|
478
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341562381627392)</td>
|
|
479
|
+
</tr>
|
|
480
|
+
|
|
481
|
+
<tr>
|
|
482
|
+
<td rowspan="1" colSpan="1" >获取指定礼物分类下的礼物关系</td>
|
|
483
|
+
|
|
484
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341571868094464)</td>
|
|
485
|
+
</tr>
|
|
486
|
+
|
|
487
|
+
<tr>
|
|
488
|
+
<td rowspan="6" colSpan="1" >礼物多语言管理</td>
|
|
489
|
+
|
|
490
|
+
<td rowspan="1" colSpan="1" >添加礼物多语言信息</td>
|
|
491
|
+
|
|
492
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341579611611136)</td>
|
|
493
|
+
</tr>
|
|
494
|
+
|
|
495
|
+
<tr>
|
|
496
|
+
<td rowspan="1" colSpan="1" >删除指定礼物多语言信息</td>
|
|
497
|
+
|
|
498
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341598501920768)</td>
|
|
499
|
+
</tr>
|
|
500
|
+
|
|
501
|
+
<tr>
|
|
502
|
+
<td rowspan="1" colSpan="1" >获取礼物多语言信息</td>
|
|
503
|
+
|
|
504
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341588810166272)</td>
|
|
505
|
+
</tr>
|
|
506
|
+
|
|
507
|
+
<tr>
|
|
508
|
+
<td rowspan="1" colSpan="1" >添加礼物分类多语言信息</td>
|
|
509
|
+
|
|
510
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341603609534464)</td>
|
|
511
|
+
</tr>
|
|
512
|
+
|
|
513
|
+
<tr>
|
|
514
|
+
<td rowspan="1" colSpan="1" >删除指定礼物分类多语言信息</td>
|
|
515
|
+
|
|
516
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341624911425536)</td>
|
|
517
|
+
</tr>
|
|
518
|
+
|
|
519
|
+
<tr>
|
|
520
|
+
<td rowspan="1" colSpan="1" >获取礼物分类多语言信息</td>
|
|
521
|
+
|
|
522
|
+
<td rowspan="1" colSpan="1" >[请求示例](https://write.woa.com/document/180341612525645824)</td>
|
|
523
|
+
</tr>
|
|
524
|
+
</table>
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
### 计费与送礼扣费流程
|
|
528
|
+
|
|
529
|
+
当观众赠送礼物时,需要确保其账户余额充足,并完成实际的扣费操作,然后才能触发礼物特效的播放和广播。
|
|
530
|
+
|
|
531
|
+
#### 实现方式
|
|
532
|
+
1. **后台配置回调**:在 LiveKit 后台配置您的自建计费系统的回调 URL。参考 [回调配置文档](https://write.woa.com/document/183772947196690432)。
|
|
533
|
+
|
|
534
|
+
2. **客户端发送**:客户端调用 `sendGift`。
|
|
535
|
+
|
|
536
|
+
3. **后台交互**:LiveKit 后台调用您的回调 URL,您的计费系统执行扣费并返回结果。
|
|
537
|
+
|
|
538
|
+
4. **结果同步**:扣费成功,AtomicXCore 广播 `onReceiveGift` 事件;扣费失败,`sendGift` 的 `completion` 收到错误。
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
#### 调用流程图
|
|
542
|
+
|
|
543
|
+

|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
#### 涉及 REST API 接口一览
|
|
547
|
+
<table>
|
|
548
|
+
<tr>
|
|
549
|
+
<td rowspan="1" colSpan="1" >接口</td>
|
|
550
|
+
|
|
551
|
+
<td rowspan="1" colSpan="1" >说明</td>
|
|
552
|
+
|
|
553
|
+
<td rowspan="1" colSpan="1" >请求示例</td>
|
|
554
|
+
</tr>
|
|
555
|
+
|
|
556
|
+
<tr>
|
|
557
|
+
<td rowspan="1" colSpan="1" >回调配置 - 发送礼物之前回调</td>
|
|
558
|
+
|
|
559
|
+
<td rowspan="1" colSpan="1" >客户后台可以通过该回调决定是否通过送礼前校验等场景</td>
|
|
560
|
+
|
|
561
|
+
<td rowspan="1" colSpan="1" >[调用示例](https://write.woa.com/document/183772947196690432)</td>
|
|
562
|
+
</tr>
|
|
563
|
+
</table>
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
### 实现全屏礼物动画播放
|
|
567
|
+
|
|
568
|
+
当直播间有用户(包括自己)发送了"火箭"、"嘉年华"等豪华礼物时,全屏播放一个酷炫的礼物动画(例如 SVGA 动画),营造热烈的氛围。
|
|
569
|
+
|
|
570
|
+
#### 实现方式
|
|
571
|
+
|
|
572
|
+
`AtomicXCore` 本身不包含礼物动画播放器,您需要根据业务需求选择并集成第三方库。以下是两种方案的对比:
|
|
573
|
+
<table>
|
|
574
|
+
<tr>
|
|
575
|
+
<td rowspan="1" colSpan="1" >**对比项**</td>
|
|
576
|
+
|
|
577
|
+
<td rowspan="1" colSpan="1" >**基础方案 (SVGAPlayer-Android)**</td>
|
|
578
|
+
|
|
579
|
+
<td rowspan="1" colSpan="1" >**高级方案 (TCEffectPlayerKit)**</td>
|
|
580
|
+
</tr>
|
|
581
|
+
|
|
582
|
+
<tr>
|
|
583
|
+
<td rowspan="1" colSpan="1" >计费</td>
|
|
584
|
+
|
|
585
|
+
<td rowspan="1" colSpan="1" >免费 (开源库)</td>
|
|
586
|
+
|
|
587
|
+
<td rowspan="1" colSpan="1" >付费 (需购买 License),请参见 [付费指引](https://cloud.tencent.com/document/product/616/116461)</td>
|
|
588
|
+
</tr>
|
|
589
|
+
|
|
590
|
+
<tr>
|
|
591
|
+
<td rowspan="1" colSpan="1" >集成方式</td>
|
|
592
|
+
|
|
593
|
+
<td rowspan="1" colSpan="1" >需手动集成 SVGAPlayer 库 (例如通过 Gradle)</td>
|
|
594
|
+
|
|
595
|
+
<td rowspan="1" colSpan="1" >需额外集成 TCEffectPlayerKit 并进行鉴权</td>
|
|
596
|
+
</tr>
|
|
597
|
+
|
|
598
|
+
<tr>
|
|
599
|
+
<td rowspan="1" colSpan="1" >动画格式支持</td>
|
|
600
|
+
|
|
601
|
+
<td rowspan="1" colSpan="1" >仅支持 SVGA</td>
|
|
602
|
+
|
|
603
|
+
<td rowspan="1" colSpan="1" >SVGA、PAG、WebP、Lottie、MP4 等多种格式</td>
|
|
604
|
+
</tr>
|
|
605
|
+
|
|
606
|
+
<tr>
|
|
607
|
+
<td rowspan="1" colSpan="1" >性能</td>
|
|
608
|
+
|
|
609
|
+
<td rowspan="1" colSpan="1" >建议 SVGA 文件 ≤ 10MB</td>
|
|
610
|
+
|
|
611
|
+
<td rowspan="1" colSpan="1" >支持更大的动画文件,复杂特效/多动画并发/低端机表现更优</td>
|
|
612
|
+
</tr>
|
|
613
|
+
|
|
614
|
+
<tr>
|
|
615
|
+
<td rowspan="1" colSpan="1" >推荐场景</td>
|
|
616
|
+
|
|
617
|
+
<td rowspan="1" colSpan="1" >礼物动画格式统一为 SVGA,且文件大小可控</td>
|
|
618
|
+
|
|
619
|
+
<td rowspan="1" colSpan="1" >需要支持多种动画格式,或对动画性能/设备兼容性有更高要求</td>
|
|
620
|
+
</tr>
|
|
621
|
+
</table>
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
本章节主要演示基础方案的集成。如果您选择高级方案,请参见 [TCEffectPlayer 集成指引](https://cloud.tencent.com/document/product/616/116472)。
|
|
625
|
+
|
|
626
|
+
#### 基础方案实现:使用 SVGAPlayer
|
|
627
|
+
1. **集成 SVGAPlayer**: 在您的 `build.gradle` 文件中,添加 `SVGAPlayer` 的依赖并同步项目。
|
|
628
|
+
|
|
629
|
+
``` gradle
|
|
630
|
+
dependencies {
|
|
631
|
+
// ... other dependencies
|
|
632
|
+
implementation 'com.github.yyued:SVGAPlayer-Android:2.6.1'
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
2. **监听礼物事件**: 订阅 `GiftStore` 的 `GiftListener`。
|
|
636
|
+
|
|
637
|
+
3. **解析并播放**: 当收到 `onReceiveGift` 事件时,检查 `gift.resourceURL` 是否有效且指向一个 SVGA 文件。如果是,则使用 `SVGAParser` 解析 URL,并将解析后的 `SVGAVideoEntity` 交给 `SVGAPlayer` 实例播放。
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
#### 代码示例
|
|
641
|
+
``` kotlin
|
|
642
|
+
import android.os.Bundle
|
|
643
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
644
|
+
import com.opensource.svgaplayer.SVGACallback
|
|
645
|
+
import com.opensource.svgaplayer.SVGAParser
|
|
646
|
+
import com.opensource.svgaplayer.SVGAVideoEntity
|
|
647
|
+
import com.opensource.svgaplayer.SVGAImageView
|
|
648
|
+
import io.trtc.tuikit.atomicxcore.api.gift.Gift
|
|
649
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftListener
|
|
650
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftStore
|
|
651
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveUserInfo
|
|
652
|
+
import java.net.URL
|
|
653
|
+
|
|
654
|
+
class LiveRoomActivity : AppCompatActivity() {
|
|
655
|
+
private lateinit var giftStore: GiftStore
|
|
656
|
+
private lateinit var svgaImageView: SVGAImageView
|
|
657
|
+
private lateinit var svgaParser: SVGAParser
|
|
658
|
+
|
|
659
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
660
|
+
super.onCreate(savedInstanceState)
|
|
661
|
+
setContentView(R.layout.activity_live_room)
|
|
662
|
+
setupSVGAPlayer()
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
private fun setupSVGAPlayer() {
|
|
666
|
+
svgaImageView = findViewById(R.id.svga_player)
|
|
667
|
+
svgaParser = SVGAParser(this)
|
|
668
|
+
svgaImageView.visibility = android.view.View.GONE
|
|
669
|
+
|
|
670
|
+
// 设置礼物播放次数为一次
|
|
671
|
+
svgaImageView.loops = 1
|
|
672
|
+
|
|
673
|
+
// 设置播放完成回调,用于隐藏和清理
|
|
674
|
+
svgaImageView.callback = object : SVGACallback {
|
|
675
|
+
override fun onFinished() {
|
|
676
|
+
svgaImageView.visibility = android.view.View.GONE
|
|
677
|
+
svgaImageView.clear()
|
|
678
|
+
}
|
|
679
|
+
override fun onPause() {}
|
|
680
|
+
override fun onRepeat() {}
|
|
681
|
+
override fun onStep(frame: Int, percentage: Double) {}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
fun setupGiftSubscription(liveId: String) {
|
|
686
|
+
giftStore = GiftStore.create(liveId)
|
|
687
|
+
|
|
688
|
+
giftStore.addGiftListener(object : GiftListener() {
|
|
689
|
+
override fun onReceiveGift(liveID: String, gift: Gift, count: Int, sender: LiveUserInfo) {
|
|
690
|
+
if (gift.resourceURL.isNotEmpty()) {
|
|
691
|
+
try {
|
|
692
|
+
val url = URL(gift.resourceURL)
|
|
693
|
+
playAnimation(url)
|
|
694
|
+
} catch (e: Exception) {
|
|
695
|
+
println("无效的动画URL: ${gift.resourceURL}")
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
})
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
private fun playAnimation(url: URL) {
|
|
703
|
+
// 4. 解析播放
|
|
704
|
+
svgaParser.decodeFromURL(url, object : SVGAParser.ParseCompletion {
|
|
705
|
+
override fun onComplete(videoItem: SVGAVideoEntity) {
|
|
706
|
+
runOnUiThread {
|
|
707
|
+
svgaImageView.setVideoItem(videoItem)
|
|
708
|
+
svgaImageView.visibility = android.view.View.VISIBLE
|
|
709
|
+
svgaImageView.startAnimation()
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
override fun onError() {
|
|
714
|
+
println("SVGA 动画解析失败")
|
|
715
|
+
// 可以在此添加失败重试或上报逻辑
|
|
716
|
+
}
|
|
717
|
+
})
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
### 在弹幕区展示礼物赠送消息
|
|
723
|
+
|
|
724
|
+
当有用户发送礼物时,不仅播放动画,同时在公屏弹幕区域显示一条系统消息,例如:“【观众昵称】送出了【礼物名称】x【数量】”,让所有观众都能看到。
|
|
725
|
+
|
|
726
|
+
#### 实现方式
|
|
727
|
+
1. **监听事件**:订阅 `giftStore` 的 `GiftListener`。
|
|
728
|
+
|
|
729
|
+
2. **获取信息**:收到 `onReceiveGift` 事件后,提取发送者 sender、礼物 gift 和数量 count。
|
|
730
|
+
|
|
731
|
+
3. **获取弹幕 Store**:使用 `BarrageStore.create(liveID)` 获取与当前房间绑定的实例。
|
|
732
|
+
|
|
733
|
+
4. **拼接消息**:创建一条 `Barrage` 结构体,设置 `messageType = BarrageType.TEXT`,textContent 为拼接好的字符串(例如 “[`sender.userName`] 送出了 [`gift.name`] x [`count`]”)。
|
|
734
|
+
|
|
735
|
+
5. **本地插入**:调用 `barrageStore.appendLocalTip(message: giftTip)` 将消息插入本地列表。
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
#### 代码示例
|
|
739
|
+
``` kotlin
|
|
740
|
+
import io.trtc.tuikit.atomicxcore.api.barrage.Barrage
|
|
741
|
+
import io.trtc.tuikit.atomicxcore.api.barrage.BarrageStore
|
|
742
|
+
import io.trtc.tuikit.atomicxcore.api.barrage.BarrageType
|
|
743
|
+
import io.trtc.tuikit.atomicxcore.api.gift.Gift
|
|
744
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftListener
|
|
745
|
+
import io.trtc.tuikit.atomicxcore.api.gift.GiftStore
|
|
746
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveUserInfo
|
|
747
|
+
|
|
748
|
+
// 在 LiveRoomManager 或类似的顶层管理器中
|
|
749
|
+
class LiveRoomManager(
|
|
750
|
+
private val liveId: String
|
|
751
|
+
) {
|
|
752
|
+
private val giftStore: GiftStore = GiftStore.create(liveId)
|
|
753
|
+
private val barrageStore: BarrageStore = BarrageStore.create(liveId)
|
|
754
|
+
|
|
755
|
+
private fun setupGiftToBarrageFlow() {
|
|
756
|
+
giftStore.addGiftListener(object : GiftListener() {
|
|
757
|
+
override fun onReceiveGift(liveID: String, gift: Gift, count: Int, sender: LiveUserInfo) {
|
|
758
|
+
// 1. 监听事件 2. 获取信息
|
|
759
|
+
|
|
760
|
+
// 4. 拼接消息
|
|
761
|
+
val tipText = "送出了 ${gift.name} x $count"
|
|
762
|
+
val giftTip = Barrage(
|
|
763
|
+
liveID = liveID,
|
|
764
|
+
messageType = BarrageType.TEXT,
|
|
765
|
+
textContent = tipText
|
|
766
|
+
sender = sender
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
// 5. 本地插入
|
|
770
|
+
barrageStore.appendLocalTip(giftTip)
|
|
771
|
+
}
|
|
772
|
+
})
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
## API 文档
|
|
778
|
+
|
|
779
|
+
关于 [GiftStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.gift/-gift-store/index.html) 及其相关类的所有公开接口、属性和方法的详细信息,请参阅随 [AtomicXCore](https://tencent-rtc.github.io/TUIKit_Android/index.html) 框架的官方 API 文档。本指南使用到的相关 Store 如下:
|
|
780
|
+
<table>
|
|
781
|
+
<tr>
|
|
782
|
+
<td rowspan="1" colSpan="1" >Store/Component</td>
|
|
783
|
+
|
|
784
|
+
<td rowspan="1" colSpan="1" >功能描述</td>
|
|
785
|
+
|
|
786
|
+
<td rowspan="1" colSpan="1" >API 文档</td>
|
|
787
|
+
</tr>
|
|
788
|
+
|
|
789
|
+
<tr>
|
|
790
|
+
<td rowspan="1" colSpan="1" >GiftStore</td>
|
|
791
|
+
|
|
792
|
+
<td rowspan="1" colSpan="1" >礼物互动:获取礼物列表,发送 / 接收礼物,监听礼物事件(含发送者、礼物详情)。</td>
|
|
793
|
+
|
|
794
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.gift/-gift-store/index.html)</td>
|
|
795
|
+
</tr>
|
|
796
|
+
|
|
797
|
+
<tr>
|
|
798
|
+
<td rowspan="1" colSpan="1" >BarrageStore</td>
|
|
799
|
+
|
|
800
|
+
<td rowspan="1" colSpan="1" >弹幕功能:发送文本 / 自定义弹幕,维护弹幕列表,实时监听弹幕状态。</td>
|
|
801
|
+
|
|
802
|
+
<td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.barrage/-barrage-store/index.html)</td>
|
|
803
|
+
</tr>
|
|
804
|
+
</table>
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
## 常见问题
|
|
808
|
+
|
|
809
|
+
### `GiftStore` 的礼物列表是空的,我该怎么办?
|
|
810
|
+
|
|
811
|
+
您必须主动调用 `refreshUsableGifts(completion)`来从您的业务后台拉取礼物数据。这些礼物数据需要在您的业务后台通过服务端 REST API 进行配置。
|
|
812
|
+
|
|
813
|
+
### 如何实现礼物的多语言展示(例如中文、英文)?
|
|
814
|
+
|
|
815
|
+
`GiftStore` 提供了 `setLanguage(language: String)`接口。您可以在 `refreshUsableGifts` 之前调用此方法,传入目标语言代码(例如 "en" 或 "zh-CN")。服务端会根据此语言代码,返回对应语言的礼物名称和描述。
|
|
816
|
+
|
|
817
|
+
### 我调用 sendGift 发送了礼物,礼物动画为什么重复播放了两次?
|
|
818
|
+
|
|
819
|
+
`onReceiveGift` 事件是对房间内所有成员的广播(包括发送者自己)。如果您在 `sendGift` 的 `completion` 成功回调里执行了一次UI操作,同时又在 `onReceiveGift` 订阅中执行了相同的UI操作,就会造成重复。
|
|
820
|
+
- **实践教程**:UI 的更新(例如播放动画、弹幕提示)只在 `onReceiveGift` 事件的订阅中处理。`sendGift` 的 `completion`回调仅用于处理发送失败的逻辑(例如提示用户"发送失败"或"余额不足")。
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
### 礼物扣费逻辑在哪里实现?
|
|
824
|
+
|
|
825
|
+
礼物扣费逻辑完全由您的自建计费系统负责。`AtomicXCore` 通过后台回调机制与您的计费系统对接。客户端调用 `sendGift` 触发回调,您的后台服务完成扣费后,将结果返回给 `AtomicXCore` 后台,从而决定礼物事件是否广播。
|
|
826
|
+
|
|
827
|
+
### 送礼通知会被禁言或频控拦截吗?
|
|
828
|
+
|
|
829
|
+
不会。送礼通知(`onReceiveGift` 事件)不受禁言或消息频控影响,确保可靠投递。
|
|
830
|
+
|
|
831
|
+
### 礼物动画播放卡顿怎么办?
|
|
832
|
+
|
|
833
|
+
请检查您的 SVGA 文件大小,基础播放器建议不要超过 10MB。如果文件过大或动画复杂,您可以考虑集成 TUILiveKit 提供的高级特效播放器,以获得更优的性能表现。
|