Skip to main content
Version: 4.x.x

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 of Room class.
  • This method can be called after the room is created using VideoSDK.createRoom().
  • join() is async throws, so call it with try await inside a Task.
  • To choose the camera the video opens on, pass defaultCamera (.front or .back) to createRoom().
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() throws ERROR_OPERATION_IN_PROGRESS while a join is running, and ERROR_ALREADY_IN_REQUESTED_STATE once you are in the room.
  • If the join fails, the room state changes to FAILED (you receive onRoomStateChanged) and join() throws the error. The failure is usually also sent to onError, so handle it in one place.
  • If you call leave() while the join is still running, the join is cancelled and join() returns without throwing. Treat onRoomJoined as the sign that you are in the room.
  • join() returns before the mic and camera from micEnabled and camEnabled start. Wait for onStreamEnabled before you treat local media as on.

Events associated with Join​

The following callbacks are received when a participant successfully joins.

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