Skip to content

Commit 323d8e7

Browse files
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>
1 parent 3550b49 commit 323d8e7

File tree

6 files changed

+14
-31
lines changed

6 files changed

+14
-31
lines changed

apps/guide/content/docs/voice/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ After this, you'll be able to play Ogg and WebM Opus files without any other dep
6262
- [`@noble/ciphers`](https://www.npmjs.com/package/@noble/ciphers)
6363
- [`libsodium-wrappers`](https://www.npmjs.com/package/libsodium-wrappers)
6464

65-
#### DAVE Protocol Support
65+
#### DAVE Protocol Support for end-to-end encryption of voice audio
6666

67-
- [`@snazzah/davey`](https://www.npmjs.com/package/@snazzah/davey) - to enable end-to-end encryption with the DAVE protocol.
67+
- [`@snazzah/davey`](https://www.npmjs.com/package/@snazzah/davey)
6868

6969
<Callout>
70-
Some Discord clients already require the DAVE protocol for end-to-end encryption in voice chat. Ensure you have
71-
`@snazzah/davey` installed to avoid compatibility issues.
70+
At this time, `@snazzah/davey` is the only supported DAVE protocol library in this package, and comes pre-installed.
71+
In the future, we may support other libraries once they are created.
7272
</Callout>
7373

7474
<Callout>

packages/voice/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ try installing another.
6565
**DAVE Protocol Libraries (e2ee)**
6666

6767
> [!NOTE]
68-
> 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.
68+
> 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.
6969
7070
- `@snazzah/davey`: ^0.1.6
7171

packages/voice/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"homepage": "https://discord.js.org",
6464
"funding": "https://github.com/discordjs/discord.js?sponsor",
6565
"dependencies": {
66+
"@snazzah/davey": "^0.1.8",
6667
"@types/ws": "^8.18.1",
6768
"discord-api-types": "^0.38.36",
6869
"prism-media": "^1.3.5",
@@ -75,7 +76,6 @@
7576
"@discordjs/scripts": "workspace:^",
7677
"@favware/cliff-jumper": "^6.0.0",
7778
"@noble/ciphers": "^2.1.1",
78-
"@snazzah/davey": "^0.1.8",
7979
"@types/node": "^22.19.2",
8080
"@vitest/coverage-v8": "^4.0.15",
8181
"cross-env": "^10.1.0",

packages/voice/src/networking/DAVESession.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Buffer } from 'node:buffer';
22
import { EventEmitter } from 'node:events';
3+
import Davey from '@snazzah/davey';
34
import type { VoiceDavePrepareEpochData, VoiceDavePrepareTransitionData } from 'discord-api-types/voice/v8';
45
import { SILENCE_FRAME } from '../audio/AudioPlayer';
56

@@ -25,8 +26,6 @@ interface ProposalsResult {
2526
welcome?: Buffer;
2627
}
2728

28-
let Davey: any = null;
29-
3029
/**
3130
* The amount of seconds that a previous transition should be valid for.
3231
*/
@@ -45,16 +44,6 @@ const TRANSITION_EXPIRY_PENDING_DOWNGRADE = 24;
4544
*/
4645
export const DEFAULT_DECRYPTION_FAILURE_TOLERANCE = 36;
4746

48-
// eslint-disable-next-line no-async-promise-executor
49-
export const daveLoadPromise = new Promise<void>(async (resolve) => {
50-
try {
51-
const lib = await import('@snazzah/davey');
52-
Davey = lib;
53-
} catch {}
54-
55-
resolve();
56-
});
57-
5847
interface TransitionResult {
5948
success: boolean;
6049
transitionId: number;
@@ -69,8 +58,8 @@ export interface DAVESessionOptions {
6958
/**
7059
* The maximum DAVE protocol version supported.
7160
*/
72-
export function getMaxProtocolVersion(): number | null {
73-
return Davey?.DAVE_PROTOCOL_VERSION;
61+
export function getMaxProtocolVersion(): number {
62+
return Davey.DAVE_PROTOCOL_VERSION;
7463
}
7564

7665
export interface DAVESession extends EventEmitter {
@@ -135,12 +124,6 @@ export class DAVESession extends EventEmitter {
135124
public session: SessionMethods | undefined;
136125

137126
public constructor(protocolVersion: number, userId: string, channelId: string, options: DAVESessionOptions) {
138-
if (Davey === null)
139-
throw new Error(
140-
`Cannot utilize the DAVE protocol as the @snazzah/davey package has not been installed.
141-
- Use the generateDependencyReport() function for more information.\n`,
142-
);
143-
144127
super();
145128

146129
this.protocolVersion = protocolVersion;
@@ -379,6 +362,7 @@ export class DAVESession extends EventEmitter {
379362
const canDecrypt = this.session?.ready && (this.protocolVersion !== 0 || this.session?.canPassthrough(userId));
380363
if (packet.equals(SILENCE_FRAME) || !canDecrypt || !this.session) return packet;
381364
try {
365+
// @ts-expect-error - const enum is exported and works (todo: drop const modifier on Davey end)
382366
const buffer = this.session.decrypt(userId, Davey.MediaType.AUDIO, packet);
383367
this.consecutiveFailures = 0;
384368
return buffer;

packages/voice/src/networking/Networking.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ export class Networking extends EventEmitter {
363363
*/
364364
private createDaveSession(protocolVersion: number) {
365365
if (
366-
getMaxProtocolVersion() === null ||
367366
this.options.daveEncryption === false ||
368367
(this.state.code !== NetworkingStatusCode.SelectingProtocol &&
369368
this.state.code !== NetworkingStatusCode.Ready &&
@@ -412,7 +411,7 @@ export class Networking extends EventEmitter {
412411
user_id: this.state.connectionOptions.userId,
413412
session_id: this.state.connectionOptions.sessionId,
414413
token: this.state.connectionOptions.token,
415-
max_dave_protocol_version: this.options.daveEncryption === false ? 0 : (getMaxProtocolVersion() ?? 0),
414+
max_dave_protocol_version: this.options.daveEncryption === false ? 0 : getMaxProtocolVersion(),
416415
},
417416
});
418417
this.state = {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)