Skip to main content
Version: 5.x.x

Join Room - Flutter

Overview​

Before joining the room, it has to be initialized. If you have not initialized a room yet, you can follow the guide here.

join()​

  • To join the room you can call the join() on the created Room object.
  • join() returns a Future that completes once the room is joined. If the room cannot be joined, it throws a VideoSDKError, for example 4002 for an invalid token or 3073 for an empty room id.
  • On Android, the SDK does not ask for camera or microphone permission. Call VideoSDK.requestPermissions() before you join, or the camera and microphone stay off.
  • A Room joins only once. After it leaves, or after join() fails, create a new Room to join again.
  • If the token has the ask_join permission, join() does not complete while you wait in the lobby. It completes once a participant with the allow_join permission lets you in. To learn more, see Waiting Lobby.
import 'dart:async' show unawaited;
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class RoomScreen extends StatefulWidget {
...
}

class _RoomScreenState extends State<RoomScreen> {
late Room _room;

@override
void initState() {
super.initState();
//Creating a new Room based on the passed roomId and token from the Joining Screen
// create room
_room = VideoSDK.createRoom(
roomId: widget.roomId,
token: widget.token,
participantName: "John Doe",
micEnabled: true,
camEnabled: true,
defaultCamera: FacingMode.FRONT, // Camera the webcam starts on
);

//Calling Join after the room object is created
unawaited(joinRoom());
}

Future<void> joinRoom() async {
// On Android, the SDK does not ask for camera or microphone permission.
await VideoSDK.requestPermissions();
try {
await _room.join();
} on VideoSDKError catch (error) {
// For example 4002 (invalid token) or 3073 (empty room id).
print("Join failed: ${error.code} ${error.name}");
}
}

@override
Widget build(BuildContext context) {
return YourRoomWidget();
}
}

Events associated with Join​

Following callbacks are received when a participant is successfully joined.

import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';

class RoomScreen extends StatefulWidget {
...
}

class _RoomScreenState extends State<RoomScreen> {
late Room _room;

@override
void initState() {
...

setupRoomEventListener();
}

@override
Widget build(BuildContext context) {
return YourRoomWidget();
}

void setupRoomEventListener() {
_room.on(Events.roomJoined, (){
// Room joined Successfully
Participant localParticipant = _room.localParticipant;
});
_room.on(Events.participantJoined, (Participant participant){
// New Participant joined the room
});
}
}

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