diff --git a/client/src/client/services/media/objects/Channel.jsx b/client/src/client/services/media/objects/Channel.jsx index 7aef84a31..5d99bc1be 100644 --- a/client/src/client/services/media/objects/Channel.jsx +++ b/client/src/client/services/media/objects/Channel.jsx @@ -38,6 +38,12 @@ export class Channel { this.updateVolume(); } + setMediaMuted(muted) { + this.sounds.forEach((sound) => { + sound.setMediaMuted(muted); + }); + } + setChannelVolume(newVolume, cancelFade = true) { this.channelVolume = newVolume; this.updateVolume(cancelFade); diff --git a/client/src/client/services/media/objects/Mixer.jsx b/client/src/client/services/media/objects/Mixer.jsx index ea679ed25..eb8951c66 100644 --- a/client/src/client/services/media/objects/Mixer.jsx +++ b/client/src/client/services/media/objects/Mixer.jsx @@ -16,6 +16,10 @@ export class Mixer { // execute the function and remove it from the map this.destructionHandlers = {}; + // set with channel tags and scores + // if scores are over 1, then the channel will be muted + this.inhibbitors = {}; + // loop over channels and call tick() setInterval(() => { this.tick(); @@ -43,6 +47,22 @@ export class Mixer { } delete this.destructionHandlers[key]; }); + + // go over all channels and check if they should be inhibited + this.channels.forEach((channel) => { + let score = 0; + channel.tags.forEach((value, tag) => { + if (this.inhibbitors[tag] != null) { + score += this.inhibbitors[tag]; + } + }); + + if (score > 1) { + channel.setChannelVolume(0); + } else { + channel.setChannelVolume(100); + } + }); } whenFinished(channelId, handler) { diff --git a/client/src/client/services/media/objects/Sound.jsx b/client/src/client/services/media/objects/Sound.jsx index 4ff0b1e5a..79413d2e6 100644 --- a/client/src/client/services/media/objects/Sound.jsx +++ b/client/src/client/services/media/objects/Sound.jsx @@ -219,6 +219,13 @@ export class Sound extends AudioSourceProcessor { this.controller.connect(node); } + setMediaMuted(muted) { + this.whenInitialized(() => { + // override mute state + this.soundElement.muted = muted; + }); + } + registerMixer(mixer, channel) { this.mixer = mixer; this.channel = channel; diff --git a/client/src/client/services/world/objects/SpeakerPlayer.jsx b/client/src/client/services/world/objects/SpeakerPlayer.jsx index 0b5fa83b6..3c09647f3 100644 --- a/client/src/client/services/world/objects/SpeakerPlayer.jsx +++ b/client/src/client/services/world/objects/SpeakerPlayer.jsx @@ -26,11 +26,12 @@ export class SpeakerPlayer { async initialize() { const createdChannel = new Channel(this.id); createdChannel.trackable = true; + createdChannel.setTag('SPEAKER'); + createdChannel.setTag(this.id); this.channel = createdChannel; const createdMedia = new Sound(this.source); this.media = createdMedia; createdChannel.mixer = MediaManager.mixer; - createdChannel.addSound(createdMedia); MediaManager.mixer.addChannel(createdChannel); @@ -41,8 +42,6 @@ export class SpeakerPlayer { createdMedia.startDate(this.startInstant, true); } await createdMedia.finalize(); - createdChannel.setTag(this.id); - createdChannel.setTag('SPECIAL'); MediaManager.mixer.updateCurrent(); if (this.doPickup) {