Files
discord.js/packages/voice/src/joinVoiceChannel.ts
Snazzah 8bdea6232b feat: implement DAVE end-to-end encryption (#10921)
* feat(voice): implement DAVE E2EE encryption

* chore(voice): update dependencies

* chore(voice): update debug logs and dependency report

* feat(voice): emit and propogate DAVESession errors

* chore(voice): export dave session things

* chore(voice): move expiry numbers to consts

* feat(voice): keep track of and pass connected client IDs

* fix(voice): dont set initial transitions as pending

* feat(voice): dave encryption

* chore(voice): directly reference package name in import

* feat(voice): dave decryption

* chore(deps): update @snazzah/davey

* fix(voice): handle decryption failure tolerance

* fix(voice): move and update decryption failure logic to DAVESession

* feat(voice): propogate voice privacy code

* fix(voice): actually send a transition ready when ready

* feat(voice): propogate transitions and verification code function

* feat(voice): add dave options

* chore: resolve format change requests

* chore: emit debug messages on bad transitions

* chore: downgrade commit/welcome errors as debug messages

* chore: resolve formatting change requests

* chore: update davey dependency

* chore: add types for underlying dave session

* fix: fix rebase

* chore: change "ID" to "id" in typedocs

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
2025-07-13 17:02:56 +00:00

79 lines
1.9 KiB
TypeScript

import type { JoinConfig } from './DataStore';
import { createVoiceConnection } from './VoiceConnection';
import type { DiscordGatewayAdapterCreator } from './util/adapter';
/**
* The options that can be given when creating a voice connection.
*/
export interface CreateVoiceConnectionOptions {
adapterCreator: DiscordGatewayAdapterCreator;
/**
* Whether to use the DAVE protocol for end-to-end encryption. Defaults to true.
*/
daveEncryption?: boolean | undefined;
/**
* If true, debug messages will be enabled for the voice connection and its
* related components. Defaults to false.
*/
debug?: boolean | undefined;
/**
* The amount of consecutive decryption failures needed to try to
* re-initialize the end-to-end encrypted session to recover. Defaults to 24.
*/
decryptionFailureTolerance?: number | undefined;
}
/**
* The options that can be given when joining a voice channel.
*/
export interface JoinVoiceChannelOptions {
/**
* The id of the Discord voice channel to join.
*/
channelId: string;
/**
* An optional group identifier for the voice connection.
*/
group?: string;
/**
* The id of the guild that the voice channel belongs to.
*/
guildId: string;
/**
* Whether to join the channel deafened (defaults to true)
*/
selfDeaf?: boolean;
/**
* Whether to join the channel muted (defaults to true)
*/
selfMute?: boolean;
}
/**
* Creates a VoiceConnection to a Discord voice channel.
*
* @param options - the options for joining the voice channel
*/
export function joinVoiceChannel(options: CreateVoiceConnectionOptions & JoinVoiceChannelOptions) {
const joinConfig: JoinConfig = {
selfDeaf: true,
selfMute: false,
group: 'default',
...options,
};
return createVoiceConnection(joinConfig, {
adapterCreator: options.adapterCreator,
debug: options.debug,
daveEncryption: options.daveEncryption,
decryptionFailureTolerance: options.decryptionFailureTolerance,
});
}