DaveManager
Manages the DAVE (Discord Audio/Video Encryption) MLS session lifecycle for a voice connection.
Owns the MLS session, encryptor, per-user decryptors, and SSRC-to-user-ID mapping. The owner (Voice.Connection)
passes it the voice gateway's DAVE opcodes and sets sendMessage, through which it answers, onTransitionExecuted
and onMediaReadyChanged. libdave objects come from createSession, createEncryptor and createDecryptor, which
tests replace with stand-ins.
Summary
Properties
DaveManager.daveSession :: dave.Session?DaveManager.daveEncryptor :: dave.Encryptor?DaveManager.daveDecryptors :: { [string]: dave.Decryptor }DaveManager.recognizedUserIds :: { [string]: true }DaveManager.roster :: { [string]: true }DaveManager.pendingTransitions :: { [number]: number }DaveManager.pendingSelfRatchets :: { [number]: dave.KeyRatchet }DaveManager.selfRatchetApplied :: booleanDaveManager.reinitializing :: booleanDaveManager.mediaReady :: booleanDaveManager.ssrcToUserId :: { [number]: string }DaveManager.protocolVersion :: numberDaveManager.mediaProtocolVersion :: number?DaveManager.externalSender :: buffer?DaveManager.channelId :: stringDaveManager.userId :: stringDaveManager.ssrc :: number?DaveManager.createSession :: (authSessionId: string, onMlsFailure: ((source: string, reason: string) -> ())?) -> dave.SessionDaveManager.createEncryptor :: () -> dave.EncryptorDaveManager.createDecryptor :: () -> dave.DecryptorDaveManager.sendMessage :: ((message: string | buffer, purpose: string) -> ())?DaveManager.onTransitionExecuted :: ((rosterSize: number) -> ())?DaveManager.onMediaReadyChanged :: ((ready: boolean) -> ())?DaveManager.logger :: logger.LoggerMethods
DaveManager:cleanup()DaveManager:handleSessionDescription(protocolVersion: number, channelId: string, userId: string, ssrc: number?)DaveManager:handleClientsConnect(userIds: { string })DaveManager:handleClientDisconnect(userId: string)DaveManager:handlePrepareTransition(payload: any)DaveManager:handleExecuteTransition(payload: any)DaveManager:hasPendingDowngrade() → booleanDaveManager:handlePrepareEpoch(payload: any)DaveManager:handleExternalSender(payload: buffer)DaveManager:handleProposals(payload: buffer)DaveManager:handleCommitTransition(payload: buffer)DaveManager:handleWelcome(payload: buffer)Properties
Section titled “Properties”daveSession
Section titled “daveSession”daveEncryptor
Section titled “daveEncryptor”daveDecryptors
Section titled “daveDecryptors”{ [string]: dave.Decryptor } }
recognizedUserIds
Section titled “recognizedUserIds”{ [string]: true } }
Users connected to the media session: added by op 11, removed by op 13. libdave rejects an add proposal or a welcome naming anyone else. It survives a group reset.
roster
Section titled “roster”{ [string]: true } }
Every member of the MLS group, the bot included, mirrored from the change set each commit or welcome returns. Cleared by a group reset.
pendingTransitions
Section titled “pendingTransitions”{ [number]: number } }
The protocol version each prepared transition moves to, by transition id, until it executes.
pendingSelfRatchets
Section titled “pendingSelfRatchets”{ [number]: dave.KeyRatchet } }
The bot's own key ratchet, held by transition id until that transition executes. There is at most one: a newer commit supersedes an older one.
selfRatchetApplied
Section titled “selfRatchetApplied”Whether the encryptor holds a key from the current session. False again after a group reset.
reinitializing
Section titled “reinitializing”True while recovering from a commit or welcome libdave could not process, so a burst of failures sends one op 31. Cleared by the next processed commit or welcome, or an executed transition.
mediaReady
Section titled “mediaReady”Whether audio can flow: true when media is not under DAVE (mediaProtocolVersion 0), or under DAVE once the
encryptor holds a key from the current session. Never true before Session Description or after cleanup.
ssrcToUserId
Section titled “ssrcToUserId”{ [number]: string } }
protocolVersion
Section titled “protocolVersion”The MLS session's DAVE protocol version: set at Session Description, by a group reset and when a transition executes. 0 without a session.
mediaProtocolVersion
Section titled “mediaProtocolVersion”The DAVE protocol version media is sent and received under: set at Session Description and when a transition
executes, nil before Session Description and after cleanup.
externalSender
Section titled “externalSender”The voice gateway's MLS external sender (op 25), applied to every session a group reset creates.
channelId
Section titled “channelId”The MLS group id, which is the voice channel's id; set at Session Description.
userId
Section titled “userId”The bot's user id; set at Session Description.
The bot's audio ssrc, which every new encryptor is told is Opus; set at Session Description.
createSession
Section titled “createSession”Makes the MLS session; dave.Session.new unless a test replaces it.
createEncryptor
Section titled “createEncryptor”Makes the encryptor; dave.Encryptor.new unless a test replaces it.
createDecryptor
Section titled “createDecryptor”Makes a decryptor; dave.Decryptor.new unless a test replaces it.
sendMessage
Section titled “sendMessage”Sends a message to the voice gateway, set by the owner: a string as JSON text, a buffer as a binary frame.
purpose names it in logs.
onTransitionExecuted
Section titled “onTransitionExecuted”Set by the owner; called when a transition executes, with the number of group members, the bot included.
onMediaReadyChanged
Section titled “onMediaReadyChanged”Set by the owner; called with the new value whenever mediaReady changes.
logger
Section titled “logger”Methods
Section titled “Methods”cleanup
Section titled “cleanup”DaveManager : cleanup ( ) -> ()
Destroys the session, the encryptor, every decryptor and every held key ratchet, then resets all DAVE state.
handleSessionDescription
Section titled “handleSessionDescription”DaveManager : handleSessionDescription ( protocolVersion , channelId , userId , ssrc ) -> ()
Starts DAVE for a new voice session from Session Description's dave_protocol_version. Version 0 needs nothing
more; above 0 it creates the MLS session and the encryptor and sends a key package (op 26).
handleClientsConnect
Section titled “handleClientsConnect”DaveManager : handleClientsConnect ( userIds ) -> ()
Adds users who connected to the media session (op 11) to the recognized set.
Parameters
| userIds: { string } |
handleClientDisconnect
Section titled “handleClientDisconnect”DaveManager : handleClientDisconnect ( userId ) -> ()
Forgets a user who left the media session (op 13): they are no longer recognized, and their decryptor is destroyed.
Parameters
| userId: string |
handlePrepareTransition
Section titled “handlePrepareTransition”DaveManager : handlePrepareTransition ( payload ) -> ()
Handles prepare transition (op 21): records the protocol version the transition moves to, which applies only when it executes. A move to version 0 lets every decryptor accept plain frames now, because senders may switch first. A payload without a numeric transition id and protocol version is ignored.
Parameters
| payload: any |
handleExecuteTransition
Section titled “handleExecuteTransition”DaveManager : handleExecuteTransition ( payload ) -> ()
Handles execute transition (op 22) for a transition this client recorded; any other transition id is ignored, and a non-numeric one is warned.
Parameters
| payload: any |
hasPendingDowngrade
Section titled “hasPendingDowngrade”DaveManager : hasPendingDowngrade ( ) -> boolean
Whether a transition to protocol version 0 is prepared and not executed yet. Senders may already send plain frames then, so the receive side accepts them.
Returns
| boolean |
handlePrepareEpoch
Section titled “handlePrepareEpoch”DaveManager : handlePrepareEpoch ( payload ) -> ()
Handles prepare epoch (op 24). Epoch 1 means the voice gateway is creating the group again, so the group is reset at the payload's protocol version, which sends a new key package. Without a numeric version in the payload it falls back to the session's version, and without a version above 0 it keeps the group. Any other epoch keeps the group.
Parameters
| payload: any |
handleExternalSender
Section titled “handleExternalSender”DaveManager : handleExternalSender ( payload ) -> ()
Stores the voice gateway's MLS external sender (op 25) and applies it to the current session; a group reset applies it to the session it creates. Sends nothing: the key package goes out when a session is created.
Parameters
| payload: buffer |
handleProposals
Section titled “handleProposals”DaveManager : handleProposals ( payload ) -> ()
Processes MLS proposals (op 27) against the recognized users and the bot, and sends the resulting commit and welcome (op 28). Sending a commit is not a transition: that arrives with the announced commit (op 29).
Parameters
| payload: buffer |
handleCommitTransition
Section titled “handleCommitTransition”DaveManager : handleCommitTransition ( payload ) -> ()
Processes an announced MLS commit (op 29), which starts with a two-byte transition id. A processed commit updates the roster and keys and readies its transition; an ignored one changes nothing; a failed one starts a recovery.
Parameters
| payload: buffer |
handleWelcome
Section titled “handleWelcome”DaveManager : handleWelcome ( payload ) -> ()
Processes an MLS welcome (op 30), which starts with a two-byte transition id, against the recognized users and the bot: libdave checks every member of the welcomed group. A processed welcome updates the roster and keys and readies its transition; a rejected one starts a recovery.
Parameters
| payload: buffer |
Functions
Section titled “Functions”DaveManager . new ( loggerInstance ) -> DaveManager
Responsible for constructing this class.
Parameters
| loggerInstance: Logger |
Returns
| DaveManager |