Skip to content

Commit

Permalink
Merge pull request #6113 from mozilla/mute-media-loading
Browse files Browse the repository at this point in the history
Override media gain when loading the scene
  • Loading branch information
keianhzo authored Jun 6, 2023
2 parents 6a51665 + be8094b commit 5d06fd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,21 +576,13 @@ function handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data)

// Mute media until the scene has been fully loaded.
// We intentionally want voice to be unmuted.
const { globalMediaVolume } = APP.store.state.preferences;
APP.store.update({
preferences: {
globalMediaVolume: 0
}
});
const audioSystem = scene.systems["hubs-systems"].audioSystem;
audioSystem.setMediaGainOverride(0);
remountUI({
messageDispatch: messageDispatch,
onSendMessage: messageDispatch.dispatch,
onLoaded: () => {
APP.store.update({
preferences: {
globalMediaVolume
}
});
audioSystem.setMediaGainOverride(1);
store.executeOnLoadActions(scene);
},
onMediaSearchResultEntrySelected: (entry, selectAction) =>
Expand Down
8 changes: 7 additions & 1 deletion src/systems/audio-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class AudioSystem {
this.outboundGainNode.connect(this.outboundAnalyser);
this.outboundAnalyser.connect(this.mediaStreamDestinationNode);
this.audioContextNeedsToBeResumed = false;
this.mediaGainOverride = 1;

this.mediaGain = this.audioContext.createGain();
this.mixer = {
Expand Down Expand Up @@ -165,6 +166,11 @@ export class AudioSystem {
window.APP.store.addEventListener("statechanged", this.onPrefsUpdated);
}

setMediaGainOverride(gain) {
this.mediaGainOverride = gain;
this.updatePrefs();
}

addStreamToOutboundAudio(id, mediaStream) {
if (this.audioNodes.has(id)) {
this.removeStreamFromOutboundAudio(id);
Expand Down Expand Up @@ -205,7 +211,7 @@ export class AudioSystem {

updatePrefs() {
const { globalVoiceVolume, globalMediaVolume, globalSFXVolume } = window.APP.store.state.preferences;
let newGain = globalMediaVolume / 100;
let newGain = this.mediaGainOverride * (globalMediaVolume / 100);
this.mixer[SourceType.MEDIA_VIDEO].gain.setTargetAtTime(newGain, this.audioContext.currentTime, GAIN_TIME_CONST);

newGain = globalSFXVolume / 100;
Expand Down

0 comments on commit 5d06fd5

Please sign in to comment.