mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13: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';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const { Error: DJSError } = require('../../errors');
|
||||
const Collection = require('../../util/Collection');
|
||||
const Util = require('../../util/Util');
|
||||
@@ -21,9 +22,14 @@ const UNRECOVERABLE_CLOSE_CODES = [4004, 4010, 4011];
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The client that instantiated this WebSocketManager
|
||||
* @type {Client}
|
||||
|
||||
@@ -257,6 +257,7 @@ class WebSocketShard extends EventEmitter {
|
||||
try {
|
||||
packet = WebSocket.unpack(this.inflate.result);
|
||||
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) {
|
||||
this.manager.client.emit(Events.SHARD_ERROR, err, this.id);
|
||||
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);
|
||||
}
|
||||
|
||||
export class WebSocketManager {
|
||||
export class WebSocketManager extends EventEmitter {
|
||||
constructor(client: Client);
|
||||
private totalShards: number | string;
|
||||
private shardQueue: Set<WebSocketShard>;
|
||||
@@ -1306,6 +1306,8 @@ declare module 'discord.js' {
|
||||
public status: Status;
|
||||
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 connect(): Promise<void>;
|
||||
private createShards(): Promise<void>;
|
||||
|
||||
Reference in New Issue
Block a user