Files
discord-decomp/actions/AudioActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

530 lines
18 KiB
TypeScript

// Metro module 8838 (f8839).
import CertifiedDeviceStore from "../stores/CertifiedDeviceStore";
import ChannelStore from "../stores/ChannelStore";
import MediaEngineStore from "../stores/MediaEngineStore";
import RTCConnectionStore from "../stores/RTCConnectionStore";
import SelectedChannelStore from "../stores/SelectedChannelStore";
import UserStore from "../stores/UserStore";
import { AnalyticEvents, InputModes } from "../Constants";
import { SoundOutputChannel } from "../modules/sound_playback/Constants";
import { MediaEngineContextTypes } from "../_bundle/Module4250";
import Logger from "../modules/debug/Logger";
import AnalyticsUtils from "../utils/AnalyticsUtils";
import debounce from "../_bundle/debounce";
import Dispatcher from "../Dispatcher";
import { snapVolumeToDefault } from "../modules/user_settings/voice/AudioSettingsUtils";
import trackVoiceAndVideoSettingsUpdate from "../modules/user_settings/voice/trackVoiceAndVideoSettingsUpdate";
import { applyInitialVideoBackgroundOption } from "../modules/video_backgrounds/applyBackgroundOption";
import { trackStreamSettingsUpdate } from "../utils/StreamQualityUtils";
let c5763_13, c5763_15, isNotSupported, trackToggleSelfMute, trackToggleSelfDeaf;
const trackDeviceChanged = function trackDeviceChanged(a0, a1, a2, a3, r3) {
const { location: location2, analyticsLocations } = r3;
if (a1 !== a2) {
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
const r10 = voiceChannelId != null ? ChannelStore.getChannel(voiceChannelId) : null;
const r23 = a0[a1];
const r12 = a0[a2];
const audioSubsystem = MediaEngineStore.getMediaEngine().getAudioSubsystem();
const audioLayer = MediaEngineStore.getMediaEngine().getAudioLayer();
const MEDIA_DEVICE_CHANGED = AnalyticEvents.MEDIA_DEVICE_CHANGED;
const r2 = r23 != null;
let r16 = "";
const r40 = {
device_from_name: CertifiedDeviceStore.getCertifiedDeviceName(a1, r2 ? r23.name : ""),
device_to_name: null,
device_type: null,
device_is_certified: null,
location: null,
location_stack: null,
voice_channel_type: null,
audio_subsystem: null,
audio_layer: null
};
if (r12 != null) {
r16 = r12.name;
}
r40.device_to_name = CertifiedDeviceStore.getCertifiedDeviceName(a2, r16);
r40.device_type = a3;
r40.device_is_certified = CertifiedDeviceStore.isCertified(a2);
r40.location = location2;
r40.location_stack = analyticsLocations;
r40.voice_channel_type = r10?.type;
r40.audio_subsystem = audioSubsystem;
r40.audio_layer = audioLayer;
AnalyticsUtils.track(MEDIA_DEVICE_CHANGED, r40);
}
};
SoundOutputChannel;
c5763_13 = new Logger("AudioActionCreators");
c5763_13.enableNativeLogger(true);
c5763_15 = debounce((a0, a1, a2) => {
AnalyticsUtils.track(AnalyticEvents.USER_VOLUME_SETTING_UPDATED, {
target_user_id: a0,
context: a1,
volume: a2,
media_session_id: RTCConnectionStore.getMediaSessionId(),
rtc_connection_id: RTCConnectionStore.getRTCConnectionId()
});
}, 300);
isNotSupported = () => false;
trackToggleSelfMute = () => {};
trackToggleSelfDeaf = () => {};
const r58 = {
enable: () => Promise.resolve(true),
toggleSelfMute: function toggleSelfMute(r2 = {}) {
const { context = MediaEngineContextTypes.DEFAULT, syncRemote = true } = r2;
if (r2.usedKeybind !== void 0) {
let playSoundEffect = r2.playSoundEffect;
if (playSoundEffect === void 0) {
playSoundEffect = true;
}
r2.location;
if (playSoundEffect) {
playSoundEffect = !MediaEngineStore.hasActiveCallKitCall();
}
const currentUser = UserStore.getCurrentUser();
if (currentUser == null ? void 0 : currentUser.isStaff()) {
c5763_13.info("Toggling self mute");
}
return MediaEngineStore.isEnabled() ? Dispatcher.dispatch({
type: "AUDIO_TOGGLE_SELF_MUTE",
context,
syncRemote,
playSoundEffect
}) : this.enable(true);
}
},
setSelfMute: function setSelfMute(a0, a1, playSoundEffect = true) {
if (playSoundEffect) {
playSoundEffect = !MediaEngineStore.hasActiveCallKitCall();
}
const currentUser = UserStore.getCurrentUser();
if (currentUser == null ? void 0 : currentUser.isStaff()) {
c5763_13.info("Setting self mute", a1);
}
Dispatcher.dispatch({
type: "AUDIO_SET_SELF_MUTE",
context: a0,
mute: a1,
playSoundEffect
});
},
setTemporarySelfMute: (a0) => {
const currentUser = UserStore.getCurrentUser();
if (currentUser == null ? void 0 : currentUser.isStaff()) {
c5763_13.info("Setting temporary self mute", a0);
}
Dispatcher.dispatch({
type: "AUDIO_SET_TEMPORARY_SELF_MUTE",
mute: a0
});
},
toggleSelfDeaf: function toggleSelfDeaf(r3 = {}) {
const { context = MediaEngineContextTypes.DEFAULT, syncRemote = true } = r3;
if (r3.usedKeybind !== void 0) {
r3.location;
Dispatcher.dispatch({
type: "AUDIO_TOGGLE_SELF_DEAF",
context,
syncRemote
});
return void 0;
}
},
toggleLocalMute: function toggleLocalMute(a0, context = MediaEngineContextTypes.DEFAULT) {
Dispatcher.dispatch({
type: "AUDIO_TOGGLE_LOCAL_MUTE",
context,
userId: a0
});
},
toggleLocalSoundboardMute: function toggleLocalSoundboardMute(a0, context = MediaEngineContextTypes.DEFAULT) {
Dispatcher.dispatch({
type: "AUDIO_TOGGLE_LOCAL_SOUNDBOARD_MUTE",
context,
userId: a0
});
},
setDisableLocalVideo: function setDisableLocalVideo(a0, a1, context = MediaEngineContextTypes.DEFAULT, persist = true, isAutomatic = false) {
Dispatcher.dispatch({
type: "AUDIO_SET_LOCAL_VIDEO_DISABLED",
context,
userId: a0,
videoToggleState: a1,
persist,
isAutomatic
});
},
setLocalVolume: function setLocalVolume(a0, a1, context = MediaEngineContextTypes.DEFAULT) {
const volume = snapVolumeToDefault(a1, context);
Dispatcher.dispatch({
type: "AUDIO_SET_LOCAL_VOLUME",
context,
userId: a0,
volume
});
c5763_15(a0, context, volume);
},
setAudioMixerSettings: function setAudioMixerSettings(a0, context = MediaEngineContextTypes.DEFAULT) {
Dispatcher.dispatch({
type: "AUDIO_SET_AUDIO_MIXER_SETTINGS",
context,
settings: a0
});
},
setSpatialAudio: (a0, a1) => {
const audioMixerSettings = MediaEngineStore.getAudioMixerSettings();
trackVoiceAndVideoSettingsUpdate("spatial_audio_enabled", a0, audioMixerSettings.enabled, a1);
Dispatcher.dispatch({
type: "AUDIO_SET_AUDIO_MIXER_SETTINGS",
context: MediaEngineContextTypes.DEFAULT,
settings: {
...audioMixerSettings,
enabled: a0
}
});
},
setLocalPan: function setLocalPan(a0, a1, a2, context = MediaEngineContextTypes.DEFAULT) {
Dispatcher.dispatch({
type: "AUDIO_SET_LOCAL_PAN",
context,
userId: a0,
left: a1,
right: a2
});
},
setMode: function setMode(a0, r11 = {}, context = MediaEngineContextTypes.DEFAULT, r22 = {}) {
const analyticsLocations = r22.analyticsLocations;
const mode = MediaEngineStore.getMode();
const modeOptions = MediaEngineStore.getModeOptions(context);
Dispatcher.dispatch({
type: "AUDIO_SET_MODE",
context,
mode: a0,
options: {
...modeOptions,
...r11
}
});
if (a0 !== mode) {
const audioSubsystem2 = MediaEngineStore.getMediaEngine().getAudioSubsystem();
const audioLayer2 = MediaEngineStore.getMediaEngine().getAudioLayer();
const voiceChannelId2 = SelectedChannelStore.getVoiceChannelId();
const r81 = voiceChannelId2 != null ? ChannelStore.getChannel(voiceChannelId2) : null;
const r88 = MediaEngineStore.getInputDevices()[MediaEngineStore.getInputDeviceId()];
AnalyticsUtils.track(AnalyticEvents.VOICE_ACTIVATION_MODE_CHANGED, {
mode: a0,
location_stack: analyticsLocations,
voice_channel_type: r81?.type,
input_device_name: r88 != null ? r88.name : "",
audio_subsystem: audioSubsystem2,
audio_layer: audioLayer2
});
} else if (a0 === InputModes.VOICE_ACTIVITY && modeOptions !== r11) {
const audioSubsystem = MediaEngineStore.getMediaEngine().getAudioSubsystem();
const audioLayer = MediaEngineStore.getMediaEngine().getAudioLayer();
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
const r19 = voiceChannelId != null ? ChannelStore.getChannel(voiceChannelId) : null;
const r54 = MediaEngineStore.getInputDevices()[MediaEngineStore.getInputDeviceId()];
AnalyticsUtils.track(AnalyticEvents.VOICE_ACTIVITY_THRESHOLD_CHANGED, {
location_stack: analyticsLocations,
voice_channel_type: r19?.type,
input_device_name: r54 != null ? r54.name : "",
audio_subsystem: audioSubsystem,
audio_layer: audioLayer,
old_threshold: modeOptions.threshold,
new_threshold: r11.threshold,
old_auto_threshold: modeOptions.autoThreshold,
new_auto_threshold: r11.autoThreshold
});
}
},
setBypassSystemInputProcessing: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_BYPASS_SYSTEM_INPUT_PROCESSING",
bypassEnabled: a0,
location: a1
});
},
setInputVolume: function setInputVolume(a0, r4 = {}) {
const analyticsLocations = r4.analyticsLocations;
Dispatcher.dispatch({
type: "AUDIO_SET_INPUT_VOLUME",
volume: a0
});
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
AnalyticsUtils.track(AnalyticEvents.MEDIA_INPUT_VOLUME_CHANGED, {
volume: a0,
location_stack: analyticsLocations,
voice_channel_type: (voiceChannelId != null ? ChannelStore.getChannel(voiceChannelId) : null)?.type
});
},
setOutputVolume: function setOutputVolume(a0, r4 = {}) {
const analyticsLocations = r4.analyticsLocations;
Dispatcher.dispatch({
type: "AUDIO_SET_OUTPUT_VOLUME",
volume: a0
});
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
AnalyticsUtils.track(AnalyticEvents.MEDIA_OUTPUT_VOLUME_CHANGED, {
volume: a0,
location_stack: analyticsLocations,
voice_channel_type: (voiceChannelId != null ? ChannelStore.getChannel(voiceChannelId) : null)?.type
});
},
setInputDevice: function setInputDevice(a0, r4 = {}) {
const { location: location2, analyticsLocations } = r4;
const inputDeviceId = MediaEngineStore.getInputDeviceId();
if (!(location2 == null && analyticsLocations == null)) {
trackDeviceChanged(MediaEngineStore.getInputDevices(), inputDeviceId, a0, "Audio Input", {
location: location2,
analyticsLocations
});
}
Dispatcher.dispatch({
type: "AUDIO_SET_INPUT_DEVICE",
id: a0,
oldId: inputDeviceId
});
},
setOutputDevice: function setOutputDevice(a0, r4 = {}) {
const { location: location2, analyticsLocations } = r4;
const outputDeviceId = MediaEngineStore.getOutputDeviceId();
if (!(location2 == null && analyticsLocations == null)) {
trackDeviceChanged(MediaEngineStore.getOutputDevices(), outputDeviceId, a0, "Audio Output", {
location: location2,
analyticsLocations
});
}
Dispatcher.dispatch({
type: "AUDIO_SET_OUTPUT_DEVICE",
id: a0,
oldId: outputDeviceId
});
},
setVideoDevice: function setVideoDevice(a0, r4 = {}) {
const { location: location2, analyticsLocations } = r4;
const videoDeviceId = MediaEngineStore.getVideoDeviceId();
if (!(location2 == null && analyticsLocations == null)) {
trackDeviceChanged(MediaEngineStore.getVideoDevices(), videoDeviceId, a0, "Video", {
location: location2,
analyticsLocations
});
}
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_VIDEO_DEVICE",
id: a0,
oldId: videoDeviceId
});
},
setActiveInputProfile: function setActiveInputProfile(a0, r2 = {}) {
const analyticsLocations = r2.analyticsLocations;
let r6 = MediaEngineStore.getActiveInputProfile();
if (r6 == null) {
r6 = void 0;
}
trackVoiceAndVideoSettingsUpdate("active_input_profile", a0, r6, analyticsLocations);
Dispatcher.dispatch({
type: "AUDIO_SET_ACTIVE_INPUT_PROFILE",
inputProfile: a0
});
},
setEchoCancellation: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_ECHO_CANCELLATION",
enabled: a0,
location: a1
});
},
setSidechainCompression: function setSidechainCompression(a0, r1 = {}) {
const analyticsLocations = r1.analyticsLocations;
trackVoiceAndVideoSettingsUpdate("stream_attenuation_enabled", a0, MediaEngineStore.getSidechainCompression(), analyticsLocations);
Dispatcher.dispatch({
type: "AUDIO_SET_SIDECHAIN_COMPRESSION",
enabled: a0
});
},
setSidechainCompressionStrength: function setSidechainCompressionStrength(a0, r1 = {}) {
const analyticsLocations = r1.analyticsLocations;
trackVoiceAndVideoSettingsUpdate("stream_attenuation_strength", a0, MediaEngineStore.getSidechainCompressionStrength(), analyticsLocations);
Dispatcher.dispatch({
type: "AUDIO_SET_SIDECHAIN_COMPRESSION_STRENGTH",
strength: a0
});
},
setLoopback: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_LOOPBACK",
loopbackReason: a0,
enabled: a1
});
},
setNoiseSuppression: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_NOISE_SUPPRESSION",
enabled: a0,
location: a1
});
},
setNoiseCancellation: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_NOISE_CANCELLATION",
enabled: a0,
location: a1
});
Dispatcher.dispatch({
type: "AUDIO_SET_NOISE_SUPPRESSION",
enabled: !a0,
location: a1
});
},
setAutomaticGainControl: (a0, a1) => {
Dispatcher.dispatch({
type: "AUDIO_SET_AUTOMATIC_GAIN_CONTROL",
enabled: a0,
location: a1
});
},
setAttenuation: (a0, a1, a2) => {
const attenuation = MediaEngineStore.getAttenuation();
const attenuateWhileSpeakingSelf = MediaEngineStore.getAttenuateWhileSpeakingSelf();
const attenuateWhileSpeakingOthers = MediaEngineStore.getAttenuateWhileSpeakingOthers();
if (attenuation !== a0) {
trackVoiceAndVideoSettingsUpdate("global_attenuation_strength", a0, attenuation);
} else if (attenuateWhileSpeakingSelf !== a1) {
trackVoiceAndVideoSettingsUpdate("global_attenuation_for_self_speak_enabled", a1, attenuateWhileSpeakingSelf);
} else if (attenuateWhileSpeakingOthers !== a2) {
trackVoiceAndVideoSettingsUpdate("global_attenuation_for_other_speak_enabled", a2, attenuateWhileSpeakingOthers);
}
Dispatcher.dispatch({
type: "AUDIO_SET_ATTENUATION",
attenuation: a0,
attenuateWhileSpeakingSelf: a1,
attenuateWhileSpeakingOthers: a2
});
},
setQoS: (a0) => {
trackVoiceAndVideoSettingsUpdate("quality_of_service_packets_enabled", a0, MediaEngineStore.getQoS());
Dispatcher.dispatch({
type: "AUDIO_SET_QOS",
enabled: a0
});
},
reset: () => {
Dispatcher.dispatch({
type: "AUDIO_RESET"
});
},
setSilenceWarning: (a0) => {
trackVoiceAndVideoSettingsUpdate("silence_warning_enabled", a0, MediaEngineStore.getEnableSilenceWarning());
Dispatcher.dispatch({
type: "AUDIO_SET_DISPLAY_SILENCE_WARNING",
enabled: a0
});
},
setDebugLogging: async (c16822_0) => {
let c26290_0;
c26290_0 = void 0;
isNotSupported();
await trackVoiceAndVideoSettingsUpdate("debug_logging_enabled", c16822_0, MediaEngineStore.getDebugLogging());
Dispatcher.dispatch({
type: "AUDIO_SET_DEBUG_LOGGING",
enabled: c16822_0
});
},
setVideoHook: (a0) => {
trackVoiceAndVideoSettingsUpdate("video_hook_enabled", a0, MediaEngineStore.getVideoHook());
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_VIDEO_HOOK",
enabled: a0
});
},
setExperimentalSoundshare: (a0) => {
trackVoiceAndVideoSettingsUpdate("experimental_soundshare_enabled", a0, MediaEngineStore.getExperimentalSoundshare());
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_EXPERIMENTAL_SOUNDSHARE",
enabled: a0
});
},
setUseSystemScreensharePicker: (a0) => {
trackVoiceAndVideoSettingsUpdate("system_screenshare_picker_enabled", a0, MediaEngineStore.getUseSystemScreensharePicker());
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_USE_SYSTEM_SCREENSHARE_PICKER",
enabled: a0
});
},
setAudioSubsystem: async (c16823_0) => {
let c26291_0;
c26291_0 = void 0;
isNotSupported();
await trackVoiceAndVideoSettingsUpdate("audio_subsystem", c16823_0, MediaEngineStore.getAudioSubsystem());
Dispatcher.dispatch({
type: "AUDIO_SET_SUBSYSTEM",
subsystem: c16823_0
});
},
setVideoEnabled: (a0) => {
applyInitialVideoBackgroundOption();
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_VIDEO_ENABLED",
enabled: a0
});
},
setGoLiveSource: (a0) => {
if (a0?.qualityOptions != null) {
trackStreamSettingsUpdate(a0.qualityOptions.preset, a0.qualityOptions.resolution, a0.qualityOptions.frameRate, a0.desktopSettings?.sound);
}
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_GO_LIVE_SOURCE",
settings: a0
});
},
setAecDump: (a0) => {
trackVoiceAndVideoSettingsUpdate("diagnostic_audio_recording_enabled", a0, MediaEngineStore.getAecDump());
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_AEC_DUMP",
enabled: a0
});
},
interact: () => {
Dispatcher.dispatch({
type: "MEDIA_ENGINE_INTERACTION_REQUIRED",
required: false
});
},
setEnableHardwareMuteNotice: (a0) => {
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_ENABLE_HARDWARE_MUTE_NOTICE",
enabled: a0
});
},
setKrispSuppressionLevel: (a0) => {
Dispatcher.dispatch({
type: "AUDIO_SET_KRISP_SUPPRESSION_LEVEL",
level: a0
});
},
setKrispModelOverride: function setKrispModelOverride(a0) {
Dispatcher.dispatch({
type: "AUDIO_SET_KRISP_MODEL_OVERRIDE",
model: a0
});
if (MediaEngineStore.getNoiseCancellation()) {
this.setNoiseCancellation(false);
this.setNoiseCancellation(true);
}
},
setNoiseCancellationEnableStats: (a0) => {},
setOpenH264Enabled: (a0) => {
Dispatcher.dispatch({
type: "MEDIA_ENGINE_SET_OPENH264_ENABLED",
enabled: a0
});
},
resetMediaEngineSettings: (a0) => Dispatcher.dispatch({
type: "MEDIA_ENGINE_RESET_SETTINGS",
overrides: a0
})
};
export default r58;