A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): publish the mic in a moved-to room right away
Hampus07f2d35353ad
diff --git a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsxindex eac3a996e..9c300726d 100644--- a/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx+++ b/fluxer_app/src/features/voice/engine/v2/VoiceEngineV2AppMediaExecutionAdapter.tsx@@ -236,6 +236,8 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {private localSpeakingMeter: VoiceSpeakingMeter | null = null;private mediaStateSnapshot: VoiceMediaSnapshot = createVoiceMediaSnapshot();private microphoneEnablePromise: Promise<void> | null = null;+ private microphoneEnableRoom: Room | null = null;+ private microphoneEnableGeneration = 0;private microphoneRefreshQueue: Promise<void> = Promise.resolve();private queuedMicrophoneRefresh: QueuedMicrophoneRefresh | null = null;private voiceInputRecovery: {lease: VoiceInputContextLease; cleanup: () => void} | null = null;@@ -493,6 +495,8 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {if (isPermissionDeniedError(e)) {this.handleMicrophonePermissionDenied();this.syncVoiceState({self_mute: true});+ } else if (isMicrophoneEnableFailureLatched()) {+ this.syncVoiceState({self_mute: true});}}}@@ -877,7 +881,7 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {assertObjectLike<Room>(room, 'enableMicrophone.room');assertOptionalNonEmptyString(channelId, 'enableMicrophone.channelId');assertObjectLike<VoiceEngineV2MicrophoneOptions>(options, 'enableMicrophone.options');- if (this.microphoneEnablePromise) {+ if (this.microphoneEnablePromise && this.microphoneEnableRoom === room) {await this.microphoneEnablePromise;if (this.hasLiveMicrophonePublication(room) || this.microphoneEnablePromise !== null) {return;@@ -886,11 +890,16 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {channelId,});}- this.microphoneEnablePromise = this.enableMicrophoneNow(room, channelId, options);+ const enable = this.enableMicrophoneNow(room, channelId, options);+ this.microphoneEnablePromise = enable;+ this.microphoneEnableRoom = room;try {- await this.microphoneEnablePromise;+ await enable;} finally {- this.microphoneEnablePromise = null;+ if (this.microphoneEnablePromise === enable) {+ this.microphoneEnablePromise = null;+ this.microphoneEnableRoom = null;+ }}}@@ -926,6 +935,7 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {}const ctx: MicrophoneEnableContext = {room, channelId, options};const state: MicrophoneEnableState = createInitialMicrophoneEnableState();+ const generation = ++this.microphoneEnableGeneration;try {await this.acquireMicrophoneDevice(ctx, state);if (!ctx.room.localParticipant) {@@ -940,6 +950,10 @@ class VoiceEngineV2AppMediaExecutionAdapter extends Store {this.transitionMicrophoneFailureLatch({type: 'microphone.enableSucceeded'});logger.info('Successfully enabled microphone');} catch (e: unknown) {+ if (generation !== this.microphoneEnableGeneration) {+ logger.warn('Microphone enable for a replaced room failed', {channelId, error: e});+ throw e;+ }this.transitionMicrophoneFailureLatch({type: 'microphone.enableFailed',channelId: ctx.channelId ?? this.getActiveChannelId(),