panelistFocusChanged function

Future<void> panelistFocusChanged(
  1. PanelistFocusChangedOptions options
)

Handles the panelistFocusChanged socket event. Called when the host toggles focus mode on/off.

Example:

socket.on("panelistFocusChanged", (data) async {
  await panelistFocusChanged(PanelistFocusChangedOptions(
    data: PanelistFocusChangedData.fromMap(data),
    updatePanelistsFocused: (focused) => setState(() => panelistsFocused = focused),
    updateMuteOthersMic: (mute) => setState(() => muteOthersMic = mute),
    updateMuteOthersCamera: (mute) => setState(() => muteOthersCamera = mute),
    updatePanelists: (panelists) => setState(() => this.panelists = panelists),
    currentPanelistsFocused: panelistsFocused,
    currentPanelists: panelists,
    onScreenChanges: () async { ... },
  ));
});

Implementation

Future<void> panelistFocusChanged(PanelistFocusChangedOptions options) async {
  try {
    final data = options.data;

    // Check if focus state or panelists changed (for triggering rerender)
    final focusChanged = options.currentPanelistsFocused != null &&
        options.currentPanelistsFocused != data.focusEnabled;

    // Compare panelist lists by their IDs
    final currentPanelistIds =
        (options.currentPanelists ?? []).map((p) => p.id).toList()..sort();
    final newPanelistIds = data.panelists.map((p) => p.id).toList()..sort();
    final panelistsChanged =
        currentPanelistIds.join(',') != newPanelistIds.join(',');

    options.updatePanelistsFocused?.call(data.focusEnabled);
    options.updateMuteOthersMic?.call(data.muteOthersMic);
    options.updateMuteOthersCamera?.call(data.muteOthersCamera);

    if (options.updatePanelists != null) {
      final participantPanelists =
          data.panelists.map((p) => p.toParticipant()).toList();
      options.updatePanelists!(participantPanelists);
    }

    // Trigger screen rerender if focus or panelists changed
    if ((focusChanged || panelistsChanged) && options.onScreenChanges != null) {
      await options.onScreenChanges!();
    }
  } catch (e) {
    debugPrint('Error handling panelistFocusChanged: $e');
  }
}