@tencent-rtc/mcp 1.3.2 → 1.3.4

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.
Files changed (51) hide show
  1. package/package.json +1 -1
  2. package/resource/doc/livekit/live/android/live-audience-list.md +334 -0
  3. package/resource/doc/livekit/live/android/live-audio-effect.md +380 -0
  4. package/resource/doc/livekit/live/android/live-barrage.md +565 -0
  5. package/resource/doc/livekit/live/android/live-base-beauty.md +275 -0
  6. package/resource/doc/livekit/live/android/live-co-guest-interaction.md +629 -0
  7. package/resource/doc/livekit/live/android/live-gift.md +822 -0
  8. package/resource/doc/livekit/live/android/live-host-interaction.md +888 -0
  9. package/resource/doc/livekit/live/android/live-integration.md +972 -0
  10. package/resource/doc/livekit/live/android/live-live-list.md +575 -0
  11. package/resource/doc/livekit/live/android/workflow.md +189 -0
  12. package/tools/common/record-prompt.js +2 -2
  13. package/tools/common/record-prompt.js.map +1 -1
  14. package/tools/definitions/get_native_live_extra_features_def.js +87 -0
  15. package/tools/definitions/get_native_live_extra_features_def.js.map +1 -0
  16. package/tools/definitions/get_native_live_interaction_def.js +74 -0
  17. package/tools/definitions/get_native_live_interaction_def.js.map +1 -0
  18. package/tools/definitions/get_native_live_uikit_integration_def.js +49 -0
  19. package/tools/definitions/get_native_live_uikit_integration_def.js.map +1 -0
  20. package/tools/definitions/record_prompt_def.js +42 -11
  21. package/tools/definitions/record_prompt_def.js.map +1 -1
  22. package/tools/definitions/record_result_def.js +1 -1
  23. package/tools/index.js +6 -0
  24. package/tools/index.js.map +1 -1
  25. package/tools/live/get-native-live-uikit-integration.js +101 -0
  26. package/tools/live/get-native-live-uikit-integration.js.map +1 -0
  27. package/tools/live/get-web-live-component-detail.js +1 -1
  28. package/tools/live/get-web-live-component-detail.js.map +1 -1
  29. package/tools/live/get-web-live-state-detail.js +1 -1
  30. package/tools/live/get-web-live-state-detail.js.map +1 -1
  31. package/tools/live/get-web-live-uikit-integration.js +6 -6
  32. package/tools/live/get-web-live-uikit-integration.js.map +1 -1
  33. package/tools/live/get_native_live_extra_features.js +105 -0
  34. package/tools/live/get_native_live_extra_features.js.map +1 -0
  35. package/tools/live/get_native_live_interaction.js +101 -0
  36. package/tools/live/get_native_live_interaction.js.map +1 -0
  37. package/utils/report-cls-client.js +1 -1
  38. package/utils/report-es-client.js +1 -1
  39. /package/resource/doc/livekit/{vue → live/vue}/components/barrage.md +0 -0
  40. /package/resource/doc/livekit/{vue → live/vue}/components/co-guest-panel.md +0 -0
  41. /package/resource/doc/livekit/{vue → live/vue}/components/live-audience-list.md +0 -0
  42. /package/resource/doc/livekit/{vue → live/vue}/components/live-scene-panel.md +0 -0
  43. /package/resource/doc/livekit/{vue → live/vue}/components/live-view.md +0 -0
  44. /package/resource/doc/livekit/{vue → live/vue}/components/stream-mixer.md +0 -0
  45. /package/resource/doc/livekit/{vue → live/vue}/faq.md +0 -0
  46. /package/resource/doc/livekit/{vue → live/vue}/live-list-integration.md +0 -0
  47. /package/resource/doc/livekit/{vue → live/vue}/live-player-desk-integration.md +0 -0
  48. /package/resource/doc/livekit/{vue → live/vue}/live-player-h5-integration.md +0 -0
  49. /package/resource/doc/livekit/{vue → live/vue}/live-pusher-integration.md +0 -0
  50. /package/resource/doc/livekit/{vue → live/vue}/states/live-state.md +0 -0
  51. /package/resource/doc/livekit/{vue → live/vue}/workflow.md +0 -0
