diff --git a/client/public/metadata.json b/client/public/metadata.json index f45bf248d7..c6a3e16632 100644 --- a/client/public/metadata.json +++ b/client/public/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":185,"buildTag":"dev","buildDate":"Mon Dec 11 2023","build":"1.125.185 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":186,"buildTag":"dev","buildDate":"Mon Dec 11 2023","build":"1.125.186 dev"} \ No newline at end of file diff --git a/client/src/client/services/socket/HandlerRegistry.jsx b/client/src/client/services/socket/HandlerRegistry.jsx index aeea2e2b1d..05fc89aaa8 100644 --- a/client/src/client/services/socket/HandlerRegistry.jsx +++ b/client/src/client/services/socket/HandlerRegistry.jsx @@ -14,6 +14,7 @@ import { HandleVoiceBlur } from './handlers/voice/HandleVoiceBlur'; import { handleSpeakerCreate } from './handlers/speakers/HandleSpeakerCreate'; import { HandleSpeakerDestroy } from './handlers/speakers/HandleSpeakerDestroy'; import { HandleVoiceModerationStatus } from './handlers/voice/HandleVoiceModerationStatus'; +import { HandleVoiceDeafen } from './handlers/voice/HandleToggleDeafenCommand'; export class HandlerRegistry { constructor(socket) { @@ -42,6 +43,7 @@ export class HandlerRegistry { registerClassHandler('ClientVoiceDropPayload', HandleVoiceDrop); registerClassHandler('ClientVoiceUpdatePeerLocationsPayload', HandleVoicePeerMovement); registerClassHandler('ClientVoiceChatToggleMicrophonePayload', HandleMicToggleRequest); + registerClassHandler('ClientVoiceChatToggleDeafenPayload', HandleVoiceDeafen); registerClassHandler('ClientVoiceBlurUiPayload', HandleVoiceBlur); registerClassHandler('ClientModerationStatusPayload', HandleVoiceModerationStatus); } diff --git a/client/src/client/services/socket/handlers/voice/HandleToggleDeafenCommand.jsx b/client/src/client/services/socket/handlers/voice/HandleToggleDeafenCommand.jsx new file mode 100644 index 0000000000..5dbff77aa9 --- /dev/null +++ b/client/src/client/services/socket/handlers/voice/HandleToggleDeafenCommand.jsx @@ -0,0 +1,8 @@ +import { getGlobalState, setGlobalState } from '../../../../../state/store'; +import { VoiceModule } from '../../../voice/VoiceModule'; + +export function HandleVoiceDeafen() { + const newState = !getGlobalState().settings.voicechatDeafened; + setGlobalState({ settings: { voicechatDeafened: newState }, voiceState: { deafenedBefore: true } }); + VoiceModule.peerManager.setDeafened(newState); +} diff --git a/client/src/client/services/voice/peers/PeerManager.jsx b/client/src/client/services/voice/peers/PeerManager.jsx index 07fffd6d96..f916fb640e 100644 --- a/client/src/client/services/voice/peers/PeerManager.jsx +++ b/client/src/client/services/voice/peers/PeerManager.jsx @@ -28,6 +28,7 @@ export class PeerManager { this.setMute = this.setMute.bind(this); let lastStateMuted = false; + let lastStateDeafened = false; this.unsub = store.subscribe(() => { const { settings } = store.getState(); @@ -35,6 +36,24 @@ export class PeerManager { lastStateMuted = settings.voicechatMuted; this.setMute(lastStateMuted); } + + if (settings.voicechatDeafened !== lastStateDeafened) { + lastStateDeafened = settings.voicechatDeafened; + this.setDeafened(lastStateDeafened); + } + }); + } + + setDeafened(state) { + if (state) { + VoiceModule.pushSocketEvent(VoiceStatusChangeEvent.SELF_DEAFEN); + } else { + VoiceModule.pushSocketEvent(VoiceStatusChangeEvent.SELF_UNDEAFEN); + } + + // apply to current streams + VoiceModule.peerMap.forEach((peer) => { + peer.stream.setMuteOverride(state); }); } diff --git a/client/src/components/voice/VoiceSettings.jsx b/client/src/components/voice/VoiceSettings.jsx index e25f004e39..e7fbe9cb57 100644 --- a/client/src/components/voice/VoiceSettings.jsx +++ b/client/src/components/voice/VoiceSettings.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { connect } from 'react-redux'; import AdvancedVoiceSettings from './AdvancedVoiceSettings'; import { setGlobalState } from '../../state/store'; -import { reRenderAllGainNodes, VoiceModule, VoiceStatusChangeEvent } from '../../client/services/voice/VoiceModule'; +import { reRenderAllGainNodes } from '../../client/services/voice/VoiceModule'; import { Tooltip } from '../tooltip/tooltip'; import ExtraVoiceSettings from './ExtraVoiceSettings'; import { msg } from '../../client/OpenAudioAppContainer'; @@ -50,22 +50,7 @@ class VoiceSettings extends React.Component { toggleDeafen() { const deafened = !this.props.voicechatDeafened; - - if (this.props.voiceState.deafenedBefore) { - // broadcast state update - if (deafened) { - VoiceModule.pushSocketEvent(VoiceStatusChangeEvent.SELF_DEAFEN); - } else { - VoiceModule.pushSocketEvent(VoiceStatusChangeEvent.SELF_UNDEAFEN); - } - } - setGlobalState({ settings: { voicechatDeafened: deafened }, voiceState: { deafenedBefore: true } }); - - // apply to current streams - VoiceModule.peerMap.forEach((peer) => { - peer.stream.setMuteOverride(deafened); - }); } render() { diff --git a/client/src/metadata.json b/client/src/metadata.json index f45bf248d7..c6a3e16632 100644 --- a/client/src/metadata.json +++ b/client/src/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":185,"buildTag":"dev","buildDate":"Mon Dec 11 2023","build":"1.125.185 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":186,"buildTag":"dev","buildDate":"Mon Dec 11 2023","build":"1.125.186 dev"} \ No newline at end of file diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/packets/client/voice/PacketClientToggleDeafen.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/packets/client/voice/PacketClientToggleDeafen.java new file mode 100644 index 0000000000..4577c08d32 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/packets/client/voice/PacketClientToggleDeafen.java @@ -0,0 +1,17 @@ +package com.craftmend.openaudiomc.generic.networking.packets.client.voice; + +import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacket; +import com.craftmend.openaudiomc.generic.networking.abstracts.PacketChannel; +import com.craftmend.openaudiomc.generic.networking.payloads.client.voice.ClientVoiceChatToggleMicrophonePayload; + +public class PacketClientToggleMicrophone extends AbstractPacket { + + public PacketClientToggleMicrophone(ClientVoiceChatToggleMicrophonePayload payload) { + super( + payload, + PacketChannel.CLIENT_OUT_TOGGLE_MIC, + null + ); + } + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/client/voice/ClientVoiceChatToggleDeafenPayload.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/client/voice/ClientVoiceChatToggleDeafenPayload.java new file mode 100644 index 0000000000..47f4070718 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/client/voice/ClientVoiceChatToggleDeafenPayload.java @@ -0,0 +1,11 @@ +package com.craftmend.openaudiomc.generic.networking.payloads.client.voice; + +import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacketPayload; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ClientVoiceChatToggleDeafenPayload extends AbstractPacketPayload { + +}