refactor(voice): remove the unused voice state ack (#2716)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-12 01:37:45 +02:00
1 parent 3e79530389
commit e1bc6c2f7e
16 files changed
+21 -581

No files matched your search

@@ -67,7 +67,6 @@ import {handleCallDelete} from '@app/features/voice/events/CallDelete';
import {handleCallUpdate} from '@app/features/voice/events/CallUpdate';
import {handleEntranceSoundPlay} from '@app/features/voice/events/EntranceSoundPlay';
import {handleVoiceServerUpdate} from '@app/features/voice/events/VoiceServerUpdate';
import {handleVoiceStateAck} from '@app/features/voice/events/VoiceStateAck';
import {handleVoiceStateUpdate} from '@app/features/voice/events/VoiceStateUpdate';
export interface GatewayGeoipPayload {
@@ -143,7 +142,6 @@ export function createHandlerRegistry(): GatewayHandlerRegistry {
registry.set('SAVED_MESSAGE_DELETE', handleSavedMessageDelete as GatewayEventHandler);
registry.set('PRESENCE_UPDATE', handlePresenceUpdate as GatewayEventHandler);
registry.set('PRESENCE_UPDATE_BULK', handlePresenceUpdateBulk as GatewayEventHandler);
registry.set('VOICE_STATE_ACK', handleVoiceStateAck as GatewayEventHandler);
registry.set('VOICE_STATE_UPDATE', handleVoiceStateUpdate as GatewayEventHandler);
registry.set('VOICE_SERVER_UPDATE', handleVoiceServerUpdate as GatewayEventHandler);
registry.set('CALL_CREATE', handleCallCreate as GatewayEventHandler);
@@ -36,7 +36,6 @@ import {
selectMediaEngineGatewayErrorDecision,
shouldCancelMediaEngineReconnectForServerVoiceStateRemoval,
shouldImmediatelyDisconnectMediaEngineForServerVoiceStateRemoval,
shouldNotifyCameraUserLimitRejection,
shouldRunMediaEngineDeferredDisconnect,
transitionMediaEngineFacadeSnapshot,
} from '@app/features/voice/engine/MediaEngineFacadeStateMachine';
@@ -47,7 +46,6 @@ import {
CLAIM_YOUR_ACCOUNT_TO_START_OR_JOIN_1_DESCRIPTOR,
DEFERRED_DISCONNECT_TIMEOUT_MS,
RECONNECT_SUCCEEDED_PICK_A_SCREEN_AGAIN_IF_YOU_DESCRIPTOR,
VOICE_CAMERA_USER_LIMIT_REACHED_DESCRIPTOR,
VOICE_CHANNEL_NO_LONGER_AVAILABLE_DESCRIPTOR,
VOICE_CONNECTION_FAILED_DESCRIPTOR,
VOICE_CONNECTION_LIMIT_REACHED_DESCRIPTOR,
@@ -136,7 +134,6 @@ import {VoiceEngineV2AppStatsHostAdapter} from '@app/features/voice/engine/v2/Vo
import VoiceEngineV2AppSubscriptionAdapter from '@app/features/voice/engine/v2/VoiceEngineV2AppSubscriptionAdapter';
import voiceEngineV2AppVoiceStateAdapter from '@app/features/voice/engine/v2/VoiceEngineV2AppVoiceStateAdapter';
import type {DisplayScreenShareCaptureContext} from '@app/features/voice/engine/voice_screen_share_manager/shared';
import type {VoiceStateAckPayload} from '@app/features/voice/events/VoiceStateAck';
import CallMediaPrefs from '@app/features/voice/state/CallMediaPrefs';
import {type ChannelE2EEStatus, computeChannelE2EEStatus} from '@app/features/voice/state/ChannelE2EEStatus';
import LocalVoiceState from '@app/features/voice/state/LocalVoiceState';
@@ -156,7 +153,6 @@ import {getActiveVoiceProcessingMode} from '@app/features/voice/utils/VoiceProce
import type {NativeAudioStartOptions} from '@app/types/electron.d';
import {ME} from '@fluxer/constants/src/AppConstants';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import {VOICE_CHANNEL_CAMERA_USER_LIMIT} from '@fluxer/constants/src/LimitConstants';
import type {
VoiceEngineV2AudioMode,
VoiceEngineV2CameraOptions,
@@ -1925,41 +1921,6 @@ class MediaEngineFacade extends Store {
return voiceEngineV2AppVoiceStateAdapter.getAllVoiceStates();
}
handleGatewayVoiceStateAck(data: VoiceStateAckPayload): void {
if (shouldNotifyCameraUserLimitRejection({status: data.status, errorCode: data.error_code})) {
this.handleCameraUserLimitRejection();
}
const canonicalState = data.canonical_state;
if (!canonicalState?.channel_id || !canonicalState.connection_id) {
logger.debug('Ignoring voice state ack without canonical connection state', {
mutationId: data.mutation_id,
status: data.status,
guildId: data.guild_id,
channelId: data.channel_id,
connectionId: data.connection_id,
});
return;
}
this.applyEngineGatewayEcho(
this.toEngineGatewayVoiceState(canonicalState, canonicalState.guild_id ?? data.guild_id ?? null),
);
}
private handleCameraUserLimitRejection(): void {
logger.warn('Camera enable rejected by the gateway camera user limit', {
limit: VOICE_CHANNEL_CAMERA_USER_LIMIT,
});
void this.setCameraEnabled(false, {sendUpdate: false}).catch((error) => {
logger.warn('Failed to turn the camera back off after a camera user limit rejection', {error});
});
if (!this.i18n) return;
this.showVoiceErrorModal(
VOICE_CAMERA_USER_LIMIT_REACHED_DESCRIPTOR,
'voice.media-engine-facade.camera-user-limit-error-modal',
{voiceChannelCameraUserLimit: VOICE_CHANNEL_CAMERA_USER_LIMIT},
);
}
private toEngineGatewayVoiceState(
source: {
guild_id?: string | null;
@@ -10,10 +10,8 @@ import {
selectMediaEngineGatewayErrorDecision,
shouldCancelMediaEngineReconnectForServerVoiceStateRemoval,
shouldImmediatelyDisconnectMediaEngineForServerVoiceStateRemoval,
shouldNotifyCameraUserLimitRejection,
shouldRunMediaEngineDeferredDisconnect,
transitionMediaEngineFacadeSnapshot,
VOICE_CAMERA_USER_LIMIT_ERROR_CODE,
} from './MediaEngineFacadeStateMachine';
function connected(guildId: string | null = 'guild-1', channelId = 'channel-1') {
@@ -434,27 +432,4 @@ describe('MediaEngineFacadeStateMachine', () => {
}),
).toEqual({type: 'navigate-channel-gate'});
});
it('notifies only for rejected voice state acks carrying the camera user limit error code', () => {
expect(
shouldNotifyCameraUserLimitRejection({
status: 'rejected',
errorCode: VOICE_CAMERA_USER_LIMIT_ERROR_CODE,
}),
).toBe(true);
expect(
shouldNotifyCameraUserLimitRejection({
status: 'applied',
errorCode: VOICE_CAMERA_USER_LIMIT_ERROR_CODE,
}),
).toBe(false);
expect(
shouldNotifyCameraUserLimitRejection({
status: 'rejected',
errorCode: 'VOICE_PERMISSION_DENIED',
}),
).toBe(false);
expect(shouldNotifyCameraUserLimitRejection({})).toBe(false);
expect(shouldNotifyCameraUserLimitRejection({status: 'rejected'})).toBe(false);
});
});
@@ -84,18 +84,6 @@ export interface MediaEngineFacadeGatewayErrorInput {
channelId: string | null;
}
export const VOICE_CAMERA_USER_LIMIT_ERROR_CODE = 'VOICE_CAMERA_USER_LIMIT';
export interface MediaEngineFacadeVoiceStateAckRejectionInput {
status?: string;
errorCode?: string;
}
export function shouldNotifyCameraUserLimitRejection(input: MediaEngineFacadeVoiceStateAckRejectionInput): boolean {
if (input.status !== 'rejected') return false;
return input.errorCode === VOICE_CAMERA_USER_LIMIT_ERROR_CODE;
}
export type MediaEngineFacadeGatewayErrorDecision =
| {type: 'ignore'}
| {
@@ -1,22 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {GatewayHandlerContext} from '@app/features/gateway/events/EventRouter';
import type {VoiceState} from '@app/features/gateway/types/GatewayVoiceTypes';
import MediaEngine from '@app/features/voice/engine/MediaEngineFacade';
export interface VoiceStateAckPayload {
mutation_id?: string;
runtime_epoch?: string | null;
connection_id?: string | null;
guild_id?: string | null;
channel_id?: string | null;
status?: string;
server_version?: number;
canonical_state?: VoiceState | null;
error_code?: string;
error_message?: string;
}
export function handleVoiceStateAck(data: VoiceStateAckPayload, _context: GatewayHandlerContext): void {
MediaEngine.handleGatewayVoiceStateAck(data);
}