@discordeno/gateway 22.0.1-next.db7afea → 22.0.1-next.dc9c9d1

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/dist/Shard.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'node:buffer';
2
1
  import { type Inflate, type ZstdDecompress } from 'node:zlib';
3
2
  import type { DiscordGatewayPayload, DiscordUpdatePresence } from '@discordeno/types';
4
3
  import { LeakyBucket, logger } from '@discordeno/utils';
@@ -51,12 +50,19 @@ export declare class DiscordenoShard {
51
50
  /** zlib inflate/zstd buffer. */
52
51
  inflateBuffer: Uint8Array | null;
53
52
  /**
54
- * A function that will be called once the socket is closed and handleClose() has finished updating internal states.
53
+ * A function that will be called once the socket is closed and the internal states have been updated.
55
54
  *
56
55
  * @private
57
56
  * This is for internal purposes only, and subject to breaking changes.
58
57
  */
59
- resolveAfterClose?: (close: CloseEvent) => void;
58
+ resolveAfterClose?: () => void;
59
+ /**
60
+ * A function that stops the connection attempts {@link connectWithRetries} is making, if there are any.
61
+ *
62
+ * @private
63
+ * This is for internal purposes only, and subject to breaking changes.
64
+ */
65
+ cancelConnectRetries?: () => void;
60
66
  constructor(options: ShardCreateOptions);
61
67
  /** The gateway configuration which is used to connect to Discord. */
62
68
  get gatewayConfig(): ShardGatewayConfig;
@@ -74,6 +80,20 @@ export declare class DiscordenoShard {
74
80
  * @param bypassRequest - Whether to bypass the requestIdentify handler and identify immediately. This should be used carefully as it can cause invalid sessions.
75
81
  */
76
82
  identify(bypassRequest?: boolean): Promise<void>;
83
+ /**
84
+ * Connect the shard with the gateway, trying again with an exponential backoff for as long as the opening handshake fails.
85
+ *
86
+ * @param options.waitForTurn - Awaited before every attempt, for example to wait until the shard is allowed to identify.
87
+ * @param options.beforeAttempt - Called right before every attempt, unless the shard has been asked to close while waiting for its turn.
88
+ * @returns Whether the shard is connected. `false` when the shard has been asked to close before an attempt succeeded.
89
+ *
90
+ * @private
91
+ * This is for internal purposes only, and subject to breaking changes.
92
+ */
93
+ connectWithRetries(options: {
94
+ waitForTurn?: () => Promise<void>;
95
+ beforeAttempt: () => void;
96
+ }): Promise<boolean>;
77
97
  /** Check whether the connection to Discord is currently open. */
78
98
  isOpen(): boolean;
79
99
  /** Attempt to resume the previous shards session with the gateway. */
@@ -85,18 +105,31 @@ export declare class DiscordenoShard {
85
105
  send(message: ShardSocketRequest, highPriority?: boolean): Promise<void>;
86
106
  /** Shutdown the this. Forcefully disconnect the shard from Discord. The shard may not attempt to reconnect with Discord. */
87
107
  shutdown(): Promise<void>;
108
+ /**
109
+ * Put the shard offline after its opening handshake failed or was aborted.
110
+ *
111
+ * @remarks
112
+ * Runtimes report a socket which never opened differently: Node 22 fires only an error, and a handshake aborted by {@link close} reports a close
113
+ * event first on Node 24. This is therefore called from whichever of the two arrives first, instead of {@link handleClose}. There is no session
114
+ * and no heartbeat to clean up at this point, and no reconnect is attempted here: {@link connect} rejects, and {@link identify} and
115
+ * {@link resume} try again through {@link connectWithRetries}.
116
+ *
117
+ * @private
118
+ * This is for internal purposes only, and subject to breaking changes.
119
+ */
120
+ handleFailedHandshake(): void;
88
121
  /** Handle a gateway connection error */
89
122
  handleError(error: Event): void;
90
123
  /** Handle a gateway connection close. */
91
124
  handleClose(close: CloseEvent): Promise<void>;
92
125
  /** Handle an incoming gateway message. */
93
- handleMessage(message: MessageEvent): Promise<void>;
126
+ handleMessage(message: MessageEvent<ArrayBuffer | string>): Promise<void>;
94
127
  /**
95
128
  * Decompress a zlib/zstd compressed packet
96
129
  *
97
130
  * @private
98
131
  */
99
- decompressPacket(data: ArrayBuffer | Buffer): Promise<DiscordGatewayPayload | null>;
132
+ decompressPacket(data: ArrayBuffer): Promise<string | null>;
100
133
  /** Handles a incoming gateway packet. */
101
134
  handleDiscordPacket(packet: DiscordGatewayPayload): Promise<void>;
102
135
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Shard.d.ts","sourceRoot":"","sources":["../src/Shard.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