tencent cloud

Tencent Real-Time Communication

Release Notes and Announcements
Release Notes
Recent Product Announcement
TRTC Live (TUILiveKit) Product Launch Announcement
TRTC Conference Official Editions Launched
The commercial version of Conference is coming soon
Terms and Conditions Applicable to $9.9 Starter Package
Rules for the "First Subscription $100 Discount" Promotion
Announcement on the Start of Beta Testing for Multi-person Audio and Video Conference
TRTC Call Official Editions Launched
License Required for Video Playback in New Version of LiteAV SDK
TRTC to Offer Monthly Packages
Product Introduction
Overview
Concepts
Features
Strengths
Use Cases
Performance Statistics
Tencent RTC Quickplay: Experience Ultimate Real-Time Audio and Video Interaction!
Purchase Guide
Billing Overview
Free Minutes
Monthly subscription
Pay-as-you-go
TRTC Overdue and Suspension Policy
FAQs
Refund Instructions
User Tutorial
Free Demo
Call
Overview
Activate the Service
Run Demo
Integration
Offline Call Push
Conversational Chat
On-Cloud Recording
AI Noise Reduction
UI Customization
Calls integration to Chat
Additional Features
No UI Integration
Server APIs
Client APIs
Solution
ErrorCode
Release Notes
FAQs
Conference
Overview(TUIRoomKit)
Activate the Service (TUIRoomKit)
Run Demo(TUIRoomKit)
Integration(TUIRoomKit)
Screen Sharing (TUIRoomKit)
Schedule a meeting (TUIRoomKit)
In-meeting Call (TUIRoomKit)
UI Customization(TUIRoomKit)
Virtual Background (TUIRoomKit)
Conference Control (TUIRoomKit)
Cloud Recording (TUIRoomKit)
AI Noise Reduction (TUIRoomKit)
In-Conference Chat (TUIRoomKit)
Robot Streaming (TUIRoomKit)
Enhanced Features (TUIRoomKit)
Client APIs (TUIRoomKit)
Server APIs (TUIRoomKit)
FAQs (TUIRoomKit)
Error Code (TUIRoomKit)
SDK Update Log (TUIRoomKit)
Live
Billing of Video Live Component
Overview
Activating the Service (TUILiveKit)
Run Demo
No UI Integration
UI Customization
Live Broadcast Monitoring
Video Live Streaming
Voice Chat Room
Advanced Features
Client APIs
Server APIs
Error Codes
Release Notes
FAQs
RTC Engine
Activate Service
SDK Download
API Examples
Usage Guidelines
API Reference Manual
Advanced Features
AI Integration
Overview
Configure MCP Server
Install Skills
Integration Guide
FAQ
RTC RESTFUL API
History
Introduction
API Category
Room Management APIs
Stream mixing and relay APIs
On-cloud recording APIs
Data Monitoring APIs
Pull stream Relay Related interface
Web Record APIs
AI Service APIs
Cloud Slicing APIs
Cloud Moderation APIs
Making API Requests
Call Quality Monitoring APIs
Usage Statistics APIs
Data Types
Appendix
Error Codes
Console Guide
Application Management
Package Management
Usage Statistics
Monitoring Dashboard
Development Assistance
Solution
Real-Time Chorus
FAQs
Migration Guide
Billing
Features
UserSig
Firewall Restrictions
How to Downsize Installation Package
Android and iOS
Web
Flutter
Electron
TRTCCalling for Web
Audio and Video Quality
Others
Legacy Documentation
RTC RoomEngine SDK(Old)
Integrating TUIRoom (Web)
Integrating TUIRoom (Android)
Integrating TUIRoom (iOS)
Integrating TUIRoom (Flutter)
Integrating TUIRoom (Electron)
TUIRoom APIs
On-Cloud Recording and Playback (Old)
RTC Analytics Monthly Packages (Previous Version)
Protocols and Policies
Compliance
Security White Paper
Notes on Information Security
Service Level Agreement
Apple Privacy Policy: PrivacyInfo.xcprivacy
TRTC Policy
Privacy Policy
Data Processing And Security Agreement
Glossary

Audience List (iOS)

PDF
Focus Mode
Font Size
Last updated: 2025-12-25 11:10:23
LiveAudienceStore is a module in AtomicXCore designed for managing audience information in live streaming rooms. With LiveAudienceStore, you can implement a comprehensive audience list and management system for your live streaming application.


Core Features

