422 lines
15 KiB
TypeScript
422 lines
15 KiB
TypeScript
// Module ID: 17999
|
|
// Function ID: 18000
|
|
// Name: clips/ClipsManager
|
|
// Dependencies: [5, 4935, 502, 2051, 1999, 4913, 4929, 2005, 7231, 1085, 4932, 6613, 13486, 4945, 4942, 1252, 2028, 584, 13487, 4490, 1369, 13485, 2]
|
|
|
|
// Module 17999 (clips/ClipsManager)
|
|
import DispatcherDefault from "Dispatcher" /* 584 */;
|
|
import AnalyticsUtilsDefault from "AnalyticsUtils" /* 1252 */;
|
|
import PlatformUtils from "PlatformUtils" /* 1369 */;
|
|
import UserSettings from "UserSettings" /* 2028 */;
|
|
import DiscordNativeDefault from "DiscordNative" /* 4490 */;
|
|
import Constants2 from "Constants" /* 4932 */;
|
|
import SystemAnalyticsStore from "SystemAnalyticsStore" /* 4935 */;
|
|
import StreamKeyUtils from "StreamKeyUtils" /* 4942 */;
|
|
import BaseConnectionEvent from "BaseConnectionEvent" /* 4945 */;
|
|
import isClipsEnabled from "isClipsEnabled" /* 13485 */;
|
|
import ClipsExperiment from "ClipsExperiment" /* 13486 */;
|
|
import isClientClipsCapableDefault from "isClientClipsCapable" /* 13487 */;
|
|
import _asyncToGenerator from "_asyncToGenerator" /* 5 */;
|
|
import AuthenticationStore from "AuthenticationStore" /* 502 */;
|
|
import ChannelStore from "ChannelStore" /* 2051 */;
|
|
import MediaEngineStore from "MediaEngineStore" /* 1999 */;
|
|
import RTCConnectionStore from "RTCConnectionStore" /* 4913 */;
|
|
import StreamRTCConnectionStore from "StreamRTCConnectionStore" /* 4929 */;
|
|
import ClipsStore from "ClipsStore" /* 2005 */;
|
|
import ClipsConstants from "ClipsConstants" /* 7231 */;
|
|
import Constants from "Constants" /* 1085 */;
|
|
import AutomaticLifecycleManager from "AutomaticLifecycleManager" /* 6613 */;
|
|
import size from "module_2" /* 2 */;
|
|
|
|
const StreamKeyUtilsAll = StreamKeyUtils;
|
|
let _self, c4, c5;
|
|
|
|
let closure_12;
|
|
let closure_14;
|
|
let closure_15;
|
|
let closure_16;
|
|
let closure_17;
|
|
let closure_18;
|
|
let map1;
|
|
const getSystemAnalyticsInfo = SystemAnalyticsStore.getSystemAnalyticsInfo;
|
|
({ WINDOWS_HARDWARE_AUTO_ENABLE_GPU_REGEX: closure_12, WINDOWS_HARDWARE_MINIMUM_GPU_REGEX: map1, CLIPS_HARDWARE_CLASSIFICATION_VERSION: closure_14, ClipsHardwareClassification: closure_15, CLIP_RUNTIME: closure_16 } = ClipsConstants);
|
|
({ AnalyticEvents: closure_17, RTCConnectionStates: closure_18 } = Constants);
|
|
const StreamTypes = Constants2.StreamTypes;
|
|
class ClipsManager extends AutomaticLifecycleManager {
|
|
constructor() {
|
|
const applyArgumentsResult = HermesBuiltin.applyArguments(this, new.target);
|
|
applyArgumentsResult.actions = {
|
|
POST_CONNECTION_OPEN() {
|
|
return applyArgumentsResult.handlePostConnectionOpen();
|
|
},
|
|
RTC_CONNECTION_FLAGS(arg0) {
|
|
return applyArgumentsResult.handleRTCConnectionFlags(arg0);
|
|
},
|
|
RTC_CONNECTION_USERS_MERGED(userIds) {
|
|
return applyArgumentsResult.handleRTCUsersUpdate(userIds);
|
|
},
|
|
CLIPS_INIT_FAILURE(arg0) {
|
|
return applyArgumentsResult.handleClipsInitFailure(arg0);
|
|
},
|
|
CLIPS_SETTINGS_UPDATE(arg0) {
|
|
return applyArgumentsResult.applyNativeClipsSettings(arg0);
|
|
},
|
|
CLIPS_ALLOW_VOICE_RECORDING_UPDATE() {
|
|
return applyArgumentsResult.handleClipsAllowVoiceRecordingUpdate();
|
|
},
|
|
STREAM_START() {
|
|
return applyArgumentsResult.applyNativeClipsSettings();
|
|
},
|
|
STREAM_DELETE(arg0) {
|
|
return applyArgumentsResult.handleStreamEnded(arg0);
|
|
},
|
|
STREAM_CLOSE(arg0) {
|
|
return applyArgumentsResult.handleStreamEnded(arg0);
|
|
},
|
|
RUNNING_GAME_TOGGLE_DETECTION(arg0) {
|
|
return applyArgumentsResult.handleClipsInitOnToggleDetection(arg0);
|
|
},
|
|
RUNNING_GAMES_CHANGE(arg0) {
|
|
return applyArgumentsResult.handleClipsInitOnGamesChange(arg0);
|
|
},
|
|
CLIPS_RESTART() {
|
|
return applyArgumentsResult.fireClipsInitEvent(true);
|
|
},
|
|
RTC_CONNECTION_VIDEO(arg0) {
|
|
return applyArgumentsResult.handleRTCConnectionVideo(arg0);
|
|
},
|
|
RTC_CONNECTION_STATE(arg0) {
|
|
return applyArgumentsResult.handleRTCConnectionState(arg0);
|
|
}
|
|
};
|
|
return applyArgumentsResult;
|
|
}
|
|
handleRTCConnectionState(state) {
|
|
let context;
|
|
let streamKey;
|
|
({ context, streamKey } = state);
|
|
state = state.state;
|
|
const obj = ClipsExperiment;
|
|
if (obj.areClipsAvailable()) {
|
|
if (state === constants3.RTC_CONNECTED) {
|
|
const self = this;
|
|
const id = AuthenticationStore.getId();
|
|
if (BaseConnectionEvent.MediaEngineContextTypes.DEFAULT === context) {
|
|
const result = self.applyUserVoiceRecording(id);
|
|
const result1 = self.applyUserSoundboardRecording(id);
|
|
} else if (BaseConnectionEvent.MediaEngineContextTypes.STREAM === context) {
|
|
if (null != streamKey) {
|
|
const tmpResult = StreamKeyUtils;
|
|
if (tmpResult.decodeStreamKey(streamKey).ownerId === id) {
|
|
const rTCConnection = StreamRTCConnectionStore.getRTCConnection(streamKey);
|
|
if (null != rTCConnection) {
|
|
self.applyStreamRecording(id, rTCConnection);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
handleRTCUsersUpdate(userIds) {
|
|
const self = this;
|
|
userIds = userIds.userIds;
|
|
if (userIds.context === BaseConnectionEvent.MediaEngineContextTypes.DEFAULT) {
|
|
const item = userIds.forEach((item) => {
|
|
const result = self.applyUserVoiceRecording(item);
|
|
const result1 = self.applyUserSoundboardRecording(item);
|
|
});
|
|
}
|
|
}
|
|
handleRTCConnectionFlags(arg0) {
|
|
let CALL;
|
|
let channelId;
|
|
let guildId;
|
|
let userId;
|
|
const self = this;
|
|
({ userId, guildId, channelId } = arg0);
|
|
const result = this.maybeShowClipsWarning(userId);
|
|
const result1 = this.applyUserVoiceRecording(userId);
|
|
const result2 = this.applyUserSoundboardRecording(userId);
|
|
const getRTCConnection = StreamRTCConnectionStore.getRTCConnection;
|
|
const encodeStreamKey = StreamKeyUtilsAll.encodeStreamKey;
|
|
StreamKeyUtilsAll;
|
|
if (null != guildId) {
|
|
CALL = StreamTypes.GUILD;
|
|
} else {
|
|
CALL = StreamTypes.CALL;
|
|
}
|
|
const rTCConnection = getRTCConnection(encodeStreamKey({ streamType: CALL, ownerId: userId, channelId, guildId }));
|
|
if (null != rTCConnection) {
|
|
self.applyStreamRecording(userId, rTCConnection);
|
|
}
|
|
}
|
|
handleClipsInitFailure(arg0) {
|
|
let applicationName;
|
|
let errMsg;
|
|
({ applicationName, errMsg } = arg0);
|
|
const obj = AnalyticsUtilsDefault;
|
|
const obj2 = { application_name: applicationName, error_message: errMsg, clip_runtime };
|
|
obj.track(constants2.CLIPS_INIT_FAILURE, obj2);
|
|
}
|
|
maybeShowClipsWarning(userId) {
|
|
const channelId = RTCConnectionStore.getChannelId();
|
|
if (null != channelId) {
|
|
const obj3 = ClipsStore;
|
|
if (!ClipsStore.getClipsWarningShown(channelId)) {
|
|
let setting = userId !== AuthenticationStore.getId() && obj3.isClipsEnabledForUser(userId);
|
|
if (setting) {
|
|
const ClipsAllowVoiceRecording = UserSettings.ClipsAllowVoiceRecording;
|
|
setting = ClipsAllowVoiceRecording.getSetting();
|
|
}
|
|
if (setting) {
|
|
const self = this;
|
|
const obj2 = { type: "CLIPS_SHOW_CALL_WARNING", channelId };
|
|
const obj = DispatcherDefault;
|
|
obj.dispatch(obj2);
|
|
this.showClipsToast();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
handleClipsAllowVoiceRecordingUpdate() {
|
|
const self = this;
|
|
const userIds = RTCConnectionStore.getUserIds();
|
|
if (userIds != null) {
|
|
const item = userIds.forEach((item) => self.maybeShowClipsWarning(item));
|
|
}
|
|
}
|
|
handlePostConnectionOpen() {
|
|
if (isClientClipsCapableDefault(MediaEngineStore)) {
|
|
const self = this;
|
|
const result = this.applyNativeClipsSettings();
|
|
let obj = ClipsExperiment;
|
|
if (obj.areClipsAvailable()) {
|
|
const clipsFromStorage = self.loadClipsFromStorage();
|
|
self.maybeStartNtpClock();
|
|
let obj2 = ClipsStore;
|
|
const tmp7 = null != ClipsStore.getHardwareClassification() && null != obj2.getHardwareClassificationForDecoupled() && obj2.getHardwareClassificationVersion() === authStore2;
|
|
if (!tmp7) {
|
|
const result1 = self.classifyHardwareAndTrack();
|
|
result1.then((classification) => {
|
|
const obj = DispatcherDefault;
|
|
const obj2 = { type: "CLIPS_CLASSIFY_HARDWARE", classification };
|
|
obj.dispatch(obj2);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
loadClipsFromStorage() {
|
|
|
|
}
|
|
handleRTCConnectionVideo(arg0) {
|
|
let channelId;
|
|
let context;
|
|
let guildId;
|
|
let userId;
|
|
({ userId, guildId } = arg0);
|
|
({ context, channelId } = arg0);
|
|
if (context === BaseConnectionEvent.MediaEngineContextTypes.STREAM) {
|
|
if (isClientClipsCapableDefault(MediaEngineStore)) {
|
|
let CALL;
|
|
const getRTCConnection = StreamRTCConnectionStore.getRTCConnection;
|
|
const encodeStreamKey = StreamKeyUtilsAll.encodeStreamKey;
|
|
StreamKeyUtilsAll;
|
|
if (null != guildId) {
|
|
CALL = StreamTypes.GUILD;
|
|
} else {
|
|
CALL = StreamTypes.CALL;
|
|
}
|
|
const obj = { streamType: CALL, ownerId: userId, channelId, guildId };
|
|
const rTCConnection = getRTCConnection(encodeStreamKey(obj));
|
|
if (null != rTCConnection) {
|
|
const self = this;
|
|
this.applyStreamRecording(userId, rTCConnection);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
classifyHardwareAndTrack() {
|
|
const self = this;
|
|
return (async (arg0, value) => {
|
|
let closure_0;
|
|
let closure_1;
|
|
let tmp;
|
|
let v1;
|
|
if (c5 === 2) {
|
|
c5 = 3;
|
|
const str = "Generator functions may not be called on executing generators";
|
|
throw new TypeError("Generator functions may not be called on executing generators");
|
|
} else if (tmp3 === 3) {
|
|
if (arg0 === 1) {
|
|
throw value;
|
|
} else if (arg0 === 2) {
|
|
const obj2 = { value, done: true };
|
|
return obj2;
|
|
} else {
|
|
return { value: "IconComponent", done: null };
|
|
}
|
|
} else {
|
|
let c3;
|
|
try {
|
|
let gpuModels;
|
|
let classification;
|
|
c5 = 2;
|
|
const tmp4 = c4;
|
|
if (0 === c4) {
|
|
if (arg0 === 1) {
|
|
c5 = 3;
|
|
throw value;
|
|
} else if (arg0 === 2) {
|
|
c5 = 3;
|
|
const obj3 = { value, done: true };
|
|
return obj3;
|
|
} else {
|
|
_self = undefined;
|
|
gpuModels = undefined;
|
|
classification = undefined;
|
|
c3 = 1;
|
|
c4 = 2;
|
|
c5 = 1;
|
|
const obj4 = {
|
|
value: c4(function*() {
|
|
let gpus;
|
|
let gpuModels = tmp4;
|
|
const tmp = yield closure_2_5();
|
|
if (tmp != null) {
|
|
gpus = tmp.gpus;
|
|
}
|
|
if (null != gpus) {
|
|
const gpus1 = tmp.gpus;
|
|
const mapped = gpus1.map((brand) => brand.brand);
|
|
gpuModels = mapped.filter((item) => null != item && "" !== item);
|
|
const obj6 = { gpuModels, classification: tmp.classifyHardware(gpuModels) };
|
|
return obj6;
|
|
}
|
|
const processUtils = closure_2_1(closure_2_3[19]).processUtils;
|
|
yield processUtils.getSystemInfo();
|
|
const gpus2 = arg1.gpus;
|
|
const gpuModels2 = gpus2.map((model) => model.model);
|
|
const obj = { gpuModels: gpuModels2, classification: tmp.classifyHardware(gpuModels2) };
|
|
return obj;
|
|
})(),
|
|
done: false
|
|
};
|
|
return obj4;
|
|
}
|
|
} else if (1 === tmp4) {
|
|
c3 = 0;
|
|
c5 = 3;
|
|
const obj5 = { value: constants.UNKNOWN, done: true };
|
|
return obj5;
|
|
} else if (arg0 === 1) {
|
|
c5 = 3;
|
|
throw value;
|
|
} else if (arg0 === 2) {
|
|
c3 = 0;
|
|
c5 = 3;
|
|
let obj6 = { value, done: true };
|
|
return obj6;
|
|
} else {
|
|
_self = value;
|
|
gpuModels = _self.gpuModels;
|
|
classification = _self.classification;
|
|
const obj7 = tmp(c3[15]);
|
|
const obj8 = { classification, version, gpu_models: gpuModels, clip_runtime };
|
|
obj7.track(constants2.CLIPS_HARDWARE_CLASSIFICATION, obj8);
|
|
c3 = 0;
|
|
c5 = 3;
|
|
let obj = { value: classification, done: true };
|
|
return obj;
|
|
}
|
|
} catch (tmp9) {
|
|
let closure_2 = tmp9;
|
|
if (0 === c3) {
|
|
c5 = 3;
|
|
throw tmp9;
|
|
} else {
|
|
c4 = 1;
|
|
}
|
|
}
|
|
}
|
|
})();
|
|
}
|
|
classifyHardware(arr) {
|
|
let regex;
|
|
let regex2;
|
|
const obj = PlatformUtils;
|
|
if (obj.isWindows()) {
|
|
let MEETS_AUTO_ENABLE;
|
|
const someResult = arr.some((item) => regex.test(item));
|
|
if (someResult) {
|
|
MEETS_AUTO_ENABLE = tmp10.MEETS_AUTO_ENABLE;
|
|
} else {
|
|
MEETS_AUTO_ENABLE = tmp9 ? tmp10.MEETS_MINIMUM : tmp10.BELOW_MINIMUM;
|
|
}
|
|
return MEETS_AUTO_ENABLE;
|
|
} else {
|
|
let UNKNOWN;
|
|
const tmpResult = PlatformUtils;
|
|
if (tmpResult.isMac()) {
|
|
let MEETS_MINIMUM;
|
|
const app = DiscordNativeDefault.app;
|
|
if ("arm64" === app.getAppArch()) {
|
|
MEETS_MINIMUM = constants.MEETS_AUTO_ENABLE;
|
|
} else {
|
|
MEETS_MINIMUM = constants.MEETS_MINIMUM;
|
|
}
|
|
UNKNOWN = MEETS_MINIMUM;
|
|
} else {
|
|
UNKNOWN = constants.UNKNOWN;
|
|
}
|
|
return UNKNOWN;
|
|
}
|
|
}
|
|
applyUserVoiceRecording(id) {
|
|
if (isClientClipsCapableDefault(MediaEngineStore)) {
|
|
const rTCConnection = RTCConnectionStore.getRTCConnection();
|
|
const obj = RTCConnectionStore;
|
|
if (null != rTCConnection) {
|
|
const channel = ChannelStore.getChannel(obj.getChannelId());
|
|
let isGuildStageVoiceResult;
|
|
if (channel != null) {
|
|
isGuildStageVoiceResult = channel.isGuildStageVoice();
|
|
}
|
|
if (isGuildStageVoiceResult) {
|
|
rTCConnection.setClipRecordUser(id, "audio", false);
|
|
} else if (id !== AuthenticationStore.getId()) {
|
|
rTCConnection.setClipRecordUser(id, "audio", ClipsStore.isVoiceRecordingAllowedForUser(id));
|
|
} else {
|
|
const setClipRecordUser = rTCConnection.setClipRecordUser;
|
|
const obj3 = isClipsEnabled;
|
|
setClipRecordUser(id, "audio", obj3.isClipsEnabled());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
applyUserSoundboardRecording(id) {
|
|
if (isClientClipsCapableDefault(MediaEngineStore)) {
|
|
const rTCConnection = RTCConnectionStore.getRTCConnection();
|
|
if (null != rTCConnection) {
|
|
const setClipRecordUser = rTCConnection.setClipRecordUser;
|
|
const obj = isClipsEnabled;
|
|
setClipRecordUser(id, "soundboard", obj.isClipsEnabled());
|
|
}
|
|
}
|
|
}
|
|
applyStreamRecording(userId, rTCConnection) {
|
|
if (isClientClipsCapableDefault(MediaEngineStore)) {
|
|
if (AuthenticationStore.getId() === userId) {
|
|
const obj = isClipsEnabled;
|
|
const isClipsEnabledResult = obj.isClipsEnabled();
|
|
rTCConnection.setClipRecordUser(userId, "audio", isClipsEnabledResult);
|
|
rTCConnection.setClipRecordUser(userId, "video", isClipsEnabledResult);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const prototype = ClipsManager.prototype;
|
|
let result = size.fileFinishedImporting("modules/clips/ClipsManager.tsx");
|
|
|
|
export default ClipsManager;
|