Skip to main content
Version: 5.x.x

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 Participant object as parameter.
  • It can be subscribed to using the Room object.

Events.participantLeft​

  • This event is triggered when someone leaves the room, along with the Participant who left and the reason. You can refer to the reason details here.
  • It can be subscribed to using the Room object.
  • When Events.participantLeft is triggered, a LeaveReason is also provided. Each LeaveReason has a code and a message.
  • The table below outlines the possible reason codes and their descriptions:
ReasonCodeMessage
LeaveReason.WEBSOCKET_DISCONNECTED1001Socket disconnected
LeaveReason.REMOVE_PEER1002Participant was removed from the room
LeaveReason.REMOVE_PEER_VIEWER_MODE_CHANGED1003Participant Removed because viewer mode was changed
LeaveReason.REMOVE_PEER_MEDIA_RELAY_STOP1004Participant Removed because media relay was stopped
LeaveReason.SWITCH_ROOM1005Participant switched to a different room
LeaveReason.ROOM_CLOSE1006The room has been closed
LeaveReason.UNKNOWN1007Participant disconnected due to an unknown reason
LeaveReason.REMOVE_ALL1008Remove All from the room
LeaveReason.MEETING_END_API1009Room Ended.
LeaveReason.REMOVE_PEER_API1010Participant removed from the room
LeaveReason.DUPLICATE_PARTICIPANT1011Leaving room, since this participantId joined from another device

Events.cameraRequested​

  • This event is triggered for participant B, when another participant, A requests to enable their webcam.
  • Upon accepting the request, participant B's webcam will be enabled.
  • It can be subscribed to using the Room object.
  • The handler receives a Map<String, dynamic> with an accept and a reject function. Call one of them, once.

Events.micRequested​

  • This event is triggered for participant B, when another participant, A requests to enable their mic.
  • Upon accepting the request, participant B's mic will be enabled.
  • It can be subscribed to using the Room object.
  • The handler receives a Map<String, dynamic> with an accept and a reject function. 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