@tencent-rtc/mcp 1.3.4 → 1.3.6

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 (122) hide show
  1. package/index.js +4 -4
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/resource/doc/chatuikit/android/features/theme.md +363 -0
  5. package/resource/doc/chatuikit/{android/client_api_Android.md → faq/android_sdk/client-api.md} +0 -2
  6. package/resource/doc/chatuikit/faq/common/product.md +8 -0
  7. package/resource/doc/chatuikit/faq/flutter_sdk/faq.md +53 -0
  8. package/resource/doc/chatuikit/{iOS/client_api_iOS.md → faq/ios_sdk/client-api.md} +0 -2
  9. package/resource/doc/chatuikit/flutter/features/theme.md +379 -0
  10. package/resource/doc/chatuikit/flutter/integration.md +413 -0
  11. package/resource/doc/chatuikit/flutter/workflow.md +941 -0
  12. package/resource/doc/chatuikit/iOS/features/theme.md +416 -0
  13. package/resource/doc/chatuikit/react/components/chat-setting.md +86 -0
  14. package/resource/doc/chatuikit/react/components/contact-list.md +1093 -0
  15. package/resource/doc/chatuikit/react/components/search.md +745 -0
  16. package/resource/doc/chatuikit/vue/components/chat-setting.md +64 -0
  17. package/resource/doc/chatuikit/vue/components/contact-list.md +679 -0
  18. package/resource/doc/chatuikit/vue/components/search.md +1384 -0
  19. package/resource/doc/livekit/live/android/workflow.md +137 -6
  20. package/resource/doc/livekit/live/ios/live-audience-list.md +339 -0
  21. package/resource/doc/livekit/live/ios/live-audio-effect.md +370 -0
  22. package/resource/doc/livekit/live/ios/live-barrage.md +517 -0
  23. package/resource/doc/livekit/live/ios/live-base-beauty.md +247 -0
  24. package/resource/doc/livekit/live/ios/live-co-guest-interaction.md +518 -0
  25. package/resource/doc/livekit/live/ios/live-gift.md +783 -0
  26. package/resource/doc/livekit/live/ios/live-host-interaction.md +815 -0
  27. package/resource/doc/livekit/live/ios/live-integration.md +931 -0
  28. package/resource/doc/livekit/live/ios/live-live-list.md +485 -0
  29. package/resource/doc/livekit/live/ios/workflow.md +454 -0
  30. package/resource/doc/rtcengine/web/plugin/20-advanced-customized-capture-rendering.md +87 -0
  31. package/resource/doc/rtcengine/web/plugin/21-advanced-auto-play-policy.md +87 -0
  32. package/resource/doc/rtcengine/web/plugin/22-advanced-audio-mixer.md +175 -0
  33. package/resource/doc/rtcengine/web/plugin/23-advanced-support-detection.md +221 -0
  34. package/resource/doc/rtcengine/web/plugin/24-advanced-network-quality.md +140 -0
  35. package/resource/doc/rtcengine/web/plugin/25-advanced-device-change.md +99 -0
  36. package/resource/doc/rtcengine/web/plugin/26-advanced-publish-cdn-stream.md +451 -0
  37. package/resource/doc/rtcengine/web/plugin/27-advanced-small-stream.md +151 -0
  38. package/resource/doc/rtcengine/web/plugin/28-advanced-beauty.md +322 -0
  39. package/resource/doc/rtcengine/web/plugin/29-advanced-water-mark.md +149 -0
  40. package/resource/doc/rtcengine/web/plugin/30-advanced-cross-room-link.md +96 -0
  41. package/resource/doc/rtcengine/web/plugin/31-advanced-plugins-overview.md +330 -0
  42. package/resource/doc/rtcengine/web/plugin/34-advanced-proxy.md +248 -0
  43. package/resource/doc/rtcengine/web/plugin/35-advanced-ai-denoiser.md +81 -0
  44. package/resource/doc/rtcengine/web/plugin/36-advanced-virtual-background.md +242 -0
  45. package/resource/doc/rtcengine/web/plugin/37-advanced-voice-changer.md +99 -0
  46. package/resource/doc/rtcengine/web/plugin/39-advanced-video-decoder.md +33 -0
  47. package/resource/doc/rtcengine/web/plugin/40-advanced-video-mixer.md +379 -0
  48. package/resource/doc/rtcengine/web/plugin/41-advanced-small-stream-auto-switcher.md +91 -0
  49. package/resource/doc/rtcengine/web/plugin/42-advanced-realtime-transcriber.md +315 -0
  50. package/resource/doc/rtcengine/web/plugin/43-advanced-face-detection.md +180 -0
  51. package/resource/doc/tuicallkit/android/workflow.md +0 -0
  52. package/resource/doc/tuicallkit/flutter/workflow.md +331 -0
  53. package/tools/call/get-native-call-integration.js +27 -11
  54. package/tools/call/get-native-call-integration.js.map +1 -1
  55. package/tools/chat/get-native-chat-feature-detail.js +30 -0
  56. package/tools/chat/get-native-chat-feature-detail.js.map +1 -0
  57. package/tools/chat/get-native-chat-integration.js +30 -12
  58. package/tools/chat/get-native-chat-integration.js.map +1 -1
  59. package/tools/common/get-faq.js +2 -4
  60. package/tools/common/get-faq.js.map +1 -1
  61. package/tools/definitions/get_native_call_uikit_integration_def.js +17 -7
  62. package/tools/definitions/get_native_call_uikit_integration_def.js.map +1 -1
  63. package/tools/definitions/get_native_chat_feature_detail_def.js +32 -0
  64. package/tools/definitions/get_native_chat_feature_detail_def.js.map +1 -0
  65. package/tools/definitions/get_native_chat_uikit_integration_def.js +19 -7
  66. package/tools/definitions/get_native_chat_uikit_integration_def.js.map +1 -1
  67. package/tools/definitions/{get_native_live_extra_features_def.js → get_native_live_uikit_extra_features_def.js} +3 -3
  68. package/tools/definitions/get_native_live_uikit_extra_features_def.js.map +1 -0
  69. package/tools/definitions/{get_native_live_interaction_def.js → get_native_live_uikit_interaction_def.js} +3 -3
  70. package/tools/definitions/get_native_live_uikit_interaction_def.js.map +1 -0
  71. package/tools/definitions/get_web_chat_uikit_component_detail_def.js +49 -10
  72. package/tools/definitions/get_web_chat_uikit_component_detail_def.js.map +1 -1
  73. package/tools/index.js +6 -4
  74. package/tools/index.js.map +1 -1
  75. package/tools/live/{get_native_live_extra_features.js → get_native_live_uikit_extra_features.js} +4 -4
  76. package/tools/live/get_native_live_uikit_extra_features.js.map +1 -0
  77. package/tools/live/{get_native_live_interaction.js → get_native_live_uikit_interaction.js} +4 -4
  78. package/tools/live/get_native_live_uikit_interaction.js.map +1 -0
  79. package/tools/rtcengine/get-rtcengine-web-sdk-integration.js.map +1 -1
  80. package/tools/rtcengine/get-trtc-sdk-faq.js +32 -0
  81. package/tools/rtcengine/get-trtc-sdk-faq.js.map +1 -0
  82. package/tools/rtcengine/get-trtc-web-sdk-faq.js +1 -1
  83. package/tools/rtcengine/get-trtc-web-sdk-integration.js.map +1 -1
  84. package/tools/rtcengine/get-trtc-web-sdk-plugin.js +45 -0
  85. package/tools/rtcengine/get-trtc-web-sdk-plugin.js.map +1 -0
  86. package/utils/handle-component-name.js +0 -16
  87. package/utils/handle-component-name.js.map +1 -1
  88. package/utils/report-cls-client.js +1 -1
  89. package/utils/report-es-client.js +1 -1
  90. package/resource/doc/chatuikit/android/generate_UserSig.md +0 -306
  91. package/resource/doc/chatuikit/android/integrarte_only_tuichat_Android.md +0 -290
  92. package/resource/doc/chatuikit/android/quick_start_Android.md +0 -138
  93. package/resource/doc/chatuikit/android/show_typing_Android.md +0 -43
  94. package/resource/doc/chatuikit/flutter/generate_UserSig.md +0 -306
  95. package/resource/doc/chatuikit/flutter/integrate_tuikit_Flutter.md +0 -133
  96. package/resource/doc/chatuikit/iOS/generate_UserSig.md +0 -306
  97. package/resource/doc/chatuikit/iOS/integrate_only_tuichat_iOS.md +0 -748
  98. package/resource/doc/chatuikit/iOS/quick_start_iOS.md +0 -163
  99. package/resource/doc/chatuikit/iOS/show_typing_iOS.md +0 -52
  100. package/resource/doc/tuicallkit/flutter/how_to_run_flutter_callkit_demo.md +0 -101
  101. package/resource/doc/tuicallkit/iOS/how_to_run_iOS_callkit_demo.md +0 -98
  102. package/tools/definitions/get_native_live_extra_features_def.js.map +0 -1
  103. package/tools/definitions/get_native_live_interaction_def.js.map +0 -1
  104. package/tools/live/get_native_live_extra_features.js.map +0 -1
  105. package/tools/live/get_native_live_interaction.js.map +0 -1
  106. /package/resource/doc/chatuikit/android/{integrate_tuikit_Android.md → integration.md} +0 -0
  107. /package/resource/doc/chatuikit/{faq/native_sdk/faq.md → android/workflow.md} +0 -0
  108. /package/resource/doc/chatuikit/{flutter/client_api_Flutter.md → faq/flutter_sdk/client-api.md} +0 -0
  109. /package/resource/doc/chatuikit/iOS/{integrate_tuikit_iOS.md → integration.md} +0 -0
  110. /package/resource/doc/{tuicallkit/android/.gitkeep → chatuikit/iOS/workflow.md} +0 -0
  111. /package/resource/doc/chatuikit/react/components/{chatheader.md → chat-header.md} +0 -0
  112. /package/resource/doc/chatuikit/vue/components/{chatheader.md → chat-header.md} +0 -0
  113. /package/resource/doc/tuicallkit/android/{how_to_integrated_android_callkit.md → integration.md} +0 -0
  114. /package/resource/doc/tuicallkit/{android/api_TUICallObserver.md → faq/android_sdk/call-observer-api.md} +0 -0
  115. /package/resource/doc/tuicallkit/{android/api_TUICallKit.md → faq/android_sdk/callkit-api.md} +0 -0
  116. /package/resource/doc/tuicallkit/{flutter/api_TUICallDefine.md → faq/flutter_sdk/call-define-api.md} +0 -0
  117. /package/resource/doc/tuicallkit/{flutter/api_TUICallObserver.md → faq/flutter_sdk/call-observer-api.md} +0 -0
  118. /package/resource/doc/tuicallkit/{flutter/api_TUICallKit.md → faq/flutter_sdk/callkit-api.md} +0 -0
  119. /package/resource/doc/tuicallkit/{iOS/api_TUICallObserver.md → faq/ios_sdk/call-observer-api.md} +0 -0
  120. /package/resource/doc/tuicallkit/{iOS/api_TUICallKit.md → faq/ios_sdk/callkit-api.md} +0 -0
  121. /package/resource/doc/tuicallkit/flutter/{how_to_integrated_flutter_callkit.md → integration.md} +0 -0
  122. /package/resource/doc/tuicallkit/iOS/{how_to_integrated_iOS_callkit.md → integration.md} +0 -0
