diff --git a/app/index.js b/app/index.js index 0143741..3c74d15 100644 --- a/app/index.js +++ b/app/index.js @@ -141,6 +141,12 @@ class GlobalBindings { this.selfMute = ko.observable() this.selfDeaf = ko.observable() + this.selfMute.subscribe(mute => { + if (voiceHandler) { + voiceHandler.setMute(mute) + } + }) + this.select = element => { this.selected(element) } @@ -411,6 +417,9 @@ class GlobalBindings { this.thisUser().talking('off') } }) + if (this.selfMute()) { + voiceHandler.setMute(true) + } } this.messageBoxHint = ko.pureComputed(() => { diff --git a/app/voice.js b/app/voice.js index ea48c20..1703c36 100644 --- a/app/voice.js +++ b/app/voice.js @@ -13,9 +13,20 @@ class VoiceHandler extends Writable { super({ objectMode: true }) this._client = client this._outbound = null + this._mute = false + } + + setMute (mute) { + this._mute = mute + if (mute) { + this._stopOutbound() + } } _getOrCreateOutbound () { + if (this._mute) { + throw new Error('tried to send audio while self-muted') + } if (!this._outbound) { if (!this._client) { this._outbound = DropStream.obj() @@ -65,7 +76,11 @@ export class ContinuousVoiceHandler extends VoiceHandler { } _write (data, _, callback) { - this._getOrCreateOutbound().write(data, callback) + if (this._mute) { + callback() + } else { + this._getOrCreateOutbound().write(data, callback) + } } } @@ -83,7 +98,7 @@ export class PushToTalkVoiceHandler extends VoiceHandler { } _write (data, _, callback) { - if (this._pushed) { + if (this._pushed && !this._mute) { this._getOrCreateOutbound().write(data, callback) } else { callback() @@ -128,7 +143,7 @@ export class VADVoiceHandler extends VoiceHandler { } _write (data, _, callback) { - if (this._active) { + if (this._active && !this._mute) { if (this._backlog.length > 0) { for (let oldData of this._backlog) { this._getOrCreateOutbound().write(oldData)