decord/beta/source/modules/go_live/ApplicationStreamingManager.tsx
2026-10-12 16:32:48 +00:00

413 lines
18 KiB
TypeScript

// Module ID: 18675
// Function ID: 18676
// Name: go_live/ApplicationStreamingManager
// Dependencies: [5897, 502, 2065, 5020, 5211, 2116, 7429, 1390, 5898, 1085, 12, 7444, 1102, 584, 5900, 2060, 6808, 5289, 18655, 2]
// Module 18675 (go_live/ApplicationStreamingManager)
import DispatcherDefault from "Dispatcher" /* 584 */;
import DurationsDefault from "Durations" /* 1102 */;
import AVError from "AVError" /* 5289 */;
import StreamKeyUtils from "StreamKeyUtils" /* 5900 */;
import StreamActionCreators from "StreamActionCreators" /* 7444 */;
import AVErrorContext from "AVErrorContext" /* 18655 */;
import ApplicationStreamingStore from "ApplicationStreamingStore" /* 5897 */;
import AuthenticationStore from "AuthenticationStore" /* 502 */;
import ChannelStore from "ChannelStore" /* 2065 */;
import GuildMemberCountStore from "GuildMemberCountStore" /* 5020 */;
import RTCRegionStore from "RTCRegionStore" /* 5211 */;
import SelectedChannelStore from "SelectedChannelStore" /* 2116 */;
import StreamRTCConnectionStore from "StreamRTCConnectionStore" /* 7429 */;
import UserStore from "UserStore" /* 1390 */;
import Constants_mod from "Constants" /* 5898 */;
import Constants_mod2 from "Constants" /* 1085 */;
import module_12 from "module_12" /* 12 */;
import AutomaticLifecycleManager from "AutomaticLifecycleManager" /* 6808 */;
import size from "module_2" /* 2 */;
let allActiveStreamKeys, channel, memberCount;
let GO_LIVE_NOTIFY_FRIENDS_MIN_MEMBER_COUNT;
let STREAM_NOTIFY_GUILD_MAX_SIZE;
let c10;
let tmp;
let unpackModuleId;
const Timers = tmp(2060);
function updateRegion(encodeStreamKeyResult, preferredRegion) {
if (preferredRegion == null) {
preferredRegion = RTCRegionStore.getPreferredRegion();
}
const tmp3 = null != preferredRegion && preferredRegion !== RTCRegionStore.getRegion(StreamRTCConnectionStore.getHostname(encodeStreamKeyResult));
if (tmp3) {
const obj = StreamActionCreators;
obj.changeStreamRegion(encodeStreamKeyResult, preferredRegion);
}
}
let Constants = Constants_mod2;
({ GO_LIVE_NOTIFY_FRIENDS_MIN_MEMBER_COUNT, STREAM_NOTIFY_GUILD_MAX_SIZE } = Constants);
Constants = Constants_mod2;
({ ApplicationStreamDeleteReasons: c10, ApplicationStreamStates: unpackModuleId } = Constants);
module_12.debounce(StreamActionCreators.notifyStreamStart, 1000);
let closure_12 = {};
let closure_13 = {};
let closure_14 = 3 * DurationsDefault.Millis.MINUTE;
let closure_15 = 5 * DurationsDefault.Millis.SECOND;
let closure_16 = 12 * DurationsDefault.Millis.SECOND;
let c17 = null;
const set = new Set();
class BaseApplicationStreamingManager extends AutomaticLifecycleManager {
constructor() {
const f135668 = (item) => {
if (!streamMarkedFull.isStreamMarkedFull(item)) {
set.delete(item);
}
};
const applyArgumentsResult = HermesBuiltin.applyArguments(this, new.target);
require = applyArgumentsResult;
applyArgumentsResult.handleStreamWatch = function handleStreamWatch(streamKey) {
let isGuildStageVoiceResult;
streamKey = streamKey.streamKey;
const allowMultiple = streamKey.allowMultiple;
let tmp = streamKey;
let tmp2 = closure_2;
let obj = streamKey(closure_2[14]);
channel = channel.getChannel(obj.decodeStreamKey(streamKey).channelId);
if (channel != null) {
isGuildStageVoiceResult = channel.isGuildStageVoice();
}
allActiveStreamKeys = allActiveStreamKeys.getAllActiveStreamKeys();
if (!allActiveStreamKeys.includes(streamKey)) {
let timeout = closure_13[streamKey];
let tmp4 = closure_13;
if (timeout == null) {
const self = this;
const self2 = this;
timeout = new tmp(tmp2[15]).Timeout();
}
tmp4[streamKey] = timeout;
timeout.start(isGuildStageVoiceResult ? closure_16 : closure_15, () => {
const obj = closure_2_1(closure_2_2[13]);
const obj2 = { type: "STREAM_TIMED_OUT", streamKey: encodeStreamKeyResult };
obj.dispatch(obj2);
});
}
const tmp6 = closure_12;
if (closure_12[streamKey] != null) {
closure_12[streamKey].stop();
}
delete tmp6[streamKey];
if (!allowMultiple) {
const allActiveStreams = authStore.getAllActiveStreams();
const item = allActiveStreams.forEach((ownerId) => {
const obj = StreamKeyUtils;
const encodeStreamKeyResult = obj.encodeStreamKey(ownerId);
let tmp4 = ownerId.ownerId !== AuthenticationStore.getId();
const tmp = require;
const tmp2 = dependencyMap;
if (tmp4) {
tmp4 = encodeStreamKeyResult !== streamKey;
}
if (tmp4) {
const tmpResult = tmp(tmp2[11]);
tmpResult.stopStream(encodeStreamKeyResult, false);
}
});
}
};
applyArgumentsResult.handleStreamStart = function handleStreamStart(channelId) {
let guildId;
let isGuildStageVoiceResult;
let streamType;
channelId = channelId.channelId;
({ streamType, guildId } = channelId);
channel = ChannelStore.getChannel(channelId);
let obj2 = StreamKeyUtils;
let obj = { streamType, guildId, channelId, ownerId: AuthenticationStore.getId() };
const encodeStreamKeyResult = obj2.encodeStreamKey(obj);
if (channel != null) {
isGuildStageVoiceResult = channel.isGuildStageVoice();
}
allActiveStreamKeys = StreamRTCConnectionStore.getAllActiveStreamKeys();
if (!allActiveStreamKeys.includes(encodeStreamKeyResult)) {
let timeout = closure_13[encodeStreamKeyResult];
const tmp5 = closure_13;
if (timeout == null) {
const self = this;
const self2 = this;
timeout = new Timers.Timeout();
}
tmp5[encodeStreamKeyResult] = timeout;
timeout.start(isGuildStageVoiceResult ? closure_16 : closure_15, () => {
const obj = closure_2_1(closure_2_2[13]);
const obj2 = { type: "STREAM_TIMED_OUT", streamKey: encodeStreamKeyResult };
obj.dispatch(obj2);
});
}
const result = require.platformHandleStreamStart(channelId);
};
applyArgumentsResult.handleStreamCreate = function handleStreamCreate(streamKey) {
streamKey = streamKey.streamKey;
const tmp = closure_1_13;
if (closure_1_13[streamKey] != null) {
closure_1_13[streamKey].stop();
}
delete tmp[streamKey];
const item = set.forEach(f135668);
const obj2 = StreamKeyUtils;
const decodeStreamKeyResult = obj2.decodeStreamKey(streamKey);
memberCount = memberCount.getMemberCount(decodeStreamKeyResult.guildId);
};
applyArgumentsResult.handleStreamUpdate = function handleStreamUpdate(streamKey) {
let obj4;
streamKey = streamKey.streamKey;
const paused = streamKey.paused;
const tmp = closure_1_13;
if (closure_1_13[streamKey] != null) {
closure_1_13[streamKey].stop();
}
delete tmp[streamKey];
const item = set.forEach(f135668);
if (!paused) {
const rTCConnection = StreamRTCConnectionStore.getRTCConnection(streamKey);
let mediaEngineConnectionId;
if (rTCConnection != null) {
mediaEngineConnectionId = rTCConnection.getMediaEngineConnectionId();
}
if (null != mediaEngineConnectionId) {
const obj2 = { type: "MEDIA_ENGINE_CONNECTION_USER_STATS_RESET", mediaEngineConnectionId, userId: obj4.decodeStreamKey(streamKey).ownerId };
const dispatch = DispatcherDefault.dispatch;
DispatcherDefault;
obj4 = StreamKeyUtils;
dispatch(obj2);
}
}
};
applyArgumentsResult.handleStreamDelete = function handleStreamDelete(streamKey) {
streamKey = streamKey.streamKey;
const reason = streamKey.reason;
const tmp = closure_13;
if (closure_13[streamKey] != null) {
closure_13[streamKey].stop();
}
delete tmp[streamKey];
if (reason === constants.STREAM_FULL) {
const obj2 = { type: AVError.AVError.STREAM_FULL };
const reportAVError = AVError.reportAVError;
AVError;
const obj3 = AVErrorContext;
const merged = Object.assign(obj3.getStreamErrorContext(streamKey));
reportAVError(obj2);
const obj4 = set;
if (!set.has(streamKey)) {
obj4.add(streamKey);
const result = require.platformShowStreamFull();
}
}
};
applyArgumentsResult.handleStreamClose = function handleStreamClose(streamKey) {
streamKey = streamKey.streamKey;
const tmp = closure_1_12;
if (closure_1_12[streamKey] != null) {
closure_1_12[streamKey].stop();
}
delete tmp[streamKey];
const tmp3 = closure_1_13;
if (closure_1_13[streamKey] != null) {
closure_1_13[streamKey].stop();
}
delete tmp3[streamKey];
};
applyArgumentsResult.handleVoiceChannelSelect = function handleVoiceChannelSelect(channelId) {
let id;
channelId = channelId.channelId;
if (null != channelId) {
c17 = null;
const item = set.forEach(f135668);
const allApplicationStreamsForChannel = authStore.getAllApplicationStreamsForChannel(channelId);
const found = allApplicationStreamsForChannel.find((ownerId) => {
let tmp = ownerId.ownerId !== id.getId();
if (tmp) {
isStreamMarkedFull = isStreamMarkedFull.isStreamMarkedFull;
const obj = closure_1_0(closure_1_2[14]);
tmp = !isStreamMarkedFull(obj.encodeStreamKey(ownerId));
}
return tmp;
});
if (null != found) {
const ownerId = found.ownerId;
if (SelectedChannelStore.getVoiceChannelId() === channelId) {
channel = ChannelStore.getChannel(channelId);
if (null != channel) {
if (channel.isDM()) {
if (null == authStore.getActiveStreamForUser(ownerId, channel.getGuildId())) {
const streamForUser = obj3.getStreamForUser(ownerId, channel.getGuildId());
if (null != streamForUser) {
let obj = StreamKeyUtils;
const encodeStreamKeyResult = obj.encodeStreamKey(streamForUser);
const tmp2 = require;
const tmp3 = dependencyMap;
if (encodeStreamKeyResult !== c17) {
const tmp7 = !authStore.isStreamMarkedFull(encodeStreamKeyResult);
if (tmp7) {
c17 = encodeStreamKeyResult;
const tmp2Result = tmp2(tmp3[11]);
tmp2Result.watchStream(streamForUser, { noFocus: true });
}
}
}
}
}
}
}
}
}
};
applyArgumentsResult.handleVoiceStateUpdates = function handleVoiceStateUpdates(voiceStates) {
voiceStates = voiceStates.voiceStates;
let item = voiceStates.forEach(function(item) {
let channelId;
let guildId;
let selfStream;
let streamMarkedFull;
let userId;
({ userId, channelId, guildId, selfStream } = item);
const result = closure_1_0.platformHandleVoiceStateUpdate(item);
if (userId !== AuthenticationStore.getId()) {
let tmp3 = !selfStream;
if (selfStream) {
tmp3 = null == channelId;
}
if (tmp3) {
tmp3 = set.size > 0;
}
if (tmp3) {
item = set.forEach(f135668);
}
if (null != channelId) {
if (selfStream) {
if (SelectedChannelStore.getVoiceChannelId() === channelId) {
channel = ChannelStore.getChannel(channelId);
if (null != channel) {
if (channel.isDM()) {
let obj = authStore;
if (null == authStore.getActiveStreamForUser(userId, channel.getGuildId())) {
const streamForUser = obj.getStreamForUser(userId, channel.getGuildId());
if (null != streamForUser) {
const obj2 = StreamKeyUtils;
const encodeStreamKeyResult = obj2.encodeStreamKey(streamForUser);
let tmp14 = encodeStreamKeyResult !== c17;
const tmp10 = require;
const tmp11 = dependencyMap;
if (tmp14) {
let flag2 = !obj.isStreamMarkedFull(encodeStreamKeyResult);
obj.isStreamMarkedFull(encodeStreamKeyResult);
if (flag2) {
c17 = encodeStreamKeyResult;
const tmp10Result = tmp10(tmp11[11]);
tmp10Result.watchStream(streamForUser, { noFocus: true });
flag2 = true;
}
tmp14 = flag2;
}
}
}
}
}
}
}
const activeStreamForUser = authStore.getActiveStreamForUser(userId, guildId);
if (null != activeStreamForUser) {
if (activeStreamForUser.channelId === channelId) {
if (!selfStream) {
if (activeStreamForUser.state !== constants.ENDED) {
const obj5 = StreamKeyUtils;
const encodeStreamKeyResult1 = obj5.encodeStreamKey(activeStreamForUser);
let timeout = closure_2_12[encodeStreamKeyResult1];
const tmp19 = require;
const tmp20 = dependencyMap;
const tmp22 = closure_2_12;
if (timeout == null) {
const self = this;
const self2 = this;
timeout = new tmp19(tmp20[15]).Timeout();
}
timeout.start(closure_2_14, () => {
const obj = closure_2_0(closure_2_2[11]);
return obj.closeStream(encodeStreamKeyResult1, false);
});
tmp22[encodeStreamKeyResult1] = timeout;
}
}
if (selfStream) {
if (activeStreamForUser.state === constants.ENDED) {
const obj10 = StreamKeyUtils;
const obj11 = closure_2_12[obj10.encodeStreamKey(activeStreamForUser)];
const tmp33 = closure_2_12;
if (obj11 != null) {
obj11.stop();
}
delete tmp33[tmp32];
const streamForUser1 = obj4.getStreamForUser(userId, guildId);
if (null != streamForUser1) {
const isStreamMarkedFull = obj4.isStreamMarkedFull;
const tmp30Result = StreamKeyUtils;
if (!isStreamMarkedFull(tmp30Result.encodeStreamKey(streamForUser1))) {
const tmp30Result2 = StreamActionCreators;
tmp30Result2.watchStream(streamForUser1);
}
}
}
}
}
}
}
}
});
};
applyArgumentsResult.handleCallUpdate = function handleCallUpdate(region) {
region = region.region;
const channelId = region.channelId;
const currentUserActiveStream = authStore.getCurrentUserActiveStream();
let channelId1;
if (currentUserActiveStream != null) {
channelId1 = currentUserActiveStream.channelId;
}
if (channelId1 === channelId) {
const obj = StreamKeyUtils;
const encodeStreamKeyResult = obj.encodeStreamKey(currentUserActiveStream);
const tmp3 = require;
const tmp4 = dependencyMap;
if (region == null) {
region = RTCRegionStore.getPreferredRegion();
}
const tmp7 = null != region && region !== RTCRegionStore.getRegion(StreamRTCConnectionStore.getHostname(encodeStreamKeyResult));
if (tmp7) {
const tmp3Result = tmp3(tmp4[11]);
tmp3Result.changeStreamRegion(encodeStreamKeyResult, region);
}
}
};
applyArgumentsResult.handleChannelUpdates = function handleChannelUpdates(channels) {
channels = channels.channels;
const currentUserActiveStream = authStore.getCurrentUserActiveStream();
if (null != currentUserActiveStream) {
const iter = channels[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
if (currentUserActiveStream.channelId === nextResult.id) {
let obj = StreamKeyUtils;
let tmp11 = updateRegion(obj.encodeStreamKey(currentUserActiveStream), tmp6.rtcRegion);
}
continue;
}
}
};
applyArgumentsResult.handleSessionReset = function handleSessionReset() {
set.clear();
};
applyArgumentsResult.actions = { STREAM_WATCH: applyArgumentsResult.handleStreamWatch, STREAM_START: applyArgumentsResult.handleStreamStart, STREAM_CREATE: applyArgumentsResult.handleStreamCreate, STREAM_UPDATE: applyArgumentsResult.handleStreamUpdate, STREAM_DELETE: applyArgumentsResult.handleStreamDelete, STREAM_CLOSE: applyArgumentsResult.handleStreamClose, CALL_UPDATE: applyArgumentsResult.handleCallUpdate, CHANNEL_UPDATES: applyArgumentsResult.handleChannelUpdates, VOICE_CHANNEL_SELECT: applyArgumentsResult.handleVoiceChannelSelect, VOICE_STATE_UPDATES: applyArgumentsResult.handleVoiceStateUpdates, CONNECTION_CLOSED: applyArgumentsResult.handleSessionReset, LOGOUT: applyArgumentsResult.handleSessionReset };
return applyArgumentsResult;
}
}
let result = size.fileFinishedImporting("modules/go_live/ApplicationStreamingManager.tsx");
export default BaseApplicationStreamingManager;