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 createdRoomobject. join()returns aFuturethat completes once the room is joined. If the room cannot be joined, it throws aVideoSDKError, for example4002for an invalid token or3073for 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
Roomjoins only once. After it leaves, or afterjoin()fails, create a newRoomto join again. - If the token has the
ask_joinpermission,join()does not complete while you wait in the lobby. It completes once a participant with theallow_joinpermission 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.
- Local Participant will receive a
Events.roomJoinedevent, when successfully joined. This event can arrive afterjoin()completes.room.localParticipantis set when it fires, so read it in this event's handler. - Remote Participant will receive a
Events.participantJoinedevent with the newly joinedParticipantobject from the event callback.
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

