Skip to content

Commit

Permalink
refactor(ClientVoiceManager): make public, remove Client#voiceConnect…
Browse files Browse the repository at this point in the history
…ions (#3186)

* docs: make voice public

* typings: Update typings to match the docs

* typings: ClientVoiceManager is nullable in Client

Co-Authored-By: vladfrangu <[email protected]>

* typings: Mark client as readonly

Co-Authored-By: vladfrangu <[email protected]>

* src: Make the client readonly

* src: Remove Client#voiceConnections getter in favor of ClientVoiceManager#connections
  • Loading branch information
vladfrangu authored and SpaceEEC committed Apr 8, 2019
1 parent 152d2e8 commit 70d4b44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
11 changes: 0 additions & 11 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Client extends BaseClient {
/**
* The voice manager of the client (`null` in browsers)
* @type {?ClientVoiceManager}
* @private
*/
this.voice = !browser ? new ClientVoiceManager(this) : null;

Expand Down Expand Up @@ -157,16 +156,6 @@ class Client extends BaseClient {
}
}

/**
* All active voice connections that have been established, mapped by guild ID
* @type {Collection<Snowflake, VoiceConnection>}
* @readonly
*/
get voiceConnections() {
if (browser) return new Collection();
return this.voice.connections;
}

/**
* All custom emojis that the client has access to, mapped by their IDs
* @type {GuildEmojiStore<Snowflake, GuildEmoji>}
Expand Down
4 changes: 3 additions & 1 deletion src/client/voice/ClientVoiceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class ClientVoiceManager {
/**
* The client that instantiated this voice manager
* @type {Client}
* @readonly
* @name ClientVoiceManager#client
*/
this.client = client;
Object.defineProperty(this, 'client', { value: client });

/**
* A collection mapping connection IDs to the Connection objects
Expand Down
20 changes: 14 additions & 6 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ declare module 'discord.js' {
export class Client extends BaseClient {
constructor(options?: ClientOptions);
private actions: object;
private voice: object;
private _eval(script: string): any;
private _validateOptions(options?: ClientOptions): void;

public broadcasts: VoiceBroadcast[];
public channels: ChannelStore;
public readonly emojis: GuildEmojiStore;
public guilds: GuildStore;
Expand All @@ -146,9 +144,8 @@ declare module 'discord.js' {
public readonly uptime: number;
public user: ClientUser | null;
public users: UserStore;
public readonly voiceConnections: Collection<Snowflake, VoiceConnection>;
public voice: ClientVoiceManager | null;
public ws: WebSocketManager;
public createVoiceBroadcast(): VoiceBroadcast;
public destroy(): void;
public fetchApplication(): Promise<ClientApplication>;
public fetchInvite(invite: InviteResolvable): Promise<Invite>;
Expand Down Expand Up @@ -234,6 +231,15 @@ declare module 'discord.js' {
public once(event: string, listener: Function): this;
}

export class ClientVoiceManager {
constructor(client: Client);
public readonly client: Client;
public connections: Collection<Snowflake, VoiceConnection>;
public broadcasts: VoiceBroadcast[];

public createBroadcast(): VoiceBroadcast;
}

export class ClientApplication extends Base {
constructor(client: Client, data: object);
public botPublic?: boolean;
Expand Down Expand Up @@ -1114,6 +1120,7 @@ declare module 'discord.js' {
class VoiceBroadcast extends EventEmitter {
constructor(client: Client);
public client: Client;
public dispatchers: StreamDispatcher[];
public readonly dispatcher: BroadcastDispatcher;
public play(input: string | Readable, options?: StreamOptions): BroadcastDispatcher;

Expand Down Expand Up @@ -1148,10 +1155,11 @@ declare module 'discord.js' {
}

class VoiceConnection extends EventEmitter {
constructor(voiceManager: object, channel: VoiceChannel);
constructor(voiceManager: ClientVoiceManager, channel: VoiceChannel);
private authentication: object;
private sockets: object;
private ssrcMap: Map<number, boolean>;
private _speaking: Map<Snowflake, Readonly<Speaking>>;
private _disconnect(): void;
private authenticate(): void;
private authenticateFailed(reason: string): void;
Expand All @@ -1175,7 +1183,7 @@ declare module 'discord.js' {
public receiver: VoiceReceiver;
public speaking: Readonly<Speaking>;
public status: VoiceStatus;
public voiceManager: object;
public voiceManager: ClientVoiceManager;
public disconnect(): void;
public play(input: VoiceBroadcast | Readable | string, options?: StreamOptions): StreamDispatcher;

Expand Down

0 comments on commit 70d4b44

Please sign in to comment.