Skip to main content

Co-Host Management

Room posts support co-hosting, allowing multiple broadcasters to stream together. This guide covers the complete co-host invitation system, from sending invitations to managing co-host participation during broadcasts.

Overview

Co-hosts are invited broadcasters who can stream together with the room host. They appear with a special badge in the chat and have broadcasting capabilities within the room.

Invite Co-Hosts

Send invitations to users to join as broadcasters

Accept/Decline

Invited users can accept or decline invitations

Track Status

Monitor invitation status in real-time

Co-Stream

Multiple hosts broadcast together simultaneously

For Hosts

Send Co-Host Invitation

Hosts can invite users to join as co-hosts during a live session. Co-host invitations are sent one user at a time.
Co-host invitations are sent one user at a time. To invite multiple co-hosts, call the invitation function for each user.
Parameters
ParameterTypeRequiredDescription
userIdstringYesUser ID to invite as co-host
roomIdstringYesID of the room
do {
    try await room.createInvitation("<user_id>")
    print("Co-host invitation sent successfully.")
} catch {
    print("Failed to send co-host invitation: \(error.localizedDescription)")
}

Get Sent Co-Host Invitations

Hosts can view all co-host invitations they’ve sent to track invitation status.
var token: AmityNotificationToken?
let repository = AmityInvitationRepository(client: client)
token = repository.getInvitations(
    targetId: room.roomId,
    targetType: .room
).observe({ collection, change, error in
    // Observe changes in the invitation collection
})

Cancel Co-Host Invitation

Hosts can cancel pending invitations before they are accepted.
do {
    try await invitation.cancel()
    print("Invitation cancelled successfully")
} catch {
    print("Failed to cancel invitation: \(error.localizedDescription)")
}

For Invited Users

Get My Room Invitations

Users can retrieve all their pending room co-host invitations.
var token: AmityNotificationToken?
let repository = AmityInvitationRepository(client: client)
token = repository.getMyRoomInvitations().observe({ collection, change, error in
    // Observe changes in the collection
})

Check Co-Host Invitation Status

Check the status of a room co-host invitation. Status Values
StatusDescriptionUser Action
pendingInvitation awaiting responseCan accept or decline
acceptedUser has acceptedCo-host in room
rejectedUser has declinedNo further action
cancelledHost cancelled invitationNo longer valid
if let invitation = await room.getInvitation() {
    switch invitation.status {
    case .pending:
        print("Co-host invitation is pending.")
    case .approved:
        print("Co-host invitation is approved.")
    case .rejected:
        print("Co-host invitation is rejected.")
    case .canceled:
        print("Co-host invitation is canceled.")
    @unknown default:
        print("Unknown invitation status.")
    }
}

Accept Co-Host Invitation

Accept a pending co-host invitation to join the broadcast.
if let invitation = await room.getInvitation() {
    do {
        try await invitation.accept()
        print("Co-host invitation accepted successfully.")
    } catch {
        print("Failed to accept invitation: \(error.localizedDescription)")
    }
}

Decline Co-Host Invitation

Decline a co-host invitation if unable to join the broadcast.
if let invitation = await room.getInvitation() {
    do {
        try await invitation.reject()
        print("Co-host invitation declined successfully.")
    } catch {
        print("Failed to decline invitation: \(error.localizedDescription)")
    }
}

Co-Host Joining the Broadcast

After accepting an invitation, co-hosts need to get their broadcast data and connect to LiveKit:
import LiveKit

func joinAsBroadcaster(roomId: String) async {
    do {
        // 1. Get broadcaster credentials
        let broadcastData = try await roomRepository.getBroadcastData(roomId: roomId)
        
        guard case .coHosts(let data) = broadcastData else {
            print("Invalid broadcast data")
            return
        }
        
        // 2. Connect to LiveKit
        let liveKitRoom = Room()
        try await liveKitRoom.connect(url: data.coHostUrl, token: data.coHostToken)
        
        // 3. Start publishing tracks
        try await liveKitRoom.localParticipant.setCamera(enabled: true)
        try await liveKitRoom.localParticipant.setMicrophone(enabled: true)
        
        print("Joined broadcast as co-host!")
    } catch {
        print("Failed to join: \(error)")
    }
}

Best Practices

  • Coordinate with co-hosts before going live
  • Establish clear roles and speaking order
  • Test audio and video connections with all hosts
  • Have a backup plan if a co-host disconnects
  • Send invitations early to give users time to prepare
  • Handle expired or cancelled invitations gracefully
  • Provide clear UI feedback for invitation status
  • Allow hosts to re-invite users who declined
  • Monitor co-host connection status
  • Handle co-host disconnection gracefully
  • Use host and co-host badges for clear identification
  • Coordinate mute/unmute to avoid audio issues

Troubleshooting

Problem: User doesn’t see the co-host invitationSolutions:
  • Verify the user ID is correct
  • Check that the room is in a valid state
  • Ensure the user has permissions to receive invitations
  • Try re-sending the invitation
Problem: Co-host accepted but can’t join broadcastSolutions:
  • Verify the room is still live
  • Check that broadcast data is retrieved correctly
  • Ensure network connectivity is stable
  • Validate LiveKit connection credentials
Problem: Co-hosts frequently disconnectingSolutions:
  • Check network stability for all participants
  • Monitor bandwidth requirements
  • Consider reducing video quality
  • Implement reconnection logic

Next Steps

Start Broadcasting

Get broadcaster data and connect to LiveKit

Recorded Playback

Handle recorded room playback after broadcast ends

Live Viewing

How viewers watch your live broadcast

Manage Rooms

Query, update, and control room lifecycle