isSpeakerInMyBreakoutRoom function

bool isSpeakerInMyBreakoutRoom(
  1. String speakerName,
  2. TranslationConsumerSwitchParameters parameters
)

Check if a speaker is in the current user's breakout room (or main room). Returns true if the speaker's audio should be active (they are in our room).

This mirrors the logic in resumePauseAudioStreams.dart to ensure parity:

  • In webinars: host audio is always active for non-hosts
  • In conferences: host audio depends on hostNewRoom vs current user's room
  • Regular participants: must be in the same limitedBreakRoom

Implementation

bool isSpeakerInMyBreakoutRoom(
  String speakerName,
  TranslationConsumerSwitchParameters parameters,
) {
  final breakOutRoomStarted = parameters.breakOutRoomStarted;
  final breakOutRoomEnded = parameters.breakOutRoomEnded;
  final limitedBreakRoom = parameters.limitedBreakRoom ?? [];
  final participants = parameters.participants;
  final islevel = parameters.islevel;
  final eventType = parameters.eventType;
  final hostNewRoom = parameters.hostNewRoom ?? -1;
  final breakoutRooms = parameters.breakoutRooms ?? [];
  final member = parameters.member;

  // If breakout rooms are not active, everyone is in the same room
  if (!breakOutRoomStarted || breakOutRoomEnded) {
    return true;
  }

  // Check if the speaker is the host
  final host = participants.where((p) => p.islevel == '2').firstOrNull;
  final speakerIsHost = host?.name == speakerName;

  // If current user is NOT the host, apply host audio logic
  if (islevel != '2') {
    // For webinars, host audio is always included
    if (eventType == EventType.webinar && speakerIsHost) {
      return true;
    }

    // For conferences, check if host should be audible based on hostNewRoom
    if (eventType == EventType.conference && speakerIsHost) {
      // Find which breakout room the current user is in
      int memberBreakRoom = -1;
      for (int i = 0; i < breakoutRooms.length; i++) {
        if (breakoutRooms[i].any((p) => p.name == member)) {
          memberBreakRoom = i;
          break;
        }
      }
      final inBreakRoom = memberBreakRoom != -1;

      if (inBreakRoom) {
        // User is in a breakout room
        return memberBreakRoom == hostNewRoom;
      } else {
        // User is in main room
        if (hostNewRoom == -1) {
          return true; // Host is also in main room
        }
        return hostNewRoom == memberBreakRoom && memberBreakRoom != -1;
      }
    }
  }

  // For regular participants (non-host), check if they're in our limitedBreakRoom
  return limitedBreakRoom.any((p) => p.name == speakerName);
}