CoHostStore

abstract class CoHostStore

Live host connection management related interfaces, managing creation, joining, leaving and other operations for host-to-host connections.

Overview

CoHostStore Manages all host-to-host connection related operations, including initiating connection requests, cancelling, accepting, rejecting and exiting connections. Cross-room connection feature allows hosts from different live rooms to interact in real-time. CoHostStore provides a comprehensive set of APIs to manage the entire cross-room connection lifecycle.

Core Features

  • Bidirectional Connection: Hosts can initiate connection requests to other hosts, and also receive connection requests from other hosts

  • State Management: Real-time tracking of connection status, connected hosts, invitation list and applicants

  • Event-Driven Architecture: Provides connection event stream for monitoring various connection state changes

  • Layout Templates: Supports multiple connection layout templates, such as dynamic grid layout and 1-to-6 layout

Important: Always use the method CoHostStore.create with a non-empty string liveID to create a CoHostStore instance. Do not attempt to initialize directly. Connection state updates are delivered through the coHostState publisher. Subscribe to it to receive real-time updates about connection status, connected hosts, invitations and applications.

Cross-Room Connection Workflow

The following table shows a typical cross-room connection workflow:

StepRoleActionTriggered Event
1Host ACall requestHostConnectionCoHostListener.onCoHostRequestReceived
2Host BCall acceptHostConnectionCoHostListener.onCoHostRequestAccepted
3SystemHosts connected successfullyCoHostListener.onCoHostUserJoined

Warning: If a connection request does not receive a response within the specified timeout, the CoHostListener.onCoHostRequestTimeout event will be triggered. Always handle timeout scenarios in your UI.

Usage Example

// Create store instance
val store = CoHostStore.create("live_room_123")

// Subscribe to state changes
lifecycleScope.launch {
store.coHostState.coHostStatus.collect { status ->
println("Connection status: $status")
}
}

lifecycleScope.launch {
store.coHostState.connected.collect { connected ->
println("Connected hosts: ${connected.size}")
}
}

// Add connection event listener
store.addCoHostListener(object : CoHostListener() {
override fun onCoHostRequestReceived(inviter: SeatUserInfo, extensionInfo: String) {
println("Received connection request from ${inviter.userName}")
// Show accept/reject UI
}
override fun onCoHostRequestAccepted(invitee: SeatUserInfo) {
println("Connection request accepted by ${invitee.userName}")
}
override fun onCoHostUserJoined(userInfo: SeatUserInfo) {
println("Host ${userInfo.userName} joined connection")
}
})

// Initiate connection request
store.requestHostConnection(
targetHostLiveID = "target_live_id",
layoutTemplate = CoHostLayoutTemplate.HOST_DYNAMIC_GRID,
timeout = 30,
extraInfo = "",
completion = { code, message ->
if (code == 0) {
println("Connection request sent successfully")
}
}
)

Warning: If a connection request does not receive a response within the specified timeout, the `CoHostEvent/onCoHostRequestTimeout(inviter:invitee:)` event will be triggered. Always handle timeout scenarios in your UI.

Topics

Creating Instance

Observing State and Events

Connection Operations

See Also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val coHostState: CoHostState

Cross-room connection related state data provided externally by CoHostStore

Functions

Link copied to clipboard
abstract fun acceptHostConnection(fromHostLiveID: String?, completion: CompletionHandler?)

Accept host connection request

Link copied to clipboard
abstract fun addCoHostListener(listener: CoHostListener?)

Add connection callback listener

Link copied to clipboard
abstract fun cancelHostConnection(toHostLiveID: String?, completion: CompletionHandler?)

Cancel host connection request

Link copied to clipboard
abstract fun exitHostConnection(completion: CompletionHandler?)

Exit host connection

Link copied to clipboard
abstract fun getCoHostCandidates(cursor: String, completion: CompletionHandler?)

Get recommended host list that can connect with current host

Link copied to clipboard
abstract fun rejectHostConnection(fromHostLiveID: String?, completion: CompletionHandler?)

Reject host connection request

Link copied to clipboard
abstract fun removeCoHostListener(listener: CoHostListener?)

Remove connection callback listener

Link copied to clipboard
abstract fun requestHostConnection(targetHostLiveID: String?, layoutTemplate: CoHostLayoutTemplate, timeout: Int, extraInfo: String?, completion: CompletionHandler?)

Initiate host connection request