mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user