banParticipant function

Future<void> banParticipant(
  1. BanParticipantOptions options
)

Bans a participant by removing them from the active and display names lists, updating the participants list, and reordering the streams if necessary.

This function checks if the participant, identified by name in options, is present in either activeNames or dispActiveNames within the parameters. If found, the participant is removed from participants, the updated list is saved via updateParticipants, and the streams are reordered.

Example Usage:

final options = BanParticipantOptions(
  name: 'JohnDoe',
  parameters: BanParticipantParameters(
    activeNames: ['JohnDoe', 'JaneDoe'],
    dispActiveNames: ['JohnDoe'],
    participants: [Participant(name: 'JohnDoe'), Participant(name: 'JaneDoe')],
    updateParticipants: (updatedList) {
      print('Participants updated: $updatedList');
    },
    reorderStreams: (options) async {
      print('Streams reordered with options: $options');
    },
  ),
);

await banParticipant(options);

In this example:

  • The function removes JohnDoe from activeNames, dispActiveNames, and participants.
  • It updates the participants list and reorders streams to reflect the change.

Implementation

Future<void> banParticipant(BanParticipantOptions options) async {
  final params = options.parameters;

  // Check if the participant is in the active or display names list
  if (params.activeNames.contains(options.name) ||
      params.dispActiveNames.contains(options.name)) {
    // Filter out the banned participant from the participants list
    params.participants
        .removeWhere((participant) => participant.name == options.name);

    // Update the participants list
    params.updateParticipants(params.participants);

    // Reorder streams after participant removal
    final optionsReorder = ReorderStreamsOptions(
      screenChanged: true,
      parameters: params,
    );
    await params.reorderStreams(optionsReorder);
  }
}