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

89 lines
3.4 KiB
TypeScript

// Metro module 12852 (f12853).
import ChannelRTCStore from "../../calls/ChannelRTCStore";
import AuthenticationStore from "../../../stores/AuthenticationStore";
import CallStore from "../../../stores/CallStore";
import RTCConnectionStore from "../../../stores/RTCConnectionStore";
import { EMPTY_STRING_SNOWFLAKE_ID, RTCConnectionStates } from "../../../Constants";
import { ParticipantTypes } from "../../calls/CallConstants";
import { useStateFromStoresArray, useStateFromStores } from "../../../_bundle/Module589";
import useVoiceStateForRemoteSession from "../../game_console/hooks/useVoiceStateForRemoteSession";
let c8861_10 = {
...{
initialized: false,
callId: void 0
}
};
let c8861_11 = {
DISCONNECTED: "disconneted",
DISCONNECTING: "disconnecting",
CONNECTING: "connecting",
RINGING: "ringing",
CONNECTED: "connected"
};
export default function _default(r13 = EMPTY_STRING_SNOWFLAKE_ID) {
let CONNECTING, initialized;
let c20254_2, stateFromStores;
const EMPTY_STRING_SNOWFLAKE_ID2 = r13;
let r10 = arguments[1];
if (r10 === void 0) {
r10 = false;
}
let r5 = arguments[2];
if (r5 === void 0) {
r5 = false;
}
c20254_2 = void 0;
stateFromStores = void 0;
const id = AuthenticationStore.getId();
const stateFromStoresArray = useStateFromStoresArray([CallStore], () => {
const call = CallStore.getCall(EMPTY_STRING_SNOWFLAKE_ID2);
const r8 = call != null ? call.ringing.filter((item) => item !== id) : [];
c8861_10.initialized = c8861_10.initialized || r8.length > 0;
return r8;
}, [EMPTY_STRING_SNOWFLAKE_ID2, id]);
const r30 = ChannelRTCStore.getParticipants(EMPTY_STRING_SNOWFLAKE_ID2).filter((item) => item.type !== ParticipantTypes.ACTIVITY && item.user.id !== id);
const voiceStateForRemoteSession = useVoiceStateForRemoteSession();
c20254_2 = voiceStateForRemoteSession;
stateFromStores = useStateFromStores([RTCConnectionStore], RTCConnectionStore.getRTCConnectionId, []);
const stateFromStores2 = useStateFromStores([RTCConnectionStore], () => {
if (c20254_2?.channelId === EMPTY_STRING_SNOWFLAKE_ID2) {
c8861_10.initialized = true;
return RTCConnectionStates.RTC_CONNECTED;
}
const callId = c8861_10.callId;
if (!(stateFromStores != null && callId === stateFromStores)) {
c8861_10.initialized = false;
}
c8861_10.callId = stateFromStores;
const state = RTCConnectionStore.getState();
c8861_10.initialized = c8861_10.initialized || state !== RTCConnectionStates.DISCONNECTED && state !== RTCConnectionStates.RTC_DISCONNECTED;
return state;
}, [stateFromStores, voiceStateForRemoteSession, EMPTY_STRING_SNOWFLAKE_ID2]);
const initialized2 = c8861_10.initialized || r5;
L18: {
c8861_10.initialized = initialized2;
CONNECTING = c8861_11.CONNECTING;
initialized = c8861_10.initialized;
if (r10) {
CONNECTING = c8861_11.DISCONNECTING;
} else {
if (initialized && stateFromStores2 === RTCConnectionStates.DISCONNECTED) {
CONNECTING = c8861_11.DISCONNECTED;
break L18;
}
if (stateFromStoresArray.length > 0 && r30.length === stateFromStoresArray.length) {
CONNECTING = c8861_11.RINGING;
break L18;
}
if (stateFromStores2 === RTCConnectionStates.RTC_CONNECTED) {
CONNECTING = c8861_11.CONNECTED;
}
}
}
return {
state: CONNECTING,
initialized
};
};
export { c8861_11 as CallStates };