Join Room - iOS
Overview
createRoom() returns a new instance of Room. If you have not initialized a room yet, you can follow the guide here. The room does not join automatically, so to join it you have to call join().
join()
- To join the room you can call the
join()method ofRoomclass. - This method can be called after the room is created using
VideoSDK.createRoom(). join()isasync throws, so call it withtry awaitinside aTask.- To choose the camera the video opens on, pass
defaultCamera(.frontor.back) tocreateRoom().
- Swift
private func initializeRoom() {
do {
// create the room
room = try VideoSDK.createRoom(
roomId: "abcd-wxyz-efgh",
token: "<your token>",
participantName: "John Doe",
micEnabled: true,
camEnabled: true,
participantId: "JD",
defaultCamera: .front // .front, .back
)
} catch {
print("Failed to create the room: \(error)")
return
}
// Add event listener for listening upcoming events of room
room?.addEventListener(self)
// join
Task {
do {
try await room?.join()
} catch {
print("Failed to join the room: \(error)")
}
}
}
Keep these in mind when you call join():
- A second
join()throwsERROR_OPERATION_IN_PROGRESSwhile a join is running, andERROR_ALREADY_IN_REQUESTED_STATEonce you are in the room. - If the join fails, the room state changes to
FAILED(you receiveonRoomStateChanged) andjoin()throws the error. The failure is usually also sent toonError, so handle it in one place. - If you call
leave()while the join is still running, the join is cancelled andjoin()returns without throwing. TreatonRoomJoinedas the sign that you are in the room. join()returns before the mic and camera frommicEnabledandcamEnabledstart. Wait foronStreamEnabledbefore you treat local media as on.
Events associated with Join
The following callbacks are received when a participant successfully joins.
- Local Participant will receive an
onRoomJoinedevent, when successfully joined. - Remote Participant will receive an
onParticipantJoinedevent with the newly joinedParticipantobject from the event callback.
- Swift
extension RoomViewController: RoomEventListener {
// Event to know room is joined
func onRoomJoined() {
print("You just joined the room")
}
// Event to know some other participant joined
func onParticipantJoined(_ participant: Participant) {
print("A new remote participant \(participant.displayName) just joined the room")
}
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord

