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

295 lines
15 KiB
TypeScript

// Metro module 10740 (f10741).
import { useRef, useMemo, useCallback } from "react";
import { View } from "react-native";
import EmbeddedActivitiesStore from "../../../activities/EmbeddedActivitiesStore";
import ChannelRTCStore from "../../../calls/ChannelRTCStore";
import GameConsoleStore from "../../../game_console/GameConsoleStore";
import ApplicationStreamingStore from "../../../../stores/ApplicationStreamingStore";
import AuthenticationStore from "../../../../stores/AuthenticationStore";
import MediaEngineStore from "../../../../stores/MediaEngineStore";
import ChannelCallLifecycleStore from "../ChannelCallLifecycleStore";
import { ParticipantTypes } from "../../../calls/CallConstants";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import { CALL_ACTION_BAR_HEIGHT, FIVE_BUTTON_LAYOUT_ACTION_BAR_HEIGHT, FIVE_BUTTON_CONTAINER_PADDING_TOP, FIVE_BUTTON_CONTAINER_PADDING_BOTTOM } from "../useActionBarHeight";
import useHasVideoPermission from "../../useHasVideoPermission";
import { useStateFromStores, useStateFromStoresObject } from "../../../../_bundle/Module589";
import useChannelVideoLimit from "../../useChannelVideoLimit";
import { useStageHasMedia } from "../../../stage_channels/StageMediaHooks";
import { CameraLottie } from "../../../../design/components/LottieIcon/native/generated/CameraLottie";
import { handleToggleVideo, showCameraDisabledAlert, useMaskedSpeakerStates, handleDisconnect } from "../../../voice_calls/native/CallsUtils";
import { openIgnoreThermalStateAlert } from "../../../activities/native/openIgnoreThermalStateAlert";
import { ToggledActionButton, PrimaryActionButton } from "./CallBarAction";
import { intl, t } from "../../../../intl/index.native";
import Module10744 from "../../../../_bundle/Module10744";
import useScreenshareUtils from "../useScreenshareUtils";
import { useIsConnectedToVoiceChannel } from "../../../voice_chat/VoiceChatHooks";
import Module10761 from "../../../../_bundle/Module10761";
import Module10762 from "../../../../_bundle/Module10762";
import ChannelRTCActionCreators from "../../../../actions/ChannelRTCActionCreators";
import { stopStream } from "../../../../actions/StreamActionCreators";
import { encodeStreamKey } from "../../../go_live/utils/StreamKeyUtils";
import EmbeddedActivitiesNativeManager from "../../../activities/native/EmbeddedActivitiesNativeManager";
import Module10763 from "../../../../_bundle/Module10763";
import useIsRemote from "../../../game_console/hooks/useIsRemote";
import useIsVideoMode from "../useIsVideoMode";
import useAnalyticsLocations, { AnalyticsLocationProvider } from "../../../app_analytics/useAnalyticsLocations";
import AnalyticsLocation from "../../../app_analytics/AnalyticsLocation";
import { useIsFiveButtonLayout } from "../useIsFiveButtonLayout";
import { CallConnectingActionBar } from "./ChannelCallConnectingScreen";
import { ChannelCallMicButton } from "./ChannelCallMicButton";
import { DisconnectRemoteButton } from "./DisconnectRemoteButton";
let useStyles, ScreenshareButton, AudioRouteButton, DisconnectCallButton, DisconnectStreamButton, LeaveActivityButton, c7219_24, useActionBarSecondButton, c7219_26, useActionBarPrimaryButtons;
const VideoButton = function VideoButton(props) {
let stateFromStores2, ref, callback;
const { channel, isSmallSize } = props;
stateFromStores2 = void 0;
ref = void 0;
callback = void 0;
const hasVideoPermission = useHasVideoPermission(channel);
let c18239_1 = hasVideoPermission;
const stateFromStores = useStateFromStores([ChannelCallLifecycleStore], () => ChannelCallLifecycleStore.isReactingToThermalState());
stateFromStores2 = useStateFromStores([MediaEngineStore], () => MediaEngineStore.isVideoEnabled());
const reachedLimit = useChannelVideoLimit(channel).reachedLimit;
const stageHasMedia = useStageHasMedia(channel.id);
ref = useRef(null);
const memo = useMemo(() => <CameraLottie ref={ref} animation={stateFromStores2 ? "mute" : "unmute"} />, [stateFromStores2]);
callback = useCallback((a0) => {
handleToggleVideo(a0);
if (ref != null) {
const current = ref.current;
if (current != null) {
current.play();
}
}
}, []);
return <ToggledActionButton appearsDisabled={hasVideoPermission ? stageHasMedia ? !stageHasMedia : reachedLimit : !hasVideoPermission} isActive={stateFromStores2} onPress={useCallback(() => {
if (c18239_1) {
if (stateFromStores) {
openIgnoreThermalStateAlert(() => callback(channel));
} else {
callback(channel);
}
} else {
showCameraDisabledAlert();
}
}, [channel, hasVideoPermission, stateFromStores, callback])} accessibilityLabel={intl.string(t.HK4JIu)} source={Module10744} isSmallSize={isSmallSize} lottieComponent={memo} />;
};
ScreenshareButton = function ScreenshareButton(props) {
const { channel: channel6, isSmallSize } = props;
const screenshareUtils = useScreenshareUtils(channel6);
const isActive = screenshareUtils.isActive;
let onPress2 = screenshareUtils.onPress;
const { imgSource, isFeatureEnabled } = screenshareUtils;
if (!isFeatureEnabled) {
onPress2 = () => {};
}
return <ToggledActionButton appearsDisabled={!isFeatureEnabled} source={imgSource} isActive={isActive} accessibilityLabel={intl.string(t.XF1nZz)} onPress={onPress2} isSmallSize={isSmallSize} />;
};
AudioRouteButton = function AudioRouteButton(props) {
const { channel: channel2, isSmallSize } = props;
const maskedSpeakerStates = useMaskedSpeakerStates();
const { isAudioRouteEnabled, toggleAudio, routeSource } = maskedSpeakerStates;
const isConnectedToVoiceChannel = useIsConnectedToVoiceChannel(channel2);
return <ToggledActionButton isActive={isAudioRouteEnabled} source={routeSource} onPress={() => {
toggleAudio(channel2.id, isConnectedToVoiceChannel);
}} accessibilityLabel={intl.string(t["A/Ly/2"])} isSmallSize={isSmallSize} />;
};
DisconnectCallButton = function DisconnectCallButton(props) {
const { channel: channel3, isSmallSize } = props;
return <PrimaryActionButton source={Module10761} accessibilityLabel={intl.string(t["6vrfgt"])} isSmallSize={isSmallSize} onPress={() => {
handleDisconnect(channel3);
}} />;
};
DisconnectStreamButton = function DisconnectStreamButton(props) {
let stateFromStores4;
const { channel: channel4, isSmallSize } = props;
stateFromStores4 = void 0;
const stateFromStores3 = useStateFromStores([ChannelRTCStore, AuthenticationStore], () => {
const selectedParticipant = ChannelRTCStore.getSelectedParticipant(channel4.id);
return selectedParticipant != null && selectedParticipant.type !== ParticipantTypes.ACTIVITY ? selectedParticipant.user.id !== AuthenticationStore.getId() ? selectedParticipant?.id : null : selectedParticipant?.id;
});
stateFromStores4 = useStateFromStores([ApplicationStreamingStore], () => stateFromStores3 != null ? ApplicationStreamingStore.getActiveStreamForStreamKey(stateFromStores3) : null);
return stateFromStores4 != null ? <PrimaryActionButton source={Module10762} accessibilityLabel={intl.string(t.q3O3J8)} isSmallSize={isSmallSize} onPress={() => {
ChannelRTCActionCreators.selectParticipant(channel4.id, null);
stopStream(encodeStreamKey(stateFromStores4));
}} /> : null;
};
LeaveActivityButton = function LeaveActivityButton(props) {
const isSmallSize = props.isSmallSize;
return <PrimaryActionButton accessibilityLabel={intl.string(t.k0Aph0)} onPress={function onPress() {
const currentEmbeddedActivity = EmbeddedActivitiesStore.getCurrentEmbeddedActivity();
EmbeddedActivitiesNativeManager.leaveActivity({
location: currentEmbeddedActivity?.location,
applicationId: currentEmbeddedActivity?.applicationId
});
}} source={Module10763} isSmallSize={isSmallSize} />;
};
useActionBarSecondButton = function useActionBarSecondButton({ channel: channel6 }) {
let SCREEN_SHARE_END;
let r7 = useIsConnectedToVoiceChannel(channel6);
const isActive = useScreenshareUtils(channel6).isActive;
const isRemote = useIsRemote();
const AUDIO_ROUTE = c7219_24.AUDIO_ROUTE;
const r8 = r7 ? !isRemote : r7;
const r22 = {};
r22[AUDIO_ROUTE] = r8;
r22[c7219_24.NONE] = true;
r22[c7219_24.SCREEN_SHARE_END] = (r7 ? !isRemote : r7) && isActive;
const SCREEN_SHARE_START = c7219_24.SCREEN_SHARE_START;
if (r7) {
r7 = !isRemote;
}
L20: {
r22[SCREEN_SHARE_START] = r7;
const isVideoMode = useIsVideoMode();
if (r22[c7219_24.SCREEN_SHARE_END]) {
SCREEN_SHARE_END = c7219_24.SCREEN_SHARE_END;
} else {
if (!(r22[c7219_24.AUDIO_ROUTE] && channel6.isPrivate()) && !(r22[c7219_24.AUDIO_ROUTE] && !isVideoMode)) {
if (r22[c7219_24.SCREEN_SHARE_START]) {
SCREEN_SHARE_END = c7219_24.SCREEN_SHARE_START;
break L20;
}
SCREEN_SHARE_END = c7219_24.NONE;
break L20;
}
SCREEN_SHARE_END = c7219_24.AUDIO_ROUTE;
}
}
return SCREEN_SHARE_END;
};
useActionBarPrimaryButtons = function useActionBarPrimaryButtons({ channel: channel5 }) {
const isConnectedToVoiceChannel2 = useIsConnectedToVoiceChannel(channel5);
const stateFromStores5 = useStateFromStores([ChannelRTCStore, AuthenticationStore], () => {
const selectedParticipant = ChannelRTCStore.getSelectedParticipant(channel5.id);
return selectedParticipant != null && selectedParticipant.type !== ParticipantTypes.ACTIVITY ? selectedParticipant.user.id !== AuthenticationStore.getId() ? selectedParticipant?.id : null : selectedParticipant?.id;
});
const stateFromStores6 = useStateFromStores([ApplicationStreamingStore], () => stateFromStores5 != null ? ApplicationStreamingStore.getActiveStreamForStreamKey(stateFromStores5) : null);
const stateFromStores7 = useStateFromStores([EmbeddedActivitiesStore], () => EmbeddedActivitiesStore.getCurrentEmbeddedActivity() != null);
const stateFromStoresObject = useStateFromStoresObject([GameConsoleStore], () => ({
awaitingRemote: GameConsoleStore.getAwaitingRemoteSessionInfo() != null,
remoteSessionId: GameConsoleStore.getRemoteSessionId()
}));
let awaitingRemote = stateFromStoresObject.awaitingRemote;
const remoteSessionId = stateFromStoresObject.remoteSessionId;
const r42 = {};
r42[c7219_26.END_ACTIVITY] = stateFromStores7;
r42[c7219_26.END_CALL] = isConnectedToVoiceChannel2;
const END_REMOTE = c7219_26.END_REMOTE;
if (!awaitingRemote) {
awaitingRemote = remoteSessionId != null;
}
r42[END_REMOTE] = awaitingRemote;
r42[c7219_26.END_STREAM] = stateFromStores6 != null;
return r42;
};
useStyles = createStyles({
container: {
height: CALL_ACTION_BAR_HEIGHT,
justifyContent: "center",
alignItems: "center",
flexDirection: "row"
},
containerForFiveButtonLayout: {
height: FIVE_BUTTON_LAYOUT_ACTION_BAR_HEIGHT,
paddingHorizontal: 16,
paddingTop: FIVE_BUTTON_CONTAINER_PADDING_TOP,
paddingBottom: FIVE_BUTTON_CONTAINER_PADDING_BOTTOM,
justifyContent: "center",
flexDirection: "row"
}
});
c7219_24 = {
NONE: 0,
0: "NONE",
SCREEN_SHARE_START: 1,
1: "SCREEN_SHARE_START",
SCREEN_SHARE_END: 2,
2: "SCREEN_SHARE_END",
AUDIO_ROUTE: 3,
3: "AUDIO_ROUTE"
};
c7219_26 = {
END_STREAM: 0,
0: "END_STREAM",
END_ACTIVITY: 1,
1: "END_ACTIVITY",
END_CALL: 2,
2: "END_CALL",
END_REMOTE: 3,
3: "END_REMOTE"
};
export default function ChannelCallActionBar(props) {
let r54, r60, r85;
const { channel: channel6, shouldShowConnectingScreen = false } = props;
const styles = useStyles();
const isRemote = useIsRemote();
const actionBarSecondButton = useActionBarSecondButton({
channel: channel6
});
const actionBarPrimaryButtons = useActionBarPrimaryButtons({
channel: channel6
});
const r17 = actionBarPrimaryButtons[c7219_26.END_STREAM] ? c7219_26.END_STREAM : actionBarPrimaryButtons[c7219_26.END_REMOTE] ? c7219_26.END_REMOTE : actionBarPrimaryButtons[c7219_26.END_ACTIVITY] ? c7219_26.END_ACTIVITY : c7219_26.END_CALL;
const analyticsLocations = useAnalyticsLocations(AnalyticsLocation.CHANNEL_CALL_ACTION_BAR).analyticsLocations;
const isFiveButtonLayout = useIsFiveButtonLayout(channel6.id);
const style = isFiveButtonLayout ? styles.containerForFiveButtonLayout : styles.container;
if (shouldShowConnectingScreen) {
r85 = <CallConnectingActionBar channel={channel6} />;
} else {
const r18 = isRemote ? null : <VideoButton channel={channel6} isSmallSize={isFiveButtonLayout} />;
L23: {
r54 = [r18, , , ,];
if (c7219_24.AUDIO_ROUTE === actionBarSecondButton) {
r60 = <AudioRouteButton isSmallSize={isFiveButtonLayout} channel={channel6} />;
} else {
if (c7219_24.SCREEN_SHARE_START !== actionBarSecondButton && c7219_24.SCREEN_SHARE_END !== actionBarSecondButton) {
c7219_24.NONE;
r60 = null;
break L23;
}
r60 = <ScreenshareButton channel={channel6} isSmallSize={isFiveButtonLayout} />;
}
}
r54[1] = r60;
r54[2] = <ChannelCallMicButton channel={channel6} isSmallSize={isFiveButtonLayout} />;
r54[3] = c7219_26.END_REMOTE === r17 ? <DisconnectRemoteButton channel={channel6} isSmallSize={isFiveButtonLayout} /> : c7219_26.END_STREAM === r17 ? <DisconnectStreamButton channel={channel6} isSmallSize={isFiveButtonLayout} /> : c7219_26.END_ACTIVITY === r17 ? <LeaveActivityButton isSmallSize={isFiveButtonLayout} /> : c7219_26.END_CALL === r17 ? <DisconnectCallButton channel={channel6} isSmallSize={isFiveButtonLayout} /> : null;
r85 = <>{r54}</>;
}
return <AnalyticsLocationProvider value={analyticsLocations}>
<View pointerEvents="box-none" style={style}>{r85}</View>
</AnalyticsLocationProvider>;
};
export { VideoButton };
export { ScreenshareButton };
export { AudioRouteButton };
export { DisconnectCallButton };
export { DisconnectStreamButton };
export { c7219_24 as ActionBarSecondButton };
export function useActionBarSecondButtons({ channel: channel6 }) {
let r11 = useIsConnectedToVoiceChannel(channel6);
const isActive = useScreenshareUtils(channel6).isActive;
const isRemote = useIsRemote();
const AUDIO_ROUTE = c7219_24.AUDIO_ROUTE;
const r20 = r11 ? !isRemote : r11;
const r21 = {};
r21[AUDIO_ROUTE] = r20;
r21[c7219_24.NONE] = true;
r21[c7219_24.SCREEN_SHARE_END] = (r11 ? !isRemote : r11) && isActive;
const SCREEN_SHARE_START = c7219_24.SCREEN_SHARE_START;
if (r11) {
r11 = !isRemote;
}
r21[SCREEN_SHARE_START] = r11;
return r21;
}
export { useActionBarSecondButton };
export { c7219_26 as ActionBarPrimaryButton };
export { useActionBarPrimaryButtons };
export function useActionBarPrimaryButton(a0) {
const actionBarPrimaryButtons = useActionBarPrimaryButtons({
channel: a0.channel
});
return actionBarPrimaryButtons[c7219_26.END_STREAM] ? c7219_26.END_STREAM : actionBarPrimaryButtons[c7219_26.END_REMOTE] ? c7219_26.END_REMOTE : actionBarPrimaryButtons[c7219_26.END_ACTIVITY] ? c7219_26.END_ACTIVITY : c7219_26.END_CALL;
}