Real-Time Audience List: Fetch and display the list of users currently in the room.
Audience Statistics: Get the real-time total viewer count.
Event Monitoring: Listen for events when viewers join or leave the room.
Role Management: The host can grant or revoke administrator privileges for viewers.
Room Management: The host or administrator can remove specific viewers from the live room.

Core Concepts

Core Concept
Type
Core Responsibilities & Description
LiveUserInfo
class
Data model representing a viewer.
Contains basic profile information such as userID, userName, and avatarURL.
LiveAudienceState
struct
State container for the audience module.
Exposes audienceList (StateFlow) for the real-time user list and audienceCount for the total viewer count.
LiveAudienceEvent
enum
Event listener for audience changes.
Provides callbacks like .onAudienceJoined and .onAudienceLeft to handle incremental list updates.
LiveAudienceStore
class
Primary interface for audience management.
Used to fetch list snapshots, perform admin operations (e.g., kicking users), and subscribe to real-time events.

Implementation

Step 1: Component Integration

Video Live Streaming: Please refer to Quick Start to integrate AtomicXCore.
Voice Chat Room: Please refer to Quick Start to integrate AtomicXCore.

Step 2: Initialize and Retrieve the Audience List

Get a LiveAudienceStore instance linked to the liveId and fetch the initial audience snapshot.
import Foundation
import AtomicXCore
import Combine

class AudienceManager {
private let liveId: String
private let audienceStore: LiveAudienceStore
private var cancellables = Set<AnyCancellable>()
// Expose the [full] audience list publisher for UI layer subscription
let audienceListPublisher = CurrentValueSubject<[LiveUserInfo], Never>([])
// Expose the audience count publisher
let audienceCountPublisher = PassthroughSubject<UInt, Never>()

init(liveId: String) {
self.liveId = liveId
// 1. Get the LiveAudienceStore instance by liveId
self.audienceStore = LiveAudienceStore.create(liveID: liveId)
// 2. Subscribe to state and events
subscribeToAudienceState()
subscribeToAudienceEvents()
// 3. Proactively fetch initial data for the first screen
fetchInitialAudienceList()
}

/// Proactively fetch a snapshot of the audience list
func fetchInitialAudienceList() {
audienceStore.fetchAudienceList { [weak self] result in
switch result {
case .success:
print("Successfully fetched the audience list for the first time")
// On success, data will be automatically updated via the state subscription channel below
case .failure(let error):
print("Failed to fetch the audience list for the first time: \\(error.localizedDescription)")
}
}
}
// ... subsequent code
}

Step 3: Subscribe to State and Events

Observe the audienceStore state and listen for events to receive list snapshots and real-time join/leave updates
extension AudienceManager {
/// Subscribe to state to get audience count and list snapshot
private func subscribeToAudienceState() {
audienceStore.state
.subscribe()
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
// state.audienceList is a full snapshot
self?.audienceListPublisher.send(state.audienceList)
// state.audienceCount is the real-time total
self?.audienceCountPublisher.send(state.audienceCount)
}
.store(in: &cancellables)
}

/// Subscribe to events to handle real-time audience join/leave
private func subscribeToAudienceEvents() {
audienceStore.liveAudienceEventPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] event in
guard let self = self else { return }
var currentList = self.audienceListPublisher.value
switch event {
case .onAudienceJoined(let newAudience):
print("Audience \\(newAudience.userName) joined the live room")
// Incremental update: add the new audience member to the end of the current list
if !currentList.contains(where: { $0.userID == newAudience.userID }) {
currentList.append(newAudience)
self.audienceListPublisher.send(currentList)
}
case .onAudienceLeft(let departedAudience):
print("Audience \\(departedAudience.userName) left the live room")
// Incremental update: remove the departed audience member from the current list
currentList.removeAll { $0.userID == departedAudience.userID }
self.audienceListPublisher.send(currentList)
}
}
.store(in: &cancellables)
}
}

Step 4: Manage Audience

As a host or administrator, you can manage viewers in the live room.

4.1 Kick a Viewer Out of the Live Room

Call the kickUserOutOfRoom API to remove a specified user from the live room.
extension AudienceManager {
func kick(userId: String) {
audienceStore.kickUserOutOfRoom(userID: userId) { result in
switch result {
case .success:
print("Successfully kicked user \\(userId) out of the room")
// After a successful kick, you will receive an onAudienceLeft event
case .failure(let error):
print("Failed to kick user \\(userId) out: \\(error.localizedDescription)")
}
}
}
}

