mediaweasel 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/index.cjs +1538 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +236 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +236 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1469 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1538 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let __snazzah_davey = require("@snazzah/davey");
|
|
25
|
+
__snazzah_davey = __toESM(__snazzah_davey);
|
|
26
|
+
let __stablelib_xchacha20poly1305 = require("@stablelib/xchacha20poly1305");
|
|
27
|
+
__stablelib_xchacha20poly1305 = __toESM(__stablelib_xchacha20poly1305);
|
|
28
|
+
let node_crypto = require("node:crypto");
|
|
29
|
+
node_crypto = __toESM(node_crypto);
|
|
30
|
+
let node_dgram = require("node:dgram");
|
|
31
|
+
node_dgram = __toESM(node_dgram);
|
|
32
|
+
let node_events = require("node:events");
|
|
33
|
+
node_events = __toESM(node_events);
|
|
34
|
+
let node_net = require("node:net");
|
|
35
|
+
node_net = __toESM(node_net);
|
|
36
|
+
let discord_api_types_v10 = require("discord-api-types/v10");
|
|
37
|
+
discord_api_types_v10 = __toESM(discord_api_types_v10);
|
|
38
|
+
let discord_api_types_voice_v8 = require("discord-api-types/voice/v8");
|
|
39
|
+
discord_api_types_voice_v8 = __toESM(discord_api_types_voice_v8);
|
|
40
|
+
let ws = require("ws");
|
|
41
|
+
ws = __toESM(ws);
|
|
42
|
+
|
|
43
|
+
//#region src/audio/frameBuffer.ts
|
|
44
|
+
function toError$1(value) {
|
|
45
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
46
|
+
}
|
|
47
|
+
var FrameBuffer = class {
|
|
48
|
+
highWaterMark;
|
|
49
|
+
lowWaterMark;
|
|
50
|
+
#destroyed = false;
|
|
51
|
+
#done = false;
|
|
52
|
+
#error;
|
|
53
|
+
#iterator;
|
|
54
|
+
#pulling = false;
|
|
55
|
+
#queue = [];
|
|
56
|
+
constructor(source, options = {}) {
|
|
57
|
+
const highWaterMark = options.highWaterMark ?? 50;
|
|
58
|
+
const lowWaterMark = options.lowWaterMark ?? Math.floor(highWaterMark / 2);
|
|
59
|
+
if (!Number.isSafeInteger(highWaterMark) || highWaterMark < 1) throw new RangeError("highWaterMark must be a positive integer");
|
|
60
|
+
if (!Number.isSafeInteger(lowWaterMark) || lowWaterMark < 0 || lowWaterMark >= highWaterMark) throw new RangeError("lowWaterMark must be an integer from 0 to highWaterMark - 1");
|
|
61
|
+
this.highWaterMark = highWaterMark;
|
|
62
|
+
this.lowWaterMark = lowWaterMark;
|
|
63
|
+
this.#iterator = Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
|
|
64
|
+
this.#pull();
|
|
65
|
+
}
|
|
66
|
+
get done() {
|
|
67
|
+
return this.#done;
|
|
68
|
+
}
|
|
69
|
+
get ended() {
|
|
70
|
+
return this.#done && this.#queue.length === 0;
|
|
71
|
+
}
|
|
72
|
+
get error() {
|
|
73
|
+
return this.#error;
|
|
74
|
+
}
|
|
75
|
+
get length() {
|
|
76
|
+
return this.#queue.length;
|
|
77
|
+
}
|
|
78
|
+
shift() {
|
|
79
|
+
const frame = this.#queue.shift();
|
|
80
|
+
if (this.#queue.length <= this.lowWaterMark) this.#pull();
|
|
81
|
+
return frame;
|
|
82
|
+
}
|
|
83
|
+
destroy() {
|
|
84
|
+
if (this.#destroyed) return;
|
|
85
|
+
this.#destroyed = true;
|
|
86
|
+
this.#done = true;
|
|
87
|
+
this.#queue.length = 0;
|
|
88
|
+
Promise.resolve(this.#iterator.return?.()).catch(() => {});
|
|
89
|
+
}
|
|
90
|
+
async #pull() {
|
|
91
|
+
if (this.#pulling || this.#done) return;
|
|
92
|
+
this.#pulling = true;
|
|
93
|
+
try {
|
|
94
|
+
while (this.#queue.length < this.highWaterMark) {
|
|
95
|
+
const result = await this.#iterator.next();
|
|
96
|
+
if (this.#destroyed) return;
|
|
97
|
+
if (result.done) {
|
|
98
|
+
this.#done = true;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const frame = result.value;
|
|
102
|
+
this.#queue.push(Buffer.isBuffer(frame) ? frame : Buffer.from(frame.buffer, frame.byteOffset, frame.byteLength));
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (this.#destroyed) return;
|
|
106
|
+
this.#error = toError$1(error);
|
|
107
|
+
this.#done = true;
|
|
108
|
+
} finally {
|
|
109
|
+
this.#pulling = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/audio/oggDemuxer.ts
|
|
116
|
+
const CAPTURE_PATTERN = Buffer.from("OggS");
|
|
117
|
+
const OPUS_HEAD = Buffer.from("OpusHead");
|
|
118
|
+
const OPUS_TAGS = Buffer.from("OpusTags");
|
|
119
|
+
const PAGE_HEADER_LENGTH = 27;
|
|
120
|
+
const FLAG_CONTINUED = 1;
|
|
121
|
+
const FLAG_BOS = 2;
|
|
122
|
+
const FLAG_EOS = 4;
|
|
123
|
+
const MAX_SYNC_BYTES = 65536;
|
|
124
|
+
const CRC_TABLE = new Uint32Array(256);
|
|
125
|
+
for (let i = 0; i < 256; i++) {
|
|
126
|
+
let crc = i << 24;
|
|
127
|
+
for (let bit = 0; bit < 8; bit++) crc = crc & 2147483648 ? crc << 1 ^ 79764919 : crc << 1;
|
|
128
|
+
CRC_TABLE[i] = crc >>> 0;
|
|
129
|
+
}
|
|
130
|
+
function oggCrc(page) {
|
|
131
|
+
let crc = 0;
|
|
132
|
+
for (let i = 0; i < page.length; i++) {
|
|
133
|
+
const byte = i >= 22 && i < 26 ? 0 : page[i];
|
|
134
|
+
crc = (crc << 8 ^ CRC_TABLE[(crc >>> 24 ^ byte) & 255]) >>> 0;
|
|
135
|
+
}
|
|
136
|
+
return crc;
|
|
137
|
+
}
|
|
138
|
+
function startsWith(packet, magic) {
|
|
139
|
+
return packet.length >= magic.length && packet.subarray(0, magic.length).equals(magic);
|
|
140
|
+
}
|
|
141
|
+
function validateOpusHead(packet) {
|
|
142
|
+
if (packet.length < 19) throw new Error("OpusHead packet is too short");
|
|
143
|
+
if (packet[8] >> 4 !== 0) throw new Error(`Unsupported OpusHead version ${packet[8]}`);
|
|
144
|
+
const channels = packet[9];
|
|
145
|
+
const mappingFamily = packet[18];
|
|
146
|
+
if (channels === 0 || channels > 2 || mappingFamily !== 0) throw new Error(`Unsupported Opus channel layout (${channels} channels, family ${mappingFamily})`);
|
|
147
|
+
}
|
|
148
|
+
var OggOpusDemuxer = class {
|
|
149
|
+
#buffer = Buffer.alloc(0);
|
|
150
|
+
#discarded = 0;
|
|
151
|
+
#foundOpus = false;
|
|
152
|
+
#synced = false;
|
|
153
|
+
#awaitingTags = false;
|
|
154
|
+
#expectedSequence = 0;
|
|
155
|
+
#partial = [];
|
|
156
|
+
#serial;
|
|
157
|
+
push(chunk) {
|
|
158
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
159
|
+
this.#buffer = this.#buffer.length === 0 ? bytes : Buffer.concat([this.#buffer, bytes]);
|
|
160
|
+
return this.#readPages(false);
|
|
161
|
+
}
|
|
162
|
+
end() {
|
|
163
|
+
const packets = this.#readPages(true);
|
|
164
|
+
this.#buffer = Buffer.alloc(0);
|
|
165
|
+
if (!this.#foundOpus) throw new Error(this.#synced ? "No Opus stream found in Ogg input" : "Input is not an Ogg stream");
|
|
166
|
+
return packets;
|
|
167
|
+
}
|
|
168
|
+
#readPages(final) {
|
|
169
|
+
const packets = [];
|
|
170
|
+
const buffer = this.#buffer;
|
|
171
|
+
let offset = 0;
|
|
172
|
+
while (buffer.length - offset >= PAGE_HEADER_LENGTH) {
|
|
173
|
+
let skipTo;
|
|
174
|
+
let pageLength = 0;
|
|
175
|
+
if (!buffer.subarray(offset, offset + 4).equals(CAPTURE_PATTERN)) {
|
|
176
|
+
const next = buffer.indexOf(CAPTURE_PATTERN, offset + 1);
|
|
177
|
+
skipTo = next === -1 ? buffer.length - (CAPTURE_PATTERN.length - 1) : next;
|
|
178
|
+
} else {
|
|
179
|
+
const segmentCount = buffer[offset + 26];
|
|
180
|
+
pageLength = PAGE_HEADER_LENGTH + segmentCount;
|
|
181
|
+
for (let i = 0; i < segmentCount && offset + PAGE_HEADER_LENGTH + i < buffer.length; i++) pageLength += buffer[offset + PAGE_HEADER_LENGTH + i];
|
|
182
|
+
const complete = buffer.length - offset >= pageLength;
|
|
183
|
+
if (!complete && !final && buffer[offset + 4] === 0) break;
|
|
184
|
+
if (!(complete && buffer[offset + 4] === 0 && buffer.readUInt32LE(offset + 22) === oggCrc(buffer.subarray(offset, offset + pageLength)))) skipTo = offset + 1;
|
|
185
|
+
}
|
|
186
|
+
if (skipTo !== void 0) {
|
|
187
|
+
this.#discarded += skipTo - offset;
|
|
188
|
+
offset = skipTo;
|
|
189
|
+
if (!this.#synced && this.#discarded > MAX_SYNC_BYTES) throw new Error("Input is not an Ogg stream");
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
this.#synced = true;
|
|
193
|
+
this.#readPage(buffer.subarray(offset, offset + pageLength), packets);
|
|
194
|
+
offset += pageLength;
|
|
195
|
+
}
|
|
196
|
+
this.#buffer = buffer.subarray(offset);
|
|
197
|
+
return packets;
|
|
198
|
+
}
|
|
199
|
+
#readPage(page, packets) {
|
|
200
|
+
const flags = page[5];
|
|
201
|
+
const serial = page.readUInt32LE(14);
|
|
202
|
+
const sequence = page.readUInt32LE(18);
|
|
203
|
+
const headerLength = PAGE_HEADER_LENGTH + page[26];
|
|
204
|
+
const segments = page.subarray(PAGE_HEADER_LENGTH, headerLength);
|
|
205
|
+
if (flags & FLAG_BOS) {
|
|
206
|
+
const head = page.subarray(headerLength, headerLength + (segments[0] ?? 0));
|
|
207
|
+
if (this.#serial !== void 0 && this.#awaitingTags || !startsWith(head, OPUS_HEAD)) return;
|
|
208
|
+
validateOpusHead(head);
|
|
209
|
+
this.#foundOpus = true;
|
|
210
|
+
this.#serial = serial;
|
|
211
|
+
this.#expectedSequence = sequence + 1 >>> 0;
|
|
212
|
+
this.#awaitingTags = true;
|
|
213
|
+
this.#partial = [];
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (serial !== this.#serial) return;
|
|
217
|
+
const continued = (flags & FLAG_CONTINUED) !== 0;
|
|
218
|
+
if (sequence !== this.#expectedSequence || !continued) this.#partial = [];
|
|
219
|
+
this.#expectedSequence = sequence + 1 >>> 0;
|
|
220
|
+
let skipping = continued && this.#partial.length === 0;
|
|
221
|
+
let bodyOffset = headerLength;
|
|
222
|
+
for (const lacing of segments) {
|
|
223
|
+
if (!skipping) this.#partial.push(page.subarray(bodyOffset, bodyOffset + lacing));
|
|
224
|
+
bodyOffset += lacing;
|
|
225
|
+
if (lacing === 255) continue;
|
|
226
|
+
if (skipping) {
|
|
227
|
+
skipping = false;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const packet = Buffer.concat(this.#partial);
|
|
231
|
+
this.#partial = [];
|
|
232
|
+
if (this.#awaitingTags) {
|
|
233
|
+
this.#awaitingTags = false;
|
|
234
|
+
if (startsWith(packet, OPUS_TAGS)) continue;
|
|
235
|
+
}
|
|
236
|
+
if (packet.length > 0) packets.push(packet);
|
|
237
|
+
}
|
|
238
|
+
if (this.#partial.length > 0) this.#partial = [Buffer.concat(this.#partial)];
|
|
239
|
+
if (flags & FLAG_EOS) {
|
|
240
|
+
this.#serial = void 0;
|
|
241
|
+
this.#partial = [];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
async function* demuxOggOpus(source) {
|
|
246
|
+
const demuxer = new OggOpusDemuxer();
|
|
247
|
+
for await (const chunk of source) yield* demuxer.push(chunk);
|
|
248
|
+
yield* demuxer.end();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/audio/opus.ts
|
|
253
|
+
const OPUS_SILENCE_FRAME = Buffer.from([
|
|
254
|
+
248,
|
|
255
|
+
255,
|
|
256
|
+
254
|
|
257
|
+
]);
|
|
258
|
+
const MAX_PACKET_SAMPLES = 5760;
|
|
259
|
+
function getFrameSamples(config) {
|
|
260
|
+
if (config < 12) return [
|
|
261
|
+
480,
|
|
262
|
+
960,
|
|
263
|
+
1920,
|
|
264
|
+
2880
|
|
265
|
+
][config % 4];
|
|
266
|
+
if (config < 16) return config % 2 === 0 ? 480 : 960;
|
|
267
|
+
return 120 << config % 4;
|
|
268
|
+
}
|
|
269
|
+
/** Returns the duration of an Opus packet in 48 kHz samples, read from its TOC byte. */
|
|
270
|
+
function opusPacketSamples(packet) {
|
|
271
|
+
const toc = packet[0];
|
|
272
|
+
if (toc === void 0) throw new RangeError("Opus packet is empty");
|
|
273
|
+
let frameCount;
|
|
274
|
+
switch (toc & 3) {
|
|
275
|
+
case 0:
|
|
276
|
+
frameCount = 1;
|
|
277
|
+
break;
|
|
278
|
+
case 1:
|
|
279
|
+
case 2:
|
|
280
|
+
frameCount = 2;
|
|
281
|
+
break;
|
|
282
|
+
default: {
|
|
283
|
+
const countByte = packet[1];
|
|
284
|
+
if (countByte === void 0) throw new RangeError("Opus packet is missing its frame count");
|
|
285
|
+
frameCount = countByte & 63;
|
|
286
|
+
if (frameCount === 0) throw new RangeError("Opus packet has a frame count of 0");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const samples = frameCount * getFrameSamples(toc >> 3);
|
|
290
|
+
if (samples > MAX_PACKET_SAMPLES) throw new RangeError("Opus packet is longer than 120 ms");
|
|
291
|
+
return samples;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/types.ts
|
|
296
|
+
let VoiceConnectionDestroyedReason = /* @__PURE__ */ function(VoiceConnectionDestroyedReason$1) {
|
|
297
|
+
VoiceConnectionDestroyedReason$1["AdapterUnavailable"] = "adapter_unavailable";
|
|
298
|
+
VoiceConnectionDestroyedReason$1["Error"] = "error";
|
|
299
|
+
VoiceConnectionDestroyedReason$1["Manual"] = "manual";
|
|
300
|
+
VoiceConnectionDestroyedReason$1["WebSocketClose"] = "websocket_close";
|
|
301
|
+
return VoiceConnectionDestroyedReason$1;
|
|
302
|
+
}({});
|
|
303
|
+
let VoiceRtcpPacketType = /* @__PURE__ */ function(VoiceRtcpPacketType$1) {
|
|
304
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["SenderReport"] = 200] = "SenderReport";
|
|
305
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["ReceiverReport"] = 201] = "ReceiverReport";
|
|
306
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["SourceDescription"] = 202] = "SourceDescription";
|
|
307
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["Bye"] = 203] = "Bye";
|
|
308
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["ApplicationDefined"] = 204] = "ApplicationDefined";
|
|
309
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["TransportLayerFeedback"] = 205] = "TransportLayerFeedback";
|
|
310
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["PayloadSpecificFeedback"] = 206] = "PayloadSpecificFeedback";
|
|
311
|
+
VoiceRtcpPacketType$1[VoiceRtcpPacketType$1["ExtendedReport"] = 207] = "ExtendedReport";
|
|
312
|
+
return VoiceRtcpPacketType$1;
|
|
313
|
+
}({});
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/voiceConnection.ts
|
|
317
|
+
const SUPPORTED_MODES = node_crypto.getCiphers().includes("aes-256-gcm") ? [discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize, discord_api_types_voice_v8.VoiceEncryptionMode.AeadXChaCha20Poly1305RtpSize] : [discord_api_types_voice_v8.VoiceEncryptionMode.AeadXChaCha20Poly1305RtpSize];
|
|
318
|
+
const NON_RECOVERABLE_CLOSE_CODES = new Set([
|
|
319
|
+
4014,
|
|
320
|
+
4021,
|
|
321
|
+
4022
|
|
322
|
+
]);
|
|
323
|
+
const OPUS_PAYLOAD_TYPE = 120;
|
|
324
|
+
const UDP_KEEP_ALIVE_PACKET = Buffer.from([
|
|
325
|
+
128,
|
|
326
|
+
200,
|
|
327
|
+
0,
|
|
328
|
+
0
|
|
329
|
+
]);
|
|
330
|
+
const TRANSPORT_NONCE_SUFFIX_LENGTH = 4;
|
|
331
|
+
const TRANSPORT_TAG_LENGTH = 16;
|
|
332
|
+
const CONNECTION_TIMEOUT_MS = 1e4;
|
|
333
|
+
const RECONNECT_TIMEOUT_MS = 5e3;
|
|
334
|
+
const MAX_REJOIN_ATTEMPTS = 3;
|
|
335
|
+
const REJOIN_DELAY_MS = 1e3;
|
|
336
|
+
const UDP_TIMEOUT_MS = 1e4;
|
|
337
|
+
const UDP_DISCOVERY_RETRY_MS = 500;
|
|
338
|
+
function isRtcpPacketType(value) {
|
|
339
|
+
return value >= 192 && value <= 223;
|
|
340
|
+
}
|
|
341
|
+
function isDaveFrame(packet) {
|
|
342
|
+
return packet.length > 2 && packet[packet.length - 1] === 250 && packet[packet.length - 2] === 250;
|
|
343
|
+
}
|
|
344
|
+
function parseIpDiscoveryResponse(message) {
|
|
345
|
+
if (message.length < 10 || message.readUInt16BE(0) !== 2) return void 0;
|
|
346
|
+
const terminator = message.indexOf(0, 8);
|
|
347
|
+
if (terminator === -1 || terminator > message.length - 2) return void 0;
|
|
348
|
+
const address = message.toString("utf8", 8, terminator);
|
|
349
|
+
if ((0, node_net.isIP)(address) === 0) return void 0;
|
|
350
|
+
return {
|
|
351
|
+
address,
|
|
352
|
+
port: message.readUInt16BE(message.length - 2)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function toError(value) {
|
|
356
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
357
|
+
}
|
|
358
|
+
var VoiceConnection = class extends node_events.EventEmitter {
|
|
359
|
+
channelId;
|
|
360
|
+
consecutiveDecryptionFailures = 0;
|
|
361
|
+
decryptionFailureTolerance;
|
|
362
|
+
guildId;
|
|
363
|
+
selfDeaf;
|
|
364
|
+
selfMute;
|
|
365
|
+
rejoinAttempts = 0;
|
|
366
|
+
sequence = 0;
|
|
367
|
+
timestamp = 0;
|
|
368
|
+
transformOutboundPacket;
|
|
369
|
+
daveProtocolVersion = 0;
|
|
370
|
+
daveSession;
|
|
371
|
+
lastTransitionId;
|
|
372
|
+
reinitializing = false;
|
|
373
|
+
users = /* @__PURE__ */ new Set();
|
|
374
|
+
#adapter;
|
|
375
|
+
#connectionTimeout;
|
|
376
|
+
#credentials;
|
|
377
|
+
#daveDowngraded = false;
|
|
378
|
+
#destroyed = false;
|
|
379
|
+
#endpoint;
|
|
380
|
+
#heartbeat;
|
|
381
|
+
#lastSequence = -1;
|
|
382
|
+
#missedHeartbeats = 0;
|
|
383
|
+
#pendingTransitions = /* @__PURE__ */ new Map();
|
|
384
|
+
#sendNonce = 0;
|
|
385
|
+
#serverUpdate;
|
|
386
|
+
#session;
|
|
387
|
+
#stateUpdate;
|
|
388
|
+
#ssrc;
|
|
389
|
+
ssrcUserMap = /* @__PURE__ */ new Map();
|
|
390
|
+
#state = { status: "created" };
|
|
391
|
+
#transport;
|
|
392
|
+
#udp;
|
|
393
|
+
#udpRemote;
|
|
394
|
+
#udpDiscoveryRetry;
|
|
395
|
+
#udpTimeout;
|
|
396
|
+
#ws;
|
|
397
|
+
#xchacha;
|
|
398
|
+
constructor(options) {
|
|
399
|
+
super();
|
|
400
|
+
this.guildId = options.guildId;
|
|
401
|
+
this.channelId = options.channelId;
|
|
402
|
+
this.selfDeaf = options.selfDeaf ?? false;
|
|
403
|
+
this.selfMute = options.selfMute ?? false;
|
|
404
|
+
this.decryptionFailureTolerance = options.decryptionFailureTolerance ?? 36;
|
|
405
|
+
this.transformOutboundPacket = options.transformOutboundPacket;
|
|
406
|
+
this.#transport = options.transport ?? {};
|
|
407
|
+
this.#adapter = options.adapterCreator({
|
|
408
|
+
destroy: () => this.#destroy({
|
|
409
|
+
status: "destroyed",
|
|
410
|
+
reason: VoiceConnectionDestroyedReason.AdapterUnavailable
|
|
411
|
+
}, void 0, false, false),
|
|
412
|
+
onVoiceServerUpdate: (packet) => this.#addVoiceServerUpdate(packet),
|
|
413
|
+
onVoiceStateUpdate: (packet) => this.#addVoiceStateUpdate(packet)
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
get state() {
|
|
417
|
+
return this.#state;
|
|
418
|
+
}
|
|
419
|
+
get endpoint() {
|
|
420
|
+
return this.#endpoint;
|
|
421
|
+
}
|
|
422
|
+
joinChannel() {
|
|
423
|
+
if (this.#destroyed || this.#state.status !== "created") return;
|
|
424
|
+
this.#transition({ status: "signalling" });
|
|
425
|
+
this.#startConnectionTimeout();
|
|
426
|
+
if (!this.#sendVoiceStateUpdate(this.channelId)) this.#destroy({
|
|
427
|
+
status: "destroyed",
|
|
428
|
+
reason: VoiceConnectionDestroyedReason.AdapterUnavailable
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
switchChannel(channelId) {
|
|
432
|
+
if (this.#destroyed || this.channelId == channelId) return false;
|
|
433
|
+
this.channelId = channelId;
|
|
434
|
+
this.#stateUpdate = void 0;
|
|
435
|
+
this.#serverUpdate = void 0;
|
|
436
|
+
this.#resetVoiceSession();
|
|
437
|
+
this.#closeTransports();
|
|
438
|
+
this.#transition({ status: "signalling" });
|
|
439
|
+
this.#startConnectionTimeout();
|
|
440
|
+
if (this.#sendVoiceStateUpdate(channelId)) return true;
|
|
441
|
+
this.#destroy({
|
|
442
|
+
status: "destroyed",
|
|
443
|
+
reason: VoiceConnectionDestroyedReason.AdapterUnavailable
|
|
444
|
+
});
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
disconnect(error) {
|
|
448
|
+
if (this.#destroyed) return;
|
|
449
|
+
const state = error === void 0 ? {
|
|
450
|
+
status: "destroyed",
|
|
451
|
+
reason: VoiceConnectionDestroyedReason.Manual
|
|
452
|
+
} : {
|
|
453
|
+
status: "destroyed",
|
|
454
|
+
reason: VoiceConnectionDestroyedReason.Error,
|
|
455
|
+
error
|
|
456
|
+
};
|
|
457
|
+
this.#destroy(state, error, true, true);
|
|
458
|
+
}
|
|
459
|
+
get voicePrivacyCode() {
|
|
460
|
+
const code = this.daveSession?.voicePrivacyCode;
|
|
461
|
+
return code === "" ? void 0 : code;
|
|
462
|
+
}
|
|
463
|
+
get daveReady() {
|
|
464
|
+
return this.daveProtocolVersion !== 0 && !this.#daveDowngraded && (this.daveSession?.ready ?? false);
|
|
465
|
+
}
|
|
466
|
+
async getVerificationCode(userId) {
|
|
467
|
+
if (this.daveSession === void 0) throw new Error("DAVE session is not available");
|
|
468
|
+
return this.daveSession.getVerificationCode(userId);
|
|
469
|
+
}
|
|
470
|
+
setSpeaking(enabled, delay = 0) {
|
|
471
|
+
if (this.#destroyed || this.#ssrc === void 0 || this.#ws?.readyState !== ws.default.OPEN) return false;
|
|
472
|
+
this.#sendJson({
|
|
473
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.Speaking,
|
|
474
|
+
d: {
|
|
475
|
+
delay,
|
|
476
|
+
speaking: enabled ? discord_api_types_voice_v8.VoiceSpeakingFlags.Microphone : 0,
|
|
477
|
+
ssrc: this.#ssrc
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
sendPacket(op, d) {
|
|
483
|
+
if (this.#destroyed || this.#ws?.readyState !== ws.default.OPEN) return false;
|
|
484
|
+
this.#sendJson({
|
|
485
|
+
op,
|
|
486
|
+
d
|
|
487
|
+
});
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
sendUdpPacket(packet) {
|
|
491
|
+
const remote = this.#udpRemote;
|
|
492
|
+
if (this.#destroyed || this.#state.status !== "ready" || this.#udp === void 0 || remote === void 0) return false;
|
|
493
|
+
try {
|
|
494
|
+
this.#udp.send(packet, remote.port, remote.ip);
|
|
495
|
+
return true;
|
|
496
|
+
} catch (error) {
|
|
497
|
+
this.#emitError(toError(error));
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
encryptDaveOpusPacket(packet) {
|
|
502
|
+
if (packet.equals(OPUS_SILENCE_FRAME) || this.daveProtocolVersion === 0 || this.#daveDowngraded) return packet;
|
|
503
|
+
if (this.daveSession === void 0 || !this.daveSession.ready) throw new Error("DAVE session is not ready");
|
|
504
|
+
if (!this.daveSession.canEncrypt) throw new Error("DAVE session has no encryption key yet");
|
|
505
|
+
return this.daveSession.encryptOpus(packet);
|
|
506
|
+
}
|
|
507
|
+
decryptDavePacket(userId, mediaType, packet) {
|
|
508
|
+
if (packet.equals(OPUS_SILENCE_FRAME)) return packet;
|
|
509
|
+
const daveSession = this.daveSession;
|
|
510
|
+
if (this.#canDaveDecrypt(userId)) return daveSession.decrypt(userId, mediaType, packet);
|
|
511
|
+
if (daveSession !== void 0 && isDaveFrame(packet)) throw new Error(`DAVE frame from ${userId} cannot be decrypted yet`);
|
|
512
|
+
if (this.daveProtocolVersion === 0 || this.#daveDowngraded) return packet;
|
|
513
|
+
throw new Error("DAVE session is not ready");
|
|
514
|
+
}
|
|
515
|
+
encryptTransportPacket(header, payload) {
|
|
516
|
+
const session = this.#session;
|
|
517
|
+
if (this.#state.status !== "ready" || session === void 0) throw new Error("Voice connection is not ready");
|
|
518
|
+
const nonce = Buffer.alloc(session.encryptionMode === discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize ? 12 : 24);
|
|
519
|
+
this.#sendNonce = this.#sendNonce + 1 >>> 0;
|
|
520
|
+
nonce.writeUInt32BE(this.#sendNonce, 0);
|
|
521
|
+
let encrypted;
|
|
522
|
+
if (session.encryptionMode === discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize) {
|
|
523
|
+
const cipher = node_crypto.createCipheriv("aes-256-gcm", session.secretKey, nonce);
|
|
524
|
+
cipher.setAAD(header);
|
|
525
|
+
encrypted = Buffer.concat([
|
|
526
|
+
cipher.update(payload),
|
|
527
|
+
cipher.final(),
|
|
528
|
+
cipher.getAuthTag()
|
|
529
|
+
]);
|
|
530
|
+
} else {
|
|
531
|
+
const xchacha = this.#xchacha ??= new __stablelib_xchacha20poly1305.XChaCha20Poly1305(session.secretKey);
|
|
532
|
+
encrypted = Buffer.from(xchacha.seal(nonce, payload, header));
|
|
533
|
+
}
|
|
534
|
+
return Buffer.concat([
|
|
535
|
+
header,
|
|
536
|
+
encrypted,
|
|
537
|
+
nonce.subarray(0, TRANSPORT_NONCE_SUFFIX_LENGTH)
|
|
538
|
+
]);
|
|
539
|
+
}
|
|
540
|
+
decryptTransportPacket(packet) {
|
|
541
|
+
const session = this.#session;
|
|
542
|
+
if (this.#state.status !== "ready" || session === void 0) throw new Error("Voice connection is not ready");
|
|
543
|
+
const headerLength = this.#getRtpHeaderLength(packet);
|
|
544
|
+
if (packet.length < headerLength + TRANSPORT_TAG_LENGTH + TRANSPORT_NONCE_SUFFIX_LENGTH) throw new Error("Encrypted RTP packet is too short");
|
|
545
|
+
const nonce = Buffer.alloc(session.encryptionMode === discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize ? 12 : 24);
|
|
546
|
+
packet.copy(nonce, 0, packet.length - TRANSPORT_NONCE_SUFFIX_LENGTH);
|
|
547
|
+
const header = packet.subarray(0, headerLength);
|
|
548
|
+
const encryptedEnd = packet.length - TRANSPORT_NONCE_SUFFIX_LENGTH;
|
|
549
|
+
let payload;
|
|
550
|
+
if (session.encryptionMode === discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize) {
|
|
551
|
+
const tagStart = encryptedEnd - TRANSPORT_TAG_LENGTH;
|
|
552
|
+
const decipher = node_crypto.createDecipheriv("aes-256-gcm", session.secretKey, nonce);
|
|
553
|
+
decipher.setAAD(header);
|
|
554
|
+
decipher.setAuthTag(packet.subarray(tagStart, encryptedEnd));
|
|
555
|
+
payload = Buffer.concat([decipher.update(packet.subarray(headerLength, tagStart)), decipher.final()]);
|
|
556
|
+
} else {
|
|
557
|
+
const opened = (this.#xchacha ??= new __stablelib_xchacha20poly1305.XChaCha20Poly1305(session.secretKey)).open(nonce, packet.subarray(headerLength, encryptedEnd), header);
|
|
558
|
+
if (opened === null) throw new Error("Failed to authenticate XChaCha20-Poly1305 packet");
|
|
559
|
+
payload = Buffer.from(opened);
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
header,
|
|
563
|
+
nonce,
|
|
564
|
+
payload
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
prepareAudioFrame(opusPacket, frameSize) {
|
|
568
|
+
const session = this.#session;
|
|
569
|
+
if (this.#state.status !== "ready" || session === void 0) return void 0;
|
|
570
|
+
frameSize ??= opusPacketSamples(opusPacket);
|
|
571
|
+
if (!Number.isSafeInteger(frameSize) || frameSize <= 0 || frameSize > 4294967295) throw new RangeError("frameSize must be a positive uint32 sample count");
|
|
572
|
+
const header = Buffer.allocUnsafe(12);
|
|
573
|
+
header[0] = 128;
|
|
574
|
+
header[1] = OPUS_PAYLOAD_TYPE;
|
|
575
|
+
header.writeUInt16BE(this.sequence, 2);
|
|
576
|
+
header.writeUInt32BE(this.timestamp, 4);
|
|
577
|
+
header.writeUInt32BE(session.ssrc, 8);
|
|
578
|
+
this.sequence = this.sequence + 1 & 65535;
|
|
579
|
+
this.timestamp = this.timestamp + frameSize >>> 0;
|
|
580
|
+
if (this.daveProtocolVersion !== 0 && !this.#daveDowngraded && !opusPacket.equals(OPUS_SILENCE_FRAME) && !(this.daveSession?.ready && this.daveSession.canEncrypt)) return void 0;
|
|
581
|
+
return this.encryptTransportPacket(header, this.encryptDaveOpusPacket(opusPacket));
|
|
582
|
+
}
|
|
583
|
+
sendAudioFrame(opusPacket, frameSize) {
|
|
584
|
+
const packet = this.prepareAudioFrame(opusPacket, frameSize);
|
|
585
|
+
return packet !== void 0 && this.sendUdpPacket(packet);
|
|
586
|
+
}
|
|
587
|
+
sendSilenceFrames(count = 5) {
|
|
588
|
+
let sent = true;
|
|
589
|
+
for (let i = 0; i < count; i++) if (!this.sendAudioFrame(OPUS_SILENCE_FRAME)) sent = false;
|
|
590
|
+
return sent;
|
|
591
|
+
}
|
|
592
|
+
recoverFromInvalidTransition(transitionId) {
|
|
593
|
+
this.#warn(`Invalidating transition ${transitionId}`);
|
|
594
|
+
this.reinitializing = true;
|
|
595
|
+
this.consecutiveDecryptionFailures = 0;
|
|
596
|
+
const invalidTransition = {
|
|
597
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.DaveMlsInvalidCommitWelcome,
|
|
598
|
+
d: { transition_id: transitionId }
|
|
599
|
+
};
|
|
600
|
+
this.#sendJson(invalidTransition);
|
|
601
|
+
this.#reinitializeDave();
|
|
602
|
+
}
|
|
603
|
+
#addVoiceStateUpdate(packet) {
|
|
604
|
+
if (this.#destroyed || packet.guild_id !== this.guildId) return;
|
|
605
|
+
this.#stateUpdate = packet;
|
|
606
|
+
if (packet.channel_id === null) {
|
|
607
|
+
this.#debug("Voice state has no channel; waiting for the voice WebSocket to close");
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
this.channelId = packet.channel_id;
|
|
611
|
+
this.#maybeConnect();
|
|
612
|
+
}
|
|
613
|
+
#addVoiceServerUpdate(packet) {
|
|
614
|
+
if (this.#destroyed || packet.guild_id !== this.guildId) return;
|
|
615
|
+
this.#serverUpdate = packet.endpoint === null ? void 0 : packet;
|
|
616
|
+
if (packet.endpoint === null) {
|
|
617
|
+
/** @see https://docs.discord.com/developers/events/gateway-events#voice-server-update */
|
|
618
|
+
this.#debug("Discord removed the current voice endpoint; waiting for reallocation");
|
|
619
|
+
this.#resetVoiceSession();
|
|
620
|
+
this.#closeTransports();
|
|
621
|
+
this.#transition({ status: "signalling" });
|
|
622
|
+
this.#startConnectionTimeout();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
this.#maybeConnect();
|
|
626
|
+
}
|
|
627
|
+
#maybeConnect() {
|
|
628
|
+
const serverUpdate = this.#serverUpdate;
|
|
629
|
+
const stateUpdate = this.#stateUpdate;
|
|
630
|
+
if (serverUpdate?.endpoint == null || stateUpdate?.channel_id == null) return;
|
|
631
|
+
const credentials = {
|
|
632
|
+
endpoint: serverUpdate.endpoint,
|
|
633
|
+
sessionId: stateUpdate.session_id,
|
|
634
|
+
token: serverUpdate.token,
|
|
635
|
+
userId: stateUpdate.user_id
|
|
636
|
+
};
|
|
637
|
+
if (this.#ws !== void 0 && this.#credentials?.endpoint === credentials.endpoint && this.#credentials.sessionId === credentials.sessionId && this.#credentials.token === credentials.token) return;
|
|
638
|
+
this.#resetVoiceSession();
|
|
639
|
+
this.#credentials = credentials;
|
|
640
|
+
this.#openWebSocket(credentials, "identify");
|
|
641
|
+
}
|
|
642
|
+
#openWebSocket(credentials, mode) {
|
|
643
|
+
if (mode === "identify") this.#closeTransports();
|
|
644
|
+
else this.#closeWebSocket();
|
|
645
|
+
const endpoint = new URL(credentials.endpoint.startsWith("wss://") ? credentials.endpoint : `wss://${credentials.endpoint}`);
|
|
646
|
+
if (endpoint.port === "80") endpoint.port = "";
|
|
647
|
+
endpoint.searchParams.set("v", discord_api_types_voice_v8.VoiceGatewayVersion);
|
|
648
|
+
this.#endpoint = endpoint;
|
|
649
|
+
this.#debug(`Connecting to voice endpoint ${endpoint.host}`);
|
|
650
|
+
this.#transition({
|
|
651
|
+
status: "connecting",
|
|
652
|
+
endpoint,
|
|
653
|
+
phase: mode === "resume" ? "resuming" : "identifying"
|
|
654
|
+
});
|
|
655
|
+
this.#startConnectionTimeout();
|
|
656
|
+
let socket;
|
|
657
|
+
try {
|
|
658
|
+
socket = new ws.default(endpoint, this.#transport.webSocket ?? {});
|
|
659
|
+
} catch (error) {
|
|
660
|
+
this.#destroy({
|
|
661
|
+
status: "destroyed",
|
|
662
|
+
reason: VoiceConnectionDestroyedReason.Error,
|
|
663
|
+
error: toError(error)
|
|
664
|
+
}, toError(error));
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
this.#ws = socket;
|
|
668
|
+
socket.on("open", () => {
|
|
669
|
+
if (this.#ws !== socket) return;
|
|
670
|
+
this.emit("connect");
|
|
671
|
+
if (mode === "resume") {
|
|
672
|
+
const resume = {
|
|
673
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.Resume,
|
|
674
|
+
d: {
|
|
675
|
+
seq_ack: this.#lastSequence,
|
|
676
|
+
server_id: this.guildId,
|
|
677
|
+
session_id: credentials.sessionId,
|
|
678
|
+
token: credentials.token
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
this.#sendJson(resume);
|
|
682
|
+
this.#debug("Voice WebSocket opened and requested session resume");
|
|
683
|
+
} else {
|
|
684
|
+
const identify = {
|
|
685
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.Identify,
|
|
686
|
+
d: {
|
|
687
|
+
max_dave_protocol_version: __snazzah_davey.DAVE_PROTOCOL_VERSION,
|
|
688
|
+
server_id: this.guildId,
|
|
689
|
+
session_id: credentials.sessionId,
|
|
690
|
+
token: credentials.token,
|
|
691
|
+
user_id: credentials.userId
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
this.#sendJson(identify);
|
|
695
|
+
this.#debug("Voice WebSocket opened and identified");
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
socket.on("message", (data, isBinary) => {
|
|
699
|
+
if (this.#ws !== socket) return;
|
|
700
|
+
try {
|
|
701
|
+
if (isBinary) {
|
|
702
|
+
const buffer = Buffer.isBuffer(data) ? data : Array.isArray(data) ? Buffer.concat(data) : Buffer.from(data);
|
|
703
|
+
this.#handleBinaryPacket(buffer);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
const parsed = JSON.parse(data.toString());
|
|
707
|
+
this.#handleJsonPacket(parsed);
|
|
708
|
+
} catch (error) {
|
|
709
|
+
const packetError = toError(error);
|
|
710
|
+
this.#emitError(packetError);
|
|
711
|
+
this.#destroy({
|
|
712
|
+
status: "destroyed",
|
|
713
|
+
reason: VoiceConnectionDestroyedReason.Error,
|
|
714
|
+
error: packetError
|
|
715
|
+
}, packetError);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
socket.on("error", (error) => this.#emitError(error));
|
|
719
|
+
socket.on("close", (code, reason) => {
|
|
720
|
+
if (this.#destroyed || this.#ws !== socket) return;
|
|
721
|
+
this.#ws = void 0;
|
|
722
|
+
this.#clearHeartbeat();
|
|
723
|
+
this.#handleWebSocketClose(code, reason.toString());
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
#handleWebSocketClose(code, reason) {
|
|
727
|
+
const wasReady = this.#state.status === "ready";
|
|
728
|
+
const disconnectedState = {
|
|
729
|
+
status: "disconnected",
|
|
730
|
+
closeCode: code,
|
|
731
|
+
closeReason: reason
|
|
732
|
+
};
|
|
733
|
+
this.#transition(disconnectedState);
|
|
734
|
+
this.emit("disconnect", disconnectedState);
|
|
735
|
+
if (this.#destroyed || this.#state !== disconnectedState) return;
|
|
736
|
+
if (NON_RECOVERABLE_CLOSE_CODES.has(code) || this.#stateUpdate?.channel_id === null) {
|
|
737
|
+
this.#awaitReconnect(code, reason);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if ((code === 4015 || code < 4e3) && wasReady && this.#session !== void 0 && this.#credentials !== void 0) {
|
|
741
|
+
this.#debug(`Voice WebSocket closed (${code}); resuming the session`);
|
|
742
|
+
this.#openWebSocket(this.#credentials, "resume");
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
this.#requestGatewayRejoin(`Voice WebSocket closed (${code}): ${reason}`);
|
|
746
|
+
}
|
|
747
|
+
#awaitReconnect(code, reason) {
|
|
748
|
+
const timeout = this.#transport.reconnectTimeout ?? RECONNECT_TIMEOUT_MS;
|
|
749
|
+
this.#debug(`Voice WebSocket closed (${code}); waiting ${timeout}ms for a reconnect`);
|
|
750
|
+
this.#serverUpdate = void 0;
|
|
751
|
+
this.#resetVoiceSession();
|
|
752
|
+
this.#closeTransports();
|
|
753
|
+
this.#clearConnectionTimeout();
|
|
754
|
+
this.#connectionTimeout = setTimeout(() => {
|
|
755
|
+
this.#destroy({
|
|
756
|
+
status: "destroyed",
|
|
757
|
+
reason: VoiceConnectionDestroyedReason.WebSocketClose,
|
|
758
|
+
closeCode: code,
|
|
759
|
+
closeReason: reason
|
|
760
|
+
}, /* @__PURE__ */ new Error(`Voice WebSocket closed (${code}): ${reason}`));
|
|
761
|
+
}, timeout);
|
|
762
|
+
this.#connectionTimeout.unref();
|
|
763
|
+
}
|
|
764
|
+
#requestGatewayRejoin(cause) {
|
|
765
|
+
if (this.#destroyed) return;
|
|
766
|
+
const maxAttempts = this.#transport.maxRejoinAttempts ?? MAX_REJOIN_ATTEMPTS;
|
|
767
|
+
if (this.rejoinAttempts >= maxAttempts) {
|
|
768
|
+
const error = /* @__PURE__ */ new Error(`Voice connection failed after ${this.rejoinAttempts} rejoin attempts: ${cause}`);
|
|
769
|
+
this.#destroy({
|
|
770
|
+
status: "destroyed",
|
|
771
|
+
reason: VoiceConnectionDestroyedReason.Error,
|
|
772
|
+
error
|
|
773
|
+
}, error, true);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
this.rejoinAttempts++;
|
|
777
|
+
const delay = this.rejoinAttempts === 1 ? 0 : (this.#transport.rejoinDelay ?? REJOIN_DELAY_MS) * 2 ** (this.rejoinAttempts - 2);
|
|
778
|
+
this.#debug(`${cause}; rejoining in ${delay}ms (attempt ${this.rejoinAttempts}/${maxAttempts})`);
|
|
779
|
+
this.#serverUpdate = void 0;
|
|
780
|
+
this.#stateUpdate = void 0;
|
|
781
|
+
this.#resetVoiceSession();
|
|
782
|
+
this.#closeTransports();
|
|
783
|
+
this.#transition({ status: "signalling" });
|
|
784
|
+
this.#clearConnectionTimeout();
|
|
785
|
+
this.#connectionTimeout = setTimeout(() => {
|
|
786
|
+
this.#startConnectionTimeout();
|
|
787
|
+
if (!this.#sendVoiceStateUpdate(this.channelId)) this.#destroy({
|
|
788
|
+
status: "destroyed",
|
|
789
|
+
reason: VoiceConnectionDestroyedReason.AdapterUnavailable
|
|
790
|
+
});
|
|
791
|
+
}, delay);
|
|
792
|
+
this.#connectionTimeout.unref();
|
|
793
|
+
}
|
|
794
|
+
#handleJsonPacket(packet) {
|
|
795
|
+
this.emit("wsPacket", packet);
|
|
796
|
+
if (this.#hasListeners("debug")) this.#debug(`Rec: ${JSON.stringify(packet)}`);
|
|
797
|
+
if ("seq" in packet && typeof packet.seq === "number") this.#lastSequence = packet.seq;
|
|
798
|
+
switch (packet.op) {
|
|
799
|
+
case discord_api_types_voice_v8.VoiceOpcodes.Hello:
|
|
800
|
+
this.#handleHello(packet.d);
|
|
801
|
+
break;
|
|
802
|
+
case discord_api_types_voice_v8.VoiceOpcodes.Ready:
|
|
803
|
+
this.#handleReady(packet.d);
|
|
804
|
+
break;
|
|
805
|
+
case discord_api_types_voice_v8.VoiceOpcodes.SessionDescription:
|
|
806
|
+
this.#handleSessionDescription(packet.d);
|
|
807
|
+
break;
|
|
808
|
+
case discord_api_types_voice_v8.VoiceOpcodes.Resumed:
|
|
809
|
+
this.#handleResumed();
|
|
810
|
+
break;
|
|
811
|
+
case discord_api_types_voice_v8.VoiceOpcodes.HeartbeatAck:
|
|
812
|
+
this.#handleHeartbeatAck(packet.d);
|
|
813
|
+
break;
|
|
814
|
+
case discord_api_types_voice_v8.VoiceOpcodes.Speaking:
|
|
815
|
+
this.ssrcUserMap.set(packet.d.ssrc, packet.d.user_id);
|
|
816
|
+
if (packet.d.speaking) this.emit("speakingStart", packet.d.user_id);
|
|
817
|
+
else this.emit("speakingStop", packet.d.user_id);
|
|
818
|
+
break;
|
|
819
|
+
case discord_api_types_voice_v8.VoiceOpcodes.ClientsConnect:
|
|
820
|
+
this.#handleClientsConnect(packet.d);
|
|
821
|
+
break;
|
|
822
|
+
case discord_api_types_voice_v8.VoiceOpcodes.ClientDisconnect:
|
|
823
|
+
this.#handleClientDisconnect(packet.d);
|
|
824
|
+
break;
|
|
825
|
+
case discord_api_types_voice_v8.VoiceOpcodes.DavePrepareTransition:
|
|
826
|
+
this.#handlePrepareTransition(packet.d);
|
|
827
|
+
break;
|
|
828
|
+
case discord_api_types_voice_v8.VoiceOpcodes.DaveExecuteTransition:
|
|
829
|
+
this.#handleExecuteTransition(packet.d);
|
|
830
|
+
break;
|
|
831
|
+
case discord_api_types_voice_v8.VoiceOpcodes.DavePrepareEpoch:
|
|
832
|
+
this.#handlePrepareEpoch(packet.d);
|
|
833
|
+
break;
|
|
834
|
+
default:
|
|
835
|
+
this.emit("unknown", packet);
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
#handleHello(data) {
|
|
840
|
+
this.#clearHeartbeat();
|
|
841
|
+
this.#missedHeartbeats = 0;
|
|
842
|
+
this.#heartbeat = setInterval(() => {
|
|
843
|
+
if (this.#missedHeartbeats >= 3) {
|
|
844
|
+
this.#debug("Voice WebSocket missed three heartbeat acknowledgements");
|
|
845
|
+
const socket = this.#ws;
|
|
846
|
+
this.#clearHeartbeat();
|
|
847
|
+
socket?.close();
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
this.#sendHeartbeat();
|
|
851
|
+
}, data.heartbeat_interval);
|
|
852
|
+
this.#heartbeat.unref();
|
|
853
|
+
this.#sendHeartbeat();
|
|
854
|
+
}
|
|
855
|
+
#handleReady(data) {
|
|
856
|
+
const mode = SUPPORTED_MODES.find((candidate) => data.modes.includes(candidate));
|
|
857
|
+
if (mode === void 0) throw new Error("Voice ready payload has no usable UDP transport");
|
|
858
|
+
this.#ssrc = data.ssrc;
|
|
859
|
+
this.#clearConnectionTimeout();
|
|
860
|
+
this.#debug(`Connecting to UDP: ${data.ip}:${data.port}`);
|
|
861
|
+
this.#transition({
|
|
862
|
+
status: "discovering_ip",
|
|
863
|
+
ip: data.ip,
|
|
864
|
+
port: data.port
|
|
865
|
+
});
|
|
866
|
+
this.#udpRemote = {
|
|
867
|
+
ip: data.ip,
|
|
868
|
+
port: data.port
|
|
869
|
+
};
|
|
870
|
+
const socket = (0, node_dgram.createSocket)({
|
|
871
|
+
...this.#transport.udpSocket,
|
|
872
|
+
type: (0, node_net.isIPv6)(data.ip) ? "udp6" : "udp4"
|
|
873
|
+
});
|
|
874
|
+
this.#udp = socket;
|
|
875
|
+
socket.on("error", (error) => {
|
|
876
|
+
this.#emitError(error);
|
|
877
|
+
this.#requestGatewayRejoin(`Voice UDP socket errored: ${error.message}`);
|
|
878
|
+
});
|
|
879
|
+
socket.on("message", (message) => {
|
|
880
|
+
if (this.#state.status === "ready") this.#handleUdpPacket(message);
|
|
881
|
+
else if (this.#state.status === "discovering_ip") this.#handleIpDiscoveryResponse(message, mode, socket, data);
|
|
882
|
+
});
|
|
883
|
+
socket.on("close", () => {
|
|
884
|
+
if (!this.#destroyed && this.#udp === socket) this.#requestGatewayRejoin("Voice UDP socket closed");
|
|
885
|
+
});
|
|
886
|
+
const discovery = Buffer.alloc(74);
|
|
887
|
+
discovery.writeUInt16BE(1, 0);
|
|
888
|
+
discovery.writeUInt16BE(70, 2);
|
|
889
|
+
discovery.writeUInt32BE(data.ssrc, 4);
|
|
890
|
+
socket.send(discovery, data.port, data.ip);
|
|
891
|
+
this.#udpDiscoveryRetry = setInterval(() => {
|
|
892
|
+
socket.send(discovery, data.port, data.ip);
|
|
893
|
+
}, UDP_DISCOVERY_RETRY_MS);
|
|
894
|
+
this.#udpDiscoveryRetry.unref();
|
|
895
|
+
this.#udpTimeout = setTimeout(() => {
|
|
896
|
+
this.#emitError(/* @__PURE__ */ new Error("Voice UDP IP discovery timed out"));
|
|
897
|
+
this.#requestGatewayRejoin("Voice UDP IP discovery timed out");
|
|
898
|
+
}, this.#transport.udpTimeout ?? UDP_TIMEOUT_MS);
|
|
899
|
+
this.#udpTimeout.unref();
|
|
900
|
+
}
|
|
901
|
+
#handleIpDiscoveryResponse(message, mode, socket, ready) {
|
|
902
|
+
const discovered = parseIpDiscoveryResponse(message);
|
|
903
|
+
if (discovered === void 0) {
|
|
904
|
+
this.#warn(`Ignored a malformed UDP IP discovery response (${message.length} bytes)`);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const { address, port } = discovered;
|
|
908
|
+
this.#clearUdpTimers();
|
|
909
|
+
this.#debug(`Discovered IP: ${address}:${port} (${message.toString("hex")})`);
|
|
910
|
+
if (this.#hasListeners("ipDiscovered")) {
|
|
911
|
+
this.emit("ipDiscovered", {
|
|
912
|
+
address,
|
|
913
|
+
port,
|
|
914
|
+
serverAddress: ready.ip,
|
|
915
|
+
serverPort: ready.port,
|
|
916
|
+
ssrc: ready.ssrc
|
|
917
|
+
});
|
|
918
|
+
if (this.#destroyed || this.#udp !== socket) return;
|
|
919
|
+
}
|
|
920
|
+
this.#transition({
|
|
921
|
+
status: "selecting_protocol",
|
|
922
|
+
mode
|
|
923
|
+
});
|
|
924
|
+
this.#startConnectionTimeout();
|
|
925
|
+
const selectProtocol = {
|
|
926
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.SelectProtocol,
|
|
927
|
+
d: {
|
|
928
|
+
data: {
|
|
929
|
+
address,
|
|
930
|
+
mode,
|
|
931
|
+
port
|
|
932
|
+
},
|
|
933
|
+
protocol: "udp"
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
this.#sendJson(selectProtocol);
|
|
937
|
+
}
|
|
938
|
+
#handleSessionDescription(data) {
|
|
939
|
+
if (this.#ssrc === void 0) throw new Error("Voice session has no SSRC");
|
|
940
|
+
if (data.mode !== discord_api_types_voice_v8.VoiceEncryptionMode.AeadAes256GcmRtpSize && data.mode !== discord_api_types_voice_v8.VoiceEncryptionMode.AeadXChaCha20Poly1305RtpSize) throw new Error(`Voice session selected unsupported encryption mode ${data.mode}`);
|
|
941
|
+
if (data.secret_key.length !== 32) throw new Error("Voice session secret key is not 32 bytes");
|
|
942
|
+
this.daveProtocolVersion = data.dave_protocol_version;
|
|
943
|
+
this.#daveDowngraded = this.daveProtocolVersion === 0;
|
|
944
|
+
this.#reinitializeDave();
|
|
945
|
+
const session = {
|
|
946
|
+
daveProtocolVersion: data.dave_protocol_version,
|
|
947
|
+
encryptionMode: data.mode,
|
|
948
|
+
secretKey: Uint8Array.from(data.secret_key),
|
|
949
|
+
ssrc: this.#ssrc
|
|
950
|
+
};
|
|
951
|
+
this.#session = session;
|
|
952
|
+
this.#xchacha?.clean();
|
|
953
|
+
this.#xchacha = data.mode === discord_api_types_voice_v8.VoiceEncryptionMode.AeadXChaCha20Poly1305RtpSize ? new __stablelib_xchacha20poly1305.XChaCha20Poly1305(session.secretKey) : void 0;
|
|
954
|
+
this.rejoinAttempts = 0;
|
|
955
|
+
this.#clearConnectionTimeout();
|
|
956
|
+
this.#transition({
|
|
957
|
+
status: "ready",
|
|
958
|
+
session
|
|
959
|
+
});
|
|
960
|
+
this.setSpeaking(false);
|
|
961
|
+
this.sendAudioFrame(OPUS_SILENCE_FRAME);
|
|
962
|
+
this.emit("ready", session);
|
|
963
|
+
}
|
|
964
|
+
#handleResumed() {
|
|
965
|
+
if (this.#session === void 0) {
|
|
966
|
+
this.#requestGatewayRejoin("Voice session resumed without a session description");
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
this.#clearConnectionTimeout();
|
|
970
|
+
this.#transition({
|
|
971
|
+
status: "ready",
|
|
972
|
+
session: this.#session
|
|
973
|
+
});
|
|
974
|
+
this.emit("resumed");
|
|
975
|
+
this.emit("ready", this.#session);
|
|
976
|
+
}
|
|
977
|
+
#handleHeartbeatAck(data) {
|
|
978
|
+
this.#missedHeartbeats = 0;
|
|
979
|
+
const latency = Date.now() - data.t;
|
|
980
|
+
this.emit("pong", latency);
|
|
981
|
+
this.#debug(`Voice heartbeat latency ${latency}ms`);
|
|
982
|
+
}
|
|
983
|
+
#handleClientsConnect(data) {
|
|
984
|
+
for (const userId of data.user_ids) this.users.add(userId);
|
|
985
|
+
this.emit("usersConnect", data.user_ids);
|
|
986
|
+
}
|
|
987
|
+
#handleClientDisconnect(data) {
|
|
988
|
+
this.users.delete(data.user_id);
|
|
989
|
+
for (const [ssrc, userId] of this.ssrcUserMap) if (userId === data.user_id) this.ssrcUserMap.delete(ssrc);
|
|
990
|
+
this.emit("userDisconnect", data.user_id);
|
|
991
|
+
}
|
|
992
|
+
#handlePrepareTransition(data) {
|
|
993
|
+
this.#debug(`Preparing for DAVE transition (${data.transition_id}, v${data.protocol_version})`);
|
|
994
|
+
this.#pendingTransitions.set(data.transition_id, data.protocol_version);
|
|
995
|
+
try {
|
|
996
|
+
this.daveSession?.prepareTransition(data.transition_id, data.protocol_version);
|
|
997
|
+
} catch (error) {
|
|
998
|
+
this.#warn(`Failed to prepare DAVE transition: ${toError(error)}`);
|
|
999
|
+
}
|
|
1000
|
+
if (data.protocol_version === 0) this.daveSession?.setPassthroughMode(true);
|
|
1001
|
+
if (data.transition_id === 0) this.#executeTransition(data.transition_id);
|
|
1002
|
+
else this.#sendDaveTransitionReady(data.transition_id);
|
|
1003
|
+
}
|
|
1004
|
+
#handleExecuteTransition(data) {
|
|
1005
|
+
this.#debug(`Executing DAVE transition (${data.transition_id})`);
|
|
1006
|
+
if (this.#executeTransition(data.transition_id)) this.emit("transitioned", data.transition_id);
|
|
1007
|
+
}
|
|
1008
|
+
#handlePrepareEpoch(data) {
|
|
1009
|
+
this.#debug(`Preparing for DAVE epoch (${data.epoch})`);
|
|
1010
|
+
if (data.epoch === 1) {
|
|
1011
|
+
this.daveProtocolVersion = data.protocol_version;
|
|
1012
|
+
this.#reinitializeDave();
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
#handleUdpPacket(message) {
|
|
1016
|
+
this.emit("udpPacket", message);
|
|
1017
|
+
if (message.length < 2) {
|
|
1018
|
+
this.#warn("Dropped a UDP packet shorter than an RTP/RTCP header");
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (isRtcpPacketType(message[1])) {
|
|
1022
|
+
if (this.#hasListeners("rtcpPacket")) this.#handleRtcpPackets(message);
|
|
1023
|
+
} else if (this.#hasListeners("opus")) this.#handleOpusPacket(message);
|
|
1024
|
+
}
|
|
1025
|
+
#handleRtcpPackets(message) {
|
|
1026
|
+
let offset = 0;
|
|
1027
|
+
while (offset < message.length) {
|
|
1028
|
+
if (message.length - offset < 4) {
|
|
1029
|
+
this.#warn("Dropped RTCP packet with a truncated common header");
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
const first = message[offset];
|
|
1033
|
+
const version = first >> 6;
|
|
1034
|
+
if (version !== 2) {
|
|
1035
|
+
this.#warn(`Received RTCP packet with an invalid version: ${version}`);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const packetType = message[offset + 1];
|
|
1039
|
+
if (!isRtcpPacketType(packetType)) {
|
|
1040
|
+
this.#warn(`Received RTCP packet with an invalid payload type: ${packetType}`);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
const length = message.readUInt16BE(offset + 2);
|
|
1044
|
+
const packetLength = (length + 1) * 4;
|
|
1045
|
+
if (packetLength < 4 || offset + packetLength > message.length) {
|
|
1046
|
+
this.#warn(`Received RTCP packet with an invalid length: ${packetLength}`);
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
const rawPacket = message.subarray(offset, offset + packetLength);
|
|
1050
|
+
const ssrc = rawPacket.length >= 8 ? rawPacket.readUInt32BE(4) : void 0;
|
|
1051
|
+
const packet = {
|
|
1052
|
+
data: rawPacket.subarray(ssrc === void 0 ? 4 : 8),
|
|
1053
|
+
length,
|
|
1054
|
+
packetType,
|
|
1055
|
+
padding: (first & 32) !== 0,
|
|
1056
|
+
receptionCount: first & 31,
|
|
1057
|
+
ssrc,
|
|
1058
|
+
userId: ssrc === void 0 ? void 0 : this.ssrcUserMap.get(ssrc) ?? this.ssrcUserMap.get(ssrc - 3 >>> 0),
|
|
1059
|
+
version
|
|
1060
|
+
};
|
|
1061
|
+
this.emit("rtcpPacket", packet);
|
|
1062
|
+
offset += packetLength;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
#handleOpusPacket(message) {
|
|
1066
|
+
if (message.length < 12) {
|
|
1067
|
+
this.#warn("Dropped RTP packet with a truncated fixed header");
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const first = message[0];
|
|
1071
|
+
const second = message[1];
|
|
1072
|
+
const version = first >> 6;
|
|
1073
|
+
if (version !== 2) {
|
|
1074
|
+
this.#warn(`Received RTP packet with an invalid version: ${version}`);
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if ((second & 127) !== OPUS_PAYLOAD_TYPE) return;
|
|
1078
|
+
const headerLength = 12 + (first & 15) * 4 + ((first & 16) !== 0 ? 4 : 0);
|
|
1079
|
+
if (message.length < headerLength) {
|
|
1080
|
+
this.#warn("Dropped RTP packet with a truncated CSRC or extension header");
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (message.length < headerLength + TRANSPORT_TAG_LENGTH + TRANSPORT_NONCE_SUFFIX_LENGTH) {
|
|
1084
|
+
this.#warn("Dropped encrypted RTP packet that was too short");
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
let transport;
|
|
1088
|
+
try {
|
|
1089
|
+
transport = this.decryptTransportPacket(message);
|
|
1090
|
+
} catch {
|
|
1091
|
+
this.#warn("Failed to decrypt received RTP packet");
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
let opus = transport.payload;
|
|
1095
|
+
if ((first & 32) !== 0) {
|
|
1096
|
+
if (opus.length === 0) {
|
|
1097
|
+
this.#warn("Packet was dropped due to invalid RTP padding");
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
const paddingLength = opus[opus.length - 1];
|
|
1101
|
+
if (paddingLength === 0 || paddingLength > opus.length) {
|
|
1102
|
+
this.#warn("Packet was dropped due to invalid RTP padding");
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
opus = opus.subarray(0, opus.length - paddingLength);
|
|
1106
|
+
}
|
|
1107
|
+
if ((first & 16) !== 0) {
|
|
1108
|
+
const extensionLength = transport.header.readUInt16BE(transport.header.length - 2) * 4;
|
|
1109
|
+
if (extensionLength > opus.length) {
|
|
1110
|
+
this.#warn("Packet was dropped due to a truncated RTP extension");
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
opus = opus.subarray(extensionLength);
|
|
1114
|
+
}
|
|
1115
|
+
if (opus.length === 0) return;
|
|
1116
|
+
const ssrc = message.readUInt32BE(8);
|
|
1117
|
+
const userId = this.ssrcUserMap.get(ssrc);
|
|
1118
|
+
const daveSession = this.daveSession;
|
|
1119
|
+
if (!opus.equals(OPUS_SILENCE_FRAME) && daveSession !== void 0) {
|
|
1120
|
+
if (daveSession.ready && userId === void 0) {
|
|
1121
|
+
this.#warn("Packet was dropped due to having an undefined user ID during a DAVE session");
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
if (!daveSession.ready && this.daveProtocolVersion !== 0 && !this.#daveDowngraded) {
|
|
1125
|
+
this.#warn("Packet was dropped due to the DAVE session not being ready yet");
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
if (userId !== void 0) {
|
|
1129
|
+
if (!this.#canDaveDecrypt(userId) && isDaveFrame(opus)) {
|
|
1130
|
+
this.#debug(`Packet was dropped due to it being encrypted while ${userId} cannot be decrypted`);
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
try {
|
|
1134
|
+
opus = this.decryptDavePacket(userId, __snazzah_davey.MediaType.AUDIO, opus);
|
|
1135
|
+
this.consecutiveDecryptionFailures = 0;
|
|
1136
|
+
} catch {
|
|
1137
|
+
if (!this.daveReady) {
|
|
1138
|
+
this.#debug(`Failed to decrypt received E2EE packet from ${userId} (session downgraded)`);
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
const pendingTransitions = this.#pendingTransitions.size;
|
|
1142
|
+
const counted = !this.reinitializing && pendingTransitions === 0;
|
|
1143
|
+
if (counted) this.consecutiveDecryptionFailures++;
|
|
1144
|
+
const reason = this.reinitializing ? "reinitializing session" : pendingTransitions > 0 ? `${pendingTransitions} pending transition(s)` : `${this.consecutiveDecryptionFailures} consecutive fails`;
|
|
1145
|
+
this.#warn(`Failed to decrypt received E2EE packet from ${userId} (${reason})`);
|
|
1146
|
+
if (counted && this.decryptionFailureTolerance > 0 && this.lastTransitionId !== void 0 && this.consecutiveDecryptionFailures > this.decryptionFailureTolerance) this.recoverFromInvalidTransition(this.lastTransitionId);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
this.emit("opus", message.readUInt32BE(4), message.readUInt16BE(2), userId, opus);
|
|
1152
|
+
}
|
|
1153
|
+
#getRtpHeaderLength(packet) {
|
|
1154
|
+
if (packet.length < 12) throw new Error("RTP packet is shorter than 12 bytes");
|
|
1155
|
+
let headerLength = 12 + (packet[0] & 15) * 4;
|
|
1156
|
+
if (packet.length < headerLength) throw new Error("RTP packet has a truncated CSRC list");
|
|
1157
|
+
if ((packet[0] & 16) !== 0) headerLength += 4;
|
|
1158
|
+
if (packet.length < headerLength) throw new Error("RTP packet has a truncated extension header");
|
|
1159
|
+
return headerLength;
|
|
1160
|
+
}
|
|
1161
|
+
#handleBinaryPacket(message) {
|
|
1162
|
+
this.emit("wsPacket", message);
|
|
1163
|
+
if (message.length < 3) throw new Error("Malformed binary voice packet");
|
|
1164
|
+
this.#lastSequence = message.readUInt16BE(0);
|
|
1165
|
+
const opcode = message.readUInt8(2);
|
|
1166
|
+
const payload = message.subarray(3);
|
|
1167
|
+
if (opcode === discord_api_types_voice_v8.VoiceOpcodes.DaveMlsExternalSender) {
|
|
1168
|
+
this.daveSession?.setExternalSender(payload);
|
|
1169
|
+
this.#debug("Set MLS external sender");
|
|
1170
|
+
} else if (opcode === discord_api_types_voice_v8.VoiceOpcodes.DaveMlsProposals) {
|
|
1171
|
+
if (payload.length < 1 || this.daveSession === void 0) return;
|
|
1172
|
+
const operation = payload.readUInt8(0);
|
|
1173
|
+
if (operation !== 0 && operation !== 1) return;
|
|
1174
|
+
try {
|
|
1175
|
+
const result = this.daveSession.processProposals(operation, payload.subarray(1), [...this.users, this.daveSession.userId]);
|
|
1176
|
+
if (result.commit !== void 0) this.#sendBinary(discord_api_types_voice_v8.VoiceOpcodes.DaveMlsCommitWelcome, result.welcome === void 0 ? result.commit : Buffer.concat([result.commit, result.welcome]));
|
|
1177
|
+
this.#debug("MLS proposals processed");
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
this.#warn(`MLS proposals errored: ${toError(error)}`);
|
|
1180
|
+
if (this.lastTransitionId === void 0) this.disconnect(/* @__PURE__ */ new Error("Failed to process MLS proposals"));
|
|
1181
|
+
else if (!this.reinitializing) this.recoverFromInvalidTransition(this.lastTransitionId);
|
|
1182
|
+
}
|
|
1183
|
+
} else if (opcode === discord_api_types_voice_v8.VoiceOpcodes.DaveMlsAnnounceCommitTransition) {
|
|
1184
|
+
if (payload.length < 2 || this.daveSession === void 0) return;
|
|
1185
|
+
const transitionId = payload.readUInt16BE(0);
|
|
1186
|
+
try {
|
|
1187
|
+
if (!this.daveSession.processCommit(payload.subarray(2))) {
|
|
1188
|
+
this.#debug(`MLS commit ignored (transition ID: ${transitionId})`);
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
this.daveSession.prepareTransition(transitionId, this.daveSession.protocolVersion);
|
|
1192
|
+
if (transitionId === 0) {
|
|
1193
|
+
this.lastTransitionId = transitionId;
|
|
1194
|
+
this.reinitializing = false;
|
|
1195
|
+
this.emit("transitioned", transitionId);
|
|
1196
|
+
} else {
|
|
1197
|
+
this.#pendingTransitions.set(transitionId, this.daveProtocolVersion);
|
|
1198
|
+
this.#sendDaveTransitionReady(transitionId);
|
|
1199
|
+
}
|
|
1200
|
+
this.#debug(`MLS commit processed (transition ID: ${transitionId})`);
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
this.#warn(`MLS commit errored: ${toError(error)}`);
|
|
1203
|
+
this.recoverFromInvalidTransition(transitionId);
|
|
1204
|
+
}
|
|
1205
|
+
} else if (opcode === discord_api_types_voice_v8.VoiceOpcodes.DaveMlsWelcome) {
|
|
1206
|
+
if (payload.length < 2 || this.daveSession === void 0) return;
|
|
1207
|
+
const transitionId = payload.readUInt16BE(0);
|
|
1208
|
+
try {
|
|
1209
|
+
this.daveSession.processWelcome(payload.subarray(2), [...this.users, this.daveSession.userId]);
|
|
1210
|
+
this.daveSession.prepareTransition(transitionId, this.daveSession.protocolVersion);
|
|
1211
|
+
if (transitionId === 0) {
|
|
1212
|
+
this.lastTransitionId = transitionId;
|
|
1213
|
+
this.reinitializing = false;
|
|
1214
|
+
this.emit("transitioned", transitionId);
|
|
1215
|
+
} else {
|
|
1216
|
+
this.#pendingTransitions.set(transitionId, this.daveProtocolVersion);
|
|
1217
|
+
this.#sendDaveTransitionReady(transitionId);
|
|
1218
|
+
}
|
|
1219
|
+
this.#debug(`MLS welcome processed (transition ID: ${transitionId})`);
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
this.#warn(`MLS welcome errored: ${toError(error)}`);
|
|
1222
|
+
this.recoverFromInvalidTransition(transitionId);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
#reinitializeDave() {
|
|
1227
|
+
this.#pendingTransitions.clear();
|
|
1228
|
+
const credentials = this.#credentials;
|
|
1229
|
+
if (credentials === void 0 || this.daveProtocolVersion === 0) {
|
|
1230
|
+
const hadSession = this.daveSession !== void 0;
|
|
1231
|
+
this.daveSession?.reset();
|
|
1232
|
+
if (hadSession) {
|
|
1233
|
+
this.daveSession?.setPassthroughMode(true);
|
|
1234
|
+
this.#debug("DAVE session reset");
|
|
1235
|
+
}
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (this.daveSession === void 0) {
|
|
1239
|
+
this.daveSession = new __snazzah_davey.DAVESession(this.daveProtocolVersion, credentials.userId, this.channelId);
|
|
1240
|
+
this.#debug(`DAVE session initialized for protocol version ${this.daveProtocolVersion}`);
|
|
1241
|
+
} else {
|
|
1242
|
+
this.daveSession.reinit(this.daveProtocolVersion, credentials.userId, this.channelId);
|
|
1243
|
+
this.#debug(`DAVE session reinitialized for protocol version ${this.daveProtocolVersion}`);
|
|
1244
|
+
}
|
|
1245
|
+
if (this.#daveDowngraded) this.daveSession.setPassthroughMode(true);
|
|
1246
|
+
this.#sendBinary(discord_api_types_voice_v8.VoiceOpcodes.DaveMlsKeyPackage, this.daveSession.getSerializedKeyPackage());
|
|
1247
|
+
}
|
|
1248
|
+
#executeTransition(transitionId) {
|
|
1249
|
+
const version = this.#pendingTransitions.get(transitionId);
|
|
1250
|
+
if (version === void 0) {
|
|
1251
|
+
this.#warn(`Received execute transition without a pending transition (${transitionId})`);
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
if (transitionId !== 0) {
|
|
1255
|
+
let executed = false;
|
|
1256
|
+
try {
|
|
1257
|
+
executed = this.daveSession?.executeTransition(transitionId) ?? false;
|
|
1258
|
+
if (!executed) this.#warn(`Failed to execute DAVE transition ${transitionId}: davey did not execute it`);
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
this.#warn(`Failed to execute DAVE transition ${transitionId}: ${toError(error)}`);
|
|
1261
|
+
}
|
|
1262
|
+
if (!executed) {
|
|
1263
|
+
this.#pendingTransitions.delete(transitionId);
|
|
1264
|
+
return false;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
const previousVersion = this.daveProtocolVersion;
|
|
1268
|
+
this.daveProtocolVersion = version;
|
|
1269
|
+
this.lastTransitionId = transitionId;
|
|
1270
|
+
this.reinitializing = false;
|
|
1271
|
+
this.#pendingTransitions.delete(transitionId);
|
|
1272
|
+
if (previousVersion !== version && version === 0) {
|
|
1273
|
+
this.#daveDowngraded = true;
|
|
1274
|
+
this.#debug("DAVE protocol downgraded");
|
|
1275
|
+
} else if (transitionId > 0 && this.#daveDowngraded) {
|
|
1276
|
+
this.#daveDowngraded = false;
|
|
1277
|
+
this.daveSession?.setPassthroughMode(false, 10);
|
|
1278
|
+
this.#debug("DAVE protocol upgraded");
|
|
1279
|
+
}
|
|
1280
|
+
this.#debug(`DAVE transition executed (v${previousVersion} -> v${version}, ID: ${transitionId})`);
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
#canDaveDecrypt(userId) {
|
|
1284
|
+
const session = this.daveSession;
|
|
1285
|
+
return (session?.ready ?? false) && (this.daveReady || session.canPassthrough(userId));
|
|
1286
|
+
}
|
|
1287
|
+
#sendDaveTransitionReady(transitionId) {
|
|
1288
|
+
this.#sendJson({
|
|
1289
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.DaveTransitionReady,
|
|
1290
|
+
d: { transition_id: transitionId }
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
#sendHeartbeat() {
|
|
1294
|
+
const heartbeat = {
|
|
1295
|
+
op: discord_api_types_voice_v8.VoiceOpcodes.Heartbeat,
|
|
1296
|
+
d: {
|
|
1297
|
+
seq_ack: this.#lastSequence,
|
|
1298
|
+
t: Date.now()
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
this.#missedHeartbeats++;
|
|
1302
|
+
this.#sendJson(heartbeat);
|
|
1303
|
+
const udp = this.#udp;
|
|
1304
|
+
const remote = this.#udpRemote;
|
|
1305
|
+
if (udp !== void 0 && remote !== void 0) try {
|
|
1306
|
+
udp.send(UDP_KEEP_ALIVE_PACKET, remote.port, remote.ip);
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
this.#emitError(toError(error));
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
#sendVoiceStateUpdate(channelId) {
|
|
1312
|
+
try {
|
|
1313
|
+
return this.#adapter.sendPayload({
|
|
1314
|
+
op: discord_api_types_v10.GatewayOpcodes.VoiceStateUpdate,
|
|
1315
|
+
d: {
|
|
1316
|
+
channel_id: channelId,
|
|
1317
|
+
guild_id: this.guildId,
|
|
1318
|
+
self_deaf: this.selfDeaf,
|
|
1319
|
+
self_mute: this.selfMute
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
} catch (error) {
|
|
1323
|
+
this.#emitError(toError(error));
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
#sendJson(packet) {
|
|
1328
|
+
const ws$1 = this.#ws;
|
|
1329
|
+
if (ws$1?.readyState !== ws.default.OPEN) return;
|
|
1330
|
+
let outbound = packet;
|
|
1331
|
+
if (this.transformOutboundPacket !== void 0) {
|
|
1332
|
+
try {
|
|
1333
|
+
outbound = this.transformOutboundPacket(packet) ?? packet;
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
this.#emitError(toError(error));
|
|
1336
|
+
}
|
|
1337
|
+
if (this.#ws !== ws$1 || ws$1.readyState !== ws.default.OPEN) return;
|
|
1338
|
+
}
|
|
1339
|
+
ws$1.send(JSON.stringify(outbound));
|
|
1340
|
+
}
|
|
1341
|
+
#sendBinary(opcode, payload) {
|
|
1342
|
+
if (this.#ws?.readyState !== ws.default.OPEN) return;
|
|
1343
|
+
const packet = Buffer.allocUnsafe(payload.length + 1);
|
|
1344
|
+
packet.writeUInt8(opcode, 0);
|
|
1345
|
+
payload.copy(packet, 1);
|
|
1346
|
+
this.#ws.send(packet);
|
|
1347
|
+
}
|
|
1348
|
+
#destroy(state, error, sendLeave = false, destroyAdapter = true) {
|
|
1349
|
+
if (this.#destroyed) return;
|
|
1350
|
+
this.#destroyed = true;
|
|
1351
|
+
this.#clearTimers();
|
|
1352
|
+
this.#closeTransports();
|
|
1353
|
+
this.daveSession?.reset();
|
|
1354
|
+
this.#xchacha?.clean();
|
|
1355
|
+
this.#xchacha = void 0;
|
|
1356
|
+
if (sendLeave) this.#sendVoiceStateUpdate(null);
|
|
1357
|
+
if (destroyAdapter) this.#adapter.destroy();
|
|
1358
|
+
this.#transition(state);
|
|
1359
|
+
this.emit("destroyed", state, error);
|
|
1360
|
+
this.emit("close", error);
|
|
1361
|
+
}
|
|
1362
|
+
#emitError(error) {
|
|
1363
|
+
if (this.listenerCount("error") > 0) this.emit("error", error);
|
|
1364
|
+
}
|
|
1365
|
+
#debug(message) {
|
|
1366
|
+
this.emit("debug", message);
|
|
1367
|
+
}
|
|
1368
|
+
#warn(message) {
|
|
1369
|
+
this.emit("warn", message);
|
|
1370
|
+
}
|
|
1371
|
+
#hasListeners(event) {
|
|
1372
|
+
return this.listenerCount(event) > 0;
|
|
1373
|
+
}
|
|
1374
|
+
#transition(current) {
|
|
1375
|
+
const previous = this.#state;
|
|
1376
|
+
this.#state = current;
|
|
1377
|
+
this.emit("stateChange", previous, current);
|
|
1378
|
+
}
|
|
1379
|
+
#startConnectionTimeout() {
|
|
1380
|
+
this.#clearConnectionTimeout();
|
|
1381
|
+
this.#connectionTimeout = setTimeout(() => {
|
|
1382
|
+
if (this.#state.status === "connecting" && this.#state.phase === "resuming") {
|
|
1383
|
+
this.#requestGatewayRejoin("Voice session resume timed out");
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
const error = /* @__PURE__ */ new Error("Voice connection timed out");
|
|
1387
|
+
this.#destroy({
|
|
1388
|
+
status: "destroyed",
|
|
1389
|
+
reason: VoiceConnectionDestroyedReason.Error,
|
|
1390
|
+
error
|
|
1391
|
+
}, error);
|
|
1392
|
+
}, this.#transport.connectionTimeout ?? CONNECTION_TIMEOUT_MS);
|
|
1393
|
+
this.#connectionTimeout.unref();
|
|
1394
|
+
}
|
|
1395
|
+
#clearConnectionTimeout() {
|
|
1396
|
+
if (this.#connectionTimeout !== void 0) clearTimeout(this.#connectionTimeout);
|
|
1397
|
+
this.#connectionTimeout = void 0;
|
|
1398
|
+
}
|
|
1399
|
+
#resetVoiceSession() {
|
|
1400
|
+
this.#session = void 0;
|
|
1401
|
+
this.#credentials = void 0;
|
|
1402
|
+
this.#ssrc = void 0;
|
|
1403
|
+
this.#lastSequence = -1;
|
|
1404
|
+
this.#pendingTransitions.clear();
|
|
1405
|
+
this.#daveDowngraded = false;
|
|
1406
|
+
this.#sendNonce = 0;
|
|
1407
|
+
this.sequence = 0;
|
|
1408
|
+
this.timestamp = 0;
|
|
1409
|
+
this.ssrcUserMap.clear();
|
|
1410
|
+
this.users.clear();
|
|
1411
|
+
this.consecutiveDecryptionFailures = 0;
|
|
1412
|
+
this.daveProtocolVersion = 0;
|
|
1413
|
+
this.lastTransitionId = void 0;
|
|
1414
|
+
this.reinitializing = false;
|
|
1415
|
+
this.daveSession?.reset();
|
|
1416
|
+
this.daveSession = void 0;
|
|
1417
|
+
this.#xchacha?.clean();
|
|
1418
|
+
this.#xchacha = void 0;
|
|
1419
|
+
this.#udpRemote = void 0;
|
|
1420
|
+
}
|
|
1421
|
+
#clearHeartbeat() {
|
|
1422
|
+
if (this.#heartbeat !== void 0) clearInterval(this.#heartbeat);
|
|
1423
|
+
this.#heartbeat = void 0;
|
|
1424
|
+
this.#missedHeartbeats = 0;
|
|
1425
|
+
}
|
|
1426
|
+
#clearTimers() {
|
|
1427
|
+
this.#clearConnectionTimeout();
|
|
1428
|
+
this.#clearHeartbeat();
|
|
1429
|
+
this.#clearUdpTimers();
|
|
1430
|
+
}
|
|
1431
|
+
#clearUdpTimers() {
|
|
1432
|
+
if (this.#udpDiscoveryRetry !== void 0) clearInterval(this.#udpDiscoveryRetry);
|
|
1433
|
+
this.#udpDiscoveryRetry = void 0;
|
|
1434
|
+
if (this.#udpTimeout !== void 0) clearTimeout(this.#udpTimeout);
|
|
1435
|
+
this.#udpTimeout = void 0;
|
|
1436
|
+
}
|
|
1437
|
+
#closeWebSocket() {
|
|
1438
|
+
if (this.#ws === void 0) return;
|
|
1439
|
+
const ws$1 = this.#ws;
|
|
1440
|
+
this.#ws = void 0;
|
|
1441
|
+
ws$1.removeAllListeners();
|
|
1442
|
+
ws$1.on("error", () => void 0);
|
|
1443
|
+
if (ws$1.readyState === ws.default.OPEN) ws$1.close(1e3, "Normal closure");
|
|
1444
|
+
else {
|
|
1445
|
+
this.#debug(`Terminating Voice WebSocket (state: ${ws$1.readyState})`);
|
|
1446
|
+
ws$1.terminate();
|
|
1447
|
+
}
|
|
1448
|
+
this.#clearHeartbeat();
|
|
1449
|
+
}
|
|
1450
|
+
#closeTransports() {
|
|
1451
|
+
this.#closeWebSocket();
|
|
1452
|
+
if (this.#udp !== void 0) {
|
|
1453
|
+
const udp = this.#udp;
|
|
1454
|
+
this.#udp = void 0;
|
|
1455
|
+
this.#udpRemote = void 0;
|
|
1456
|
+
udp.removeAllListeners();
|
|
1457
|
+
try {
|
|
1458
|
+
udp.close();
|
|
1459
|
+
} catch (error) {
|
|
1460
|
+
if (!(error instanceof Error) || error.message !== "Not running") throw error;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
this.#clearUdpTimers();
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
|
|
1467
|
+
//#endregion
|
|
1468
|
+
//#region src/voiceConnectionManager.ts
|
|
1469
|
+
var VoiceConnectionManager = class extends node_events.EventEmitter {
|
|
1470
|
+
#connections = /* @__PURE__ */ new Map();
|
|
1471
|
+
get size() {
|
|
1472
|
+
return this.#connections.size;
|
|
1473
|
+
}
|
|
1474
|
+
get(guildId) {
|
|
1475
|
+
return this.#connections.get(guildId);
|
|
1476
|
+
}
|
|
1477
|
+
values() {
|
|
1478
|
+
return this.#connections.values();
|
|
1479
|
+
}
|
|
1480
|
+
joinChannel(options) {
|
|
1481
|
+
const existing = this.#connections.get(options.guildId);
|
|
1482
|
+
if (existing !== void 0) return existing;
|
|
1483
|
+
const connection = new VoiceConnection(options);
|
|
1484
|
+
this.#connections.set(options.guildId, connection);
|
|
1485
|
+
connection.once("close", () => {
|
|
1486
|
+
if (this.#connections.get(options.guildId) !== connection) return;
|
|
1487
|
+
this.#connections.delete(options.guildId);
|
|
1488
|
+
this.emit("connectionDelete", options.guildId);
|
|
1489
|
+
});
|
|
1490
|
+
this.emit("connectionCreate", options.guildId, options.channelId);
|
|
1491
|
+
queueMicrotask(() => connection.joinChannel());
|
|
1492
|
+
return connection;
|
|
1493
|
+
}
|
|
1494
|
+
stop(guildId) {
|
|
1495
|
+
this.#connections.get(guildId)?.disconnect();
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
|
|
1499
|
+
//#endregion
|
|
1500
|
+
exports.FrameBuffer = FrameBuffer;
|
|
1501
|
+
exports.OggOpusDemuxer = OggOpusDemuxer;
|
|
1502
|
+
Object.defineProperty(exports, 'VoiceCloseCodes', {
|
|
1503
|
+
enumerable: true,
|
|
1504
|
+
get: function () {
|
|
1505
|
+
return discord_api_types_voice_v8.VoiceCloseCodes;
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
exports.VoiceConnection = VoiceConnection;
|
|
1509
|
+
exports.VoiceConnectionDestroyedReason = VoiceConnectionDestroyedReason;
|
|
1510
|
+
exports.VoiceConnectionManager = VoiceConnectionManager;
|
|
1511
|
+
Object.defineProperty(exports, 'VoiceEncryptionMode', {
|
|
1512
|
+
enumerable: true,
|
|
1513
|
+
get: function () {
|
|
1514
|
+
return discord_api_types_voice_v8.VoiceEncryptionMode;
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
Object.defineProperty(exports, 'VoiceGatewayVersion', {
|
|
1518
|
+
enumerable: true,
|
|
1519
|
+
get: function () {
|
|
1520
|
+
return discord_api_types_voice_v8.VoiceGatewayVersion;
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
Object.defineProperty(exports, 'VoiceOpcodes', {
|
|
1524
|
+
enumerable: true,
|
|
1525
|
+
get: function () {
|
|
1526
|
+
return discord_api_types_voice_v8.VoiceOpcodes;
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
exports.VoiceRtcpPacketType = VoiceRtcpPacketType;
|
|
1530
|
+
Object.defineProperty(exports, 'VoiceSpeakingFlags', {
|
|
1531
|
+
enumerable: true,
|
|
1532
|
+
get: function () {
|
|
1533
|
+
return discord_api_types_voice_v8.VoiceSpeakingFlags;
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
exports.demuxOggOpus = demuxOggOpus;
|
|
1537
|
+
exports.opusPacketSamples = opusPacketSamples;
|
|
1538
|
+
//# sourceMappingURL=index.cjs.map
|