CoGuestStore
Introduction
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.
Important:
Always use the factory method create(liveID:) with a valid live room ID to create a CoGuestStore instance. Do not attempt to initialize directly.
Note:
Co-guest state updates are delivered through the state publisher. Subscribe to it to receive real-time updates about connected users, invitations and applications.
Warning:
If a co-guest request does not receive a response within the specified timeout, an event with NoResponseReason.timeout will be triggered. Always handle timeout scenarios in your UI.
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
Subscribable Data
CoGuestState fields are described below:
Property | Type | Description |
connected | List of users already on seats. | |
invitees | List of users invited by host. | |
applicants | List of users who applied for co-guest received by host. | |
candidates | List of candidate users for co-guest. |
API List
Function | Description |
Create object instance. | |
Host-side event publisher. | |
Guest-side event publisher. | |
Guest applies for co-guest. | |
Guest cancels application. | |
Host accepts application. | |
Host rejects application. | |
Host invites guest to co-guest. | |
Host cancels invitation. | |
Guest accepts invitation. | |
Guest rejects invitation. | |
End co-guest session. |
Creating Instance
create
Create CoGuestStore instance
public static func create(liveID: String) -> CoGuestStore {let store: CoGuestStoreImpl = StoreFactory.shared.getStore(liveId: liveID)return store}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
liveID | String | Required | Live room ID. |
Observing State and Events
hostEventPublisher
Host-side event publisher
guestEventPublisher
Guest-side event publisher
Guest Operations
applyForSeat
Apply to go on seat
public func applyForSeat(seatIndex: Int = -1, timeout: TimeInterval, extraInfo: String?, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Request to join co-guest session as an audience member.
After calling this method, a co-guest request is sent to all hosts in the live room. The request will remain active until:
• Host accepts via acceptApplication
• Host rejects via rejectApplication
• Timeout expires
• You cancel via cancelApplication
Version
Supported since version 3.5.
Notes
Note:
If no host responds within the timeout, {ref2} event with NoResponseReason/timeout will be triggered.
Parameters
Parameter | Type | Required | Description |
seatIndex | Int | Required | Seat index, -1 means auto-assign seat. |
timeout | TimeInterval | Required | Timeout (unit: seconds). |
extraInfo | String? | Required | Extra information. |
completion | Required | Completion callback. |
cancelApplication
Cancel seat application
public func cancelApplication(completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Cancel a previously sent co-guest application. After calling this method, all hosts will be notified of the application cancellation.
Version
Supported since version 3.5.
Notes
Note:
If the application has already been processed by a host, the cancellation may have no effect.
Parameters
Parameter | Type | Required | Description |
completion | Required | Completion callback. |
acceptApplication
Accept seat application
public func acceptApplication(userID: String, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
userID | String | Required | User ID. |
completion | Required | Completion callback. |
rejectApplication
Reject seat application
public func rejectApplication(userID: String, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
userID | String | Required | User ID. |
completion | Required | Completion callback. |
Host Operations
inviteToSeat
Invite audience to seat
public func inviteToSeat(userID: String, seatIndex: Int = -1, timeout: TimeInterval, extraInfo: String?, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
userID | String | Required | Invited user ID. |
seatIndex | Int | Required | Seat index, -1 means auto-assign seat. |
timeout | TimeInterval | Required | Timeout (unit: seconds). |
extraInfo | String? | Required | Extra information. |
completion | Required | Completion callback. |
cancelInvitation
Cancel seat invitation
public func cancelInvitation(inviteeID: String, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
inviteeID | String | Required | Invited user ID. |
completion | Required | Completion callback. |
acceptInvitation
Accept seat invitation
public func acceptInvitation(inviterID: String, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
inviterID | String | Required | Inviter user ID. |
completion | Required | Completion callback. |
rejectInvitation
Reject seat invitation
public func rejectInvitation(inviterID: String, completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
inviterID | String | Required | Inviter user ID. |
completion | Required | Completion callback. |
Connection Control
disConnect
Disconnect co-guest
public func disConnect(completion: CompletionClosure?) { fatalError("\(#function) must be overridden by subclass") }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
completion | Required | Completion callback. |
Data Structures
NoResponseReason
Reason for no response to co-guest invitation sent by host or co-guest request initiated by audience
Enum Value | Value | Description |
timeout | 0 | Request timeout. |
alreadySeated | 1 | User already on seat. |
HostEvent
Callback events received on host side
Enum Value | Description |
onGuestApplicationReceived | This callback is triggered when an audience applies for co-guest. |
onGuestApplicationCancelled | This callback is triggered when an audience cancels co-guest application. |
onGuestApplicationProcessedByOtherHost | This callback is triggered when an audience's co-guest application is processed by another host. |
onHostInvitationResponded | This callback is triggered when a co-guest invitation sent by host receives a response from audience. |
onHostInvitationNoResponse | This callback is triggered when a co-guest invitation sent by host receives no response. |
GuestEvent
Callback events received on guest side
Enum Value | Description |
onHostInvitationReceived | This callback is triggered when receiving a co-guest invitation from host. |
onHostInvitationCancelled | This callback is triggered when host cancels co-guest invitation. |
onGuestApplicationResponded | This callback is triggered when audience's co-guest application receives a response from host. |
onGuestApplicationNoResponse | This callback is triggered when audience's co-guest application receives no response. |
onKickedOffSeat | This callback is triggered when audience is kicked off seat by host. |
CoGuestState
Co-guest related state data provided externally by CoGuestStore
Property | Type | Description |
connected | List of users already on seats. | |
invitees | List of users invited by host. | |
applicants | List of users who applied for co-guest received by host. | |
candidates | List of candidate users for co-guest. |
Usage Example
// Create store instancelet store = CoGuestStore.create(liveID: "live_room_123")// Subscribe to state changesstore.state.subscribe { state inprint("Connected users: \(state.connected.count)")print("Pending applications: \(state.applicants.count)")}// Subscribe to host events (for hosts)store.hostEventPublisher.sink { event inswitch event {case .onGuestApplicationReceived(let guestUser):print("Received application from \(guestUser.userName)")// Show accept/reject UIcase .onHostInvitationResponded(let isAccept, let guestUser):print("Audience \(guestUser.userName) \(isAccept ? "accepted" : "rejected")")default:break}}// Host: Accept applicationstore.acceptApplication(userID: "user_456") { code, message inif code == 0 {print("Application accepted successfully")}}