Participant Events - Flutter
VideoSDK provides various events that can be utilized to gather information about the participants in the room.
Here are the events specifically related to the participant:
Events.participantJoined
- This event is triggered when someone joins the room, returning the
Participantobject as parameter. - It can be subscribed to using the
Roomobject.
Events.participantLeft
- This event is triggered when someone leaves the room, along with the
Participantwho left and the reason. You can refer to the reason details here. - It can be subscribed to using the
Roomobject. - When
Events.participantLeftis triggered, aLeaveReasonis also provided. EachLeaveReasonhas acodeand amessage. - The table below outlines the possible reason codes and their descriptions:
| Reason | Code | Message |
|---|---|---|
LeaveReason.WEBSOCKET_DISCONNECTED | 1001 | Socket disconnected |
LeaveReason.REMOVE_PEER | 1002 | Participant was removed from the room |
LeaveReason.REMOVE_PEER_VIEWER_MODE_CHANGED | 1003 | Participant Removed because viewer mode was changed |
LeaveReason.REMOVE_PEER_MEDIA_RELAY_STOP | 1004 | Participant Removed because media relay was stopped |
LeaveReason.SWITCH_ROOM | 1005 | Participant switched to a different room |
LeaveReason.ROOM_CLOSE | 1006 | The room has been closed |
LeaveReason.UNKNOWN | 1007 | Participant disconnected due to an unknown reason |
LeaveReason.REMOVE_ALL | 1008 | Remove All from the room |
LeaveReason.MEETING_END_API | 1009 | Room Ended. |
LeaveReason.REMOVE_PEER_API | 1010 | Participant removed from the room |
LeaveReason.DUPLICATE_PARTICIPANT | 1011 | Leaving room, since this participantId joined from another device |
Events.cameraRequested
- This event is triggered for participant
B, when another participant,Arequests to enable their webcam. - Upon accepting the request, participant
B's webcam will be enabled. - It can be subscribed to using the
Roomobject. - The handler receives a
Map<String, dynamic>with anacceptand arejectfunction. Call one of them, once.
Events.micRequested
- This event is triggered for participant
B, when another participant,Arequests to enable their mic. - Upon accepting the request, participant
B's mic will be enabled. - It can be subscribed to using the
Roomobject. - The handler receives a
Map<String, dynamic>with anacceptand arejectfunction. Call one of them, once.
Example
Here is an example demonstrating the usage of all the events mentioned on this page.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';
class RoomScreen extends StatefulWidget {
//Existing configuration
}
class _RoomScreenState extends State<RoomScreen> {
late Room _room;
@override
void initState() {
super.initState();
//Existing configuration
setupRoomEventListener();
}
@override
Widget build(BuildContext context) {
return YourRoomWidget();
}
void setupRoomEventListener() {
_room.on(Events.participantJoined, (Participant participant) {
// New Participant joined the room
});
_room.on(Events.participantLeft, (Participant participant, LeaveReason reason) {
// Participant left the room.
});
_room.on(Events.cameraRequested, (Map<String, dynamic> data) async {
Function accept = data["accept"];
Function reject = data["reject"];
try {
// if the request is accepted
await accept();
// or, if the request is rejected
// await reject();
} on VideoSDKError catch (error) {
print("Could not answer the camera request: ${error.message}");
}
});
_room.on(Events.micRequested, (Map<String, dynamic> data) async {
Function accept = data["accept"];
Function reject = data["reject"];
try {
// if the request is accepted
await accept();
// or, if the request is rejected
// await reject();
} on VideoSDKError catch (error) {
print("Could not answer the mic request: ${error.message}");
}
});
}
}
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

