@discordeno/gateway 19.0.0-next.ca3defa → 19.0.0-next.ceb3d4d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ This WS service is meant for ADVANCED DEVELOPERS ONLY!
53
53
  ```ts
54
54
  createGatewayManager({
55
55
  // TODO: (docs) Fill this out
56
- });
56
+ })
57
57
  ```
58
58
 
59
59
  ## API/Docs
package/dist/Shard.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { AtLeastOne, BigString, Camelize, DiscordGatewayPayload, DiscordMember, RequestGuildMembers } from '@discordeno/types';
2
- import { Collection } from '@discordeno/utils';
3
- import WebSocket from 'ws';
2
+ import { Collection, LeakyBucket } from '@discordeno/utils';
3
+ import NodeWebSocket from 'ws';
4
4
  import type { RequestMemberRequest } from './manager.js';
5
5
  import type { BotStatusUpdate, ShardEvents, ShardGatewayConfig, ShardHeart, ShardSocketRequest, StatusUpdate, UpdateVoiceState } from './types.js';
6
6
  import { ShardState } from './types.js';
7
- export declare class Shard {
7
+ export declare class DiscordenoShard {
8
8
  /** The id of the shard */
9
9
  id: number;
10
10
  /** The connection config details that this shard will used to connect to discord. */
@@ -20,7 +20,7 @@ export declare class Shard {
20
20
  /** Current session id of the shard if present. */
21
21
  sessionId?: string;
22
22
  /** This contains the WebSocket connection to Discord, if currently connected. */
23
- socket?: WebSocket;
23
+ socket?: NodeWebSocket;
24
24
  /** Current internal state of the this. */
25
25
  state: ShardState;
26
26
  /** The url provided by discord to use when resuming a connection for this this. */
@@ -32,7 +32,7 @@ export declare class Shard {
32
32
  /** Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction */
33
33
  resolves: Map<"READY" | "RESUMED" | "INVALID_SESSION", (payload: DiscordGatewayPayload) => void>;
34
34
  /** Shard bucket. Only access this if you know what you are doing. Bucket for handling shard request rate limits. */
35
- bucket: import("@discordeno/utils").LeakyBucket;
35
+ bucket: LeakyBucket;
36
36
  /** This managers cache related settings. */
37
37
  cache: {
38
38
  requestMembers: {
@@ -48,13 +48,15 @@ export declare class Shard {
48
48
  constructor(options: ShardCreateOptions);
49
49
  /** The gateway configuration which is used to connect to Discord. */
50
50
  get gatewayConfig(): ShardGatewayConfig;
51
+ /** The url to connect to. Intially this is the discord gateway url, and then is switched to resume gateway url once a READY is received. */
52
+ get connectionUrl(): string;
51
53
  /** Calculate the amount of requests which can safely be made per rate limit interval, before the gateway gets disconnected due to an exceeded rate limit. */
52
54
  calculateSafeRequests(): number;
53
55
  checkOffline(highPriority: boolean): Promise<void>;
54
56
  /** Close the socket connection to discord if present. */
55
57
  close(code: number, reason: string): void;
56
58
  /** Connect the shard with the gateway and start heartbeating. This will not identify the shard to the gateway. */
57
- connect(): Promise<Shard>;
59
+ connect(): Promise<DiscordenoShard>;
58
60
  /** Identify the shard to the gateway. If not connected, this will also connect the shard to the gateway. */
59
61
  identify(): Promise<void>;
60
62
  /** Check whether the connection to Discord is currently open. */
@@ -68,11 +70,12 @@ export declare class Shard {
68
70
  /** Shutdown the this. Forcefully disconnect the shard from Discord. The shard may not attempt to reconnect with Discord. */
69
71
  shutdown(): Promise<void>;
70
72
  /** Handle a gateway connection close. */
71
- handleClose(close: WebSocket.CloseEvent): Promise<void>;
73
+ handleClose(close: NodeWebSocket.CloseEvent): Promise<void>;
72
74
  /** Handles a incoming gateway packet. */
73
75
  handleDiscordPacket(packet: DiscordGatewayPayload): Promise<void>;
76
+ forwardToBot(packet: DiscordGatewayPayload): void;
74
77
  /** Handle an incoming gateway message. */
75
- handleMessage(message: WebSocket.MessageEvent): Promise<void>;
78
+ handleMessage(message: NodeWebSocket.MessageEvent): Promise<void>;
76
79
  /**
77
80
  * Override in order to make the shards presence.
78
81
  * async in case devs create the presence based on eg. database values.
@@ -81,6 +84,8 @@ export declare class Shard {
81
84
  makePresence(): Promise<BotStatusUpdate | undefined>;
82
85
  /** This function communicates with the management process, in order to know whether its free to identify. When this function resolves, this means that the shard is allowed to send an identify payload to discord. */
83
86
  requestIdentify(): Promise<void>;
87
+ /** This function communicates with the management process, in order to tell it can identify the next shard. */
88
+ shardIsReady(): Promise<void>;
84
89
  /** Start sending heartbeat payloads to Discord in the provided interval. */
85
90
  startHeartbeating(interval: number): void;
86
91
  /** Stop the heartbeating process with discord. */
@@ -161,6 +166,10 @@ export interface ShardCreateOptions {
161
166
  connection: ShardGatewayConfig;
162
167
  /** The event handlers for events on the shard. */
163
168
  events: ShardEvents;
169
+ /** The handler to request a space to make an identify request. */
170
+ requestIdentify?: () => Promise<void>;
171
+ /** The handler to alert the gateway manager that this shard has received a READY event. */
172
+ shardIsReady?: () => Promise<void>;
164
173
  }
165
- export default Shard;
174
+ export default DiscordenoShard;
166
175
  //# sourceMappingURL=Shard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Shard.d.ts","sourceRoot":"","sources":["../src/Shard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,qBAAqB,EAErB,aAAa,EAEb,mBAAmB,EACpB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAY,UAAU,EAAoC,MAAM,mBAAmB,CAAA;AAE1F,OAAO,SAAS,MAAM,IAAI,CAAA;AAC1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClJ,OAAO,EAAyB,UAAU,EAAE,MAAM,YAAY,CAAA;AAE9D,qBAAa,KAAK;IAChB,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,qFAAqF;IACrF,UAAU,EAAE,kBAAkB,CAAA;IAC9B,kDAAkD;IAClD,KAAK,EAAE,UAAU,CAAA;IACjB,4HAA4H;IAC5H,2BAA2B,EAAE,MAAM,C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