Co Host Store
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
CoHostStoreinstance. 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:
| Step | Role | Action | Triggered Event |
| 1 | Host A | Call requestHostConnection | CoHostListener.onCoHostRequestReceived |
| 2 | Host B | Call acceptHostConnection | CoHostListener.onCoHostRequestAccepted |
| 3 | System | Hosts connected successfully | CoHostListener.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
CoHostStore.create - Create object instance
Observing State and Events
coHostState - Reactive state containing connection status, connected hosts, invitation list and applicants
addCoHostListener/removeCoHostListener - Connection event callbacks
Connection Operations
requestHostConnection - Initiate connection request
cancelHostConnection - Cancel connection request
acceptHostConnection/rejectHostConnection - Respond to connection request
exitHostConnection - Exit connection
getCoHostCandidates - Get recommended host list
See Also
Properties
Functions
Accept host connection request
Add connection callback listener
Cancel host connection request
Exit host connection
Get recommended host list that can connect with current host
Reject host connection request
Remove connection callback listener
Initiate host connection request