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

204 lines
7.3 KiB
TypeScript

// Metro module 4367 (f4368).
import { Linking } from "react-native";
import ApplicationStreamingStore from "../../../stores/ApplicationStreamingStore";
import ChannelStore from "../../../stores/ChannelStore";
import SelectedChannelStore from "../../../stores/SelectedChannelStore";
import { Base64JPEGPrefix, Endpoints, IOS_BUNDLE_ID, NOOP_NULL } from "../../../Constants";
import { getAppIntentScheme } from "../../activities/Constants";
import Logger from "../../debug/Logger";
import { Timeout } from "../../../_bundle/Timeout";
import { DisableStreamPreviews } from "../../user_settings/UserSettings";
import Dispatcher from "../../../Dispatcher";
import { HTTP } from "../../../_bundle/sendRequest";
import LifecycleManager from "../../../lib/LifecycleManager";
import { getVoiceEngine } from "../../../_bundle/Module4238";
import Module38 from "../../../_bundle/Module38";
import { stopStream, startStream } from "../../../actions/StreamActionCreators";
import ChannelRTCActionCreators from "../../../actions/ChannelRTCActionCreators";
import { encodeStreamKey } from "../utils/StreamKeyUtils";
import { getWindowDimensions } from "../../screen/useWindowDimensions.native";
import { handleCloseScreenshare } from "../../video_calls/native/useScreenshareUtils";
import PushNotification from "../../../lib/pushnotification/PushNotification";
import { intl, t } from "../../../intl/index.native";
import { HermesBuiltin } from "../../../_hermes/prelude";
function $mk114513($env) {
return () => {
const r1 = $env;
return (0, handleThumbnailUpload)(r1[0], r1[1]);
};
}
let c2586_13, c2586_14, c2586_15, c2586_21, c2586_22;
let env2586 = {};
const handleThumbnailUpload = async function handleThumbnailUpload(streamKey, c25057_1) {
let c25057_2, c25057_3, c25057_4;
let c25057_5 = 0;
const r12 = env2586;
L13: {
L12: {
try {
let env29318;
c25057_3 = r12;
const r33 = env29318 = {
$parent: r12
};
c25057_2 = r33;
env29318[0] = streamKey;
env29318[1] = c25057_1;
if (DisableStreamPreviews.getSetting()) {
break L13;
}
c2586_14.stop();
const previewURL = `${Base64JPEGPrefix}${c25057_1}`;
Dispatcher.dispatch({
type: "STREAM_PREVIEW_FETCH_SUCCESS",
streamKey,
previewURL
});
c25057_5 = 1;
await HTTP.post({
url: Endpoints.STREAM_PREVIEW(streamKey),
body: {
thumbnail: previewURL
},
oldFormErrors: true,
rejectWithError: false
});
c25057_5 = 0;
} catch ($e) {
const r31 = $e;
let r8 = r31;
c25057_4 = r31;
if (c25057_5 !== 0) {
while (true) {
try {
const r86 = c25057_2;
const r88 = c25057_4;
c25057_5 = 0;
env29318[2] = r88;
c2586_13.error("Failed to post stream preview", env29318[2]);
c2586_14.start(60000, $mk114513(r86));
break L12;
} catch (r84) {
r8 = r84;
c25057_4 = r84;
if (c25057_5 === 0) {
break;
}
}
}
}
throw r8;
}
}
return void 0;
}
};
const logger = new Logger("VoiceEngineStreamingManager");
c2586_13 = logger;
logger.enableNativeLogger(true);
c2586_14 = new Timeout();
c2586_15 = new Timeout();
env2586[16] = [];
env2586[20] = SelectedChannelStore.getVoiceChannelId();
c2586_21 = Symbol("#e");
class VoiceEngineStreamingManager extends LifecycleManager {
constructor() {
super(...arguments);
if (Object.prototype.hasOwnProperty.call(this, c2586_21)) {
HermesBuiltin.throwTypeError("Cannot initialize private field twice.");
throw new Error("unreachable");
}
this[c2586_21] = ({ channelId }) => {
if (env2586[20] !== channelId) {
const r5 = env2586[19];
if (r5 != null) {
r5.stopBroadcast();
}
ApplicationStreamingStore.getAllActiveStreams().forEach((item) => {
if (item.channelId !== channelId) {
stopStream(encodeStreamKey(item), false);
}
});
}
env2586[20] = channelId;
};
}
_initialize() {
const voiceEngine = getVoiceEngine();
env2586[19] = voiceEngine;
voiceEngine.setBroadcastRequestCallback(() => {
c2586_13.log("Broadcast Requested");
Module38(env2586[19] != null, "Voice Engine should be initialized in callback");
env2586[16] = [];
const channel = ChannelStore.getChannel(SelectedChannelStore.getVoiceChannelId());
const currentAppIntent = ApplicationStreamingStore.getCurrentAppIntent();
if (channel != null) {
startStream(channel.getGuildId(), channel.id, {
sourceId: "screen:0"
});
const currentUserActiveStream = ApplicationStreamingStore.getCurrentUserActiveStream();
if (currentUserActiveStream != null) {
ChannelRTCActionCreators.selectParticipant(channel.id, encodeStreamKey(currentUserActiveStream));
if (env2586[19].platform === "android") {
c2586_15.start(15000, () => {
Module38(env2586[19] != null, "Voice Engine should be initialized in callback");
const windowDimensions = getWindowDimensions();
const r31 = Math.min(512 / windowDimensions.width, 288 / windowDimensions.height);
env2586[19].setBroadcastThumbnailCallback(windowDimensions.width * r31, windowDimensions.height * r31, 300, (a0) => {
c2586_13.log("Broadcast thumbnail of size:", a0.length);
handleThumbnailUpload(encodeStreamKey(currentUserActiveStream), a0);
});
});
}
if (currentAppIntent != null) {
Linking.openURL((0, getAppIntentScheme)(currentAppIntent));
}
}
} else {
env2586[19].stopBroadcastWithError(-1, "Not currently in a voice channel");
}
});
env2586[19].setBroadcastFinishedCallback(() => {
c2586_13.log("Broadcast Finished");
c2586_14.stop();
c2586_15.stop();
handleCloseScreenshare();
});
env2586[19].setBroadcastAnnotatedCallback((a0) => {
c2586_13.log("Broadcast Annotated:", a0);
if (a0 !== IOS_BUNDLE_ID) {
const r11 = env2586[16].indexOf(a0, 0);
if (r11 > -1) {
env2586[16].splice(r11, 1);
}
env2586[16].push(a0);
}
});
env2586[19].setBroadcastBlockedCallback(() => {
c2586_13.log("Broadcast Blocked");
PushNotification.presentLocalNotification({
alertBody: intl.string(t.iYQlwv)
});
});
Dispatcher.subscribe("VOICE_CHANNEL_SELECT", this[c2586_21]);
}
_terminate() {
const voiceEngine = getVoiceEngine();
if (voiceEngine != null) {
voiceEngine.setBroadcastRequestCallback(NOOP_NULL);
voiceEngine.setBroadcastFinishedCallback(NOOP_NULL);
voiceEngine.setBroadcastAnnotatedCallback(NOOP_NULL);
voiceEngine.setBroadcastBlockedCallback(NOOP_NULL);
}
c2586_14.stop();
c2586_15.stop();
Dispatcher.unsubscribe("VOICE_CHANNEL_SELECT", this[c2586_21]);
}
getApplicationNames() {
return env2586[16];
}
}
c2586_22 = VoiceEngineStreamingManager;
const r76 = new VoiceEngineStreamingManager();
export default r76;