@@ -0,0 +1,517 @@
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/17934b0bc6e111f087ad52540099c741.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_iOS/documentation/atomicxcore/barrage)</td>
30
+
31
+ <td rowspan="1" colSpan="1" >struct</td>
32
+
33
+ <td rowspan="1" colSpan="1" >Represents the data model for a single barrage message. Contains all essential information such as sender (sender), message content (textContent or data), message type (messageType), and more.</td>
34
+ </tr>
35
+
36
+ <tr>
37
+ <td rowspan="1" colSpan="1" >[BarrageState](https://tencent-rtc.github.io/TUIKit_iOS/documentation/atomicxcore/barragestate)</td>
38
+
39
+ <td rowspan="1" colSpan="1" >struct</td>
40
+
41
+ <td rowspan="1" colSpan="1" >Represents the current state of the barrage module. The main property, messageList, is an array of [Barrage] storing all barrage messages in chronological order for the current live room. This serves as the data source for UI rendering.</td>
42
+ </tr>
43
+
44
+ <tr>
45
+ <td rowspan="1" colSpan="1" >[BarrageStore](https://tencent-rtc.github.io/TUIKit_iOS/documentation/atomicxcore/barragestore)</td>
46
+
47
+ <td rowspan="1" colSpan="1" >class</td>
48
+
49
+ <td rowspan="1" colSpan="1" >The core management class for barrage functionality. Use it to send messages (sendTextMessage, sendCustomMessage), and subscribe to its state property to receive all barrage message updates.</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/194571606121816064) to integrate AtomicXCore. Quick Start to
58
+
59
+ - **Voice Chat Room**: Please refer to [Quick Start](https://write.woa.com/document/194571595685527552) to integrate AtomicXCore.
60
+
61
+
62
+ ### Step 2: Initialize and Listen for Barrage
63
+
64
+ Obtain a `BarrageStore` instance bound to the current live room's `liveId`, and set up a subscriber to receive the latest complete barrage message list in real time.
65
+ ``` swift
66
+ import Foundation
67
+ import AtomicXCore // Import the core library
68
+ import Combine // For reactive programming
69
+
70
+ class BarrageManager {
71
+ private let liveId: String
72
+ private let barrageStore: BarrageStore
73
+ private var cancellables = Set<AnyCancellable>()
74
+
75
+ // Publisher for the complete message list, for UI layer subscription
76
+ let messagesPublisher = PassthroughSubject<[Barrage], Never>()
77
+
78
+ init(liveId: String) {
79
+ self.liveId = liveId
80
+ // 1. Obtain the BarrageStore singleton for the given liveId
81
+ self.barrageStore = BarrageStore.create(liveID: liveId)
82
+ // 2. Start listening for barrage messages immediately after initialization
83
+ subscribeToBarrageUpdates()
84
+ }
85
+
86
+ private func subscribeToBarrageUpdates() {
87
+ barrageStore.state
88
+ .subscribe() // Subscribe to all BarrageState changes
89
+ .receive(on: DispatchQueue.main) // Ensure main thread for UI safety
90
+ .sink { [weak self] barrageState in
91
+ // 3. Forward the updated message list to the UI layer
92
+ // Note: This provides the complete list, including all historical messages
93
+ self?.messagesPublisher.send(barrageState.messageList)
94
+ }
95
+ .store(in: &cancellables) // Manage subscription lifecycle
96
+ }
97
+
98
+ ```
99
+
100
+ ### Step 3: Send Text Barrage
101
+
102
+ Use the `sendTextMessage` method to broadcast a plain text message to all users in the live room.
103
+ ``` swift
104
+ extension BarrageManager {
105
+ /// Send a text barrage message
106
+ func sendTextMessage(text: String) {
107
+ // Prevent sending empty messages
108
+ guard !text.isEmpty else {
109
+ print("Barrage content cannot be empty")
110
+ return
111
+ }
112
+
113
+ // Send the message using the core API
114
+ barrageStore.sendTextMessage(text: text, extensionInfo: nil) { result in
115
+ // Handle the result in the callback, e.g., show a prompt to the user
116
+ switch result {
117
+ case .success:
118
+ print("Text barrage '\(text)' sent successfully")
119
+ case .failure(let error):
120
+ print("Failed to send text barrage: \(error.localizedDescription)")
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ #### API Parameters
128
+ <table>
129
+ <tr>
130
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
131
+
132
+ <td rowspan="1" colSpan="1" >**Type**</td>
133
+
134
+ <td rowspan="1" colSpan="1" >**Description**</td>
135
+ </tr>
136
+
137
+ <tr>
138
+ <td rowspan="1" colSpan="1" >`text`</td>
139
+
140
+ <td rowspan="1" colSpan="1" >`String`</td>
141
+
142
+ <td rowspan="1" colSpan="1" >The text content to send.</td>
143
+ </tr>
144
+
145
+ <tr>
146
+ <td rowspan="1" colSpan="1" >`extensionInfo`</td>
147
+
148
+ <td rowspan="1" colSpan="1" >`[String: String]?`</td>
149
+
150
+ <td rowspan="1" colSpan="1" >Additional extension information for business customization.</td>
151
+ </tr>
152
+
153
+ <tr>
154
+ <td rowspan="1" colSpan="1" >`completion`</td>
155
+
156
+ <td rowspan="1" colSpan="1" >`CompletionClosure?`</td>
157
+
158
+ <td rowspan="1" colSpan="1" >Callback after sending is complete, containing the success or failure result.</td>
159
+ </tr>
160
+ </table>
161
+
162
+
163
+ ### Step 4: Send Custom Barrage
164
+
165
+ Send a message containing 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`.
166
+ ``` swift
167
+ extension BarrageManager {
168
+ /// Send a custom barrage, e.g., for sending gifts
169
+ func sendGiftMessage(giftId: String, giftCount: Int) {
170
+ // 1. Define a business-recognizable ID
171
+ let businessId = "live_gift"
172
+
173
+ // 2. Encode business data as a JSON string
174
+ let giftData: [String: Any] = ["gift_id": giftId, "gift_count": giftCount]
175
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: giftData),
176
+ let jsonString = String(data: jsonData, encoding: .utf8) else {
177
+ print("Failed to encode gift data as JSON")
178
+ return
179
+ }
180
+
181
+ // 3. Send the custom message using the core API
182
+ barrageStore.sendCustomMessage(businessID: businessId, data: jsonString) { result in
183
+ switch result {
184
+ case .success:
185
+ print("Gift message (custom barrage) sent successfully")
186
+ case .failure(let error):
187
+ print("Failed to send gift message: \(error.localizedDescription)")
188
+ }
189
+ }
190
+ }
191
+ }
192
+ ```
193
+
194
+ #### API Parameters
195
+ <table>
196
+ <tr>
197
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
198
+
199
+ <td rowspan="1" colSpan="1" >**Type**</td>
200
+
201
+ <td rowspan="1" colSpan="1" >**Description**</td>
202
+ </tr>
203
+
204
+ <tr>
205
+ <td rowspan="1" colSpan="1" >`businessId`</td>
206
+
207
+ <td rowspan="1" colSpan="1" >`String`</td>
208
+
209
+ <td rowspan="1" colSpan="1" >Unique business identifier, e.g., "live_gift", used by the receiver to distinguish different custom messages.</td>
210
+ </tr>
211
+
212
+ <tr>
213
+ <td rowspan="1" colSpan="1" >`data`</td>
214
+
215
+ <td rowspan="1" colSpan="1" >`String`</td>
216
+
217
+ <td rowspan="1" colSpan="1" >Business data, usually a JSON-formatted string.</td>
218
+ </tr>
219
+
220
+ <tr>
221
+ <td rowspan="1" colSpan="1" >`completion`</td>
222
+
223
+ <td rowspan="1" colSpan="1" >`CompletionClosure?`</td>
224
+
225
+ <td rowspan="1" colSpan="1" >Callback after sending is complete.</td>
226
+ </tr>
227
+ </table>
228
+
229
+
230
+ ### Step 5: Insert Local Tip Message
231
+
232
+ Insert a local message into the current user's message list. This message is not sent to other users in the live room. Use this for system welcomes, warnings, or action tips.
233
+ ``` swift
234
+ extension BarrageManager {
235
+ /// Insert a welcome tip into the local message list
236
+ func showWelcomeMessage(for user: LiveUserInfo) {
237
+ // 1. Create a Barrage message
238
+ var welcomeTip = Barrage()
239
+ welcomeTip.messageType = .text // Reuse the text type for display
240
+ welcomeTip.textContent = "Welcome \(user.userName) to the live room!"
241
+ // sender can be left empty or set to a system user identifier
242
+
243
+ // 2. Insert the message into the local list
244
+ barrageStore.appendLocalTip(message: welcomeTip)
245
+ }
246
+ }
247
+ ```
248
+
249
+ #### API Parameters
250
+ <table>
251
+ <tr>
252
+ <td rowspan="1" colSpan="1" >**Parameter**</td>
253
+
254
+ <td rowspan="1" colSpan="1" >**Type**</td>
255
+
256
+ <td rowspan="1" colSpan="1" >**Description**</td>
257
+ </tr>
258
+
259
+ <tr>
260
+ <td rowspan="1" colSpan="1" >message</td>
261
+
262
+ <td rowspan="1" colSpan="1" >Barrage</td>
263
+
264
+ <td rowspan="1" colSpan="1" >The message object to insert locally. The SDK appends this message to the messageList in BarrageState.</td>
265
+ </tr>
266
+ </table>
267
+
268
+
269
+ ### Step 6: Manage User Speaking Permissions (Mute and Unmute)
270
+
271
+ As a host or administrator, you can manage users' chat permissions in the live room to maintain a healthy community environment.
272
+
273
+ #### Mute/Unmute a Single User
274
+
275
+ Use the `disableSendMessage` method in `LiveAudienceStore` to mute or unmute a user. This state persists even if the user rejoins the live room.
276
+ ``` swift
277
+ import AtomicXCore
278
+
279
+ // 1. Get the LiveAudienceStore instance for the current live room
280
+ let audienceStore = LiveAudienceStore.create(liveID: "your_live_id")
281
+
282
+ // 2. Specify the user ID and mute status
283
+ let userIdToMute = "user_id_to_be_muted"
284
+ let shouldDisable = true // true to mute, false to unmute
285
+
286
+ // 3. Call the API to perform the operation
287
+ audienceStore.disableSendMessage(userID: userIdToMute, isDisable: shouldDisable) { [weak self] result in
288
+ guard let self = self else { return }
289
+ switch result {
290
+ case .success:
291
+ print("\(shouldDisable ? "Muted" : "Unmuted") user \(userIdToMute) successfully")
292
+ case .failure(let error):
293
+ print("Operation failed: \(error.localizedDescription)")
294
+ }
295
+ }
296
+ ```
297
+
298
+ #### Enable/Disable Global Mute
299
+
300
+ To mute all users in the live room (usually excluding the host), update the live room information via `LiveListStore`.
301
+ ``` swift
302
+ import AtomicXCore
303
+
304
+ // 1. Get the LiveListStore singleton
305
+ let liveListStore = LiveListStore.shared
306
+
307
+ // 2. Get the current live room info and modify the global mute status
308
+ var currentLiveInfo = liveListStore.state.value.currentLive
309
+ currentLiveInfo.isMessageDisable = true // true to enable global mute, false to disable
310
+
311
+ // 3. Call the update API and specify the modify flag
312
+ liveListStore.updateLiveInfo(currentLiveInfo, modifyFlag: .isMessageDisable) { result in
313
+ switch result {
314
+ case .success:
315
+ print("Global mute status updated successfully")
316
+ case .failure(let error):
317
+ print("Operation failed: \(error.localizedDescription)")
318
+ }
319
+ }
320
+ ```
321
+
322
+ ## Advanced Features: Performance Optimization in High-Concurrency Scenarios
323
+
324
+ 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.
325
+
326
+ ### Scenario 1: Handling "Barrage Storms" in Popular Live Rooms
327
+
328
+ #### Scenario Description
329
+
330
+ During popular events, a large number of viewers may flood into the live room, with barrages updating at dozens of messages per second.
331
+
332
+ #### Technical Challenge
333
+
334
+ The SDK returns the complete barrage list at a high frequency. If you call `tableView.reloadData()` on every update, the main thread will be blocked by intensive UI layout and rendering, causing UI lag.
335
+
336
+ #### Optimization: Batch Processing & Debouncing
337
+
338
+ Do not respond to every data update. Instead, set a time threshold (e.g., 300 milliseconds). Only refresh the UI if this threshold has passed since the last refresh. This reduces dozens of `reloadData()` calls per second to just 3-4, greatly improving smoothness.
339
+
340
+ #### Code Example
341
+
342
+ Create a `BarrageUIManager` class with an internal buffer and timer to batch update data to the `UITableView`.
343
+ ``` swift
344
+ class BarrageUIManager {
345
+ private var latestMessageList: [BarrageViewModel]?
346
+ private var refreshTimer: Timer?
347
+ private weak var tableView: UITableView?
348
+ private var dataSource: [BarrageViewModel] = []
349
+
350
+ init(tableView: UITableView) {
351
+ self.tableView = tableView
352
+ // Check every 0.3 seconds if a refresh is needed
353
+ self.refreshTimer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true) { [weak self] _ in
354
+ self?.refreshUIIfNeeded()
355
+ }
356
+ }
357
+
358
+ /// Frequently called from outside, passing in the latest full list
359
+ func update(with fullList: [BarrageViewModel]) {
360
+ self.latestMessageList = fullList
361
+ }
362
+
363
+ private func refreshUIIfNeeded() {
364
+ // Check if there is new data to refresh
365
+ guard let newList = self.latestMessageList, let tableView = self.tableView else { return }
366
+ self.latestMessageList = nil // Clear the flag to avoid repeated refreshes
367
+
368
+ // Update the data source and refresh the UI
369
+ self.dataSource = newList
370
+ tableView.reloadData()
371
+ }
372
+
373
+ deinit {
374
+ refreshTimer?.invalidate()
375
+ }
376
+ }
377
+ ```
378
+
379
+ ### Scenario 2: Ensuring Memory Stability for Long-Duration Live Streams
380
+
381
+ #### Scenario Description
382
+
383
+ 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.
384
+
385
+ #### Technical Challenge
386
+
387
+ The SDK returns a full `messageList` that grows indefinitely during long live streams. Even if the UI layer throttles updates, the data layer's large array will continue to consume memory, eventually causing the app to crash.
388
+
389
+ #### Optimization: Circular Buffer with Fixed Capacity
390
+
391
+ 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.
392
+
393
+ #### Code Example
394
+
395
+ After receiving the full list from the SDK, take only the latest 500 messages (or another number you define) to update the UI.
396
+ ``` swift
397
+ class BarrageUIManager {
398
+ private let capacity: Int = 500 // Retain only the latest 500 messages
399
+ // ... (other code as above) ...
400
+
401
+ private func refreshUIIfNeeded() {
402
+ guard let fullList = self.latestMessageList, let tableView = self.tableView else { return }
403
+ self.latestMessageList = nil
404
+
405
+ // Only keep the latest N messages
406
+ let cappedList = Array(fullList.suffix(self.capacity))
407
+
408
+ self.dataSource = cappedList
409
+ tableView.reloadData()
410
+ }
411
+ }
412
+ ```
413
+
414
+ ### Scenario 3: Rendering Complex Barrage Styles with User Levels and Badges
415
+
416
+ #### Scenario Description
417
+
418
+ 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.
419
+
420
+ #### Technical Challenge
421
+
422
+ 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.
423
+
424
+ #### Optimization: Asynchronous Drawing
425
+
426
+ 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.
427
+
428
+ #### Code Example
429
+
430
+ In your custom `UITableViewCell`, enable the layer's `drawsAsynchronously` property to allow the system to perform drawing tasks on a background thread.
431
+ ``` swift
432
+ import UIKit
433
+
434
+ // In your custom barrage cell
435
+ class BarrageCell: UITableViewCell {
436
+
437
+ // ... (UILabel, UIImageView, and other subview declarations)
438
+
439
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
440
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
441
+
442
+ // Enable asynchronous drawing
443
+ self.layer.drawsAsynchronously = true
444
+ }
445
+
446
+ required init?(coder: NSCoder) {
447
+ fatalError("init(coder:) has not been implemented")
448
+ }
449
+
450
+ func configure(with viewModel: BarrageViewModel) {
451
+ // Set label text, images, etc.
452
+ // With asynchronous drawing enabled, rendering occurs on a background thread when possible
453
+ }
454
+
455
+ // Advanced: fully manual drawing
456
+ override func draw(_ rect: CGRect) {
457
+ // For finer control, manually draw text and images here using Core Graphics
458
+ // Combine generating UIImage on a background thread, then draw it in the main thread's draw method for fully asynchronous rendering
459
+ }
460
+ }
461
+ ```
462
+
463
+ ## API Documentation
464
+
465
+ For detailed information on all public interfaces, properties, and methods of [BarrageStore](https://tencent-rtc.github.io/TUIKit_iOS/documentation/atomicxcore/barragestore) and related classes, refer to the official API documentation included with the [AtomicXCore](https://tencent-rtc.github.io/TUIKit_iOS/documentation/atomicxcore) framework.
466
+
467
+ ## FAQs
468
+
469
+ ### 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?
470
+
471
+ You can implement these features using custom messages with `sendCustomMessage`.
472
+
473
+ **Implementation Steps**
474
+ 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:
475
+
476
+ ``` json
477
+ { "type": "colored_text", "text": "This is a colored bullet comment!", "color": "#FF5733" }
478
+ ```
479
+ 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`.
480
+
481
+ 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`).
482
+
483
+
484
+ ### If I call BarrageStore.create(liveID = "some_id") in different classes or files, will this create multiple instances and cause confusion?
485
+
486
+ 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.
487
+
488
+ ### Why can't I see the message I sent after calling sendTextMessage in the message list?
489
+
490
+ **Troubleshooting steps:**
491
+ 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.).
492
+
493
+ 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.
494
+
495
+ 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.
496
+
497
+ 4. **Network issues**: Ensure the device's network connection is normal. Message sending depends on network connectivity.
498
+
499
+
500
+ ### How can new viewers see historical barrage messages sent before they joined the live room?
501
+
502
+ `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.
503
+
504
+ #### **Step 1: Configure in the Live Console**
505
+ 1. Log in to [**Console > Live > Configuration**](https://console.trtc.io/live/configuration), and select your target application at the top of the page.
506
+
507
+ 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.
508
+
509
+
510
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027202808/5ca7e8c2e20c11f095b0525400e889b2.png)
511
+
512
+
513
+ #### **Step 2: Automatic Retrieval on the Client Side**
514
+
515
+ After completing the above configuration, **no changes are needed** in your client code.
516
+
517
+ 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.