@@ -0,0 +1,565 @@
1
+ This document provides a comprehensive guide for iOS developers to quickly integrate a feature-rich, high-performance live chat overlay (barrage/danmaku) system into your live streaming application using the `BarrageStore` module from the **AtomicXCore** framework.
2
+
3
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027182498/fcf29098c6bb11f0a4a55254001c06ec.png)
4
+
5
+
6
+ ## Core Features
7
+
8
+ `BarrageStore` delivers a complete barrage solution for your live streaming app. Core features include:
9
+ - Receiving and displaying barrage messages in the live room.
10
+
11
+ - Sending text barrage messages to interact with viewers.
12
+
13
+ - Sending custom business barrage messages to support complex scenarios such as gifts and likes.
14
+
15
+ - Inserting system tips into the local message list (for example, "Welcome XX to the live room").
16
+
17
+
18
+ ## Core Concepts
19
+ <table>
20
+ <tr>
21
+ <td rowspan="1" colSpan="1" >**Core Concept**</td>
22
+
23
+ <td rowspan="1" colSpan="1" >**Type**</td>
24
+
25
+ <td rowspan="1" colSpan="1" >**Core Responsibility & Description**</td>
26
+ </tr>
27
+
28
+ <tr>
29
+ <td rowspan="1" colSpan="1" >[Barrage](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.barrage/-barrage/index.html)</td>
30
+
31
+ <td rowspan="1" colSpan="1" >data class</td>
32
+
33
+ <td rowspan="1" colSpan="1" >Represents a single barrage message. Contains sender info (sender), message content (textContent or data), and message type (messageType).</td>
34
+ </tr>
35
+
36
+ <tr>
37
+ <td rowspan="1" colSpan="1" >[BarrageState](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.barrage/-barrage-state/index.html)</td>
38
+
39
+ <td rowspan="1" colSpan="1" >data class</td>
40
+
41
+ <td rowspan="1" colSpan="1" >Represents the current state of the barrage module. The main property, messageList, is a StateFlow containing all barrage messages for the current live room, ordered chronologically. This serves as the UI data source.</td>
42
+ </tr>
43
+
44
+ <tr>
45
+ <td rowspan="1" colSpan="1" >[BarrageStore](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>
46
+
47
+ <td rowspan="1" colSpan="1" >abstract class</td>
48
+
49
+ <td rowspan="1" colSpan="1" >The main manager for barrage features. Use it to send messages (sendTextMessage, sendCustomMessage) and subscribe to barrage message updates via its state property.</td>
50
+ </tr>
51
+ </table>
52
+
53
+
54
+ ## Implementation
55
+
56
+ ### Step 1: Component Integration
57
+ - **Video Live Streaming**: Please refer to [Quick Start](https://write.woa.com/document/194571606056804352) to integrate AtomicXCore.
58
+
59
+ - **Voice Chat Room**: Please refer to [Quick Start](https://write.woa.com/document/194571595678187521) to integrate AtomicXCore.
60
+
61
+
62
+ ### Step 2: Initialize and Listen to Barrages
63
+
64
+ Create a `BarrageStore` instance bound to the current live room's `liveId`, and subscribe to receive the latest barrage message list in real time.
65
+ ``` kotlin
66
+ import kotlinx.coroutines.*
67
+ import kotlinx.coroutines.flow.*
68
+ import io.trtc.tuikit.atomicxcore.api.barrage.Barrage
69
+ import io.trtc.tuikit.atomicxcore.api.barrage.BarrageStore
70
+
71
+ class BarrageManager(
72
+ private val liveId: String
73
+ ) {
74
+ private val barrageStore: BarrageStore = BarrageStore.create(liveId)
75
+ private val scope = CoroutineScope(Dispatchers.Main)
76
+
77
+ // Expose the [full] message list as a Flow for the UI layer to subscribe to
78
+ private val _messagesFlow = MutableStateFlow<List<Barrage>>(emptyList())
79
+ val messagesFlow: StateFlow<List<Barrage>> = _messagesFlow.asStateFlow()
80
+
81
+ init {
82
+ // Start listening for barrage messages immediately after initialization
83
+ subscribeToBarrageUpdates()
84
+ }
85
+
86
+ private fun subscribeToBarrageUpdates() {
87
+ scope.launch {
88
+ barrageStore.barrageState.messageList
89
+ .collect { messageList ->
90
+ // When messageList updates, pass the new list to the UI layer via Flow
91
+ // Note: This is the [complete list], including all historical messages
92
+ _messagesFlow.value = messageList
93
+ }
94
+ }
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### Step 3: Send Text Barrages
100
+
101
+ Use `sendTextMessage` to broadcast a plain text message to all users in the live room.
102
+ ``` kotlin
103
+ import io.trtc.tuikit.atomicxcore.api.CompletionHandler
104
+ import io.trtc.tuikit.atomicxcore.api.barrage.BarrageStore
105
+
106
+ class BarrageManager(
107
+ private val liveId: String
108
+ ) {
109
+ private val barrageStore: BarrageStore = BarrageStore.create(liveId)
110
+
111
+ // Send a text barrage
112
+ fun sendTextMessage(text: String) {
113
+ // We recommend adding a non-empty check to avoid sending invalid messages
114
+ if (text.isEmpty()) {
115
+ return
116
+ }
117
+
118
+ // Call the core API to send the message
119
+ barrageStore.sendTextMessage(
120
+ text,
121
+ mapOf(
122
+ "custom key" to "custom value",
123
+ ),
124
+ object : CompletionHandler {
125
+ override fun onSuccess() {
126
+ println("Text barrage '$text' sent successfully")
127
+ }
128
+
129
+ override fun onFailure(code: Int, desc: String) {
130
+ println("Failed to send text barrage: $desc")
131
+ }
132
+ }
133
+ )
134
+ }
135
+ }
136
+ ```
137
+
138
+ #### API Parameters
139
+ <table>
140
+ <tr>
141
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
142
+
143
+ <td rowspan="1" colSpan="1" >**Type**</td>
144
+
145
+ <td rowspan="1" colSpan="1" >**Description**</td>
146
+ </tr>
147
+
148
+ <tr>
149
+ <td rowspan="1" colSpan="1" >`text`</td>
150
+
151
+ <td rowspan="1" colSpan="1" >`String?`</td>
152
+
153
+ <td rowspan="1" colSpan="1" >The text content to send.</td>
154
+ </tr>
155
+
156
+ <tr>
157
+ <td rowspan="1" colSpan="1" >`extensionInfo`</td>
158
+
159
+ <td rowspan="1" colSpan="1" >`Map<String, String>?`</td>
160
+
161
+ <td rowspan="1" colSpan="1" >Additional data for business customization.</td>
162
+ </tr>
163
+
164
+ <tr>
165
+ <td rowspan="1" colSpan="1" >`completion`</td>
166
+
167
+ <td rowspan="1" colSpan="1" >`CompletionHandler?`</td>
168
+
169
+ <td rowspan="1" colSpan="1" >Callback invoked after sending, indicating success or failure.</td>
170
+ </tr>
171
+ </table>
172
+
173
+
174
+ ### Step 4: Send Custom Barrage
175
+
176
+ Send messages with custom business logic, such as gifts, likes, or gamification commands. The content format of this message is defined by the business layer. The receiver must parse and handle it based on the `businessId` and `data`.
177
+ ``` kotlin
178
+ class BarrageManager(
179
+ private val liveId: String
180
+ ) {
181
+ // Send a custom barrage, for example, to send a gift
182
+ fun sendGiftMessage(giftId: String, giftCount: Int) {
183
+ // 1. Define a business-recognizable ID
184
+ val businessId = "live_gift"
185
+
186
+ // 2. Encode business data as a JSON string
187
+ val giftData = mapOf(
188
+ "gift_id" to giftId,
189
+ "gift_count" to giftCount
190
+ )
191
+
192
+ val jsonString = try {
193
+ // Use Gson or another JSON library for serialization
194
+ // Here we assume Gson is used
195
+ Gson().toJson(giftData)
196
+ } catch (e: Exception) {
197
+ return
198
+ }
199
+
200
+ // 3. Call the core API to send the custom message
201
+ barrageStore.sendCustomMessage(
202
+ businessId,
203
+ jsonString,
204
+ object : CompletionHandler {
205
+ override fun onSuccess() {
206
+ println("Gift message (custom barrage) sent successfully")
207
+ }
208
+
209
+ override fun onFailure(code: Int, desc: String) {
210
+ println("Failed to send gift message: $desc")
211
+ }
212
+ }
213
+ )
214
+ }
215
+ }
216
+ ```
217
+
218
+ #### API Parameters
219
+ <table>
220
+ <tr>
221
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
222
+
223
+ <td rowspan="1" colSpan="1" >**Type**</td>
224
+
225
+ <td rowspan="1" colSpan="1" >**Description**</td>
226
+ </tr>
227
+
228
+ <tr>
229
+ <td rowspan="1" colSpan="1" >businessId</td>
230
+
231
+ <td rowspan="1" colSpan="1" >String</td>
232
+
233
+ <td rowspan="1" colSpan="1" >Unique business identifier (e.g., "live_gift"). Used by receivers to distinguish custom messages.</td>
234
+ </tr>
235
+
236
+ <tr>
237
+ <td rowspan="1" colSpan="1" >data</td>
238
+
239
+ <td rowspan="1" colSpan="1" >String</td>
240
+
241
+ <td rowspan="1" colSpan="1" >Business data, typically a JSON string.</td>
242
+ </tr>
243
+
244
+ <tr>
245
+ <td rowspan="1" colSpan="1" >completion</td>
246
+
247
+ <td rowspan="1" colSpan="1" >CompletionHandler?</td>
248
+
249
+ <td rowspan="1" colSpan="1" >Callback after sending.</td>
250
+ </tr>
251
+ </table>
252
+
253
+
254
+ ### Step 5: Insert Local Tip Messages
255
+
256
+ Insert a local message into the current user's message list. This message is not sent to other users and is ideal for displaying system prompts, warnings, or operation tips.
257
+ ``` kotlin
258
+ class BarrageManager(
259
+ private val liveId: String
260
+ ) {
261
+ // Insert a welcome tip into the local message list
262
+ fun showWelcomeMessage(user: LiveUserInfo) {
263
+ // 1. Create a Barrage message
264
+ val welcomeTip = Barrage(
265
+ liveID = liveId,
266
+ messageType = BarrageType.TEXT, // You can reuse the text type for display
267
+ textContent = "Welcome ${user.userName} to the live room!",
268
+ sender = LiveUserInfo() // sender can be left empty or set to a system user identifier
269
+ )
270
+
271
+ // 2. Call the API to append it to the local list
272
+ barrageStore.appendLocalTip(welcomeTip)
273
+ }
274
+ }
275
+ ```
276
+
277
+ #### API Parameters
278
+ <table>
279
+ <tr>
280
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
281
+
282
+ <td rowspan="1" colSpan="1" >**Type**</td>
283
+
284
+ <td rowspan="1" colSpan="1" >**Description**</td>
285
+ </tr>
286
+
287
+ <tr>
288
+ <td rowspan="1" colSpan="1" >message</td>
289
+
290
+ <td rowspan="1" colSpan="1" >Barrage</td>
291
+
292
+ <td rowspan="1" colSpan="1" >The message object to insert locally. The SDK appends this to messageList in BarrageState.</td>
293
+ </tr>
294
+ </table>
295
+
296
+
297
+ ### Step 6: Manage User Speaking Permissions (Mute and Unmute)
298
+
299
+ As a host or administrator, you can control user messaging permissions to maintain a healthy community environment.
300
+
301
+ #### Mute/Unmute a Single User
302
+
303
+ Use the `disableSendMessage` method in `LiveAudienceStore` to mute or unmute a user. This state persists even if the user rejoins the live room.
304
+ ``` kotlin
305
+ import io.trtc.tuikit.atomicxcore.api.*
306
+ import io.trtc.tuikit.atomicxcore.api.live.LiveAudienceStore
307
+
308
+ // 1. Get the LiveAudienceStore instance bound to the current live room
309
+ val audienceStore = LiveAudienceStore.create(liveId)
310
+
311
+ // 2. Define the user ID to operate on and the mute status
312
+ val userIdToMute = "user_id_to_be_muted"
313
+ val shouldDisable = true // true to mute, false to unmute
314
+
315
+ // 3. Call the interface to perform the operation
316
+ audienceStore.disableSendMessage(
317
+ userIdToMute,
318
+ shouldDisable,
319
+ object : CompletionHandler {
320
+ override fun onSuccess() {
321
+ println("${if (shouldDisable) "Muted" else "Unmuted"} user $userIdToMute successfully")
322
+ }
323
+
324
+ override fun onFailure(code: Int, desc: String) {
325
+ println("Operation failed: $desc")
326
+ }
327
+ }
328
+ )
329
+ ```
330
+
331
+ #### Enable/Disable Global Mute
332
+
333
+ To mute all users in the live room (usually excluding the host), update the live room information via `LiveListStore`.
334
+ ``` kotlin
335
+ import io.trtc.tuikit.atomicxcore.api.CompletionHandler
336
+ import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
337
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
338
+
339
+ // 1. Get the LiveListStore singleton
340
+ val liveListStore = LiveListStore.shared()
341
+
342
+ // 2. Get the current live room info and modify the global mute status
343
+ val currentLiveInfo = liveListStore.liveState.currentLive.value.copy(
344
+ isMessageDisable = true // true to enable global mute, false to disable
345
+ )
346
+
347
+ // 3. Call the update interface and specify the modification flag
348
+ liveListStore.updateLiveInfo(
349
+ currentLiveInfo,
350
+ listOf(LiveInfo.ModifyFlag.IS_MESSAGE_DISABLE),
351
+ object : CompletionHandler {
352
+ override fun onSuccess() {
353
+ println("Global mute status updated successfully")
354
+ }
355
+
356
+ override fun onFailure(code: Int, desc: String) {
357
+ println("Operation failed: $desc")
358
+ }
359
+ }
360
+ )
361
+ ```
362
+
363
+ ## Advanced Features: Performance Optimization in High-Concurrency Scenarios
364
+
365
+ After implementing barrage features with `BarrageStore`, use the following strategies to ensure smooth and stable user experiences in high-concurrency live streaming scenarios. This section provides optimization strategies and code samples for three core business scenarios.
366
+
367
+ ### Scenario 1: Handling "Barrage Storms" in Popular Live Rooms
368
+
369
+ #### Scenario Description
370
+
371
+ During popular events, a large number of viewers may flood into the live room, with barrages updating at dozens of messages per second.
372
+
373
+ #### Technical Challenge
374
+
375
+ The SDK returns the complete barrage list at a high frequency. If you call `adapter.notifyDataSetChanged()` on every update, the main thread may be blocked by intensive UI layout and rendering, causing UI lag.
376
+
377
+ #### Optimization: Batch Processing & Debouncing
378
+
379
+ Do not respond to every data update. Instead, set a time threshold (e.g., 300 ms). Only refresh the UI if the time since the last update exceeds this threshold. This reduces dozens of `notifyDataSetChanged()`calls per second to just 3–4, greatly improving smoothness.
380
+
381
+ #### Code Example
382
+
383
+ Create a `BarrageUIManager` class with a buffer and timer for batch updating data to the `RecyclerView`.
384
+ ``` kotlin
385
+ import android.os.Handler
386
+ import androidx.recyclerview.widget.RecyclerView
387
+ import io.trtc.tuikit.atomicxcore.api.barrage.Barrage
388
+
389
+ private const val UPDATE_DURATION_MS = 300L
390
+
391
+ class BarrageUIManager() {
392
+ private var timestampOnLastUpdate = 0L
393
+
394
+ private var dataSource: ArrayList<Barrage> = ArrayList()
395
+ private val updateViewTask = Runnable { notifyDataSetChanged() }
396
+ private val handler = Handler()
397
+ private val adapter = BarrageAdapter(dataSource)
398
+
399
+ // This method is called frequently from outside, passing in the latest full list
400
+ fun update(newList: List<Barrage>) {
401
+ handler.removeCallbacks(updateViewTask)
402
+ dataSource.clear()
403
+ dataSource.addAll(newList)
404
+ // If the refresh interval is less than 0.3 seconds, do not refresh
405
+ if (System.currentTimeMillis() - timestampOnLastUpdate < UPDATE_DURATION_MS) {
406
+ handler.postDelayed(updateViewTask, UPDATE_DURATION_MS)
407
+ return
408
+ }
409
+ }
410
+
411
+ private fun notifyDataSetChanged() {
412
+ adapter.notifyDataSetChanged()
413
+ timestampOnLastUpdate = System.currentTimeMillis()
414
+ }
415
+ }
416
+
417
+ class BarrageAdapter(dataSource: ArrayList<Barrage>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
418
+ // Implement adapter capabilities here
419
+ }
420
+ ```
421
+
422
+ ### Scenario 2: Ensuring Memory Stability for Long-Duration Live Streams
423
+
424
+ #### Scenario Description
425
+
426
+ Your app may need to support hours-long or even all-day continuous live streaming, such as game streaming or slow live streams. The app must remain stable and avoid crashes due to long-term operation.
427
+
428
+ #### Technical Challenge
429
+
430
+ The SDK returns a full `messageList` that grows indefinitely during long live streams. Even if the UI layer throttles updates, a large array in the data layer will continue consuming memory and may eventually cause the app to crash.
431
+
432
+ #### Optimization: Circular Buffer with Fixed Capacity
433
+
434
+ Ensure your data source holds only a limited number of messages. Regardless of the size of the full list returned by the SDK, only retain the latest portion for display.
435
+
436
+ #### Code Example
437
+
438
+ After receiving the full list from the SDK, take only the latest 500 messages (or another number you define) to update the UI.
439
+ ``` kotlin
440
+ class BarrageUIManager(
441
+ private val recyclerView: RecyclerView
442
+ ) {
443
+ private val capacity: Int = 500 // Only retain the latest 500 messages
444
+ // ... (other code as above) ...
445
+
446
+ private fun refreshUIIfNeeded() {
447
+ val fullList = this.latestMessageList ?: return
448
+ val adapter = recyclerView.adapter ?: return
449
+ this.latestMessageList = null
450
+
451
+ // Only take the latest N messages
452
+ val cappedList = fullList.takeLast(capacity)
453
+
454
+ dataSource.clear()
455
+ dataSource.addAll(cappedList)
456
+ adapter.notifyDataSetChanged()
457
+ }
458
+ }
459
+ ```
460
+
461
+ ### Scenario 3: Rendering Complex Barrage Styles with User Levels and Badges
462
+
463
+ #### Scenario Description
464
+
465
+ To enhance the live streaming atmosphere and highlight paying users, barrage messages may include rich visual elements such as usernames, user level icons, fan badges, and message content.
466
+
467
+ #### Technical Challenge
468
+
469
+ Rendering views with multiple images and texts, custom fonts, or complex layouts is more time-consuming than rendering plain text. High-frequency rendering of these complex views in a list increases the main thread's workload, causing lag during list scrolling.
470
+
471
+ #### Optimization: Asynchronous Drawing
472
+
473
+ Move the view rendering process off the main thread and onto a background thread. The main thread should only handle the final display of the already rendered bitmap, significantly reducing its computational load.
474
+
475
+ #### Code Example
476
+
477
+ In your custom `RecyclerView.ViewHolder`, use `AsyncLayoutInflater` or a preloading mechanism to perform rendering tasks on a background thread whenever possible.
478
+ ``` kotlin
479
+ import android.view.LayoutInflater
480
+ import androidx.asynclayoutinflater.view.AsyncLayoutInflater
481
+ import androidx.recyclerview.widget.RecyclerView
482
+
483
+ // In your custom Barrage ViewHolder
484
+ class BarrageViewHolder(
485
+ itemView: View
486
+ ) : RecyclerView.ViewHolder(itemView) {
487
+
488
+ // ... (Declarations for TextView, ImageView, etc.)
489
+
490
+ companion object {
491
+ fun create(parent: ViewGroup): BarrageViewHolder {
492
+ // Use async layout inflater to reduce main thread blocking
493
+ val inflater = AsyncLayoutInflater(parent.context)
494
+ val view = LayoutInflater.from(parent.context)
495
+ .inflate(R.layout.item_barrage, parent, false)
496
+ return BarrageViewHolder(view)
497
+ }
498
+ }
499
+
500
+ fun bind(viewModel: BarrageViewModel) {
501
+ // Set your TextView text, ImageView images, etc. here
502
+ // With async layout inflation, final rendering is done on a background thread whenever possible
503
+ }
504
+
505
+ // Advanced performance optimization: fully manual drawing
506
+ // For finer control, use Canvas to manually draw text and images
507
+ // Generate the Bitmap on a background thread, then draw it in the main thread's onDraw method for fully asynchronous rendering
508
+ }
509
+ ```
510
+
511
+ ## API Documentation
512
+
513
+ For detailed information on all public interfaces, properties, methods of [BarrageStore](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) and its related classes, refer to the official API documentation included with the [AtomicXCore](https://tencent-rtc.github.io/TUIKit_Android/index.html) framework.
514
+
515
+ ## FAQs
516
+
517
+ ### In addition to basic text barrages, we also want to implement richer styles such as "colored barrages" and "gift barrages." How can we achieve this?
518
+
519
+ You can implement these features using custom messages with `sendCustomMessage`.
520
+
521
+ **Implementation Steps**
522
+ 1. **Define the Data Structure**: Collaborate with your client and server teams to define the JSON structure for custom messages. For example, a colored barrage can be defined as:
523
+
524
+ ``` json
525
+ { "type": "colored_text", "text": "This is a colored bullet comment!", "color": "#FF5733" }
526
+ ```
527
+ 2. **Sender**: When sending, serialize this JSON structure to a string and send it via the `data` parameter of `sendCustomMessage`. The businessID can be set to a unique identifier for your use case, such as `barrage_style_v1`.
528
+
529
+ 3. **Receiver**: Upon receiving a barrage message, check whether its messageType is `BarrageType.CUSTOM` and whether the `businessID` matches. If so, parse the data string (usually as JSON), and render your custom UI style based on the parsed data (such as `color`, `text`).
530
+
531
+
532
+ ### If I call BarrageStore.create(liveID = "some_id") in different classes or files, will this create multiple instances and cause confusion?
533
+
534
+ No. The internal mechanism of **AtomicXCore** ensures that as long as you pass in the same `liveID`, you always get the same `BarrageStore` instance for that live room. You do not need to manage singletons manually.
535
+
536
+ ### Why can't I see the message I sent after calling sendTextMessage in the message list?
537
+
538
+ **Troubleshooting steps:**
539
+ 1. **Check the completion callback**: The `sendTextMessage` method provides a completion callback. Check whether the callback indicates success or failure. If it fails, the error message will indicate the problem (such as "You have been muted," "Network error," etc.).
540
+
541
+ 2. **Confirm subscription timing**: Make sure you subscribe to `barrageStore.barrageState.messageList` after the live session for the corresponding `liveID` has started. If you start listening before joining the live room, you may miss some messages.
542
+
543
+ 3. **Check liveID**: Ensure that the liveID used when creating the BarrageStore instance, joining the live room, and sending messages is exactly the same, including case sensitivity.
544
+
545
+ 4. **Network issues**: Ensure the device's network connection is normal. Message sending depends on network connectivity.
546
+
547
+
548
+ ### How can new viewers see historical barrage messages sent before they joined the live room?
549
+
550
+ `AtomicXCore` supports retrieving historical chat messages, but you need to enable this feature in the **server console**. Once configured, the SDK handles everything automatically—no additional client code is required.
551
+
552
+ #### **Step 1: Configure in the Live Console**
553
+ 1. Log in to [**Console > Live > Configuration**](https://console.trtc.io/live/configuration), and select your target application at the top of the page.
554
+
555
+ 2. On the Live Configuration page, select **View Past Messages**, and set Previous Messages Viewable to specify the number of messages (up to a maximum of 50) that new viewers can see.
556
+
557
+
558
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027202808/1215e910e09b11f095ab5254001c06ec.png)
559
+
560
+
561
+ #### **Step 2: Automatic Retrieval on the Client Side**
562
+
563
+ After completing the above configuration, **no changes are needed** in your client code.
564
+
565
+ When a new user joins the live room, `AtomicXCore` automatically retrieves the configured number of historical chat messages in the background. These messages are delivered to the UI layer through the `BarrageState` subscription channel, just like real-time messages. Your application will receive and display these historical chat messages in the same way as live messages.