diff --git a/apps/guide/content/docs/voice/index.mdx b/apps/guide/content/docs/voice/index.mdx index d59addcc9..9a5ad61a2 100644 --- a/apps/guide/content/docs/voice/index.mdx +++ b/apps/guide/content/docs/voice/index.mdx @@ -62,13 +62,13 @@ After this, you'll be able to play Ogg and WebM Opus files without any other dep - [`@noble/ciphers`](https://www.npmjs.com/package/@noble/ciphers) - [`libsodium-wrappers`](https://www.npmjs.com/package/libsodium-wrappers) -#### DAVE Protocol Support +#### DAVE Protocol Support for end-to-end encryption of voice audio -- [`@snazzah/davey`](https://www.npmjs.com/package/@snazzah/davey) - to enable end-to-end encryption with the DAVE protocol. +- [`@snazzah/davey`](https://www.npmjs.com/package/@snazzah/davey) - Some Discord clients already require the DAVE protocol for end-to-end encryption in voice chat. Ensure you have - `@snazzah/davey` installed to avoid compatibility issues. + At this time, `@snazzah/davey` is the only supported DAVE protocol library in this package, and comes pre-installed. + In the future, we may support other libraries once they are created. diff --git a/packages/voice/README.md b/packages/voice/README.md index 9f8d6dc08..a7ec18a1a 100644 --- a/packages/voice/README.md +++ b/packages/voice/README.md @@ -65,7 +65,7 @@ try installing another. **DAVE Protocol Libraries (e2ee)** > [!NOTE] -> Some Discord clients may require the DAVE protocol for end-to-end encryption in voice chat and refuse to downgrade the connection in the future. Ensure you have `@snazzah/davey` installed to avoid compatibility issues. +> At this time, `@snazzah/davey` is the only supported DAVE protocol library in this package, and comes pre-installed. In the future, we may support other libraries once they are created. - `@snazzah/davey`: ^0.1.6 diff --git a/packages/voice/package.json b/packages/voice/package.json index 939509fa3..9249aa091 100644 --- a/packages/voice/package.json +++ b/packages/voice/package.json @@ -63,6 +63,7 @@ "homepage": "https://discord.js.org", "funding": "https://github.com/discordjs/discord.js?sponsor", "dependencies": { + "@snazzah/davey": "^0.1.8", "@types/ws": "^8.18.1", "discord-api-types": "^0.38.36", "prism-media": "^1.3.5", @@ -75,7 +76,6 @@ "@discordjs/scripts": "workspace:^", "@favware/cliff-jumper": "^6.0.0", "@noble/ciphers": "^2.1.1", - "@snazzah/davey": "^0.1.8", "@types/node": "^22.19.2", "@vitest/coverage-v8": "^4.0.15", "cross-env": "^10.1.0", diff --git a/packages/voice/src/networking/DAVESession.ts b/packages/voice/src/networking/DAVESession.ts index ebb812d94..5ea2b3d06 100644 --- a/packages/voice/src/networking/DAVESession.ts +++ b/packages/voice/src/networking/DAVESession.ts @@ -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(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; diff --git a/packages/voice/src/networking/Networking.ts b/packages/voice/src/networking/Networking.ts index 5c1ff6e8f..ded6c85a0 100644 --- a/packages/voice/src/networking/Networking.ts +++ b/packages/voice/src/networking/Networking.ts @@ -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 = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2396d919e..dceecd3d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1817,6 +1817,9 @@ importers: packages/voice: dependencies: + '@snazzah/davey': + specifier: ^0.1.8 + version: 0.1.8 '@types/ws': specifier: ^8.18.1 version: 8.18.1 @@ -1848,9 +1851,6 @@ importers: '@noble/ciphers': specifier: ^2.1.1 version: 2.1.1 - '@snazzah/davey': - specifier: ^0.1.8 - version: 0.1.8 '@types/node': specifier: ^22.19.2 version: 22.19.2