Waiting Lobby - iOS
Overview
With our iOS SDK, you can implement a waiting lobby feature, which allows the host to control which participants can join the room by allowing or denying access. Here are the steps for implementing the waiting lobby.
Generating Tokens in Your Backend
Your server should generate access tokens using your API key and secret. Two different tokens need to be generated with different permissions:
HOST Token Payload
{
// ...
apikey: API_KEY, // Your API key
permissions: ['allow_join'], // Permission to directly join the room
// ...
}
GUEST Token Payload
{
// ...
apikey: API_KEY, // Your API key
permissions: ['ask_join'], // Permission to ask the host for permission to join the room
// ...
}
Explanation of parameters:
-
apikey(Mandatory): Your API key generated from the VideoSDK Dashboard, which can be obtained here. -
permissions(Mandatory): Permissions that control participant activity. Available permissions include:allow_join: Participants are allowed to join the room directly.ask_join: Participants need to ask for permission to join the room. Participants with theallow_joinpermission can accept or reject others' join requests.allow_mod: Participants are allowed to toggle camera and mic of other participants.
Then, sign this payload with your SECRET KEY and use the HS256 algorithm. For more details on authentication and tokens, refer to Authentication and Tokens.
Generating Room ID
With the tokens ready, you can now obtain the roomId from the VideoSDK's rooms API, which can be found in Create a Room.
Refer to Generating Room ID for generating the roomId.
Initialization of Room
Create the room with VideoSDK.createRoom(roomId:token:...), which takes the token as a parameter. It throws, so call it with try. The token you pass here decides whether the participant joins the room directly or waits in the lobby, so provide the allow_join token to a host and the ask_join token to a guest.
For detailed configuration options, check Initialization of Room.
- Swift
// If a participant joins as a host, provide them with the "allow_join" permission token.
// Otherwise, provide the "ask_join" permission token.
let token = isHost ? "allow_join token will be here" : "ask_join token will be here"
do {
room = try VideoSDK.createRoom(
roomId: "abcd-efgh-hijk",
token: token,
participantName: "John Doe",
micEnabled: true,
camEnabled: true
)
} catch {
print("Failed to create the room: \(error)")
return
}
room?.addEventListener(self)
Task {
do {
try await room?.join()
} catch {
print("Failed to join the room: \(error)")
}
}
A participant joining with the ask_join token does not enter the room when join() is called. The onRoomJoined event is emitted only after the host allows the request. While the guest waits, onRoomStateChanged can already report CONNECTED, so treat onRoomJoined, not the room state or the return of join(), as the sign that the guest is in the room.
Events associated with Waiting Lobby
The following events are received when a participant tries to join the room.
-
When a participant joins as a host, they will receive an
onEntryRequestedevent whenever a guest participant tries to join the room. The event provides theparticipantIdandnameof the guest, along with theallowanddenyclosures the host calls to respond to the request. -
When the host responds to a request, both the host and the guest will receive an
onEntryRespondedevent with theparticipantIdof the guest and adecisionof either.ALLOWEDor.DENIED.
- Swift
extension RoomViewController: RoomEventListener {
func onEntryRequested(
participantId: String,
name: String,
allow: @escaping () -> Void,
deny: @escaping () -> Void
) {
// The host receives this event when a guest requests to join the room
// If you want to allow the entry request
allow()
// If you want to deny the entry request
deny()
}
func onEntryResponded(participantId: String, decision: EntryDecision?) {
// participantId will be the ID of the participant who requested to join the room
if participantId == room?.localParticipant.id {
// This is the response to your own request to join
if decision == .DENIED {
// Leave the room and navigate away from the room screen
Task {
do {
try await room?.leave()
} catch {
// The join has already ended
print("Failed to leave the room: \(error)")
}
}
}
return
}
// The response is for a guest's request
if decision == .ALLOWED {
// Entry allowed
} else {
// Entry denied
}
}
}
onEntryResponded is emitted to every participant whose token includes the allow_join permission and to the participant who requested to join, including a participant receiving their own participantId with a decision of .ALLOWED. Check the participantId and the decision before treating this event as a response to a guest's request.
A guest whose request is denied is not disconnected from the room automatically. Call leave() on the guest and navigate away from the room screen when the decision is .DENIED. If the guest's join() is still running, leave() cancels it.
API Reference
The API references for all the methods and events utilized in this guide are provided below.
Got a Question? Ask us on discord

