@discordjs/ws 3.0.0-pr-11005.1765454364-f3f6d34e7 → 3.0.0-pr-10758.1765463096-d081e1706
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/defaultWorker.js +33 -12
- package/dist/defaultWorker.js.map +1 -1
- package/dist/defaultWorker.mjs +27 -6
- package/dist/defaultWorker.mjs.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +35 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -456,10 +456,7 @@ var import_collection6 = require("@discordjs/collection");
|
|
|
456
456
|
// src/ws/WebSocketShard.ts
|
|
457
457
|
var import_node_buffer = require("buffer");
|
|
458
458
|
var import_node_events2 = require("events");
|
|
459
|
-
var import_node_timers = require("timers");
|
|
460
459
|
var import_promises2 = require("timers/promises");
|
|
461
|
-
var import_node_url = require("url");
|
|
462
|
-
var import_node_util = require("util");
|
|
463
460
|
var import_collection5 = require("@discordjs/collection");
|
|
464
461
|
var import_util2 = require("@discordjs/util");
|
|
465
462
|
var import_async_queue2 = require("@sapphire/async-queue");
|
|
@@ -516,13 +513,15 @@ var Encoding = /* @__PURE__ */ ((Encoding2) => {
|
|
|
516
513
|
var CompressionMethod = /* @__PURE__ */ ((CompressionMethod2) => {
|
|
517
514
|
CompressionMethod2[CompressionMethod2["ZlibNative"] = 0] = "ZlibNative";
|
|
518
515
|
CompressionMethod2[CompressionMethod2["ZlibSync"] = 1] = "ZlibSync";
|
|
516
|
+
CompressionMethod2[CompressionMethod2["ZstdNative"] = 2] = "ZstdNative";
|
|
519
517
|
return CompressionMethod2;
|
|
520
518
|
})(CompressionMethod || {});
|
|
521
|
-
var DefaultDeviceProperty = `@discordjs/ws 3.0.0-pr-
|
|
519
|
+
var DefaultDeviceProperty = `@discordjs/ws 3.0.0-pr-10758.1765463096-d081e1706`;
|
|
522
520
|
var getDefaultSessionStore = (0, import_util.lazy)(() => new import_collection4.Collection());
|
|
523
521
|
var CompressionParameterMap = {
|
|
524
522
|
[0 /* ZlibNative */]: "zlib-stream",
|
|
525
|
-
[1 /* ZlibSync */]: "zlib-stream"
|
|
523
|
+
[1 /* ZlibSync */]: "zlib-stream",
|
|
524
|
+
[2 /* ZstdNative */]: "zstd-stream"
|
|
526
525
|
};
|
|
527
526
|
var DefaultWebSocketManagerOptions = {
|
|
528
527
|
async buildIdentifyThrottler(manager) {
|
|
@@ -618,7 +617,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
618
617
|
* Used only for native zlib inflate, zlib-sync buffering is handled by the library itself.
|
|
619
618
|
*/
|
|
620
619
|
inflateBuffer = [];
|
|
621
|
-
textDecoder = new
|
|
620
|
+
textDecoder = new TextDecoder();
|
|
622
621
|
replayedEvents = 0;
|
|
623
622
|
isAck = true;
|
|
624
623
|
sendRateLimitState = getInitialSendRateLimitState();
|
|
@@ -675,7 +674,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
675
674
|
}
|
|
676
675
|
const { version: version2, encoding, compression, useIdentifyCompression } = this.strategy.options;
|
|
677
676
|
this.identifyCompressionEnabled = useIdentifyCompression;
|
|
678
|
-
const params = new
|
|
677
|
+
const params = new URLSearchParams({ v: version2, encoding });
|
|
679
678
|
if (compression !== null) {
|
|
680
679
|
if (useIdentifyCompression) {
|
|
681
680
|
console.warn("WebSocketShard: transport compression is enabled, disabling identify compression");
|
|
@@ -699,7 +698,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
699
698
|
});
|
|
700
699
|
this.nativeInflate = inflate;
|
|
701
700
|
} else {
|
|
702
|
-
console.warn("WebSocketShard: Compression is set to native but node:zlib is not available.");
|
|
701
|
+
console.warn("WebSocketShard: Compression is set to native zlib but node:zlib is not available.");
|
|
703
702
|
params.delete("compress");
|
|
704
703
|
}
|
|
705
704
|
break;
|
|
@@ -717,6 +716,28 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
717
716
|
}
|
|
718
717
|
break;
|
|
719
718
|
}
|
|
719
|
+
case 2 /* ZstdNative */: {
|
|
720
|
+
const zlib = await getNativeZlib();
|
|
721
|
+
if (zlib && "createZstdDecompress" in zlib) {
|
|
722
|
+
this.inflateBuffer = [];
|
|
723
|
+
const inflate = zlib.createZstdDecompress({
|
|
724
|
+
chunkSize: 65535
|
|
725
|
+
});
|
|
726
|
+
inflate.on("data", (chunk) => {
|
|
727
|
+
this.inflateBuffer.push(chunk);
|
|
728
|
+
});
|
|
729
|
+
inflate.on("error", (error) => {
|
|
730
|
+
this.emit("error" /* Error */, error);
|
|
731
|
+
});
|
|
732
|
+
this.nativeInflate = inflate;
|
|
733
|
+
} else {
|
|
734
|
+
console.warn(
|
|
735
|
+
"WebSocketShard: Compression is set to native zstd but node:zlib is not available or your node version does not support zstd decompression."
|
|
736
|
+
);
|
|
737
|
+
params.delete("compress");
|
|
738
|
+
}
|
|
739
|
+
break;
|
|
740
|
+
}
|
|
720
741
|
}
|
|
721
742
|
}
|
|
722
743
|
if (this.identifyCompressionEnabled) {
|
|
@@ -773,7 +794,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
773
794
|
]);
|
|
774
795
|
this.isAck = true;
|
|
775
796
|
if (this.heartbeatInterval) {
|
|
776
|
-
|
|
797
|
+
clearInterval(this.heartbeatInterval);
|
|
777
798
|
}
|
|
778
799
|
if (this.initialHeartbeatTimeoutController) {
|
|
779
800
|
this.initialHeartbeatTimeoutController.abort();
|
|
@@ -820,7 +841,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
820
841
|
async waitForEvent(event, timeoutDuration) {
|
|
821
842
|
this.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : "indefinitely"}`]);
|
|
822
843
|
const timeoutController = new AbortController();
|
|
823
|
-
const timeout = timeoutDuration ?
|
|
844
|
+
const timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null;
|
|
824
845
|
this.timeoutAbortControllers.set(event, timeoutController);
|
|
825
846
|
const closeController = new AbortController();
|
|
826
847
|
try {
|
|
@@ -838,7 +859,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
838
859
|
return { ok: false };
|
|
839
860
|
} finally {
|
|
840
861
|
if (timeout) {
|
|
841
|
-
|
|
862
|
+
clearTimeout(timeout);
|
|
842
863
|
}
|
|
843
864
|
this.timeoutAbortControllers.delete(event);
|
|
844
865
|
if (!closeController.signal.aborted) {
|
|
@@ -999,7 +1020,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
999
1020
|
});
|
|
1000
1021
|
}
|
|
1001
1022
|
if (this.transportCompressionEnabled) {
|
|
1002
|
-
const flush = decompressable.length >= 4 && decompressable.at(-4) === 0 && decompressable.at(-3) === 0 && decompressable.at(-2) === 255 && decompressable.at(-1) === 255;
|
|
1023
|
+
const flush = this.strategy.options.compression === 2 /* ZstdNative */ || decompressable.length >= 4 && decompressable.at(-4) === 0 && decompressable.at(-3) === 0 && decompressable.at(-2) === 255 && decompressable.at(-1) === 255;
|
|
1003
1024
|
if (this.nativeInflate) {
|
|
1004
1025
|
const doneWriting = new Promise((resolve2) => {
|
|
1005
1026
|
this.nativeInflate.write(decompressable, "binary", (error) => {
|
|
@@ -1138,7 +1159,7 @@ var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter
|
|
|
1138
1159
|
}
|
|
1139
1160
|
await this.heartbeat();
|
|
1140
1161
|
this.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]);
|
|
1141
|
-
this.heartbeatInterval =
|
|
1162
|
+
this.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);
|
|
1142
1163
|
break;
|
|
1143
1164
|
}
|
|
1144
1165
|
case import_v102.GatewayOpcodes.HeartbeatAck: {
|
|
@@ -1589,7 +1610,7 @@ var WebSocketManager = class extends import_async_event_emitter2.AsyncEventEmitt
|
|
|
1589
1610
|
};
|
|
1590
1611
|
|
|
1591
1612
|
// src/index.ts
|
|
1592
|
-
var version = "3.0.0-pr-
|
|
1613
|
+
var version = "3.0.0-pr-10758.1765463096-d081e1706";
|
|
1593
1614
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1594
1615
|
0 && (module.exports = {
|
|
1595
1616
|
CloseCodes,
|