Files
discord-decomp/modules/video_calls/native/ChannelCallStore.tsx
T
2026-11-01 12:12:55 +02:00

180 lines
6.1 KiB
TypeScript

// Metro module 10235 (f10236).
import { useEffect } from "react";
import EmbeddedActivitiesStore from "../../activities/EmbeddedActivitiesStore";
import { VoiceChatDrawerState, VoiceCallOverlayType } from "./ChannelCallConstants";
import { OrientationLockState } from "../../activities/Constants";
import { ParticipantTypes } from "../../calls/CallConstants";
import { Timeout } from "../../../_bundle/Timeout";
import { OrientationType, restoreDefaultOrientation, unlockOrientation, lockOrientation, lockOrientationForiOS } from "../../device/native/DeviceOrientation";
import { create } from "../../../_bundle/Module644";
import { batchUpdates } from "../../../_bundle/Module705";
import Dispatcher from "../../../Dispatcher";
import ChannelRTCActionCreators from "../../../actions/ChannelRTCActionCreators";
import Module12 from "../../../_bundle/Module12";
import useIsPrivateAudioOnlyCall from "./useIsPrivateAudioOnlyCall";
import useSelectedParticipant from "../useSelectedParticipant";
import { useIsConnectedToVoiceChannel } from "../../voice_chat/VoiceChatHooks";
import { useStateFromStores } from "../../../_bundle/Module589";
import { isIpadOS } from "../../../utils/native/DeviceUtils";
let $mk84213 = function() {
return () => {
batchUpdates(() => c6825_10.setState({
focus: false
}));
};
};
let c6825_8 = new Timeout();
const r41 = Object;
const voiceCallOverlayLayoutStates = {};
voiceCallOverlayLayoutStates[VoiceCallOverlayType.VOICE_CONTROLS_TOGGLE_BUTTON] = {
x: void 0,
y: void 0,
width: void 0,
height: void 0,
screenOrientation: OrientationType.PORTRAIT,
hasUserInteractedSinceOrientationChange: false,
isInitialized: false,
isVisible: false
};
voiceCallOverlayLayoutStates[VoiceCallOverlayType.CAMERA_PREVIEW_PICTURE_IN_PICTURE] = {
x: void 0,
y: void 0,
width: void 0,
height: void 0,
screenOrientation: OrientationType.PORTRAIT,
hasUserInteractedSinceOrientationChange: false,
isInitialized: false,
isVisible: false
};
let c6825_9 = r41.freeze({
focus: true,
pipFocus: false,
isGestureEnabled: true,
voiceChatDrawerState: VoiceChatDrawerState.CLOSED,
voiceCallOverlayLayoutStates
});
let c6825_10 = create(() => c6825_9);
const r65 = Module12.throttle(() => {
const pipFocus = c6825_10.getState().pipFocus;
batchUpdates(() => c6825_10.setState({
pipFocus: !pipFocus
}));
}, 300);
export { c6825_8 as focusTimeout };
export function setFocus(focus) {
batchUpdates(() => c6825_10.setState({
focus
}));
}
export function toggleFocus() {
const focus2 = c6825_10.getState().focus;
batchUpdates(() => c6825_10.setState({
focus: !focus2,
pipFocus: false
}));
}
export function resetFocusTimer() {
c6825_8.stop();
c6825_8.start(5000, $mk84213());
}
export function resetFocus() {
if (c6825_10.getState().focus) {
c6825_8.stop();
c6825_8.start(5000, $mk84213());
} else {
batchUpdates(() => c6825_10.setState({
focus: true
}));
}
}
export function clearFocusTimer() {
c6825_8.stop();
}
export function setVoiceChatDrawerState(c17788_0, a1) {
const voiceChatDrawerState = a1;
if (!(a1 !== VoiceChatDrawerState.OPEN && a1 !== VoiceChatDrawerState.CLOSED)) {
Dispatcher.wait(() => ChannelRTCActionCreators.updateChatOpen(c17788_0, voiceChatDrawerState === VoiceChatDrawerState.OPEN));
}
batchUpdates(() => c6825_10.setState({
voiceChatDrawerState
}));
}
export { r65 as togglePipFocus };
export function useIsVoiceChatFocused() {
const voiceChatDrawerState2 = c6825_10().voiceChatDrawerState;
return voiceChatDrawerState2 === VoiceChatDrawerState.OPEN || voiceChatDrawerState2 === VoiceChatDrawerState.CLOSING;
}
export function useChannelCallOrientationHandlers(a0) {
const isPrivateAudioOnlyCall = useIsPrivateAudioOnlyCall(a0);
let c17789_0 = isPrivateAudioOnlyCall;
const selectedParticipant = useSelectedParticipant(a0);
let c17789_1 = selectedParticipant;
const r18 = a0.isGuildStageVoice() && selectedParticipant == null;
let c17789_2 = r18;
const voiceChatDrawerState2 = c6825_10().voiceChatDrawerState;
let r22 = voiceChatDrawerState2 === VoiceChatDrawerState.OPEN || voiceChatDrawerState2 === VoiceChatDrawerState.CLOSING;
const r2 = !useIsConnectedToVoiceChannel(a0);
if (!r22) {
r22 = r2;
}
let c17789_3 = r22;
const applicationId = EmbeddedActivitiesStore.getCurrentEmbeddedActivity()?.applicationId;
const stateFromStores = useStateFromStores([EmbeddedActivitiesStore], () => {
let r8;
if (applicationId != null) {
let r9 = EmbeddedActivitiesStore.getOrientationLockStateForApp(applicationId);
if (r9 == null) {
r9 = OrientationLockState.UNLOCKED;
}
r8 = r9;
} else {
r8 = OrientationLockState.UNLOCKED;
}
return r8;
}, [applicationId]);
useEffect(() => restoreDefaultOrientation, []);
useEffect(() => {
L16: {
if (!c17789_2 && !c17789_3) {
if (c17789_1 != null && c17789_1.type === ParticipantTypes.ACTIVITY && c17789_1.applicationId === applicationId) {
if (isIpadOS()) {
break L16;
}
if (OrientationLockState.UNLOCKED === stateFromStores) {
unlockOrientation({
unlockAfterRotatingToPreviousLock: true
});
break L16;
}
if (OrientationLockState.PORTRAIT === stateFromStores) {
lockOrientation("PORTRAIT", true);
break L16;
}
if (OrientationLockState.LANDSCAPE !== stateFromStores) {
break L16;
}
lockOrientation("LANDSCAPE", true);
break L16;
}
if (c17789_0) {
lockOrientationForiOS("PORTRAIT");
break L16;
}
unlockOrientation({
unlockAfterRotatingToPreviousLock: false
});
} else {
unlockOrientation({
unlockAfterRotatingToPreviousLock: false
});
lockOrientationForiOS("PORTRAIT");
}
}
}, [stateFromStores, selectedParticipant, applicationId, isPrivateAudioOnlyCall, r18, r22]);
}
export function resetChannelCallStore() {
c6825_8.stop();
batchUpdates(() => c6825_10.setState(c6825_9));
}
export { c6825_10 as useChannelCallStore };