new Socket
src/media.ts:171new Socket(gateway: GatewayLike, options: SocketOptions)A connection to a voice server's gateway, created by Gateway.Socket.voiceConnect().
import { Media } from 'detritus-client-socket';
Media.Socket;new Socket(gateway: GatewayLike, options: SocketOptions)The udp transport has its key and audio can be sent, unlike state being READY An e2ee call still drops frames until dave.canEncrypt
buildMediaSinkWants(): MediaSinkWantsThe wants for our current receive, video, defaultWants and userWants settings. Users are only listed once we know their ssrc, until then any applies to them.
cleanup(code?: number): voidconnect(endpoint?: string): voiddecode(data: any): anydestroyDave(): voiddisconnect(code?: number, reason?: string): voidencode(data: any): string | nullhandle(data: any): voidhandleBinary(buffer: Buffer): voidheartbeat(fromInterval?: boolean): voididentify(): voidkill(error?: any, options?: { voiceStateUpdate?: boolean }): voidon(event: string | symbol, listener: (...args: any[]) => void): thisAdds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// aThe callback function
on(event: "close", listener: (payload: { code: number; reason: string }) => any): thison(event: "flags", listener: (payload: { flags: number; userId: string }) => any): thison(event: "killed", listener: (payload: { error?: Error }) => any): thison(event: "mediaSinkWants", listener: (wants: MediaSinkWants) => any): thison(event: "open", listener: (target: BaseSocket) => any): thison(event: "packet", listener: (packet: Packet) => any): thison(
event: "platform",
listener: (payload: { platform: number; userId: string }) => any,
): thison(event: "ready", listener: () => any): thison(event: "socket", listener: (socket: BaseSocket) => any): thison(event: "state", listener: (__namedParameters: { state: SocketStates }) => any): thison(event: "transport", listener: (transport: Socket) => any): thison(event: "transportReady", listener: (transport: Socket) => any): thison(
event: "videoQuality",
listener: (payload: { quality: string; ssrc: number; userId: string }) => any,
): thison(
event: "voiceBackendVersion",
listener: (payload: { rtcWorker: string; voice: string }) => any,
): thison(event: "warn", listener: (error: Error) => any): thisonClose(target: BaseSocket, event: { code: number; reason: string }): voidonError(target: BaseSocket, event: any): voidonMessage(target: BaseSocket, event: { data: any; type: string }): voidonOpen(target: BaseSocket): voidping(timeout?: number): Promise<any>requestNewServer(): voidThe voice server stopped answering, asks discord for another one by sending our voice state again Once per server, if the new one fails too we die
resetSession(): voidForgets everything tied to the voice session, the next connection identifies instead of resuming
resolvePromises(error?: any): voidresume(): voidrtxToSSRC(rtxSSRC: number): number | nullThe video ssrc a retransmission (rtx) ssrc resends packets for
scheduleMediaSinkWants(): voidLike syncMediaSinkWants() but waits a moment, so setting the wants of many users at once sends one packet.
send(op: number, d: any, callback?: Function, direct?: boolean): voidThe callback always gets called once, with an error if the packet never went out Packets sent while disconnected are dropped, not queued
sendBinary(op: number, payload: Buffer, callback?: Function): voidsendClientConnect(
options?: { videoActive?: boolean } & VideoStreamSettings,
callback?: Function,
): voidTells the voice server (and through it everyone in the call) our ssrcs and if we're sending video The video settings are kept, so later calls only need videoActive
sendDaveTransitionReady(transitionId: number, callback?: Function): voidsendMediaSinkWants(wants: MediaSinkWants, callback?: Function): voidsendSelectProtocol(
options: { codecs?: any[]; data: { address: string; mode: string; port: number }; experiments?: any[]; protocol?: string; rtcConnectionId?: string },
callback?: Function,
): voidsendSessionUpdate(options: { codecs: any[] }, callback?: Function): voidGives the voice server a new list of codecs mid call, it answers with a SESSION_UPDATE if that changes what we send
sendSpeaking(
options: { delay?: number; hidden?: boolean; priority?: boolean; soundshare?: boolean; ssrc?: number; voice?: boolean },
callback?: Function,
): voidsendStateUpdate(
options?: { selfDeaf?: boolean; selfMute?: boolean; selfVideo?: boolean },
callback?: Function,
): voidsetChannelId(value: string): voidsetDefaultWants(value: number): voidSets what we want from users without their own value, 0 to 100. 0 makes setUserWants() an allowlist, only the users given a value are forwarded to us.
setEndpoint(value: string | null): voidsetHeartbeat(data: Hello): voidsetProtocol(value: MediaProtocols): voidsetReceive(receive: boolean): voidTurns receiving on or off while connected. Off asks the server to stop forwarding everything to us.
setState(value: SocketStates): voidsetToken(value: string): voidsetupDave(protocolVersion: number): voidsetUserWants(userId: string, value: number | null): voidSets what we want from one user, 0 to 100. 0 stops the server from forwarding them to us, null removes the value.
ssrcToUserId(ssrc: number, type?: MediaSSRCTypes): string | nullsyncMediaSinkWants(force?: boolean): voidSends our wants to the server if they changed since the last time. Nothing is sent while the server's defaults are what we want, it forwards everything it can to us (every user's audio, and their video too when we identified with video).
transportConnect(data: Ready): voiduserIdToSSRC(userId: string, type?: MediaSSRCTypes): number | nullwaitForNewServer(reason: string): voidKills us if discord sends no VOICE_SERVER_UPDATE with an endpoint in time, setToken() stops it once one comes