326 lines
12 KiB
TypeScript
326 lines
12 KiB
TypeScript
// Metro module 16694 (f16695).
|
|
import ApplicationStreamingStore from "../../stores/ApplicationStreamingStore";
|
|
import AuthenticationStore from "../../stores/AuthenticationStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildMemberCountStore from "../../stores/GuildMemberCountStore";
|
|
import RTCRegionStore from "../../stores/RTCRegionStore";
|
|
import SelectedChannelStore from "../../stores/SelectedChannelStore";
|
|
import StreamRTCConnectionStore from "../../stores/StreamRTCConnectionStore";
|
|
import "../../stores/UserStore";
|
|
import { GO_LIVE_NOTIFY_FRIENDS_MIN_MEMBER_COUNT, STREAM_NOTIFY_GUILD_MAX_SIZE } from "./Constants";
|
|
import { ApplicationStreamDeleteReasons, ApplicationStreamStates } from "../../Constants";
|
|
import { debounce } from "../../_bundle/Module12";
|
|
import { changeStreamRegion, notifyStreamStart, stopStream, watchStream, closeStream } from "../../actions/StreamActionCreators";
|
|
import Durations from "../../utils/Durations";
|
|
import { decodeStreamKey, encodeStreamKey } from "./utils/StreamKeyUtils";
|
|
import { Timeout } from "../../_bundle/Timeout";
|
|
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
|
|
import { reportAVError, AVError } from "../errors/av_errors/AVError";
|
|
import { getStreamErrorContext } from "../errors/av_errors/AVErrorContext";
|
|
function $mk100327($env) {
|
|
return () => {
|
|
const r1 = $env.$parent;
|
|
(0, r1[1])(r1[2][15]).dispatch({
|
|
type: "STREAM_TIMED_OUT",
|
|
streamKey: $env[0]
|
|
});
|
|
};
|
|
}
|
|
let c12028_12, c12028_13, c12028_14, c12028_15, c12028_16, c12028_18, c12028_20;
|
|
let $mk100326 = function() {
|
|
return (a0) => {
|
|
if (!ApplicationStreamingStore.isStreamMarkedFull(a0)) {
|
|
c12028_18.delete(a0);
|
|
}
|
|
};
|
|
};
|
|
let env12028 = {};
|
|
const updateRegion = function updateRegion(a0, a1) {
|
|
const r5 = a1 == null ? RTCRegionStore.getPreferredRegion() : a1;
|
|
if (r5 != null && r5 !== RTCRegionStore.getRegion(StreamRTCConnectionStore.getHostname(a0))) {
|
|
changeStreamRegion(a0, r5);
|
|
}
|
|
};
|
|
GO_LIVE_NOTIFY_FRIENDS_MIN_MEMBER_COUNT;
|
|
STREAM_NOTIFY_GUILD_MAX_SIZE;
|
|
debounce(notifyStreamStart, 1000);
|
|
c12028_12 = {};
|
|
c12028_13 = {};
|
|
c12028_14 = 3 * Durations.Millis.MINUTE;
|
|
c12028_15 = 5 * Durations.Millis.SECOND;
|
|
c12028_16 = 12 * Durations.Millis.SECOND;
|
|
env12028[17] = null;
|
|
c12028_18 = new Set();
|
|
class BaseApplicationStreamingManager extends AutomaticLifecycleManager {
|
|
handleStreamWatch = ({ streamKey, allowMultiple }) => {
|
|
const channel = ChannelStore.getChannel(decodeStreamKey(streamKey).channelId);
|
|
const r11 = channel == null ? void 0 : channel.isGuildStageVoice();
|
|
let env28495;
|
|
const r24 = env28495 = {
|
|
$parent: env12028
|
|
};
|
|
env28495[0] = streamKey;
|
|
if (!StreamRTCConnectionStore.getAllActiveStreamKeys().includes(streamKey)) {
|
|
let r31 = c12028_13[streamKey];
|
|
if (r31 == null) {
|
|
r31 = new Timeout();
|
|
}
|
|
c12028_13[streamKey] = r31;
|
|
r31.start.call(r31, r11 ? c12028_16 : c12028_15, $mk100327(r24));
|
|
}
|
|
const r42 = c12028_12[streamKey];
|
|
if (r42 != null) {
|
|
r42.stop();
|
|
}
|
|
delete c12028_12[streamKey];
|
|
if (!allowMultiple) {
|
|
ApplicationStreamingStore.getAllActiveStreams().forEach((item) => {
|
|
const r10 = encodeStreamKey(item);
|
|
if (item.ownerId !== AuthenticationStore.getId() && r10 !== streamKey) {
|
|
stopStream(r10, false);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
handleStreamStart = (a0) => {
|
|
const { channelId, streamType, guildId } = a0;
|
|
const r7 = env12028;
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const r23 = encodeStreamKey({
|
|
streamType,
|
|
guildId,
|
|
channelId,
|
|
ownerId: AuthenticationStore.getId()
|
|
});
|
|
const r24 = channel == null ? void 0 : channel.isGuildStageVoice();
|
|
let env28496;
|
|
const r26 = env28496 = {
|
|
$parent: r7
|
|
};
|
|
env28496[0] = r23;
|
|
if (!StreamRTCConnectionStore.getAllActiveStreamKeys().includes(r23)) {
|
|
let r33 = c12028_13[r23];
|
|
if (r33 == null) {
|
|
r33 = new Timeout();
|
|
}
|
|
c12028_13[r23] = r33;
|
|
r33.start.call(r33, r24 ? c12028_16 : c12028_15, $mk100327(r26));
|
|
}
|
|
this.platformHandleStreamStart(a0);
|
|
};
|
|
handleStreamCreate = ({ streamKey: streamKey2 }) => {
|
|
const r5 = c12028_13[streamKey2];
|
|
if (r5 != null) {
|
|
r5.stop();
|
|
}
|
|
delete c12028_13[streamKey2];
|
|
c12028_18.forEach($mk100326());
|
|
const r19 = decodeStreamKey(streamKey2);
|
|
r19.ownerId;
|
|
GuildMemberCountStore.getMemberCount(r19.guildId);
|
|
};
|
|
handleStreamUpdate = ({ streamKey: streamKey2 }) => {
|
|
const r5 = c12028_13[streamKey2];
|
|
if (r5 != null) {
|
|
r5.stop();
|
|
}
|
|
delete c12028_13[streamKey2];
|
|
c12028_18.forEach($mk100326());
|
|
};
|
|
handleStreamDelete = ({ reason, streamKey: streamKey2 }) => {
|
|
const r6 = c12028_13[streamKey2];
|
|
if (r6 != null) {
|
|
r6.stop();
|
|
}
|
|
delete c12028_13[streamKey2];
|
|
if (reason === ApplicationStreamDeleteReasons.STREAM_FULL) {
|
|
reportAVError({
|
|
type: AVError.STREAM_FULL,
|
|
...getStreamErrorContext(streamKey2)
|
|
});
|
|
if (!c12028_18.has(streamKey2)) {
|
|
c12028_18.add(streamKey2);
|
|
this.platformShowStreamFull();
|
|
}
|
|
}
|
|
};
|
|
handleStreamClose = ({ streamKey: streamKey2 }) => {
|
|
const r6 = c12028_12[streamKey2];
|
|
if (r6 != null) {
|
|
r6.stop();
|
|
}
|
|
delete c12028_12[streamKey2];
|
|
const r10 = c12028_13[streamKey2];
|
|
if (r10 != null) {
|
|
r10.stop();
|
|
}
|
|
delete c12028_13[streamKey2];
|
|
};
|
|
handleVoiceChannelSelect = (a0) => {
|
|
L11: {
|
|
const channelId = a0.channelId;
|
|
if (channelId != null) {
|
|
env12028[17] = null;
|
|
c12028_18.forEach($mk100326());
|
|
const r15 = ApplicationStreamingStore.getAllApplicationStreamsForChannel(channelId).find((item) => item.ownerId !== AuthenticationStore.getId() && !ApplicationStreamingStore.isStreamMarkedFull(encodeStreamKey(item)));
|
|
if (r15 != null) {
|
|
const ownerId = r15.ownerId;
|
|
if (SelectedChannelStore.getVoiceChannelId() === channelId) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
if (channel != null) {
|
|
if (!channel.isDM() && !channel.isGuildStageVoice()) {
|
|
break L11;
|
|
}
|
|
if (ApplicationStreamingStore.getActiveStreamForUser(ownerId, channel.getGuildId()) == null) {
|
|
const streamForUser = ApplicationStreamingStore.getStreamForUser(ownerId, channel.getGuildId());
|
|
if (streamForUser != null) {
|
|
const r40 = encodeStreamKey(streamForUser);
|
|
if (r40 !== env12028[17] && !ApplicationStreamingStore.isStreamMarkedFull(r40)) {
|
|
env12028[17] = r40;
|
|
watchStream(streamForUser, {
|
|
noFocus: true
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
handleVoiceStateUpdates = (a0) => {
|
|
a0.voiceStates.forEach((voiceState) => {
|
|
let r36;
|
|
const { userId, channelId, guildId, selfStream } = voiceState;
|
|
this.platformHandleVoiceStateUpdate(voiceState);
|
|
if (userId !== AuthenticationStore.getId()) {
|
|
if ((selfStream ? channelId == null : !selfStream) && c12028_18.size > 0) {
|
|
c12028_18.forEach($mk100326());
|
|
}
|
|
if (channelId != null) {
|
|
if (selfStream) {
|
|
L20: {
|
|
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
|
|
r36 = false;
|
|
if (voiceChannelId === channelId) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const r3 = channel == null;
|
|
r36 = false;
|
|
if (!r3) {
|
|
if (!channel.isDM()) {
|
|
const isGuildStageVoice = channel.isGuildStageVoice();
|
|
r36 = false;
|
|
if (!isGuildStageVoice) {
|
|
break L20;
|
|
}
|
|
}
|
|
const r48 = ApplicationStreamingStore.getActiveStreamForUser(userId, channel.getGuildId()) != null;
|
|
r36 = false;
|
|
if (!r48) {
|
|
const streamForUser = ApplicationStreamingStore.getStreamForUser(userId, channel.getGuildId());
|
|
const r52 = streamForUser == null;
|
|
r36 = false;
|
|
if (!r52) {
|
|
const r57 = encodeStreamKey(streamForUser);
|
|
let r59 = r57 !== env12028[17];
|
|
if (r59) {
|
|
const isStreamMarkedFull = ApplicationStreamingStore.isStreamMarkedFull(r57);
|
|
let r2 = !isStreamMarkedFull;
|
|
if (!isStreamMarkedFull) {
|
|
env12028[17] = r57;
|
|
watchStream(streamForUser, {
|
|
noFocus: true
|
|
});
|
|
r2 = true;
|
|
}
|
|
r59 = r2;
|
|
}
|
|
r36 = r59;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (r36) {
|
|
return void 0;
|
|
}
|
|
}
|
|
const activeStreamForUser = ApplicationStreamingStore.getActiveStreamForUser(userId, guildId);
|
|
if (activeStreamForUser != null && activeStreamForUser.channelId === channelId) {
|
|
if (!selfStream && activeStreamForUser.state !== ApplicationStreamStates.ENDED) {
|
|
const r80 = encodeStreamKey(activeStreamForUser);
|
|
let c31100_0 = r80;
|
|
let r82 = c12028_12[r80];
|
|
if (r82 == null) {
|
|
r82 = new Timeout();
|
|
}
|
|
r82.start(c12028_14, () => closeStream(c31100_0, false));
|
|
c12028_12[r80] = r82;
|
|
}
|
|
if (selfStream && activeStreamForUser.state === ApplicationStreamStates.ENDED) {
|
|
const r101 = encodeStreamKey(activeStreamForUser);
|
|
const r103 = c12028_12[r101];
|
|
if (r103 != null) {
|
|
r103.stop();
|
|
}
|
|
delete c12028_12[r101];
|
|
const streamForUser2 = ApplicationStreamingStore.getStreamForUser(userId, guildId);
|
|
if (streamForUser2 == null) {
|
|
return void 0;
|
|
}
|
|
if (ApplicationStreamingStore.isStreamMarkedFull(encodeStreamKey(streamForUser2))) {
|
|
return void 0;
|
|
}
|
|
watchStream(streamForUser2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|
|
handleCallUpdate = (a0) => {
|
|
const channelId = a0.channelId;
|
|
let region = a0.region;
|
|
const currentUserActiveStream = ApplicationStreamingStore.getCurrentUserActiveStream();
|
|
if (currentUserActiveStream?.channelId === channelId) {
|
|
const r17 = encodeStreamKey(currentUserActiveStream);
|
|
if (region == null) {
|
|
region = RTCRegionStore.getPreferredRegion();
|
|
}
|
|
if (region != null && region !== RTCRegionStore.getRegion(StreamRTCConnectionStore.getHostname(r17))) {
|
|
changeStreamRegion(r17, region);
|
|
}
|
|
}
|
|
};
|
|
handleChannelUpdates = ({ channels }) => {
|
|
const currentUserActiveStream = ApplicationStreamingStore.getCurrentUserActiveStream();
|
|
if (currentUserActiveStream != null) {
|
|
for (const item of channels) {
|
|
if (currentUserActiveStream.channelId === item.id) {
|
|
updateRegion(encodeStreamKey(currentUserActiveStream), item.rtcRegion);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
handleSessionReset = () => {
|
|
c12028_18.clear();
|
|
};
|
|
actions = {
|
|
STREAM_WATCH: this.handleStreamWatch,
|
|
STREAM_START: this.handleStreamStart,
|
|
STREAM_CREATE: this.handleStreamCreate,
|
|
STREAM_UPDATE: this.handleStreamUpdate,
|
|
STREAM_DELETE: this.handleStreamDelete,
|
|
STREAM_CLOSE: this.handleStreamClose,
|
|
CALL_UPDATE: this.handleCallUpdate,
|
|
CHANNEL_UPDATES: this.handleChannelUpdates,
|
|
VOICE_CHANNEL_SELECT: this.handleVoiceChannelSelect,
|
|
VOICE_STATE_UPDATES: this.handleVoiceStateUpdates,
|
|
CONNECTION_CLOSED: this.handleSessionReset,
|
|
LOGOUT: this.handleSessionReset
|
|
};
|
|
}
|
|
c12028_20 = BaseApplicationStreamingManager;
|
|
export default BaseApplicationStreamingManager;
|