4.2 Manage Admin Roles

Use the setAdministrator and revokeAdministrator APIs to grant or revoke administrator privileges for a user.
extension AudienceManager {
/// Promote user to administrator
func promoteToAdmin(userId: String) {
audienceStore.setAdministrator(userID: userId) { result in
if case .success = result {
print("Successfully promoted user \\(userId) to administrator")
}
}
}

/// Revoke user's administrator status
func revokeAdmin(userId: String) {
audienceStore.revokeAdministrator(userID: userId) { result in
if case .success = result {
print("Successfully revoked administrator status for user \\(userId)")
}
}
}
}

Advanced Features

Display Welcome Message on Entry

When a new audience member enters the live room, a welcome message is automatically displayed locally in the barrage/chat area, such as: "Welcome [User Nickname] to the live room".

Implementation

1. Listen for Join Events: Observe the LiveAudienceEvent.onAudienceJoined callback in LiveAudienceStore to receive real-time notifications when a new user enters.
2. Insert Local Message: Upon triggering the event, extract the user's nickname and immediately call the appendLocalTip API in BarrageStore to insert the system message locally.
import Foundation
import AtomicXCore
import Combine

class LiveRoomManager {
private let liveId: String
private let audienceManager: AudienceManager
private let barrageManager: BarrageManager // Assume you have implemented BarrageManager as described in the barrage documentation
private var cancellables = Set<AnyCancellable>()

init(liveId: String) {
self.liveId = liveId
// Initialize two core managers
self.audienceManager = AudienceManager(liveId: liveId)
self.barrageManager = BarrageManager(liveId: liveId)

// Set up linkage
setupWelcomeMessageFlow()
}

private func setupWelcomeMessageFlow() {
// 1. Get the LiveAudienceStore instance
let audienceStore = LiveAudienceStore.create(liveID: self.liveId)

// 2. Get the BarrageStore instance (thanks to internal mechanisms, this will be the same instance)
let barrageStore = BarrageStore.create(liveID: self.liveId)

// 3. Subscribe to audience events
audienceStore.liveAudienceEventPublisher
.receive(on: DispatchQueue.main)
.sink { event in
// 4. Only handle audience join events
guard case .onAudienceJoined(let newAudience) = event else {
return
}

// 5. Create a local tip message
var welcomeTip = Barrage()
welcomeTip.messageType = .text
welcomeTip.textContent = "Welcome \\(newAudience.userName) to the live room!"

// 6. Call BarrageStore's API to insert it into the barrage list
barrageStore.appendLocalTip(message: welcomeTip)
}
.store(in: &cancellables)
}
}

API Documentation

For detailed information on all public interfaces, properties, and methods of LiveAudienceStore and its related classes, refer to the official API documentation included with the AtomicX Core framework. The relevant Stores used in this document are as follows:
Store/Component
Feature Description
API Documentation
LiveCoreView
Core view component for live video stream display and interaction: responsible for video stream rendering and view widget handling, supporting scenarios such as host streaming, audience co-hosting, and host-to-host connection.
LiveAudienceStore
Audience management: obtain real-time audience list (ID / name / avatar), count audience numbers, and listen for audience join/leave events.
BarrageStore
Barrage feature: send text/custom barrage, maintain barrage list, and listen to barrage status in real time.

FAQs

How is the online audience count (audienceCount) in LiveAudienceState updated? What are the timing and frequency?

The audienceCount is a high-precision estimate. Updates occur based on specific triggers and are subject to system frequency controls:
Active Entry/Exit (Immediate):When a user explicitly joins or leaves the room, the count updates immediately in LiveAudienceState.
Unexpected Disconnection (Delayed):If a user disconnects abnormally (e.g., app crash, network loss), the system uses a heartbeat mechanism to verify status. The user is marked offline only after 90 seconds of inactivity, triggering a delayed count update.
Frequency Control & Rate Limiting: Audience count updates are broadcast as room messages. The system enforces a limit of 40 messages per second per room.
Note:
During high-traffic spikes (e.g., chat floods or rapid gifting), if the message rate exceeds this threshold, the system prioritizes core messages (like chat/barrage). Consequently, audience count update messages may be dropped to maintain stability.
What does this mean for developers?
Treat audienceCount as a metric for UI display purposes only. Do not rely on it for billing, critical statistics, or scenarios requiring 100% accuracy, as brief delays or data loss may occur during high-concurrency events.



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback