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 (Android)

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-02-24 17:20:26
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: Retrieve and display all audience information currently present 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 instantly detect when viewers join or leave.
Administrator Privileges: The host can promote regular viewers to administrators or revoke their admin status.
Room Management: The host or administrator can remove (kick out) any regular viewer from the live room.

Core Concepts

Core Concept
Type
Core Responsibilities & Description
LiveUserInfo
data class
Represents the basic information model of an audience member (user). It contains the user's unique identifier (userID), nickname (userName), and avatar URL (avatarURL).
LiveAudienceState
data class
Represents the current state of the audience module. Its core property audienceList is a StateFlow that stores the real-time state of the audience list; audienceCount represents the real-time state of the current total number of viewers.
LiveAudienceListener
abstract class
Represents real-time audience activity events. It includes onAudienceJoined (audience joins) and onAudienceLeft (audience leaves), used for incremental updates to the audience list.
LiveAudienceStore
abstract class
This is the core management class for interacting with audience list functionality. Through it, you can obtain audience list snapshots, perform management operations, and subscribe to its LiveAudienceListener for real-time updates.

Implementation Guide

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

Obtain a LiveAudienceStore instance bound to the current live room's liveId, and fetch the current audience list for the initial display.
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import io.trtc.tuikit.atomicxcore.api.CompletionHandler
import io.trtc.tuikit.atomicxcore.api.live.LiveAudienceStore
import io.trtc.tuikit.atomicxcore.api.live.LiveUserInfo

class AudienceManager(
private val liveId: String
) {
private val audienceStore: LiveAudienceStore = LiveAudienceStore.create(liveId)
private val scope = CoroutineScope(Dispatchers.Main)

// Expose the [full] audience list state flow for UI layer subscription
private val _audienceList = MutableStateFlow<List<LiveUserInfo>>(emptyList())
val audienceList: StateFlow<List<LiveUserInfo>> = _audienceList.asStateFlow()
// Expose the audience count state flow
private val _audienceCount = MutableStateFlow(0)
val audienceCount: StateFlow<Int> = _audienceCount.asStateFlow()
init {
// 1. Subscribe to state and events, see next section for implementation
subscribeToAudienceState()
subscribeToAudienceEvents()

// 2. Actively fetch initial data for the first screen
fetchInitialAudienceList()
}

/// Actively fetch a snapshot of the audience list once
private fun fetchInitialAudienceList() {
audienceStore.fetchAudienceList(object : CompletionHandler {
override fun onSuccess() {
println("Successfully fetched the initial audience list")
// After success, the data will be automatically updated via the state subscription channel below
}

override fun onFailure(code: Int, desc: String) {
println("Failed to fetch the initial audience list: $desc")
}
})
}
// ... subsequent code
}

Step 3: Listen to Audience List State and Real-Time Activity

Subscribe to the liveAudienceState of audienceStore and add a LiveAudienceListener to receive full list snapshots and real-time audience join/leave events. Use these updates to drive UI changes.
class AudienceManager {
/// Subscribe to state for audience count and list snapshots
private fun subscribeToAudienceState() {
scope.launch {
// audienceList is a full snapshot
audienceStore.liveAudienceState.audienceList.collect { audienceList ->
_audienceList.value = audienceList
}
}

scope.launch {
// audienceCount is the real-time total
audienceStore.liveAudienceState.audienceCount.collect { count ->
_audienceCount.value = count
}
}
}
private val liveAudienceListener = object : LiveAudienceListener() {
override fun onAudienceJoined(newAudience: LiveUserInfo) {
println("Audience ${newAudience.userName} joined the live room")
// Incremental update: add the new audience member to the end of the current list
val currentList = _audienceList.value.toMutableList()
if (!currentList.any { it.userID == newAudience.userID }) {
currentList.add(newAudience)
_audienceList.value = currentList
}
}


override fun onAudienceLeft(departedAudience: LiveUserInfo) {
println("Audience ${departedAudience.userName} left the live room")
// Incremental update: remove the departed audience member from the current list
val currentList = _audienceList.value.toMutableList()
currentList.removeAll { it.userID == departedAudience.userID }
_audienceList.value = currentList
}
}


/// Subscribe to events to handle real-time audience join/leave
private fun subscribeToAudienceEvents() {
audienceStore.addLiveAudienceListener(liveAudienceListener)
}
}

