// Metro module 15910 (f15911). import _slicedToArray from "../../../../_bundle/_slicedToArray"; import { useRef, useState, useInsertionEffect, useLayoutEffect, useEffect } from "react"; import EmbeddedActivitiesStore from "../../../activities/EmbeddedActivitiesStore"; import ChannelRTCStore from "../../../calls/ChannelRTCStore"; import FramesStore from "../../../frames/FramesStore"; import ChannelStore from "../../../../stores/ChannelStore"; import SpeakingStore from "../../../../stores/SpeakingStore"; import { VoicePanelModes } from "../../VoicePanelConstants"; import { ActivityPanelModes } from "../../../activities/panel/ActivityPanelConstants"; import useIsConnectedToVoiceChannel from "../hooks/useIsConnectedToVoiceChannel"; import { useStateFromStores, BatchedStoreListener } from "../../../../_bundle/Module589"; import { getEmbeddedActivityLocationChannelId } from "../../../activities/utils/embeddedActivityLocationUtils"; import { isActivityInTextSupportedForChannel } from "../../../activities/ActivitiesInTextUtils"; import { cheapWorkletShallowEqual } from "../../../reanimated/native/cheapWorkletShallowEqual"; import useSelfHasVideo from "../utils/useSelfHasVideo"; import throttle from "../../../../_bundle/throttle"; import calculatePIPState from "../utils/calculatePIPState"; import { getPIPMode } from "./VoicePanelPIPUtils"; import useExternalPipAspectRatioUpdater_native from "../../../external_pip/useExternalPipAspectRatioUpdater.native"; function $mk117092($env) { return (a0) => { const r1 = $env; let r6 = r1[2].getTargetDimensions(r1[1]); if (cheapWorkletShallowEqual(a0, r6)) { r6 = a0; } return r6; }; } let env11394 = {}; export function useControllerPIPState(a0) { let channelId, mode, c22597_2; let env22596 = { $parent: env11394 }; const channelId2 = a0.channelId; env22596[0] = channelId2; const { connected, focusedId } = a0; env22596[1] = focusedId; const layoutManager = a0.layoutManager; env22596[2] = layoutManager; const mode2 = a0.mode; env22596[3] = void 0; env22596[4] = void 0; env22596[5] = void 0; env22596[6] = void 0; env22596[7] = void 0; const ref2 = useRef({ id: void 0, mode: void 0, width: 0, height: 0, containerHeight: 0, showSecondaryPIP: false }); const r33 = _slicedToArray(useState(void 0), 2); const r18 = r33[0]; env22596[3] = r18; env22596[4] = r33[1]; env22596[5] = useRef(r18); useInsertionEffect(() => { env22596[5].current = env22596[3]; }); channelId = channelId2; mode = mode2; c22597_2 = void 0; const isConnectedToVoiceChannel = useIsConnectedToVoiceChannel(channelId); c22597_2 = isConnectedToVoiceChannel; const stateFromStores = useStateFromStores([EmbeddedActivitiesStore, FramesStore, ChannelStore], () => { const channel = ChannelStore.getChannel(channelId); if ((channel == null ? void 0 : channel.isVocal()) && !c22597_2) { return false; } L9: { const connectedFrame = FramesStore.getConnectedFrame(); const activityPanelMode = FramesStore.getActivityPanelMode(); if (connectedFrame != null && activityPanelMode === ActivityPanelModes.PIP) { if (mode !== VoicePanelModes.PIP && mode !== VoicePanelModes.PANEL) { break L9; } return true; } } const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation(); if (connectedActivityLocation == null) { return false; } const embeddedActivityLocationChannelId = getEmbeddedActivityLocationChannelId(connectedActivityLocation); const channel2 = ChannelStore.getChannel(embeddedActivityLocationChannelId); const activityPanelMode2 = EmbeddedActivitiesStore.getActivityPanelMode(); let r37 = channel2 != null && isActivityInTextSupportedForChannel(channel2) && embeddedActivityLocationChannelId !== channelId; const r43 = activityPanelMode2 === ActivityPanelModes.PIP && (mode === VoicePanelModes.PIP || embeddedActivityLocationChannelId !== channelId); if (r37) { r37 = r43; } return r37; }, [channelId, isConnectedToVoiceChannel, mode]); const selfHasVideo = useSelfHasVideo(channelId); const [r57] = useState(() => throttle((a0) => a0(), 1000, { leading: true })); env22596[6] = r57; useLayoutEffect(() => () => env22596[6].cancel(), [r57]); const r65 = _slicedToArray(useState(() => env22596[2].getTargetDimensions(env22596[1])), 2); const participantTargetDimensions = r65[0]; env22596[7] = r65[1]; const r71 = calculatePIPState(channelId, layoutManager, focusedId, r18, { connected, mode, focusedId, participantTargetDimensions, selfHasVideo, showSecondaryPIP: stateFromStores }); const { participant, dimensions } = r71; const id = participant?.id; let r74 = { ...ref2.current, ...dimensions, id, showSecondaryPIP: stateFromStores, mode: getPIPMode({ channelId, connected, manuallyFocusedId: focusedId, mode, selfHasVideo }) }; const current = r74; const ref = ref2; const r93 = cheapWorkletShallowEqual(current, ref.current); let c22598_2 = !r93; useEffect(() => { if (c22598_2) { ref.current = current; } }); if (r93) { r74 = ref.current; } useEffect(() => { let c28179_0; const batchedStoreListener = new BatchedStoreListener([SpeakingStore, ChannelRTCStore], () => { let c30933_0; const r8 = (() => { for (const item of SpeakingStore.getSpeakers()) { if (ChannelRTCStore.getParticipant(env22596[0], item) == null) { continue; } return item; } })(); c30933_0 = r8; const r6 = env22596[5]; if (r8 !== r6.current && r8 != null) { if (r6.current == null) { (0, env22596[4])(r8); } else { (0, env22596[6])(() => (0, env22596[4])(c30933_0)); } } }); c28179_0 = batchedStoreListener; batchedStoreListener.attach(`pipstate-change-listeners-${env22596[0]}`); return () => c28179_0.detach(); }, [channelId, r57]); useEffect(() => { (0, env22596[7])($mk117092(env22596)); return env22596[2].subscribeFromItem(function updateParticipantDimensions() { (0, env22596[7])($mk117092(env22596)); }); }, [focusedId, layoutManager, participantTargetDimensions]); useExternalPipAspectRatioUpdater_native(channelId, layoutManager, focusedId); return r74; }