LiveAudienceState is a specialized module within AtomicXCore designed for managing audience information in live streaming rooms. With LiveAudienceState, you can build a robust audience list and management system for your live streaming application.
Core Features
Real-Time Audience List: Retrieve and display information for all current viewers in the live room.
Audience Count Statistics: Access the accurate, real-time total number of viewers in the live room.
Audience Activity Monitoring: Subscribe to events to detect instantly when viewers join or leave.
Administrator Permissions: Hosts can assign or revoke administrator privileges.
Room Management: Hosts or administrators can remove regular viewers from the live room.
Example Project
Refer to our LiveAudienceList component on GitHub for a complete implementation example.
Implementation Steps
Step 1: Component Integration
Follow the Quick Start guide to integrate AtomicXCore and complete the initial setup.
Step 2: Initialize and Fetch Audience List
Obtain an instance of LiveAudienceState and proactively fetch the current audience list for initial display. The module automatically listens for changes in the live room state and updates the audience list when switching rooms.
console.log('Successfully fetched the initial audience list');
}catch(error){
console.error('Failed to fetch the initial audience list', error);
}
});
// Watch for real-time changes in audienceList to drive UI updates
watch(audienceList,(newVal)=>{
console.log('Audience list updated:', newVal);
});
Step 3: Listen for Audience List State and Real-Time Activity
Subscribe to audienceState events and reactive data to receive full list snapshots and real-time audience join/leave events, enabling dynamic UI updates.
Display Welcome Message in Barrage Area When Audience Enters
Automatically display a local welcome message in the barrage/chat area when a new audience member enters the live room, such as: "Welcome user nickname to the live room".
Implementation
Subscribe to the onAudienceJoined event and display a welcome message in the barrage/chat area.
For detailed information on all public APIs, properties, and methods of LiveAudienceState and related classes, see the official API documentation for the AtomicXCore framework. The relevant State modules referenced in this guide are:
State
Feature Description
API Documentation
LiveAudienceState
Audience management: Retrieve real-time audience list (ID / name / avatar), count audience numbers, monitor audience join/leave events.
How is the online audience count (audienceCount) updated in LiveAudienceState? What are the timing and frequency?
The audienceCount is updated with near real-time accuracy, but not always instantly. The update mechanism is as follows:
Active Room Entry/Exit: When a user actively joins or leaves the live room, the audience count is updated immediately. Changes to audienceCount in LiveAudienceState are reflected almost instantly.
Unexpected Disconnection: If a user disconnects due to network issues, app crashes, or other abnormal reasons, the system uses a heartbeat mechanism to verify their status. Only after missing heartbeats for 90 consecutive seconds is the user considered offline and the audience count updated.
Update Mechanism and Frequency Control:
All audience count change notifications, whether instant or delayed, are broadcast as messages within the room.
There is a rate limit of 40 messages per second per room.
Important: In scenarios with extremely high message traffic (e.g., barrage storms, rapid gift sending), if the room exceeds the 40 messages/second threshold, audience count change messages may be dropped to prioritize core messages (such as barrage).
What does this mean for developers?
The audienceCount provides a highly accurate, near real-time estimate. However, in extreme high-concurrency scenarios, brief delays or data loss may occur. We recommend using audienceCount for UI display purposes only, and not as the sole source for billing, analytics, or other use cases requiring absolute precision.