new Socket
src/media.ts:109new Socket(gateway: Socket, 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: Socket, options: SocketOptions)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: "killed", listener: (payload: { error?: Error }) => any): thison(event: "open", listener: (target: BaseSocket) => any): thison(event: "packet", listener: (packet: Packet) => 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: "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 (same channel, nothing about it changes). The VOICE_SERVER_UPDATE it answers with connects us there through setEndpoint() and setToken(), the transport comes back with a TRANSPORT_READY. Once per server, if the new one fails too we die
resolvePromises(error?: any): voidresume(): voidrtxToSSRC(rtxSSRC: number): number | nullThe video ssrc a retransmission (rtx) ssrc resends packets for
send(op: number, d: any, callback?: Function, direct?: boolean): voidsendBinary(op: number, payload: Buffer, callback?: Function): voidsendClientConnect(options?: { videoActive?: boolean }, callback?: Function): voidsendDaveTransitionReady(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; priority?: boolean; soundshare?: boolean; ssrc?: number; voice?: boolean },
callback?: Function,
): voidsendStateUpdate(
options?: { selfDeaf?: boolean; selfMute?: boolean; selfVideo?: boolean },
callback?: Function,
): voidsetChannelId(value: string): voidsetEndpoint(value: string | null): voidsetHeartbeat(data: Hello): voidsetProtocol(value: MediaProtocols): voidsetState(value: SocketStates): voidsetToken(value: string): voidsetupDave(protocolVersion: number): voidssrcToUserId(ssrc: number, type?: MediaSSRCTypes): string | nulltransportConnect(data: Ready): voiduserIdToSSRC(userId: string, type?: MediaSSRCTypes): number | null