Files
discord-decomp/modules/calls/VideoSpeakerStore.tsx
T
2026-11-01 12:12:55 +02:00

119 lines
4.0 KiB
TypeScript

// Metro module 10523 (f10524).
import ApplicationStreamingStore from "../../stores/ApplicationStreamingStore";
import AuthenticationStore from "../../stores/AuthenticationStore";
import MediaEngineStore from "../../stores/MediaEngineStore";
import SpeakingStore from "../../stores/SpeakingStore";
import ChannelRTCStore from "./ChannelRTCStore";
import { ParticipantTypes } from "./CallConstants";
import { encodeStreamKey } from "../go_live/utils/StreamKeyUtils";
import Module12 from "../../_bundle/Module12";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
let c7065_2, c7065_3, c7065_11, handleChannelRTCUpdate, c7065_13;
const updateSpeaker = function updateSpeaker(r2 = true) {
let r34;
let r5 = void 0;
let r11 = void 0;
const r4 = c7065_2 == null;
let r36 = null;
if (!r4) {
let r38 = ChannelRTCStore.getSelectedParticipantId(c7065_2);
if (r38 != null && ChannelRTCStore.isParticipantPoppedOut(c7065_2, r38)) {
r38 = null;
}
const lastActiveStream = ApplicationStreamingStore.getLastActiveStream();
const r44 = r38 != null ? ChannelRTCStore.getParticipant(c7065_2, r38) : null;
const r59 = r44?.type === ParticipantTypes.ACTIVITY || r44?.type === ParticipantTypes.USER && !r44.voiceState?.selfVideo ? null : r38;
let r60 = r59;
if (lastActiveStream != null) {
r60 = r59;
if (r59 == null) {
const id = ChannelRTCStore.getParticipant(c7065_2, encodeStreamKey(lastActiveStream))?.id;
r60 = id == null || ChannelRTCStore.isParticipantPoppedOut(c7065_2, id) ? r59 : id;
}
}
r36 = r60;
if (r36 == null) {
const id2 = AuthenticationStore.getId();
const r82 = Date.now();
const r83 = [];
const r84 = [];
let r90 = ChannelRTCStore.getVideoParticipants(c7065_2)[Symbol.iterator]();
const next = r90.next;
while (true) {
const r94 = r90 === void 0 ? void 0 : (r34 = next.call(r90)).done ? r90 = void 0 : r34.value;
if (r90 === void 0) {
for (const item of r84) {
const { userId, duration } = item;
if (r11 == null || duration < r11) {
r5 = userId;
r11 = duration;
}
}
r36 = r5;
if (r36 != null) {
break;
}
r36 = c7065_3 != null && r83.includes(c7065_3) ? c7065_3 : r83[0];
break;
}
try {
if (r94.user.id !== id2 && !MediaEngineStore.isLocalVideoDisabled(r94.user.id) && !ChannelRTCStore.isParticipantPoppedOut(c7065_2, r94.id)) {
r83.push(r94.user.id);
const duration2 = SpeakingStore.getSpeakingDuration(r94.user.id, r82);
if (duration2 !== 0) {
r84.push({
userId: r94.user.id,
duration: duration2
});
}
}
} catch (r127) {
if (r90 !== void 0 && typeof r90.return === "function") {
try {
r90.return();
} catch {}
}
throw r127;
}
}
}
}
if (c7065_3 !== r36) {
c7065_3 = r36;
if (r2) {
c7065_13.emitChange();
}
}
};
handleChannelRTCUpdate = function handleChannelRTCUpdate() {
c7065_11();
return false;
};
c7065_11 = Module12.throttle(updateSpeaker, 300, {
trailing: true
});
class VideoSpeakerStoreClass extends Module589.Store {
static displayName = "VideoSpeakerStore";
initialize() {
this.waitFor(ChannelRTCStore, AuthenticationStore, SpeakingStore, ApplicationStreamingStore, MediaEngineStore);
this.syncWith([ChannelRTCStore, ApplicationStreamingStore], handleChannelRTCUpdate);
}
getSpeaker(a0) {
if (c7065_2 !== a0) {
c7065_2 = a0;
c7065_3 = null;
updateSpeaker(false);
}
let r8 = c7065_3;
if (r8 == null) {
r8 = AuthenticationStore.getId();
}
return r8;
}
}
c7065_13 = new VideoSpeakerStoreClass(Dispatcher, {
AUDIO_SET_LOCAL_VIDEO_DISABLED: handleChannelRTCUpdate
});
export default c7065_13;