fix(voice): correct mute/deafen toggle semantics (#62)
This commit is contained in:
parent
98be0664c7
commit
4550c82475
@ -38,6 +38,8 @@ class LocalVoiceStateStore {
|
|||||||
hasUserSetMute = false;
|
hasUserSetMute = false;
|
||||||
hasUserSetDeaf = false;
|
hasUserSetDeaf = false;
|
||||||
|
|
||||||
|
private shouldUnmuteOnUndeafen = false;
|
||||||
|
|
||||||
private microphonePermissionGranted: boolean | null = MediaPermissionStore.isMicrophoneGranted();
|
private microphonePermissionGranted: boolean | null = MediaPermissionStore.isMicrophoneGranted();
|
||||||
private mutedByPermission = !MediaPermissionStore.isMicrophoneGranted();
|
private mutedByPermission = !MediaPermissionStore.isMicrophoneGranted();
|
||||||
private persistenceHydrationPromise: Promise<void>;
|
private persistenceHydrationPromise: Promise<void>;
|
||||||
@ -49,7 +51,11 @@ class LocalVoiceStateStore {
|
|||||||
constructor() {
|
constructor() {
|
||||||
makeAutoObservable<
|
makeAutoObservable<
|
||||||
this,
|
this,
|
||||||
'microphonePermissionGranted' | 'mutedByPermission' | '_disposers' | 'isNotifyingServerOfPermissionMute'
|
| 'microphonePermissionGranted'
|
||||||
|
| 'mutedByPermission'
|
||||||
|
| '_disposers'
|
||||||
|
| 'isNotifyingServerOfPermissionMute'
|
||||||
|
| 'shouldUnmuteOnUndeafen'
|
||||||
>(
|
>(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
@ -57,6 +63,7 @@ class LocalVoiceStateStore {
|
|||||||
mutedByPermission: false,
|
mutedByPermission: false,
|
||||||
_disposers: false,
|
_disposers: false,
|
||||||
isNotifyingServerOfPermissionMute: false,
|
isNotifyingServerOfPermissionMute: false,
|
||||||
|
shouldUnmuteOnUndeafen: false,
|
||||||
},
|
},
|
||||||
{autoBind: true},
|
{autoBind: true},
|
||||||
);
|
);
|
||||||
@ -276,6 +283,24 @@ class LocalVoiceStateStore {
|
|||||||
const newSelfMute = !this.selfMute;
|
const newSelfMute = !this.selfMute;
|
||||||
const micDenied = this.microphonePermissionGranted === false;
|
const micDenied = this.microphonePermissionGranted === false;
|
||||||
|
|
||||||
|
if (this.selfDeaf && !newSelfMute) {
|
||||||
|
this.hasUserSetMute = true;
|
||||||
|
this.hasUserSetDeaf = true;
|
||||||
|
this.shouldUnmuteOnUndeafen = false;
|
||||||
|
|
||||||
|
if (micDenied) {
|
||||||
|
this.mutedByPermission = true;
|
||||||
|
this.selfDeaf = false;
|
||||||
|
logger.debug('Mic denied: user attempted unmute while deaf; undeafening only');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selfMute = false;
|
||||||
|
this.selfDeaf = false;
|
||||||
|
logger.debug('User unmuted while deafened; also undeafened');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (micDenied && !newSelfMute) {
|
if (micDenied && !newSelfMute) {
|
||||||
this.hasUserSetMute = true;
|
this.hasUserSetMute = true;
|
||||||
this.mutedByPermission = true;
|
this.mutedByPermission = true;
|
||||||
@ -284,13 +309,10 @@ class LocalVoiceStateStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.hasUserSetMute = true;
|
this.hasUserSetMute = true;
|
||||||
|
this.selfMute = newSelfMute;
|
||||||
|
|
||||||
if (this.selfDeaf && !newSelfMute) {
|
if (!this.selfDeaf) {
|
||||||
this.selfMute = false;
|
this.shouldUnmuteOnUndeafen = false;
|
||||||
this.selfDeaf = false;
|
|
||||||
this.hasUserSetDeaf = true;
|
|
||||||
} else {
|
|
||||||
this.selfMute = newSelfMute;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('User toggled self mute', {newSelfMute, hasUserSetMute: true});
|
logger.debug('User toggled self mute', {newSelfMute, hasUserSetMute: true});
|
||||||
@ -301,12 +323,21 @@ class LocalVoiceStateStore {
|
|||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
const newSelfDeaf = !this.selfDeaf;
|
const newSelfDeaf = !this.selfDeaf;
|
||||||
this.hasUserSetDeaf = true;
|
this.hasUserSetDeaf = true;
|
||||||
|
const micDenied = this.microphonePermissionGranted === false;
|
||||||
|
|
||||||
if (newSelfDeaf) {
|
if (newSelfDeaf) {
|
||||||
this.selfMute = true;
|
const wasMutedBefore = this.selfMute || micDenied;
|
||||||
|
|
||||||
this.selfDeaf = true;
|
this.selfDeaf = true;
|
||||||
|
this.selfMute = true;
|
||||||
|
this.shouldUnmuteOnUndeafen = !wasMutedBefore;
|
||||||
} else {
|
} else {
|
||||||
this.selfDeaf = false;
|
this.selfDeaf = false;
|
||||||
|
|
||||||
|
if (this.shouldUnmuteOnUndeafen && !micDenied) {
|
||||||
|
this.selfMute = false;
|
||||||
|
}
|
||||||
|
this.shouldUnmuteOnUndeafen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('User toggled self deaf', {newSelfDeaf, hasUserSetDeaf: true});
|
logger.debug('User toggled self deaf', {newSelfDeaf, hasUserSetDeaf: true});
|
||||||
@ -367,6 +398,9 @@ class LocalVoiceStateStore {
|
|||||||
updateSelfDeaf(deafened: boolean): void {
|
updateSelfDeaf(deafened: boolean): void {
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.selfDeaf = deafened;
|
this.selfDeaf = deafened;
|
||||||
|
if (!deafened) {
|
||||||
|
this.shouldUnmuteOnUndeafen = false;
|
||||||
|
}
|
||||||
logger.debug('Self deaf updated', {deafened});
|
logger.debug('Self deaf updated', {deafened});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -411,6 +445,7 @@ class LocalVoiceStateStore {
|
|||||||
this.selfStreamAudioMute = false;
|
this.selfStreamAudioMute = false;
|
||||||
this.noiseSuppressionEnabled = true;
|
this.noiseSuppressionEnabled = true;
|
||||||
this.mutedByPermission = false;
|
this.mutedByPermission = false;
|
||||||
|
this.shouldUnmuteOnUndeafen = false;
|
||||||
});
|
});
|
||||||
if (this.microphonePermissionGranted === false) {
|
if (this.microphonePermissionGranted === false) {
|
||||||
logger.debug('Resetting preferences while microphone permission denied, keeping user muted');
|
logger.debug('Resetting preferences while microphone permission denied, keeping user muted');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user