tencent cloud

Tencent Real-Time Communication

소식 및 공지 사항
제품 업데이트
Tencent Cloud 오디오/비디오 단말 SDK 재생 업그레이드 및 권한 부여 인증 추가
TRTC 월간 구독 패키지 출시 관련 안내
제품 소개
제품 개요
기본 개념
제품 기능
제품 장점
응용 시나리오
성능 데이터
구매 가이드
Billing Overview
무료 시간 안내
Monthly subscription
Pay-as-you-go
TRTC Overdue and Suspension Policy
과금 FAQ
Refund Instructions
신규 사용자 가이드
Demo 체험
Call
개요(TUICallKit)
Activate the Service
Run Demo
빠른 통합(TUICallKit)
오프라인 푸시
Conversational Chat
온클라우드 녹화(TUICallKit)
AI Noise Reduction
UI 사용자 정의
Calls integration to Chat
Additional Features
No UI Integration
Server APIs
Client APIs
Solution
ErrorCode
릴리스 노트
FAQs
라이브 스트리밍
Billing of Video Live Component
Overview
Activating the Service (TUILiveKit)
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 다운로드
API 코드 예시
Usage Guidelines
API 클라이언트 API
고급 기능
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
콘솔 가이드
애플리케이션 관리
사용량 통계
모니터링 대시보드
개발 보조
Solution
Real-Time Chorus
FAQs
과금 개요
기능 관련
UserSig 관련
방화벽 제한 처리
설치 패키지 용량 축소 관련 질문
Andriod 및 iOS 관련
Web 관련
Flutter 관련
Electron 관련
TRTCCalling Web 관련
멀티미디어 품질 관련
기타 질문
Protocols and Policies
컴플라이언스 인증
보안 백서
정보 보안에 관한 참고 사항
Service Level Agreement
Apple Privacy Policy: PrivacyInfo.xcprivacy
TRTC 정책
개인 정보 보호 정책
데이터 처리 및 보안 계약
용어집

Audience List (iOS)

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 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.



도움말 및 지원

문제 해결에 도움이 되었나요?

피드백