mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
feature: public raw events (#3159)
* add a public alternative to the private raw event while retaining raw for use in debugging privately * only emit dispatch packets * requested changes TIL, that's neat * fix padding * requested changes * Update WebSocketManager.js
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const EventEmitter = require('events');
|
||||||
const { Error: DJSError } = require('../../errors');
|
const { Error: DJSError } = require('../../errors');
|
||||||
const Collection = require('../../util/Collection');
|
const Collection = require('../../util/Collection');
|
||||||
const Util = require('../../util/Util');
|
const Util = require('../../util/Util');
|
||||||
@@ -21,9 +22,14 @@ const UNRECOVERABLE_CLOSE_CODES = [4004, 4010, 4011];
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebSocket manager for this client.
|
* The WebSocket manager for this client.
|
||||||
|
* <info>This class forwards raw dispatch events,
|
||||||
|
* read more about it here {@link https://discordapp.com/developers/docs/topics/gateway}</info>
|
||||||
|
* @extends EventEmitter
|
||||||
*/
|
*/
|
||||||
class WebSocketManager {
|
class WebSocketManager extends EventEmitter {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
super();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client that instantiated this WebSocketManager
|
* The client that instantiated this WebSocketManager
|
||||||
* @type {Client}
|
* @type {Client}
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ class WebSocketShard extends EventEmitter {
|
|||||||
try {
|
try {
|
||||||
packet = WebSocket.unpack(this.inflate.result);
|
packet = WebSocket.unpack(this.inflate.result);
|
||||||
this.manager.client.emit(Events.RAW, packet, this.id);
|
this.manager.client.emit(Events.RAW, packet, this.id);
|
||||||
|
if (packet.op === OPCodes.DISPATCH) this.manager.emit(packet.t, packet.d, this.id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.manager.client.emit(Events.SHARD_ERROR, err, this.id);
|
this.manager.client.emit(Events.SHARD_ERROR, err, this.id);
|
||||||
return;
|
return;
|
||||||
|
|||||||
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -1291,7 +1291,7 @@ declare module 'discord.js' {
|
|||||||
constructor(id: string, token: string, options?: ClientOptions);
|
constructor(id: string, token: string, options?: ClientOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WebSocketManager {
|
export class WebSocketManager extends EventEmitter {
|
||||||
constructor(client: Client);
|
constructor(client: Client);
|
||||||
private totalShards: number | string;
|
private totalShards: number | string;
|
||||||
private shardQueue: Set<WebSocketShard>;
|
private shardQueue: Set<WebSocketShard>;
|
||||||
@@ -1306,6 +1306,8 @@ declare module 'discord.js' {
|
|||||||
public status: Status;
|
public status: Status;
|
||||||
public readonly ping: number;
|
public readonly ping: number;
|
||||||
|
|
||||||
|
public on(event: WSEventType, listener: (data: any, shardID: number) => void): this;
|
||||||
|
public once(event: WSEventType, listener: (data: any, shardID: number) => void): this;
|
||||||
private debug(message: string, shard?: WebSocketShard): void;
|
private debug(message: string, shard?: WebSocketShard): void;
|
||||||
private connect(): Promise<void>;
|
private connect(): Promise<void>;
|
||||||
private createShards(): Promise<void>;
|
private createShards(): Promise<void>;
|
||||||
|
|||||||
Reference in New Issue
Block a user