mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
types(voice): bring back typed events (#8109)
This commit is contained in:
@@ -11,8 +11,8 @@ describe('SpeakingMap', () => {
|
|||||||
const starts: string[] = [];
|
const starts: string[] = [];
|
||||||
const ends: string[] = [];
|
const ends: string[] = [];
|
||||||
|
|
||||||
speaking.on('start', (userId: string) => void starts.push(userId));
|
speaking.on('start', (userId) => void starts.push(userId));
|
||||||
speaking.on('end', (userId: string) => void ends.push(userId));
|
speaking.on('end', (userId) => void ends.push(userId));
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
speaking.onPacket(userId);
|
speaking.onPacket(userId);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/method-signature-style */
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
import type { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v10';
|
import type { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v10';
|
||||||
import type { CreateVoiceConnectionOptions } from '.';
|
import type { CreateVoiceConnectionOptions } from '.';
|
||||||
@@ -161,6 +162,32 @@ export type VoiceConnectionState =
|
|||||||
| VoiceConnectionReadyState
|
| VoiceConnectionReadyState
|
||||||
| VoiceConnectionDestroyedState;
|
| VoiceConnectionDestroyedState;
|
||||||
|
|
||||||
|
export interface VoiceConnection extends EventEmitter {
|
||||||
|
/**
|
||||||
|
* Emitted when there is an error emitted from the voice connection
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'error', listener: (error: Error) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted debugging information about the voice connection
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted when the state of the voice connection changes
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'stateChange', listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted when the state of the voice connection changes to a specific status
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on<T extends VoiceConnectionStatus>(
|
||||||
|
event: T,
|
||||||
|
listener: (oldState: VoiceConnectionState, newState: VoiceConnectionState & { status: T }) => void,
|
||||||
|
): this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A connection to the voice server of a Guild, can be used to play audio in voice channels.
|
* A connection to the voice server of a Guild, can be used to play audio in voice channels.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
|
/* eslint-disable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/method-signature-style */
|
||||||
import EventEmitter from 'node:events';
|
import EventEmitter from 'node:events';
|
||||||
import { AudioPlayerError } from './AudioPlayerError';
|
import { AudioPlayerError } from './AudioPlayerError';
|
||||||
import type { AudioResource } from './AudioResource';
|
import type { AudioResource } from './AudioResource';
|
||||||
@@ -154,10 +154,32 @@ export type AudioPlayerState =
|
|||||||
export interface AudioPlayer extends EventEmitter {
|
export interface AudioPlayer extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* Emitted when there is an error emitted from the audio resource played by the audio player
|
* Emitted when there is an error emitted from the audio resource played by the audio player
|
||||||
*
|
|
||||||
* @event
|
* @event
|
||||||
*/
|
*/
|
||||||
on: (event: 'error', listener: (error: AudioPlayerError) => void) => this;
|
on(event: 'error', listener: (error: AudioPlayerError) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted debugging information about the audio player
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted when the state of the audio player changes
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'stateChange', listener: (oldState: AudioPlayerState, newState: AudioPlayerState) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted when the audio player is subscribed to a voice connection
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on(event: 'subscribe' | 'unsubscribe', listener: (subscription: PlayerSubscription) => void): this;
|
||||||
|
/**
|
||||||
|
* Emitted when the status of state changes to a specific status
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on<T extends AudioPlayerStatus>(
|
||||||
|
event: T,
|
||||||
|
listener: (oldState: AudioPlayerState, newState: AudioPlayerState & { status: T }) => void,
|
||||||
|
): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/method-signature-style */
|
||||||
import { createSocket, Socket } from 'node:dgram';
|
import { createSocket, Socket } from 'node:dgram';
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
import { isIPv4 } from 'node:net';
|
import { isIPv4 } from 'node:net';
|
||||||
@@ -50,6 +51,13 @@ const KEEP_ALIVE_LIMIT = 12;
|
|||||||
*/
|
*/
|
||||||
const MAX_COUNTER_VALUE = 2 ** 32 - 1;
|
const MAX_COUNTER_VALUE = 2 ** 32 - 1;
|
||||||
|
|
||||||
|
export interface VoiceUDPSocket extends EventEmitter {
|
||||||
|
on(event: 'error', listener: (error: Error) => void): this;
|
||||||
|
on(event: 'close', listener: () => void): this;
|
||||||
|
on(event: 'debug', listener: (message: string) => void): this;
|
||||||
|
on(event: 'message', listener: (message: Buffer) => void): this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the UDP networking for a voice connection.
|
* Manages the UDP networking for a voice connection.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/method-signature-style */
|
||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +22,12 @@ export interface VoiceUserData {
|
|||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SSRCMap extends EventEmitter {
|
||||||
|
on(event: 'create', listener: (newData: VoiceUserData) => void): this;
|
||||||
|
on(event: 'update', listener: (oldData: VoiceUserData | undefined, newData: VoiceUserData) => void): this;
|
||||||
|
on(event: 'delete', listener: (deletedData: VoiceUserData) => void): this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps audio SSRCs to data of users in voice connections.
|
* Maps audio SSRCs to data of users in voice connections.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
|
|
||||||
|
export interface SpeakingMap extends EventEmitter {
|
||||||
|
/**
|
||||||
|
* Emitted when a user starts/stops speaking.
|
||||||
|
* @event
|
||||||
|
*/
|
||||||
|
on: (event: 'start' | 'end', listener: (userId: string) => void) => this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the speaking states of users in a voice channel.
|
* Tracks the speaking states of users in a voice channel.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user