fix(voice): always install Davey as DAVE is becoming required (#11385)

* fix(voice): always install Davey as DAVE is becoming required

* chore: requested changes

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Vlad Frangu
2026-01-25 22:28:04 +02:00
committed by GitHub
parent 3550b497f6
commit 323d8e7571
6 changed files with 14 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import { Buffer } from 'node:buffer';
import { EventEmitter } from 'node:events';
import Davey from '@snazzah/davey';
import type { VoiceDavePrepareEpochData, VoiceDavePrepareTransitionData } from 'discord-api-types/voice/v8';
import { SILENCE_FRAME } from '../audio/AudioPlayer';
@@ -25,8 +26,6 @@ interface ProposalsResult {
welcome?: Buffer;
}
let Davey: any = null;
/**
* The amount of seconds that a previous transition should be valid for.
*/
@@ -45,16 +44,6 @@ const TRANSITION_EXPIRY_PENDING_DOWNGRADE = 24;
*/
export const DEFAULT_DECRYPTION_FAILURE_TOLERANCE = 36;
// eslint-disable-next-line no-async-promise-executor
export const daveLoadPromise = new Promise<void>(async (resolve) => {
try {
const lib = await import('@snazzah/davey');
Davey = lib;
} catch {}
resolve();
});
interface TransitionResult {
success: boolean;
transitionId: number;
@@ -69,8 +58,8 @@ export interface DAVESessionOptions {
/**
* The maximum DAVE protocol version supported.
*/
export function getMaxProtocolVersion(): number | null {
return Davey?.DAVE_PROTOCOL_VERSION;
export function getMaxProtocolVersion(): number {
return Davey.DAVE_PROTOCOL_VERSION;
}
export interface DAVESession extends EventEmitter {
@@ -135,12 +124,6 @@ export class DAVESession extends EventEmitter {
public session: SessionMethods | undefined;
public constructor(protocolVersion: number, userId: string, channelId: string, options: DAVESessionOptions) {
if (Davey === null)
throw new Error(
`Cannot utilize the DAVE protocol as the @snazzah/davey package has not been installed.
- Use the generateDependencyReport() function for more information.\n`,
);
super();
this.protocolVersion = protocolVersion;
@@ -379,6 +362,7 @@ export class DAVESession extends EventEmitter {
const canDecrypt = this.session?.ready && (this.protocolVersion !== 0 || this.session?.canPassthrough(userId));
if (packet.equals(SILENCE_FRAME) || !canDecrypt || !this.session) return packet;
try {
// @ts-expect-error - const enum is exported and works (todo: drop const modifier on Davey end)
const buffer = this.session.decrypt(userId, Davey.MediaType.AUDIO, packet);
this.consecutiveFailures = 0;
return buffer;

View File

@@ -363,7 +363,6 @@ export class Networking extends EventEmitter {
*/
private createDaveSession(protocolVersion: number) {
if (
getMaxProtocolVersion() === null ||
this.options.daveEncryption === false ||
(this.state.code !== NetworkingStatusCode.SelectingProtocol &&
this.state.code !== NetworkingStatusCode.Ready &&
@@ -412,7 +411,7 @@ export class Networking extends EventEmitter {
user_id: this.state.connectionOptions.userId,
session_id: this.state.connectionOptions.sessionId,
token: this.state.connectionOptions.token,
max_dave_protocol_version: this.options.daveEncryption === false ? 0 : (getMaxProtocolVersion() ?? 0),
max_dave_protocol_version: this.options.daveEncryption === false ? 0 : getMaxProtocolVersion(),
},
});
this.state = {