CoHostStore class abstract

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

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.

Key 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 factory method CoHostStore.create with a valid live room ID to create a CoHostStore instance. Do not attempt to initialize directly.

Note: 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

Usage Example

// Create store instance
final store = CoHostStore.create('live_room_123');

// Define listeners
late final VoidCallback statusListener = _onStatusChanged;
late final VoidCallback connectedListener = _onConnectedChanged;

void _onStatusChanged() {
    print('Connection status: ${store.coHostState.coHostStatus.value}');
}

void _onConnectedChanged() {
    print('Connected hosts: ${store.coHostState.connected.value.length}');
}

// Subscribe to state changes
store.coHostState.coHostStatus.addListener(statusListener);
store.coHostState.connected.addListener(connectedListener);

// Add connection event listener
final coHostListener = CoHostListener(
    onCoHostRequestReceived: (inviter, extensionInfo) {
        print('Received connection request from ${inviter.userName}');
        // Show accept/reject UI
    },
    onCoHostRequestAccepted: (invitee) {
        print('Connection request accepted by ${invitee.userName}');
    },
    onCoHostUserJoined: (userInfo) {
        print('Host ${userInfo.userName} joined connection');
    },
);
store.addCoHostListener(coHostListener);

// Initiate connection request
final result = await store.requestHostConnection(
    targetHostLiveID: 'target_live_id',
    layoutTemplate: CoHostLayoutTemplate.hostDynamicGrid,
    timeout: 30,
    extraInfo: '',
);
if (result.code == 0) {
    print('Connection request sent successfully');
}

// Unsubscribe when done
store.coHostState.coHostStatus.removeListener(statusListener);
store.coHostState.connected.removeListener(connectedListener);
store.removeCoHostListener(coHostListener);

Topics

Creating Instance

Observing State and Events

Connection Operations

See Also

Constructors

CoHostStore()

Properties

coHostState CoHostState
Cross-room connection related state data provided externally by CoHostStore
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

acceptHostConnection(String fromHostLiveID) Future<CompletionHandler>
Accept host connection request
addCoHostListener(CoHostListener listener) → void
Add connection callback listener
cancelHostConnection(String toHostLiveID) Future<CompletionHandler>
Cancel host connection request
exitHostConnection() Future<CompletionHandler>
Exit host connection
getCoHostCandidates(String cursor) Future<CompletionHandler>
Get recommended host list that can connect with current host
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rejectHostConnection(String fromHostLiveID) Future<CompletionHandler>
Reject host connection request
removeCoHostListener(CoHostListener listener) → void
Remove connection callback listener
requestHostConnection({required String targetHostLiveID, required CoHostLayoutTemplate layoutTemplate, required int timeout, String extraInfo = ''}) Future<CompletionHandler>
Initiate host connection request
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

create(String liveID) CoHostStore
Create CoHostStore instance