製品アップデート情報
Tencent Cloudオーディオビデオ端末SDKの再生アップグレードおよび承認チェック追加に関するお知らせ
TRTCアプリケーションのサブスクリプションパッケージサービスのリリースに関する説明について
LiveAudienceStore is a module in AtomicXCore specialized in managing live streaming room audience information. With LiveAudienceStore, you can build a complete audience list and management system for your live stream application.
LiveAudienceStore:Core Concepts | Type | Core Responsibilities and Description |
class | Represents the basic information model for an audience member. Includes the user’s unique identifier ( userID), nickname (userName), and avatar URL (avatarURL). | |
class | Represents the current status of the audience module. Its core attribute audienceList is a ValueListenable<List<LiveUserInfo>>, storing a snapshot of the audience list; audienceCount signifies the total number of current audience. | |
class | Handles real-time event listening for audience activity. Includes two callbacks: onAudienceJoined (audience member joins) and onAudienceLeft (audience member leaves), used for incremental updates to the audience list. | |
class | The main management class for audience list operations. Use it to get audience snapshots, perform management actions, and receive real-time updates via addLiveAudienceListener. |
LiveAudienceStore instance bound to the current live streaming room liveId, actively pull the current audience list once for first-time show.dispose method on AudienceManager.import 'package:atomic_x_core/atomicxcore.dart';class AudienceManager {final String liveId;late final LiveAudienceStore audienceStore;late LiveAudienceListener _audienceListener;late final VoidCallback _audienceListChangedListener = _onAudienceListChanged;late final VoidCallback _audienceCountChangedListener = _onAudienceCountChanged;// Externally exposed [full] audience listList<LiveUserInfo> audienceList = [];// Externally exposed total audience countint audienceCount = 0;// Status change callbackFunction()? onStateChanged;AudienceManager({required this.liveId}) {// 1. Retrieve an instance of LiveAudienceStore by liveIdaudienceStore = LiveAudienceStore.create(liveId);// 2. Subscribe to status and events_subscribeToAudienceState();_subscribeToAudienceEvents();// 3. Actively pull first screen datafetchInitialAudienceList();}/// Proactively retrieve an audience list snapshot onceFuture<void> fetchInitialAudienceList() async {final result = await audienceStore.fetchAudienceList();if (result.isSuccess) {print("First pull audience list successfully");// Upon success, data will be auto-updated via the state subscription channel below} else {print("First pull audience list failed: ${result.errorMessage}");}}void dispose() {audienceStore.liveAudienceState.audienceList.removeListener(_audienceListChangedListener);audienceStore.liveAudienceState.audienceCount.removeListener(_audienceCountChangedListener);audienceStore.removeLiveAudienceListener(_audienceListener);}}
state subscriptions will be explained in detail in the next step.liveAudienceState and LiveAudienceListener on audienceStore to receive full audience list snapshots and real-time join/leave events, driving UI updates.extension AudienceManagerSubscription on AudienceManager {/// Subscribe to state to obtain the total count of audience and list snapshotsvoid _subscribeToAudienceState() {// Listen to audience list adjustmentsaudienceStore.liveAudienceState.audienceList.addListener(_audienceListChangedListener);// Listen to audience change rateaudienceStore.liveAudienceState.audienceCount.addListener(_audienceCountChangedListener);}void _onAudienceListChanged() {// audienceList is a full snapshotaudienceList = audienceStore.liveAudienceState.audienceList.value;onStateChanged?.call();}void _onAudienceCountChanged() {// audienceCount is the real-time total countaudienceCount = audienceStore.liveAudienceState.audienceCount.value;onStateChanged?.call();}/// Subscribe to events for processing real-time audience entry and exitvoid _subscribeToAudienceEvents() {_audienceListener = LiveAudienceListener(onAudienceJoined: (audience) {print("Audience ${audience.userName} joined the live streaming room");// Incremental update: Add new audience at the end of the current listif (!audienceList.any((a) => a.userID == audience.userID)) {audienceList.add(audience);onStateChanged?.call();}},onAudienceLeft: (audience) {print("Audience ${audience.userName} left the live streaming room");// Incremental update: Remove leaving audience from the current listaudienceList.removeWhere((a) => a.userID == audience.userID);onStateChanged?.call();},);audienceStore.addLiveAudienceListener(_audienceListener);}}
kickUserOutOfRoom API to remove designated users from the live streaming room.extension AudienceManagerActions on AudienceManager {Future<void> kick(String userId) async {final result = await audienceStore.kickUserOutOfRoom(userId);if (result.isSuccess) {print("Successfully kicked user $userId out of room");// Upon success, you will receive the onAudienceLeft event} else {print("Failed to kick out user $userId: ${result.errorMessage}");}}}
setAdministrator and revokeAdministrator APIs to manage user administrator privileges.extension AudienceManagerAdmin on AudienceManager {/// Set the user as administratorFuture<void> promoteToAdmin(String userId) async {final result = await audienceStore.setAdministrator(userId);if (result.isSuccess) {print("Successfully set user $userId as administrator");}}/// Revoke the user's administrator privilegesFuture<void> revokeAdmin(String userId) async {final result = await audienceStore.revokeAdministrator(userId);if (result.isSuccess) {print("Successfully revoked user $userId's administrator privileges");}}}
onAudienceJoined event from LiveAudienceStore to receive real-time notifications when a new audience member joins. When triggered, extract the user’s nickname and call the appendLocalTip API from BarrageStore to insert the welcome message.dispose method on LiveRoomManager.import 'package:atomic_x_core/atomicxcore.dart';class LiveRoomManager {final String liveId;late LiveAudienceListener _welcomeListener;LiveRoomManager({required this.liveId}) {_setupWelcomeMessageFlow();}void _setupWelcomeMessageFlow() {// 1. Retrieve an instance of LiveAudienceStorefinal audienceStore = LiveAudienceStore.create(liveId);// 2. Retrieve an instance of BarrageStore (thanks to the internal mechanism, this will be the same instance)final barrageStore = BarrageStore.create(liveId);// 3. Subscribe to audience events_welcomeListener = LiveAudienceListener(onAudienceJoined: (audience) {// 4. Create a local Prompt messagefinal welcomeTip = Barrage(messageType: BarrageType.text,textContent: "Welcome ${audience.userName} to the live streaming room.");// 5. Call the BarrageStore API to insert it into the bullet screen listbarrageStore.appendLocalTip(welcomeTip);},);audienceStore.addLiveAudienceListener(_welcomeListener);}void dispose() {final audienceStore = LiveAudienceStore.create(liveId);audienceStore.removeLiveAudienceListener(_welcomeListener);}}
Store/Component | Feature Description | API Reference |
LiveCoreWidget | Core view component for live video stream display and interaction. Handles video stream rendering and widget management, supporting host live streaming, audience co-hosting, and host connection scenarios. | |
LiveCoreController | LiveCoreWidget controller: used to set up live streaming ID, control preview, and perform other operations. | |
LiveAudienceStore | Audience management: get real-time audience list (ID/name/avatar), check audience size, listen to Enter/Exit Event. | |
BarrageStore | Live comments: send text/custom comments, maintain the comment list, and monitor comment status in real time. |
audienceCount is a high-precision estimate very close to real time, but under extreme high concurrency scenarios, it may have brief delay or data loss. Therefore, we recommend that you use it for UI display and should not take it as the only basis for scenarios requiring absolute accuracy such as billing or statistics.フィードバック