CoGuestStore class abstract
Live co-guest management related interfaces, managing co-guest application, invitation, acceptance, rejection and other operations between hosts and audience.
CoGuestStore Manages all co-guest related operations between hosts and audience,
including application, invitation, acceptance and rejection processes.
Co-guest feature enables real-time interaction between hosts and audience members through a seat-based system. CoGuestStore provides a comprehensive set of APIs to manage the entire co-guest lifecycle.
Key Features
- Bidirectional Invitation:Hosts can invite audience members, and audience members can also apply to join
- State Management:Real-time tracking of connected users, invitations and applications
- Event-Driven Architecture:Provides separate event streams for host and guest roles
- Timeout Handling:Built-in timeout mechanism for invitations and applications
Important: Always use the factory method CoGuestStore.create with a valid live room ID to create a
CoGuestStoreinstance. Do not attempt to initialize directly.
Note: Co-guest state updates are delivered through the coGuestState publisher. Subscribe to it to receive real-time updates about connected users, invitations and applications.
Co-Guest Workflow
The following table shows a typical co-guest workflow
| Step | Role | Action | Triggered Event |
|---|---|---|---|
| 1 | Audience | Call applyForSeat | HostListener.onGuestApplicationReceived |
| 2 | Host | Call acceptApplication | GuestListener.onGuestApplicationResponded |
| 3 | System | User connects to seat | State updated through coGuestState publisher |
Host-Initiated Flow
| Step | Role | Action | Triggered Event |
|---|---|---|---|
| 1 | Host | Call inviteToSeat | GuestListener.onHostInvitationReceived |
| 2 | Audience | Call acceptInvitation | HostListener.onHostInvitationResponded |
| 3 | System | User connects to seat | State updated through coGuestState publisher |
Usage Example
// Create store instance
final store = CoGuestStore.create('live_room_123');
// Define listeners
late final VoidCallback connectedListener = _onConnectedChanged;
late final VoidCallback applicantsListener = _onApplicantsChanged;
void _onConnectedChanged() {
print('Connected users: ${store.coGuestState.connected.value.length}');
}
void _onApplicantsChanged() {
print('Pending applications: ${store.coGuestState.applicants.value.length}');
}
// Subscribe to state changes
store.coGuestState.connected.addListener(connectedListener);
store.coGuestState.applicants.addListener(applicantsListener);
// Add host event listener (for hosts)
final hostListener = HostListener(
onGuestApplicationReceived: (guestUser) {
print('Received application from ${guestUser.userName}');
// Show accept/reject UI
},
onHostInvitationResponded: (isAccept, guestUser) {
print('Audience ${guestUser.userName} ${isAccept ? "accepted" : "rejected"}');
},
);
store.addHostListener(hostListener);
// Host: Accept application
final result = await store.acceptApplication('user_456');
if (result.code == 0) {
print('Application accepted successfully');
}
// Unsubscribe when done
store.coGuestState.connected.removeListener(connectedListener);
store.coGuestState.applicants.removeListener(applicantsListener);
store.removeHostListener(hostListener);
Topics
Creating Instance
- CoGuestStore.create : Create object instance
Observing State and Events
- coGuestState : Reactive state containing connected users, invitees, applicants and candidates
- addHostListener/removeHostListener : Host-side event callbacks
- addGuestListener/removeGuestListener : Guest-side event callbacks
Guest Operations
- applyForSeat : Guest applies for co-guest
- cancelApplication : Guest cancels application
- acceptApplication : Host accepts application
- rejectApplication : Host rejects application
Host Operations
- inviteToSeat : Host invites guest to co-guest
- cancelInvitation : Host cancels invitation
- acceptInvitation : Guest accepts invitation
- rejectInvitation : Guest rejects invitation
Connection Control
- disconnect : End co-guest session
See Also
Constructors
Properties
- coGuestState → CoGuestState
-
Co-guest related state data provided externally by CoGuestStore
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
-
acceptApplication(
String userID) → Future< CompletionHandler> - Accept seat application
-
acceptInvitation(
String inviterID) → Future< CompletionHandler> - Accept seat invitation
-
addGuestListener(
GuestListener listener) → void - Add guest-side event callback listener
-
addHostListener(
HostListener listener) → void - Add host-side event callback listener
-
applyForSeat(
{required int seatIndex, required int timeout, String? extraInfo}) → Future< CompletionHandler> - Apply to go on seat
-
cancelApplication(
) → Future< CompletionHandler> - Cancel seat application
-
cancelInvitation(
String inviteeID) → Future< CompletionHandler> - Cancel seat invitation
-
disconnect(
) → Future< CompletionHandler> - Disconnect co-guest
-
inviteToSeat(
{required String inviteeID, required int seatIndex, required int timeout, String? extraInfo}) → Future< CompletionHandler> - Invite audience to seat
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rejectApplication(
String userID) → Future< CompletionHandler> - Reject seat application
-
rejectInvitation(
String inviterID) → Future< CompletionHandler> - Reject seat invitation
-
removeGuestListener(
GuestListener listener) → void - Remove guest-side event callback listener
-
removeHostListener(
HostListener listener) → void - Remove host-side event callback listener
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create(
String liveID) → CoGuestStore - Create CoGuestStore instance