Step 4: Manage Audience (Kick and Set Administrator)

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 method to remove a specified user from the live room.
class AudienceManager {
fun kick(userId: String) {
audienceStore.kickUserOutOfRoom(userId, object : CompletionHandler {
override fun onSuccess() {
println("Successfully kicked user $userId out of the room")
// After a successful kick, you will receive an onAudienceLeft event
}

override fun onFailure(code: Int, desc: String) {
println("Failed to kick user $userId: $desc")
}
})
}
}

4.2 Set or Revoke Administrator Status

Use the setAdministrator and revokeAdministrator methods to manage a user's administrator status.
class AudienceManager {
/// Promote user to administrator
fun promoteToAdmin(userId: String) {
audienceStore.setAdministrator(userId, object : CompletionHandler {
override fun onSuccess() {
println("Successfully promoted user $userId to administrator")
}
override fun onFailure(code: Int, desc: String) {
println("Failed to set administrator: $desc")
}
})
}

/// Revoke user's administrator status
fun revokeAdmin(userId: String) {
audienceStore.revokeAdministrator(userId, object : CompletionHandler {
override fun onSuccess() {
println("Successfully revoked administrator status for user $userId")
}

override fun onFailure(code: Int, desc: String) {
println("Failed to revoke administrator: $desc")
}
})
}
}

Advanced Features

Display a Welcome Message in the Barrage Area When a Viewer Joins

When a new viewer enters the live room, a welcome message such as "Welcome [user nickname] to the live room" is automatically displayed locally in the barrage/chat area.

Implementation

Add a listener for the audience join event LiveAudienceListener.onAudienceJoined in LiveAudienceStore to receive real-time notifications when a new viewer joins. When triggered, extract the new viewer's nickname and call the appendLocalTip method of BarrageStore to insert the message locally.
import io.trtc.tuikit.atomicxcore.api.live.LiveAudienceListener
import io.trtc.tuikit.atomicxcore.api.live.LiveAudienceStore
import io.trtc.tuikit.atomicxcore.api.live.LiveUserInfo
import io.trtc.tuikit.atomicxcore.api.barrage.Barrage
import io.trtc.tuikit.atomicxcore.api.barrage.BarrageStore
import io.trtc.tuikit.atomicxcore.api.barrage.BarrageType

class LiveRoomManager(
private val liveId: String
) {

init {
// Initialize two core managers
setupWelcomeMessageFlow()
}
private val liveAudienceListener = object : LiveAudienceListener() {
override fun onAudienceJoined(audience: LiveUserInfo) {
// 3. Create a local tip message
val welcomeTip = Barrage().apply {
liveID = liveId
messageType = BarrageType.TEXT
textContent = "Welcome ${audience.userName} to the live room."
}


// 4. Get an instance of BarrageStore (this will be the same instance due to internal mechanisms)
val barrageStore = BarrageStore.create(liveId)


// 5. Use BarrageStore's method to insert it into the barrage list
barrageStore.appendLocalTip(welcomeTip)
}
}


private fun setupWelcomeMessageFlow() {
// 1. Get an instance of LiveAudienceStore
val audienceStore = LiveAudienceStore.create(liveId)

// 2. Subscribe to audience events
audienceStore.addLiveAudienceListener(liveAudienceListener)
}
}

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 update of audienceCount is not always strictly real-time. The mechanism is as follows:
Active Join/Leave: When a user actively joins or leaves the live room, the audience count change notification is triggered instantly. You will quickly observe the change in audienceCount in LiveAudienceState.
Unexpected Disconnection: If a user disconnects unexpectedly due to network issues, app crashes, and so on, the system determines their actual status using a heartbeat mechanism. Only when the user has no heartbeat for 90 consecutive seconds does the system consider them offline and trigger a count change notification.
Update Mechanism and Frequency Control:
Whether triggered instantly or with a delay, all audience count change notifications are broadcast as messages within the room.
There is an upper limit to the total number of messages per second in a room, with a per-room message rate limit of 40 messages per second.
Key Point: In scenarios with extremely high message traffic, such as "barrage storms" or rapid-fire gifting, if the message rate in the room exceeds the 40 messages/second threshold, to ensure the delivery of core messages (such as barrage), audience count change messages may be dropped by the rate-limiting policy.
What does this mean for developers?
audienceCount is a near real-time, high-precision estimate, but in extreme high-concurrency scenarios, there may be brief delays or data loss. We recommend using it for UI display only, and not as the sole basis for billing, statistics, or other scenarios requiring absolute accuracy.

도움말 및 지원

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

피드백