Enforce self-mute state client-side

This commit is contained in:
Jonas Herzig 2017-09-20 16:55:11 +02:00
parent a9d5b5ba75
commit c2d3eb59e5
2 changed files with 27 additions and 3 deletions

View file

@ -141,6 +141,12 @@ class GlobalBindings {
this.selfMute = ko.observable() this.selfMute = ko.observable()
this.selfDeaf = ko.observable() this.selfDeaf = ko.observable()
this.selfMute.subscribe(mute => {
if (voiceHandler) {
voiceHandler.setMute(mute)
}
})
this.select = element => { this.select = element => {
this.selected(element) this.selected(element)
} }
@ -411,6 +417,9 @@ class GlobalBindings {
this.thisUser().talking('off') this.thisUser().talking('off')
} }
}) })
if (this.selfMute()) {
voiceHandler.setMute(true)
}
} }
this.messageBoxHint = ko.pureComputed(() => { this.messageBoxHint = ko.pureComputed(() => {

View file

@ -13,9 +13,20 @@ class VoiceHandler extends Writable {
super({ objectMode: true }) super({ objectMode: true })
this._client = client this._client = client
this._outbound = null this._outbound = null
this._mute = false
}
setMute (mute) {
this._mute = mute
if (mute) {
this._stopOutbound()
}
} }
_getOrCreateOutbound () { _getOrCreateOutbound () {
if (this._mute) {
throw new Error('tried to send audio while self-muted')
}
if (!this._outbound) { if (!this._outbound) {
if (!this._client) { if (!this._client) {
this._outbound = DropStream.obj() this._outbound = DropStream.obj()
@ -65,8 +76,12 @@ export class ContinuousVoiceHandler extends VoiceHandler {
} }
_write (data, _, callback) { _write (data, _, callback) {
if (this._mute) {
callback()
} else {
this._getOrCreateOutbound().write(data, callback) this._getOrCreateOutbound().write(data, callback)
} }
}
} }
export class PushToTalkVoiceHandler extends VoiceHandler { export class PushToTalkVoiceHandler extends VoiceHandler {
@ -83,7 +98,7 @@ export class PushToTalkVoiceHandler extends VoiceHandler {
} }
_write (data, _, callback) { _write (data, _, callback) {
if (this._pushed) { if (this._pushed && !this._mute) {
this._getOrCreateOutbound().write(data, callback) this._getOrCreateOutbound().write(data, callback)
} else { } else {
callback() callback()
@ -128,7 +143,7 @@ export class VADVoiceHandler extends VoiceHandler {
} }
_write (data, _, callback) { _write (data, _, callback) {
if (this._active) { if (this._active && !this._mute) {
if (this._backlog.length > 0) { if (this._backlog.length > 0) {
for (let oldData of this._backlog) { for (let oldData of this._backlog) {
this._getOrCreateOutbound().write(oldData) this._getOrCreateOutbound().write(oldData)