@estuary-ai/sdk 0.1.0 → 0.1.2

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/index.mjs CHANGED
@@ -1,378 +1,3390 @@
1
- import { io } from 'socket.io-client';
1
+ import { __export, EstuaryError } from './chunk-64CWCRPS.mjs';
2
+ export { ErrorCode, EstuaryError } from './chunk-64CWCRPS.mjs';
2
3
 
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
4
+ // ../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/commons.js
5
+ var PACKET_TYPES = /* @__PURE__ */ Object.create(null);
6
+ PACKET_TYPES["open"] = "0";
7
+ PACKET_TYPES["close"] = "1";
8
+ PACKET_TYPES["ping"] = "2";
9
+ PACKET_TYPES["pong"] = "3";
10
+ PACKET_TYPES["message"] = "4";
11
+ PACKET_TYPES["upgrade"] = "5";
12
+ PACKET_TYPES["noop"] = "6";
13
+ var PACKET_TYPES_REVERSE = /* @__PURE__ */ Object.create(null);
14
+ Object.keys(PACKET_TYPES).forEach((key) => {
15
+ PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
12
16
  });
13
- var __esm = (fn, res) => function __init() {
14
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ var ERROR_PACKET = { type: "error", data: "parser error" };
18
+
19
+ // ../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/encodePacket.browser.js
20
+ var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
21
+ var withNativeArrayBuffer = typeof ArrayBuffer === "function";
22
+ var isView = (obj) => {
23
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
24
+ };
25
+ var encodePacket = ({ type, data }, supportsBinary, callback) => {
26
+ if (withNativeBlob && data instanceof Blob) {
27
+ if (supportsBinary) {
28
+ return callback(data);
29
+ } else {
30
+ return encodeBlobAsBase64(data, callback);
31
+ }
32
+ } else if (withNativeArrayBuffer && (data instanceof ArrayBuffer || isView(data))) {
33
+ if (supportsBinary) {
34
+ return callback(data);
35
+ } else {
36
+ return encodeBlobAsBase64(new Blob([data]), callback);
37
+ }
38
+ }
39
+ return callback(PACKET_TYPES[type] + (data || ""));
40
+ };
41
+ var encodeBlobAsBase64 = (data, callback) => {
42
+ const fileReader = new FileReader();
43
+ fileReader.onload = function() {
44
+ const content = fileReader.result.split(",")[1];
45
+ callback("b" + (content || ""));
46
+ };
47
+ return fileReader.readAsDataURL(data);
48
+ };
49
+ function toArray(data) {
50
+ if (data instanceof Uint8Array) {
51
+ return data;
52
+ } else if (data instanceof ArrayBuffer) {
53
+ return new Uint8Array(data);
54
+ } else {
55
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
56
+ }
57
+ }
58
+ var TEXT_ENCODER;
59
+ function encodePacketToBinary(packet, callback) {
60
+ if (withNativeBlob && packet.data instanceof Blob) {
61
+ return packet.data.arrayBuffer().then(toArray).then(callback);
62
+ } else if (withNativeArrayBuffer && (packet.data instanceof ArrayBuffer || isView(packet.data))) {
63
+ return callback(toArray(packet.data));
64
+ }
65
+ encodePacket(packet, false, (encoded) => {
66
+ if (!TEXT_ENCODER) {
67
+ TEXT_ENCODER = new TextEncoder();
68
+ }
69
+ callback(TEXT_ENCODER.encode(encoded));
70
+ });
71
+ }
72
+
73
+ // ../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js
74
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
75
+ var lookup = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256);
76
+ for (let i = 0; i < chars.length; i++) {
77
+ lookup[chars.charCodeAt(i)] = i;
78
+ }
79
+ var decode = (base64) => {
80
+ let bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
81
+ if (base64[base64.length - 1] === "=") {
82
+ bufferLength--;
83
+ if (base64[base64.length - 2] === "=") {
84
+ bufferLength--;
85
+ }
86
+ }
87
+ const arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
88
+ for (i = 0; i < len; i += 4) {
89
+ encoded1 = lookup[base64.charCodeAt(i)];
90
+ encoded2 = lookup[base64.charCodeAt(i + 1)];
91
+ encoded3 = lookup[base64.charCodeAt(i + 2)];
92
+ encoded4 = lookup[base64.charCodeAt(i + 3)];
93
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
94
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
95
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
96
+ }
97
+ return arraybuffer;
98
+ };
99
+
100
+ // ../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/decodePacket.browser.js
101
+ var withNativeArrayBuffer2 = typeof ArrayBuffer === "function";
102
+ var decodePacket = (encodedPacket, binaryType) => {
103
+ if (typeof encodedPacket !== "string") {
104
+ return {
105
+ type: "message",
106
+ data: mapBinary(encodedPacket, binaryType)
107
+ };
108
+ }
109
+ const type = encodedPacket.charAt(0);
110
+ if (type === "b") {
111
+ return {
112
+ type: "message",
113
+ data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
114
+ };
115
+ }
116
+ const packetType = PACKET_TYPES_REVERSE[type];
117
+ if (!packetType) {
118
+ return ERROR_PACKET;
119
+ }
120
+ return encodedPacket.length > 1 ? {
121
+ type: PACKET_TYPES_REVERSE[type],
122
+ data: encodedPacket.substring(1)
123
+ } : {
124
+ type: PACKET_TYPES_REVERSE[type]
125
+ };
126
+ };
127
+ var decodeBase64Packet = (data, binaryType) => {
128
+ if (withNativeArrayBuffer2) {
129
+ const decoded = decode(data);
130
+ return mapBinary(decoded, binaryType);
131
+ } else {
132
+ return { base64: true, data };
133
+ }
134
+ };
135
+ var mapBinary = (data, binaryType) => {
136
+ switch (binaryType) {
137
+ case "blob":
138
+ if (data instanceof Blob) {
139
+ return data;
140
+ } else {
141
+ return new Blob([data]);
142
+ }
143
+ case "arraybuffer":
144
+ default:
145
+ if (data instanceof ArrayBuffer) {
146
+ return data;
147
+ } else {
148
+ return data.buffer;
149
+ }
150
+ }
151
+ };
152
+
153
+ // ../node_modules/.pnpm/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/esm/index.js
154
+ var SEPARATOR = String.fromCharCode(30);
155
+ var encodePayload = (packets, callback) => {
156
+ const length = packets.length;
157
+ const encodedPackets = new Array(length);
158
+ let count = 0;
159
+ packets.forEach((packet, i) => {
160
+ encodePacket(packet, false, (encodedPacket) => {
161
+ encodedPackets[i] = encodedPacket;
162
+ if (++count === length) {
163
+ callback(encodedPackets.join(SEPARATOR));
164
+ }
165
+ });
166
+ });
167
+ };
168
+ var decodePayload = (encodedPayload, binaryType) => {
169
+ const encodedPackets = encodedPayload.split(SEPARATOR);
170
+ const packets = [];
171
+ for (let i = 0; i < encodedPackets.length; i++) {
172
+ const decodedPacket = decodePacket(encodedPackets[i], binaryType);
173
+ packets.push(decodedPacket);
174
+ if (decodedPacket.type === "error") {
175
+ break;
176
+ }
177
+ }
178
+ return packets;
179
+ };
180
+ function createPacketEncoderStream() {
181
+ return new TransformStream({
182
+ transform(packet, controller) {
183
+ encodePacketToBinary(packet, (encodedPacket) => {
184
+ const payloadLength = encodedPacket.length;
185
+ let header;
186
+ if (payloadLength < 126) {
187
+ header = new Uint8Array(1);
188
+ new DataView(header.buffer).setUint8(0, payloadLength);
189
+ } else if (payloadLength < 65536) {
190
+ header = new Uint8Array(3);
191
+ const view = new DataView(header.buffer);
192
+ view.setUint8(0, 126);
193
+ view.setUint16(1, payloadLength);
194
+ } else {
195
+ header = new Uint8Array(9);
196
+ const view = new DataView(header.buffer);
197
+ view.setUint8(0, 127);
198
+ view.setBigUint64(1, BigInt(payloadLength));
199
+ }
200
+ if (packet.data && typeof packet.data !== "string") {
201
+ header[0] |= 128;
202
+ }
203
+ controller.enqueue(header);
204
+ controller.enqueue(encodedPacket);
205
+ });
206
+ }
207
+ });
208
+ }
209
+ var TEXT_DECODER;
210
+ function totalLength(chunks) {
211
+ return chunks.reduce((acc, chunk) => acc + chunk.length, 0);
212
+ }
213
+ function concatChunks(chunks, size) {
214
+ if (chunks[0].length === size) {
215
+ return chunks.shift();
216
+ }
217
+ const buffer = new Uint8Array(size);
218
+ let j = 0;
219
+ for (let i = 0; i < size; i++) {
220
+ buffer[i] = chunks[0][j++];
221
+ if (j === chunks[0].length) {
222
+ chunks.shift();
223
+ j = 0;
224
+ }
225
+ }
226
+ if (chunks.length && j < chunks[0].length) {
227
+ chunks[0] = chunks[0].slice(j);
228
+ }
229
+ return buffer;
230
+ }
231
+ function createPacketDecoderStream(maxPayload, binaryType) {
232
+ if (!TEXT_DECODER) {
233
+ TEXT_DECODER = new TextDecoder();
234
+ }
235
+ const chunks = [];
236
+ let state = 0;
237
+ let expectedLength = -1;
238
+ let isBinary2 = false;
239
+ return new TransformStream({
240
+ transform(chunk, controller) {
241
+ chunks.push(chunk);
242
+ while (true) {
243
+ if (state === 0) {
244
+ if (totalLength(chunks) < 1) {
245
+ break;
246
+ }
247
+ const header = concatChunks(chunks, 1);
248
+ isBinary2 = (header[0] & 128) === 128;
249
+ expectedLength = header[0] & 127;
250
+ if (expectedLength < 126) {
251
+ state = 3;
252
+ } else if (expectedLength === 126) {
253
+ state = 1;
254
+ } else {
255
+ state = 2;
256
+ }
257
+ } else if (state === 1) {
258
+ if (totalLength(chunks) < 2) {
259
+ break;
260
+ }
261
+ const headerArray = concatChunks(chunks, 2);
262
+ expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
263
+ state = 3;
264
+ } else if (state === 2) {
265
+ if (totalLength(chunks) < 8) {
266
+ break;
267
+ }
268
+ const headerArray = concatChunks(chunks, 8);
269
+ const view = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length);
270
+ const n = view.getUint32(0);
271
+ if (n > Math.pow(2, 53 - 32) - 1) {
272
+ controller.enqueue(ERROR_PACKET);
273
+ break;
274
+ }
275
+ expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
276
+ state = 3;
277
+ } else {
278
+ if (totalLength(chunks) < expectedLength) {
279
+ break;
280
+ }
281
+ const data = concatChunks(chunks, expectedLength);
282
+ controller.enqueue(decodePacket(isBinary2 ? data : TEXT_DECODER.decode(data), binaryType));
283
+ state = 0;
284
+ }
285
+ if (expectedLength === 0 || expectedLength > maxPayload) {
286
+ controller.enqueue(ERROR_PACKET);
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ });
292
+ }
293
+ var protocol = 4;
294
+
295
+ // ../node_modules/.pnpm/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/esm/index.js
296
+ function Emitter(obj) {
297
+ if (obj) return mixin(obj);
298
+ }
299
+ function mixin(obj) {
300
+ for (var key in Emitter.prototype) {
301
+ obj[key] = Emitter.prototype[key];
302
+ }
303
+ return obj;
304
+ }
305
+ Emitter.prototype.on = Emitter.prototype.addEventListener = function(event, fn) {
306
+ this._callbacks = this._callbacks || {};
307
+ (this._callbacks["$" + event] = this._callbacks["$" + event] || []).push(fn);
308
+ return this;
309
+ };
310
+ Emitter.prototype.once = function(event, fn) {
311
+ function on2() {
312
+ this.off(event, on2);
313
+ fn.apply(this, arguments);
314
+ }
315
+ on2.fn = fn;
316
+ this.on(event, on2);
317
+ return this;
318
+ };
319
+ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function(event, fn) {
320
+ this._callbacks = this._callbacks || {};
321
+ if (0 == arguments.length) {
322
+ this._callbacks = {};
323
+ return this;
324
+ }
325
+ var callbacks = this._callbacks["$" + event];
326
+ if (!callbacks) return this;
327
+ if (1 == arguments.length) {
328
+ delete this._callbacks["$" + event];
329
+ return this;
330
+ }
331
+ var cb;
332
+ for (var i = 0; i < callbacks.length; i++) {
333
+ cb = callbacks[i];
334
+ if (cb === fn || cb.fn === fn) {
335
+ callbacks.splice(i, 1);
336
+ break;
337
+ }
338
+ }
339
+ if (callbacks.length === 0) {
340
+ delete this._callbacks["$" + event];
341
+ }
342
+ return this;
343
+ };
344
+ Emitter.prototype.emit = function(event) {
345
+ this._callbacks = this._callbacks || {};
346
+ var args = new Array(arguments.length - 1), callbacks = this._callbacks["$" + event];
347
+ for (var i = 1; i < arguments.length; i++) {
348
+ args[i - 1] = arguments[i];
349
+ }
350
+ if (callbacks) {
351
+ callbacks = callbacks.slice(0);
352
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
353
+ callbacks[i].apply(this, args);
354
+ }
355
+ }
356
+ return this;
357
+ };
358
+ Emitter.prototype.emitReserved = Emitter.prototype.emit;
359
+ Emitter.prototype.listeners = function(event) {
360
+ this._callbacks = this._callbacks || {};
361
+ return this._callbacks["$" + event] || [];
362
+ };
363
+ Emitter.prototype.hasListeners = function(event) {
364
+ return !!this.listeners(event).length;
365
+ };
366
+
367
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/globals.js
368
+ var nextTick = (() => {
369
+ const isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
370
+ if (isPromiseAvailable) {
371
+ return (cb) => Promise.resolve().then(cb);
372
+ } else {
373
+ return (cb, setTimeoutFn) => setTimeoutFn(cb, 0);
374
+ }
375
+ })();
376
+ var globalThisShim = (() => {
377
+ if (typeof self !== "undefined") {
378
+ return self;
379
+ } else if (typeof window !== "undefined") {
380
+ return window;
381
+ } else {
382
+ return Function("return this")();
383
+ }
384
+ })();
385
+ var defaultBinaryType = "arraybuffer";
386
+ function createCookieJar() {
387
+ }
388
+
389
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/util.js
390
+ function pick(obj, ...attr) {
391
+ return attr.reduce((acc, k) => {
392
+ if (obj.hasOwnProperty(k)) {
393
+ acc[k] = obj[k];
394
+ }
395
+ return acc;
396
+ }, {});
397
+ }
398
+ var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
399
+ var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
400
+ function installTimerFunctions(obj, opts) {
401
+ if (opts.useNativeTimers) {
402
+ obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
403
+ obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
404
+ } else {
405
+ obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
406
+ obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
407
+ }
408
+ }
409
+ var BASE64_OVERHEAD = 1.33;
410
+ function byteLength(obj) {
411
+ if (typeof obj === "string") {
412
+ return utf8Length(obj);
413
+ }
414
+ return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
415
+ }
416
+ function utf8Length(str) {
417
+ let c = 0, length = 0;
418
+ for (let i = 0, l = str.length; i < l; i++) {
419
+ c = str.charCodeAt(i);
420
+ if (c < 128) {
421
+ length += 1;
422
+ } else if (c < 2048) {
423
+ length += 2;
424
+ } else if (c < 55296 || c >= 57344) {
425
+ length += 3;
426
+ } else {
427
+ i++;
428
+ length += 4;
429
+ }
430
+ }
431
+ return length;
432
+ }
433
+ function randomString() {
434
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
435
+ }
436
+
437
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/contrib/parseqs.js
438
+ function encode(obj) {
439
+ let str = "";
440
+ for (let i in obj) {
441
+ if (obj.hasOwnProperty(i)) {
442
+ if (str.length)
443
+ str += "&";
444
+ str += encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]);
445
+ }
446
+ }
447
+ return str;
448
+ }
449
+ function decode2(qs) {
450
+ let qry = {};
451
+ let pairs = qs.split("&");
452
+ for (let i = 0, l = pairs.length; i < l; i++) {
453
+ let pair = pairs[i].split("=");
454
+ qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
455
+ }
456
+ return qry;
457
+ }
458
+
459
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transport.js
460
+ var TransportError = class extends Error {
461
+ constructor(reason, description, context) {
462
+ super(reason);
463
+ this.description = description;
464
+ this.context = context;
465
+ this.type = "TransportError";
466
+ }
467
+ };
468
+ var Transport = class extends Emitter {
469
+ /**
470
+ * Transport abstract constructor.
471
+ *
472
+ * @param {Object} opts - options
473
+ * @protected
474
+ */
475
+ constructor(opts) {
476
+ super();
477
+ this.writable = false;
478
+ installTimerFunctions(this, opts);
479
+ this.opts = opts;
480
+ this.query = opts.query;
481
+ this.socket = opts.socket;
482
+ this.supportsBinary = !opts.forceBase64;
483
+ }
484
+ /**
485
+ * Emits an error.
486
+ *
487
+ * @param {String} reason
488
+ * @param description
489
+ * @param context - the error context
490
+ * @return {Transport} for chaining
491
+ * @protected
492
+ */
493
+ onError(reason, description, context) {
494
+ super.emitReserved("error", new TransportError(reason, description, context));
495
+ return this;
496
+ }
497
+ /**
498
+ * Opens the transport.
499
+ */
500
+ open() {
501
+ this.readyState = "opening";
502
+ this.doOpen();
503
+ return this;
504
+ }
505
+ /**
506
+ * Closes the transport.
507
+ */
508
+ close() {
509
+ if (this.readyState === "opening" || this.readyState === "open") {
510
+ this.doClose();
511
+ this.onClose();
512
+ }
513
+ return this;
514
+ }
515
+ /**
516
+ * Sends multiple packets.
517
+ *
518
+ * @param {Array} packets
519
+ */
520
+ send(packets) {
521
+ if (this.readyState === "open") {
522
+ this.write(packets);
523
+ }
524
+ }
525
+ /**
526
+ * Called upon open
527
+ *
528
+ * @protected
529
+ */
530
+ onOpen() {
531
+ this.readyState = "open";
532
+ this.writable = true;
533
+ super.emitReserved("open");
534
+ }
535
+ /**
536
+ * Called with data.
537
+ *
538
+ * @param {String} data
539
+ * @protected
540
+ */
541
+ onData(data) {
542
+ const packet = decodePacket(data, this.socket.binaryType);
543
+ this.onPacket(packet);
544
+ }
545
+ /**
546
+ * Called with a decoded packet.
547
+ *
548
+ * @protected
549
+ */
550
+ onPacket(packet) {
551
+ super.emitReserved("packet", packet);
552
+ }
553
+ /**
554
+ * Called upon close.
555
+ *
556
+ * @protected
557
+ */
558
+ onClose(details) {
559
+ this.readyState = "closed";
560
+ super.emitReserved("close", details);
561
+ }
562
+ /**
563
+ * Pauses the transport, in order not to lose packets during an upgrade.
564
+ *
565
+ * @param onPause
566
+ */
567
+ pause(onPause) {
568
+ }
569
+ createUri(schema, query = {}) {
570
+ return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
571
+ }
572
+ _hostname() {
573
+ const hostname = this.opts.hostname;
574
+ return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
575
+ }
576
+ _port() {
577
+ if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
578
+ return ":" + this.opts.port;
579
+ } else {
580
+ return "";
581
+ }
582
+ }
583
+ _query(query) {
584
+ const encodedQuery = encode(query);
585
+ return encodedQuery.length ? "?" + encodedQuery : "";
586
+ }
587
+ };
588
+
589
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transports/polling.js
590
+ var Polling = class extends Transport {
591
+ constructor() {
592
+ super(...arguments);
593
+ this._polling = false;
594
+ }
595
+ get name() {
596
+ return "polling";
597
+ }
598
+ /**
599
+ * Opens the socket (triggers polling). We write a PING message to determine
600
+ * when the transport is open.
601
+ *
602
+ * @protected
603
+ */
604
+ doOpen() {
605
+ this._poll();
606
+ }
607
+ /**
608
+ * Pauses polling.
609
+ *
610
+ * @param {Function} onPause - callback upon buffers are flushed and transport is paused
611
+ * @package
612
+ */
613
+ pause(onPause) {
614
+ this.readyState = "pausing";
615
+ const pause = () => {
616
+ this.readyState = "paused";
617
+ onPause();
618
+ };
619
+ if (this._polling || !this.writable) {
620
+ let total = 0;
621
+ if (this._polling) {
622
+ total++;
623
+ this.once("pollComplete", function() {
624
+ --total || pause();
625
+ });
626
+ }
627
+ if (!this.writable) {
628
+ total++;
629
+ this.once("drain", function() {
630
+ --total || pause();
631
+ });
632
+ }
633
+ } else {
634
+ pause();
635
+ }
636
+ }
637
+ /**
638
+ * Starts polling cycle.
639
+ *
640
+ * @private
641
+ */
642
+ _poll() {
643
+ this._polling = true;
644
+ this.doPoll();
645
+ this.emitReserved("poll");
646
+ }
647
+ /**
648
+ * Overloads onData to detect payloads.
649
+ *
650
+ * @protected
651
+ */
652
+ onData(data) {
653
+ const callback = (packet) => {
654
+ if ("opening" === this.readyState && packet.type === "open") {
655
+ this.onOpen();
656
+ }
657
+ if ("close" === packet.type) {
658
+ this.onClose({ description: "transport closed by the server" });
659
+ return false;
660
+ }
661
+ this.onPacket(packet);
662
+ };
663
+ decodePayload(data, this.socket.binaryType).forEach(callback);
664
+ if ("closed" !== this.readyState) {
665
+ this._polling = false;
666
+ this.emitReserved("pollComplete");
667
+ if ("open" === this.readyState) {
668
+ this._poll();
669
+ }
670
+ }
671
+ }
672
+ /**
673
+ * For polling, send a close packet.
674
+ *
675
+ * @protected
676
+ */
677
+ doClose() {
678
+ const close = () => {
679
+ this.write([{ type: "close" }]);
680
+ };
681
+ if ("open" === this.readyState) {
682
+ close();
683
+ } else {
684
+ this.once("open", close);
685
+ }
686
+ }
687
+ /**
688
+ * Writes a packets payload.
689
+ *
690
+ * @param {Array} packets - data packets
691
+ * @protected
692
+ */
693
+ write(packets) {
694
+ this.writable = false;
695
+ encodePayload(packets, (data) => {
696
+ this.doWrite(data, () => {
697
+ this.writable = true;
698
+ this.emitReserved("drain");
699
+ });
700
+ });
701
+ }
702
+ /**
703
+ * Generates uri for connection.
704
+ *
705
+ * @private
706
+ */
707
+ uri() {
708
+ const schema = this.opts.secure ? "https" : "http";
709
+ const query = this.query || {};
710
+ if (false !== this.opts.timestampRequests) {
711
+ query[this.opts.timestampParam] = randomString();
712
+ }
713
+ if (!this.supportsBinary && !query.sid) {
714
+ query.b64 = 1;
715
+ }
716
+ return this.createUri(schema, query);
717
+ }
718
+ };
719
+
720
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/contrib/has-cors.js
721
+ var value = false;
722
+ try {
723
+ value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
724
+ } catch (err) {
725
+ }
726
+ var hasCORS = value;
727
+
728
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transports/polling-xhr.js
729
+ function empty() {
730
+ }
731
+ var BaseXHR = class extends Polling {
732
+ /**
733
+ * XHR Polling constructor.
734
+ *
735
+ * @param {Object} opts
736
+ * @package
737
+ */
738
+ constructor(opts) {
739
+ super(opts);
740
+ if (typeof location !== "undefined") {
741
+ const isSSL = "https:" === location.protocol;
742
+ let port = location.port;
743
+ if (!port) {
744
+ port = isSSL ? "443" : "80";
745
+ }
746
+ this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
747
+ }
748
+ }
749
+ /**
750
+ * Sends data.
751
+ *
752
+ * @param {String} data to send.
753
+ * @param {Function} called upon flush.
754
+ * @private
755
+ */
756
+ doWrite(data, fn) {
757
+ const req = this.request({
758
+ method: "POST",
759
+ data
760
+ });
761
+ req.on("success", fn);
762
+ req.on("error", (xhrStatus, context) => {
763
+ this.onError("xhr post error", xhrStatus, context);
764
+ });
765
+ }
766
+ /**
767
+ * Starts a poll cycle.
768
+ *
769
+ * @private
770
+ */
771
+ doPoll() {
772
+ const req = this.request();
773
+ req.on("data", this.onData.bind(this));
774
+ req.on("error", (xhrStatus, context) => {
775
+ this.onError("xhr poll error", xhrStatus, context);
776
+ });
777
+ this.pollXhr = req;
778
+ }
779
+ };
780
+ var Request = class _Request extends Emitter {
781
+ /**
782
+ * Request constructor
783
+ *
784
+ * @param {Object} options
785
+ * @package
786
+ */
787
+ constructor(createRequest, uri, opts) {
788
+ super();
789
+ this.createRequest = createRequest;
790
+ installTimerFunctions(this, opts);
791
+ this._opts = opts;
792
+ this._method = opts.method || "GET";
793
+ this._uri = uri;
794
+ this._data = void 0 !== opts.data ? opts.data : null;
795
+ this._create();
796
+ }
797
+ /**
798
+ * Creates the XHR object and sends the request.
799
+ *
800
+ * @private
801
+ */
802
+ _create() {
803
+ var _a;
804
+ const opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
805
+ opts.xdomain = !!this._opts.xd;
806
+ const xhr = this._xhr = this.createRequest(opts);
807
+ try {
808
+ xhr.open(this._method, this._uri, true);
809
+ try {
810
+ if (this._opts.extraHeaders) {
811
+ xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
812
+ for (let i in this._opts.extraHeaders) {
813
+ if (this._opts.extraHeaders.hasOwnProperty(i)) {
814
+ xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
815
+ }
816
+ }
817
+ }
818
+ } catch (e) {
819
+ }
820
+ if ("POST" === this._method) {
821
+ try {
822
+ xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
823
+ } catch (e) {
824
+ }
825
+ }
826
+ try {
827
+ xhr.setRequestHeader("Accept", "*/*");
828
+ } catch (e) {
829
+ }
830
+ (_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
831
+ if ("withCredentials" in xhr) {
832
+ xhr.withCredentials = this._opts.withCredentials;
833
+ }
834
+ if (this._opts.requestTimeout) {
835
+ xhr.timeout = this._opts.requestTimeout;
836
+ }
837
+ xhr.onreadystatechange = () => {
838
+ var _a2;
839
+ if (xhr.readyState === 3) {
840
+ (_a2 = this._opts.cookieJar) === null || _a2 === void 0 ? void 0 : _a2.parseCookies(
841
+ // @ts-ignore
842
+ xhr.getResponseHeader("set-cookie")
843
+ );
844
+ }
845
+ if (4 !== xhr.readyState)
846
+ return;
847
+ if (200 === xhr.status || 1223 === xhr.status) {
848
+ this._onLoad();
849
+ } else {
850
+ this.setTimeoutFn(() => {
851
+ this._onError(typeof xhr.status === "number" ? xhr.status : 0);
852
+ }, 0);
853
+ }
854
+ };
855
+ xhr.send(this._data);
856
+ } catch (e) {
857
+ this.setTimeoutFn(() => {
858
+ this._onError(e);
859
+ }, 0);
860
+ return;
861
+ }
862
+ if (typeof document !== "undefined") {
863
+ this._index = _Request.requestsCount++;
864
+ _Request.requests[this._index] = this;
865
+ }
866
+ }
867
+ /**
868
+ * Called upon error.
869
+ *
870
+ * @private
871
+ */
872
+ _onError(err) {
873
+ this.emitReserved("error", err, this._xhr);
874
+ this._cleanup(true);
875
+ }
876
+ /**
877
+ * Cleans up house.
878
+ *
879
+ * @private
880
+ */
881
+ _cleanup(fromError) {
882
+ if ("undefined" === typeof this._xhr || null === this._xhr) {
883
+ return;
884
+ }
885
+ this._xhr.onreadystatechange = empty;
886
+ if (fromError) {
887
+ try {
888
+ this._xhr.abort();
889
+ } catch (e) {
890
+ }
891
+ }
892
+ if (typeof document !== "undefined") {
893
+ delete _Request.requests[this._index];
894
+ }
895
+ this._xhr = null;
896
+ }
897
+ /**
898
+ * Called upon load.
899
+ *
900
+ * @private
901
+ */
902
+ _onLoad() {
903
+ const data = this._xhr.responseText;
904
+ if (data !== null) {
905
+ this.emitReserved("data", data);
906
+ this.emitReserved("success");
907
+ this._cleanup();
908
+ }
909
+ }
910
+ /**
911
+ * Aborts the request.
912
+ *
913
+ * @package
914
+ */
915
+ abort() {
916
+ this._cleanup();
917
+ }
918
+ };
919
+ Request.requestsCount = 0;
920
+ Request.requests = {};
921
+ if (typeof document !== "undefined") {
922
+ if (typeof attachEvent === "function") {
923
+ attachEvent("onunload", unloadHandler);
924
+ } else if (typeof addEventListener === "function") {
925
+ const terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
926
+ addEventListener(terminationEvent, unloadHandler, false);
927
+ }
928
+ }
929
+ function unloadHandler() {
930
+ for (let i in Request.requests) {
931
+ if (Request.requests.hasOwnProperty(i)) {
932
+ Request.requests[i].abort();
933
+ }
934
+ }
935
+ }
936
+ var hasXHR2 = (function() {
937
+ const xhr = newRequest({
938
+ xdomain: false
939
+ });
940
+ return xhr && xhr.responseType !== null;
941
+ })();
942
+ var XHR = class extends BaseXHR {
943
+ constructor(opts) {
944
+ super(opts);
945
+ const forceBase64 = opts && opts.forceBase64;
946
+ this.supportsBinary = hasXHR2 && !forceBase64;
947
+ }
948
+ request(opts = {}) {
949
+ Object.assign(opts, { xd: this.xd }, this.opts);
950
+ return new Request(newRequest, this.uri(), opts);
951
+ }
952
+ };
953
+ function newRequest(opts) {
954
+ const xdomain = opts.xdomain;
955
+ try {
956
+ if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
957
+ return new XMLHttpRequest();
958
+ }
959
+ } catch (e) {
960
+ }
961
+ if (!xdomain) {
962
+ try {
963
+ return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
964
+ } catch (e) {
965
+ }
966
+ }
967
+ }
968
+
969
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transports/websocket.js
970
+ var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
971
+ var BaseWS = class extends Transport {
972
+ get name() {
973
+ return "websocket";
974
+ }
975
+ doOpen() {
976
+ const uri = this.uri();
977
+ const protocols = this.opts.protocols;
978
+ const opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
979
+ if (this.opts.extraHeaders) {
980
+ opts.headers = this.opts.extraHeaders;
981
+ }
982
+ try {
983
+ this.ws = this.createSocket(uri, protocols, opts);
984
+ } catch (err) {
985
+ return this.emitReserved("error", err);
986
+ }
987
+ this.ws.binaryType = this.socket.binaryType;
988
+ this.addEventListeners();
989
+ }
990
+ /**
991
+ * Adds event listeners to the socket
992
+ *
993
+ * @private
994
+ */
995
+ addEventListeners() {
996
+ this.ws.onopen = () => {
997
+ if (this.opts.autoUnref) {
998
+ this.ws._socket.unref();
999
+ }
1000
+ this.onOpen();
1001
+ };
1002
+ this.ws.onclose = (closeEvent) => this.onClose({
1003
+ description: "websocket connection closed",
1004
+ context: closeEvent
1005
+ });
1006
+ this.ws.onmessage = (ev) => this.onData(ev.data);
1007
+ this.ws.onerror = (e) => this.onError("websocket error", e);
1008
+ }
1009
+ write(packets) {
1010
+ this.writable = false;
1011
+ for (let i = 0; i < packets.length; i++) {
1012
+ const packet = packets[i];
1013
+ const lastPacket = i === packets.length - 1;
1014
+ encodePacket(packet, this.supportsBinary, (data) => {
1015
+ try {
1016
+ this.doWrite(packet, data);
1017
+ } catch (e) {
1018
+ }
1019
+ if (lastPacket) {
1020
+ nextTick(() => {
1021
+ this.writable = true;
1022
+ this.emitReserved("drain");
1023
+ }, this.setTimeoutFn);
1024
+ }
1025
+ });
1026
+ }
1027
+ }
1028
+ doClose() {
1029
+ if (typeof this.ws !== "undefined") {
1030
+ this.ws.onerror = () => {
1031
+ };
1032
+ this.ws.close();
1033
+ this.ws = null;
1034
+ }
1035
+ }
1036
+ /**
1037
+ * Generates uri for connection.
1038
+ *
1039
+ * @private
1040
+ */
1041
+ uri() {
1042
+ const schema = this.opts.secure ? "wss" : "ws";
1043
+ const query = this.query || {};
1044
+ if (this.opts.timestampRequests) {
1045
+ query[this.opts.timestampParam] = randomString();
1046
+ }
1047
+ if (!this.supportsBinary) {
1048
+ query.b64 = 1;
1049
+ }
1050
+ return this.createUri(schema, query);
1051
+ }
15
1052
  };
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
1053
+ var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
1054
+ var WS = class extends BaseWS {
1055
+ createSocket(uri, protocols, opts) {
1056
+ return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts);
1057
+ }
1058
+ doWrite(_packet, data) {
1059
+ this.ws.send(data);
1060
+ }
1061
+ };
1062
+
1063
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transports/webtransport.js
1064
+ var WT = class extends Transport {
1065
+ get name() {
1066
+ return "webtransport";
1067
+ }
1068
+ doOpen() {
1069
+ try {
1070
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
1071
+ } catch (err) {
1072
+ return this.emitReserved("error", err);
1073
+ }
1074
+ this._transport.closed.then(() => {
1075
+ this.onClose();
1076
+ }).catch((err) => {
1077
+ this.onError("webtransport error", err);
1078
+ });
1079
+ this._transport.ready.then(() => {
1080
+ this._transport.createBidirectionalStream().then((stream) => {
1081
+ const decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, this.socket.binaryType);
1082
+ const reader = stream.readable.pipeThrough(decoderStream).getReader();
1083
+ const encoderStream = createPacketEncoderStream();
1084
+ encoderStream.readable.pipeTo(stream.writable);
1085
+ this._writer = encoderStream.writable.getWriter();
1086
+ const read = () => {
1087
+ reader.read().then(({ done, value: value2 }) => {
1088
+ if (done) {
1089
+ return;
1090
+ }
1091
+ this.onPacket(value2);
1092
+ read();
1093
+ }).catch((err) => {
1094
+ });
1095
+ };
1096
+ read();
1097
+ const packet = { type: "open" };
1098
+ if (this.query.sid) {
1099
+ packet.data = `{"sid":"${this.query.sid}"}`;
1100
+ }
1101
+ this._writer.write(packet).then(() => this.onOpen());
1102
+ });
1103
+ });
1104
+ }
1105
+ write(packets) {
1106
+ this.writable = false;
1107
+ for (let i = 0; i < packets.length; i++) {
1108
+ const packet = packets[i];
1109
+ const lastPacket = i === packets.length - 1;
1110
+ this._writer.write(packet).then(() => {
1111
+ if (lastPacket) {
1112
+ nextTick(() => {
1113
+ this.writable = true;
1114
+ this.emitReserved("drain");
1115
+ }, this.setTimeoutFn);
1116
+ }
1117
+ });
1118
+ }
1119
+ }
1120
+ doClose() {
1121
+ var _a;
1122
+ (_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
1123
+ }
1124
+ };
1125
+
1126
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/transports/index.js
1127
+ var transports = {
1128
+ websocket: WS,
1129
+ webtransport: WT,
1130
+ polling: XHR
1131
+ };
1132
+
1133
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/contrib/parseuri.js
1134
+ var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
1135
+ var parts = [
1136
+ "source",
1137
+ "protocol",
1138
+ "authority",
1139
+ "userInfo",
1140
+ "user",
1141
+ "password",
1142
+ "host",
1143
+ "port",
1144
+ "relative",
1145
+ "path",
1146
+ "directory",
1147
+ "file",
1148
+ "query",
1149
+ "anchor"
1150
+ ];
1151
+ function parse(str) {
1152
+ if (str.length > 8e3) {
1153
+ throw "URI too long";
1154
+ }
1155
+ const src = str, b = str.indexOf("["), e = str.indexOf("]");
1156
+ if (b != -1 && e != -1) {
1157
+ str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ";") + str.substring(e, str.length);
1158
+ }
1159
+ let m = re.exec(str || ""), uri = {}, i = 14;
1160
+ while (i--) {
1161
+ uri[parts[i]] = m[i] || "";
1162
+ }
1163
+ if (b != -1 && e != -1) {
1164
+ uri.source = src;
1165
+ uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ":");
1166
+ uri.authority = uri.authority.replace("[", "").replace("]", "").replace(/;/g, ":");
1167
+ uri.ipv6uri = true;
1168
+ }
1169
+ uri.pathNames = pathNames(uri, uri["path"]);
1170
+ uri.queryKey = queryKey(uri, uri["query"]);
1171
+ return uri;
1172
+ }
1173
+ function pathNames(obj, path) {
1174
+ const regx = /\/{2,9}/g, names = path.replace(regx, "/").split("/");
1175
+ if (path.slice(0, 1) == "/" || path.length === 0) {
1176
+ names.splice(0, 1);
1177
+ }
1178
+ if (path.slice(-1) == "/") {
1179
+ names.splice(names.length - 1, 1);
1180
+ }
1181
+ return names;
1182
+ }
1183
+ function queryKey(uri, query) {
1184
+ const data = {};
1185
+ query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function($0, $1, $2) {
1186
+ if ($1) {
1187
+ data[$1] = $2;
1188
+ }
1189
+ });
1190
+ return data;
1191
+ }
1192
+
1193
+ // ../node_modules/.pnpm/engine.io-client@6.6.4/node_modules/engine.io-client/build/esm/socket.js
1194
+ var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
1195
+ var OFFLINE_EVENT_LISTENERS = [];
1196
+ if (withEventListeners) {
1197
+ addEventListener("offline", () => {
1198
+ OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
1199
+ }, false);
1200
+ }
1201
+ var SocketWithoutUpgrade = class _SocketWithoutUpgrade extends Emitter {
1202
+ /**
1203
+ * Socket constructor.
1204
+ *
1205
+ * @param {String|Object} uri - uri or options
1206
+ * @param {Object} opts - options
1207
+ */
1208
+ constructor(uri, opts) {
1209
+ super();
1210
+ this.binaryType = defaultBinaryType;
1211
+ this.writeBuffer = [];
1212
+ this._prevBufferLen = 0;
1213
+ this._pingInterval = -1;
1214
+ this._pingTimeout = -1;
1215
+ this._maxPayload = -1;
1216
+ this._pingTimeoutTime = Infinity;
1217
+ if (uri && "object" === typeof uri) {
1218
+ opts = uri;
1219
+ uri = null;
1220
+ }
1221
+ if (uri) {
1222
+ const parsedUri = parse(uri);
1223
+ opts.hostname = parsedUri.host;
1224
+ opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
1225
+ opts.port = parsedUri.port;
1226
+ if (parsedUri.query)
1227
+ opts.query = parsedUri.query;
1228
+ } else if (opts.host) {
1229
+ opts.hostname = parse(opts.host).host;
1230
+ }
1231
+ installTimerFunctions(this, opts);
1232
+ this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
1233
+ if (opts.hostname && !opts.port) {
1234
+ opts.port = this.secure ? "443" : "80";
1235
+ }
1236
+ this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
1237
+ this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : this.secure ? "443" : "80");
1238
+ this.transports = [];
1239
+ this._transportsByName = {};
1240
+ opts.transports.forEach((t) => {
1241
+ const transportName = t.prototype.name;
1242
+ this.transports.push(transportName);
1243
+ this._transportsByName[transportName] = t;
1244
+ });
1245
+ this.opts = Object.assign({
1246
+ path: "/engine.io",
1247
+ agent: false,
1248
+ withCredentials: false,
1249
+ upgrade: true,
1250
+ timestampParam: "t",
1251
+ rememberUpgrade: false,
1252
+ addTrailingSlash: true,
1253
+ rejectUnauthorized: true,
1254
+ perMessageDeflate: {
1255
+ threshold: 1024
1256
+ },
1257
+ transportOptions: {},
1258
+ closeOnBeforeunload: false
1259
+ }, opts);
1260
+ this.opts.path = this.opts.path.replace(/\/$/, "") + (this.opts.addTrailingSlash ? "/" : "");
1261
+ if (typeof this.opts.query === "string") {
1262
+ this.opts.query = decode2(this.opts.query);
1263
+ }
1264
+ if (withEventListeners) {
1265
+ if (this.opts.closeOnBeforeunload) {
1266
+ this._beforeunloadEventListener = () => {
1267
+ if (this.transport) {
1268
+ this.transport.removeAllListeners();
1269
+ this.transport.close();
1270
+ }
1271
+ };
1272
+ addEventListener("beforeunload", this._beforeunloadEventListener, false);
1273
+ }
1274
+ if (this.hostname !== "localhost") {
1275
+ this._offlineEventListener = () => {
1276
+ this._onClose("transport close", {
1277
+ description: "network connection lost"
1278
+ });
1279
+ };
1280
+ OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
1281
+ }
1282
+ }
1283
+ if (this.opts.withCredentials) {
1284
+ this._cookieJar = createCookieJar();
1285
+ }
1286
+ this._open();
1287
+ }
1288
+ /**
1289
+ * Creates transport of the given type.
1290
+ *
1291
+ * @param {String} name - transport name
1292
+ * @return {Transport}
1293
+ * @private
1294
+ */
1295
+ createTransport(name) {
1296
+ const query = Object.assign({}, this.opts.query);
1297
+ query.EIO = protocol;
1298
+ query.transport = name;
1299
+ if (this.id)
1300
+ query.sid = this.id;
1301
+ const opts = Object.assign({}, this.opts, {
1302
+ query,
1303
+ socket: this,
1304
+ hostname: this.hostname,
1305
+ secure: this.secure,
1306
+ port: this.port
1307
+ }, this.opts.transportOptions[name]);
1308
+ return new this._transportsByName[name](opts);
1309
+ }
1310
+ /**
1311
+ * Initializes transport to use and starts probe.
1312
+ *
1313
+ * @private
1314
+ */
1315
+ _open() {
1316
+ if (this.transports.length === 0) {
1317
+ this.setTimeoutFn(() => {
1318
+ this.emitReserved("error", "No transports available");
1319
+ }, 0);
1320
+ return;
1321
+ }
1322
+ const transportName = this.opts.rememberUpgrade && _SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
1323
+ this.readyState = "opening";
1324
+ const transport = this.createTransport(transportName);
1325
+ transport.open();
1326
+ this.setTransport(transport);
1327
+ }
1328
+ /**
1329
+ * Sets the current transport. Disables the existing one (if any).
1330
+ *
1331
+ * @private
1332
+ */
1333
+ setTransport(transport) {
1334
+ if (this.transport) {
1335
+ this.transport.removeAllListeners();
1336
+ }
1337
+ this.transport = transport;
1338
+ transport.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", (reason) => this._onClose("transport close", reason));
1339
+ }
1340
+ /**
1341
+ * Called when connection is deemed open.
1342
+ *
1343
+ * @private
1344
+ */
1345
+ onOpen() {
1346
+ this.readyState = "open";
1347
+ _SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name;
1348
+ this.emitReserved("open");
1349
+ this.flush();
1350
+ }
1351
+ /**
1352
+ * Handles a packet.
1353
+ *
1354
+ * @private
1355
+ */
1356
+ _onPacket(packet) {
1357
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
1358
+ this.emitReserved("packet", packet);
1359
+ this.emitReserved("heartbeat");
1360
+ switch (packet.type) {
1361
+ case "open":
1362
+ this.onHandshake(JSON.parse(packet.data));
1363
+ break;
1364
+ case "ping":
1365
+ this._sendPacket("pong");
1366
+ this.emitReserved("ping");
1367
+ this.emitReserved("pong");
1368
+ this._resetPingTimeout();
1369
+ break;
1370
+ case "error":
1371
+ const err = new Error("server error");
1372
+ err.code = packet.data;
1373
+ this._onError(err);
1374
+ break;
1375
+ case "message":
1376
+ this.emitReserved("data", packet.data);
1377
+ this.emitReserved("message", packet.data);
1378
+ break;
1379
+ }
1380
+ }
1381
+ }
1382
+ /**
1383
+ * Called upon handshake completion.
1384
+ *
1385
+ * @param {Object} data - handshake obj
1386
+ * @private
1387
+ */
1388
+ onHandshake(data) {
1389
+ this.emitReserved("handshake", data);
1390
+ this.id = data.sid;
1391
+ this.transport.query.sid = data.sid;
1392
+ this._pingInterval = data.pingInterval;
1393
+ this._pingTimeout = data.pingTimeout;
1394
+ this._maxPayload = data.maxPayload;
1395
+ this.onOpen();
1396
+ if ("closed" === this.readyState)
1397
+ return;
1398
+ this._resetPingTimeout();
1399
+ }
1400
+ /**
1401
+ * Sets and resets ping timeout timer based on server pings.
1402
+ *
1403
+ * @private
1404
+ */
1405
+ _resetPingTimeout() {
1406
+ this.clearTimeoutFn(this._pingTimeoutTimer);
1407
+ const delay = this._pingInterval + this._pingTimeout;
1408
+ this._pingTimeoutTime = Date.now() + delay;
1409
+ this._pingTimeoutTimer = this.setTimeoutFn(() => {
1410
+ this._onClose("ping timeout");
1411
+ }, delay);
1412
+ if (this.opts.autoUnref) {
1413
+ this._pingTimeoutTimer.unref();
1414
+ }
1415
+ }
1416
+ /**
1417
+ * Called on `drain` event
1418
+ *
1419
+ * @private
1420
+ */
1421
+ _onDrain() {
1422
+ this.writeBuffer.splice(0, this._prevBufferLen);
1423
+ this._prevBufferLen = 0;
1424
+ if (0 === this.writeBuffer.length) {
1425
+ this.emitReserved("drain");
1426
+ } else {
1427
+ this.flush();
1428
+ }
1429
+ }
1430
+ /**
1431
+ * Flush write buffers.
1432
+ *
1433
+ * @private
1434
+ */
1435
+ flush() {
1436
+ if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
1437
+ const packets = this._getWritablePackets();
1438
+ this.transport.send(packets);
1439
+ this._prevBufferLen = packets.length;
1440
+ this.emitReserved("flush");
1441
+ }
1442
+ }
1443
+ /**
1444
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
1445
+ * long-polling)
1446
+ *
1447
+ * @private
1448
+ */
1449
+ _getWritablePackets() {
1450
+ const shouldCheckPayloadSize = this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
1451
+ if (!shouldCheckPayloadSize) {
1452
+ return this.writeBuffer;
1453
+ }
1454
+ let payloadSize = 1;
1455
+ for (let i = 0; i < this.writeBuffer.length; i++) {
1456
+ const data = this.writeBuffer[i].data;
1457
+ if (data) {
1458
+ payloadSize += byteLength(data);
1459
+ }
1460
+ if (i > 0 && payloadSize > this._maxPayload) {
1461
+ return this.writeBuffer.slice(0, i);
1462
+ }
1463
+ payloadSize += 2;
1464
+ }
1465
+ return this.writeBuffer;
1466
+ }
1467
+ /**
1468
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
1469
+ *
1470
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
1471
+ * `write()` method then the message would not be buffered by the Socket.IO client.
1472
+ *
1473
+ * @return {boolean}
1474
+ * @private
1475
+ */
1476
+ /* private */
1477
+ _hasPingExpired() {
1478
+ if (!this._pingTimeoutTime)
1479
+ return true;
1480
+ const hasExpired = Date.now() > this._pingTimeoutTime;
1481
+ if (hasExpired) {
1482
+ this._pingTimeoutTime = 0;
1483
+ nextTick(() => {
1484
+ this._onClose("ping timeout");
1485
+ }, this.setTimeoutFn);
1486
+ }
1487
+ return hasExpired;
1488
+ }
1489
+ /**
1490
+ * Sends a message.
1491
+ *
1492
+ * @param {String} msg - message.
1493
+ * @param {Object} options.
1494
+ * @param {Function} fn - callback function.
1495
+ * @return {Socket} for chaining.
1496
+ */
1497
+ write(msg, options, fn) {
1498
+ this._sendPacket("message", msg, options, fn);
1499
+ return this;
1500
+ }
1501
+ /**
1502
+ * Sends a message. Alias of {@link Socket#write}.
1503
+ *
1504
+ * @param {String} msg - message.
1505
+ * @param {Object} options.
1506
+ * @param {Function} fn - callback function.
1507
+ * @return {Socket} for chaining.
1508
+ */
1509
+ send(msg, options, fn) {
1510
+ this._sendPacket("message", msg, options, fn);
1511
+ return this;
1512
+ }
1513
+ /**
1514
+ * Sends a packet.
1515
+ *
1516
+ * @param {String} type: packet type.
1517
+ * @param {String} data.
1518
+ * @param {Object} options.
1519
+ * @param {Function} fn - callback function.
1520
+ * @private
1521
+ */
1522
+ _sendPacket(type, data, options, fn) {
1523
+ if ("function" === typeof data) {
1524
+ fn = data;
1525
+ data = void 0;
1526
+ }
1527
+ if ("function" === typeof options) {
1528
+ fn = options;
1529
+ options = null;
1530
+ }
1531
+ if ("closing" === this.readyState || "closed" === this.readyState) {
1532
+ return;
1533
+ }
1534
+ options = options || {};
1535
+ options.compress = false !== options.compress;
1536
+ const packet = {
1537
+ type,
1538
+ data,
1539
+ options
1540
+ };
1541
+ this.emitReserved("packetCreate", packet);
1542
+ this.writeBuffer.push(packet);
1543
+ if (fn)
1544
+ this.once("flush", fn);
1545
+ this.flush();
1546
+ }
1547
+ /**
1548
+ * Closes the connection.
1549
+ */
1550
+ close() {
1551
+ const close = () => {
1552
+ this._onClose("forced close");
1553
+ this.transport.close();
1554
+ };
1555
+ const cleanupAndClose = () => {
1556
+ this.off("upgrade", cleanupAndClose);
1557
+ this.off("upgradeError", cleanupAndClose);
1558
+ close();
1559
+ };
1560
+ const waitForUpgrade = () => {
1561
+ this.once("upgrade", cleanupAndClose);
1562
+ this.once("upgradeError", cleanupAndClose);
1563
+ };
1564
+ if ("opening" === this.readyState || "open" === this.readyState) {
1565
+ this.readyState = "closing";
1566
+ if (this.writeBuffer.length) {
1567
+ this.once("drain", () => {
1568
+ if (this.upgrading) {
1569
+ waitForUpgrade();
1570
+ } else {
1571
+ close();
1572
+ }
1573
+ });
1574
+ } else if (this.upgrading) {
1575
+ waitForUpgrade();
1576
+ } else {
1577
+ close();
1578
+ }
1579
+ }
1580
+ return this;
1581
+ }
1582
+ /**
1583
+ * Called upon transport error
1584
+ *
1585
+ * @private
1586
+ */
1587
+ _onError(err) {
1588
+ _SocketWithoutUpgrade.priorWebsocketSuccess = false;
1589
+ if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
1590
+ this.transports.shift();
1591
+ return this._open();
1592
+ }
1593
+ this.emitReserved("error", err);
1594
+ this._onClose("transport error", err);
1595
+ }
1596
+ /**
1597
+ * Called upon transport close.
1598
+ *
1599
+ * @private
1600
+ */
1601
+ _onClose(reason, description) {
1602
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
1603
+ this.clearTimeoutFn(this._pingTimeoutTimer);
1604
+ this.transport.removeAllListeners("close");
1605
+ this.transport.close();
1606
+ this.transport.removeAllListeners();
1607
+ if (withEventListeners) {
1608
+ if (this._beforeunloadEventListener) {
1609
+ removeEventListener("beforeunload", this._beforeunloadEventListener, false);
1610
+ }
1611
+ if (this._offlineEventListener) {
1612
+ const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
1613
+ if (i !== -1) {
1614
+ OFFLINE_EVENT_LISTENERS.splice(i, 1);
1615
+ }
1616
+ }
1617
+ }
1618
+ this.readyState = "closed";
1619
+ this.id = null;
1620
+ this.emitReserved("close", reason, description);
1621
+ this.writeBuffer = [];
1622
+ this._prevBufferLen = 0;
1623
+ }
1624
+ }
1625
+ };
1626
+ SocketWithoutUpgrade.protocol = protocol;
1627
+ var SocketWithUpgrade = class extends SocketWithoutUpgrade {
1628
+ constructor() {
1629
+ super(...arguments);
1630
+ this._upgrades = [];
1631
+ }
1632
+ onOpen() {
1633
+ super.onOpen();
1634
+ if ("open" === this.readyState && this.opts.upgrade) {
1635
+ for (let i = 0; i < this._upgrades.length; i++) {
1636
+ this._probe(this._upgrades[i]);
1637
+ }
1638
+ }
1639
+ }
1640
+ /**
1641
+ * Probes a transport.
1642
+ *
1643
+ * @param {String} name - transport name
1644
+ * @private
1645
+ */
1646
+ _probe(name) {
1647
+ let transport = this.createTransport(name);
1648
+ let failed = false;
1649
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
1650
+ const onTransportOpen = () => {
1651
+ if (failed)
1652
+ return;
1653
+ transport.send([{ type: "ping", data: "probe" }]);
1654
+ transport.once("packet", (msg) => {
1655
+ if (failed)
1656
+ return;
1657
+ if ("pong" === msg.type && "probe" === msg.data) {
1658
+ this.upgrading = true;
1659
+ this.emitReserved("upgrading", transport);
1660
+ if (!transport)
1661
+ return;
1662
+ SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
1663
+ this.transport.pause(() => {
1664
+ if (failed)
1665
+ return;
1666
+ if ("closed" === this.readyState)
1667
+ return;
1668
+ cleanup();
1669
+ this.setTransport(transport);
1670
+ transport.send([{ type: "upgrade" }]);
1671
+ this.emitReserved("upgrade", transport);
1672
+ transport = null;
1673
+ this.upgrading = false;
1674
+ this.flush();
1675
+ });
1676
+ } else {
1677
+ const err = new Error("probe error");
1678
+ err.transport = transport.name;
1679
+ this.emitReserved("upgradeError", err);
1680
+ }
1681
+ });
1682
+ };
1683
+ function freezeTransport() {
1684
+ if (failed)
1685
+ return;
1686
+ failed = true;
1687
+ cleanup();
1688
+ transport.close();
1689
+ transport = null;
1690
+ }
1691
+ const onerror = (err) => {
1692
+ const error = new Error("probe error: " + err);
1693
+ error.transport = transport.name;
1694
+ freezeTransport();
1695
+ this.emitReserved("upgradeError", error);
1696
+ };
1697
+ function onTransportClose() {
1698
+ onerror("transport closed");
1699
+ }
1700
+ function onclose() {
1701
+ onerror("socket closed");
1702
+ }
1703
+ function onupgrade(to) {
1704
+ if (transport && to.name !== transport.name) {
1705
+ freezeTransport();
1706
+ }
1707
+ }
1708
+ const cleanup = () => {
1709
+ transport.removeListener("open", onTransportOpen);
1710
+ transport.removeListener("error", onerror);
1711
+ transport.removeListener("close", onTransportClose);
1712
+ this.off("close", onclose);
1713
+ this.off("upgrading", onupgrade);
1714
+ };
1715
+ transport.once("open", onTransportOpen);
1716
+ transport.once("error", onerror);
1717
+ transport.once("close", onTransportClose);
1718
+ this.once("close", onclose);
1719
+ this.once("upgrading", onupgrade);
1720
+ if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
1721
+ this.setTimeoutFn(() => {
1722
+ if (!failed) {
1723
+ transport.open();
1724
+ }
1725
+ }, 200);
1726
+ } else {
1727
+ transport.open();
1728
+ }
1729
+ }
1730
+ onHandshake(data) {
1731
+ this._upgrades = this._filterUpgrades(data.upgrades);
1732
+ super.onHandshake(data);
1733
+ }
1734
+ /**
1735
+ * Filters upgrades, returning only those matching client transports.
1736
+ *
1737
+ * @param {Array} upgrades - server upgrades
1738
+ * @private
1739
+ */
1740
+ _filterUpgrades(upgrades) {
1741
+ const filteredUpgrades = [];
1742
+ for (let i = 0; i < upgrades.length; i++) {
1743
+ if (~this.transports.indexOf(upgrades[i]))
1744
+ filteredUpgrades.push(upgrades[i]);
1745
+ }
1746
+ return filteredUpgrades;
1747
+ }
1748
+ };
1749
+ var Socket = class extends SocketWithUpgrade {
1750
+ constructor(uri, opts = {}) {
1751
+ const o = typeof uri === "object" ? uri : opts;
1752
+ if (!o.transports || o.transports && typeof o.transports[0] === "string") {
1753
+ o.transports = (o.transports || ["polling", "websocket", "webtransport"]).map((transportName) => transports[transportName]).filter((t) => !!t);
1754
+ }
1755
+ super(uri, o);
1756
+ }
1757
+ };
1758
+
1759
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/url.js
1760
+ function url(uri, path = "", loc) {
1761
+ let obj = uri;
1762
+ loc = loc || typeof location !== "undefined" && location;
1763
+ if (null == uri)
1764
+ uri = loc.protocol + "//" + loc.host;
1765
+ if (typeof uri === "string") {
1766
+ if ("/" === uri.charAt(0)) {
1767
+ if ("/" === uri.charAt(1)) {
1768
+ uri = loc.protocol + uri;
1769
+ } else {
1770
+ uri = loc.host + uri;
1771
+ }
1772
+ }
1773
+ if (!/^(https?|wss?):\/\//.test(uri)) {
1774
+ if ("undefined" !== typeof loc) {
1775
+ uri = loc.protocol + "//" + uri;
1776
+ } else {
1777
+ uri = "https://" + uri;
1778
+ }
1779
+ }
1780
+ obj = parse(uri);
1781
+ }
1782
+ if (!obj.port) {
1783
+ if (/^(http|ws)$/.test(obj.protocol)) {
1784
+ obj.port = "80";
1785
+ } else if (/^(http|ws)s$/.test(obj.protocol)) {
1786
+ obj.port = "443";
1787
+ }
1788
+ }
1789
+ obj.path = obj.path || "/";
1790
+ const ipv6 = obj.host.indexOf(":") !== -1;
1791
+ const host = ipv6 ? "[" + obj.host + "]" : obj.host;
1792
+ obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
1793
+ obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port);
1794
+ return obj;
1795
+ }
1796
+
1797
+ // ../node_modules/.pnpm/socket.io-parser@4.2.5/node_modules/socket.io-parser/build/esm/index.js
1798
+ var esm_exports = {};
1799
+ __export(esm_exports, {
1800
+ Decoder: () => Decoder,
1801
+ Encoder: () => Encoder,
1802
+ PacketType: () => PacketType,
1803
+ isPacketValid: () => isPacketValid,
1804
+ protocol: () => protocol3
1805
+ });
1806
+
1807
+ // ../node_modules/.pnpm/socket.io-parser@4.2.5/node_modules/socket.io-parser/build/esm/is-binary.js
1808
+ var withNativeArrayBuffer3 = typeof ArrayBuffer === "function";
1809
+ var isView2 = (obj) => {
1810
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
1811
+ };
1812
+ var toString = Object.prototype.toString;
1813
+ var withNativeBlob2 = typeof Blob === "function" || typeof Blob !== "undefined" && toString.call(Blob) === "[object BlobConstructor]";
1814
+ var withNativeFile = typeof File === "function" || typeof File !== "undefined" && toString.call(File) === "[object FileConstructor]";
1815
+ function isBinary(obj) {
1816
+ return withNativeArrayBuffer3 && (obj instanceof ArrayBuffer || isView2(obj)) || withNativeBlob2 && obj instanceof Blob || withNativeFile && obj instanceof File;
1817
+ }
1818
+ function hasBinary(obj, toJSON) {
1819
+ if (!obj || typeof obj !== "object") {
1820
+ return false;
1821
+ }
1822
+ if (Array.isArray(obj)) {
1823
+ for (let i = 0, l = obj.length; i < l; i++) {
1824
+ if (hasBinary(obj[i])) {
1825
+ return true;
1826
+ }
1827
+ }
1828
+ return false;
1829
+ }
1830
+ if (isBinary(obj)) {
1831
+ return true;
1832
+ }
1833
+ if (obj.toJSON && typeof obj.toJSON === "function" && arguments.length === 1) {
1834
+ return hasBinary(obj.toJSON(), true);
1835
+ }
1836
+ for (const key in obj) {
1837
+ if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
1838
+ return true;
1839
+ }
1840
+ }
1841
+ return false;
1842
+ }
1843
+
1844
+ // ../node_modules/.pnpm/socket.io-parser@4.2.5/node_modules/socket.io-parser/build/esm/binary.js
1845
+ function deconstructPacket(packet) {
1846
+ const buffers = [];
1847
+ const packetData = packet.data;
1848
+ const pack = packet;
1849
+ pack.data = _deconstructPacket(packetData, buffers);
1850
+ pack.attachments = buffers.length;
1851
+ return { packet: pack, buffers };
1852
+ }
1853
+ function _deconstructPacket(data, buffers) {
1854
+ if (!data)
1855
+ return data;
1856
+ if (isBinary(data)) {
1857
+ const placeholder = { _placeholder: true, num: buffers.length };
1858
+ buffers.push(data);
1859
+ return placeholder;
1860
+ } else if (Array.isArray(data)) {
1861
+ const newData = new Array(data.length);
1862
+ for (let i = 0; i < data.length; i++) {
1863
+ newData[i] = _deconstructPacket(data[i], buffers);
1864
+ }
1865
+ return newData;
1866
+ } else if (typeof data === "object" && !(data instanceof Date)) {
1867
+ const newData = {};
1868
+ for (const key in data) {
1869
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
1870
+ newData[key] = _deconstructPacket(data[key], buffers);
1871
+ }
1872
+ }
1873
+ return newData;
1874
+ }
1875
+ return data;
1876
+ }
1877
+ function reconstructPacket(packet, buffers) {
1878
+ packet.data = _reconstructPacket(packet.data, buffers);
1879
+ delete packet.attachments;
1880
+ return packet;
1881
+ }
1882
+ function _reconstructPacket(data, buffers) {
1883
+ if (!data)
1884
+ return data;
1885
+ if (data && data._placeholder === true) {
1886
+ const isIndexValid = typeof data.num === "number" && data.num >= 0 && data.num < buffers.length;
1887
+ if (isIndexValid) {
1888
+ return buffers[data.num];
1889
+ } else {
1890
+ throw new Error("illegal attachments");
1891
+ }
1892
+ } else if (Array.isArray(data)) {
1893
+ for (let i = 0; i < data.length; i++) {
1894
+ data[i] = _reconstructPacket(data[i], buffers);
1895
+ }
1896
+ } else if (typeof data === "object") {
1897
+ for (const key in data) {
1898
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
1899
+ data[key] = _reconstructPacket(data[key], buffers);
1900
+ }
1901
+ }
1902
+ }
1903
+ return data;
1904
+ }
1905
+
1906
+ // ../node_modules/.pnpm/socket.io-parser@4.2.5/node_modules/socket.io-parser/build/esm/index.js
1907
+ var RESERVED_EVENTS = [
1908
+ "connect",
1909
+ // used on the client side
1910
+ "connect_error",
1911
+ // used on the client side
1912
+ "disconnect",
1913
+ // used on both sides
1914
+ "disconnecting",
1915
+ // used on the server side
1916
+ "newListener",
1917
+ // used by the Node.js EventEmitter
1918
+ "removeListener"
1919
+ // used by the Node.js EventEmitter
1920
+ ];
1921
+ var protocol3 = 5;
1922
+ var PacketType;
1923
+ (function(PacketType2) {
1924
+ PacketType2[PacketType2["CONNECT"] = 0] = "CONNECT";
1925
+ PacketType2[PacketType2["DISCONNECT"] = 1] = "DISCONNECT";
1926
+ PacketType2[PacketType2["EVENT"] = 2] = "EVENT";
1927
+ PacketType2[PacketType2["ACK"] = 3] = "ACK";
1928
+ PacketType2[PacketType2["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
1929
+ PacketType2[PacketType2["BINARY_EVENT"] = 5] = "BINARY_EVENT";
1930
+ PacketType2[PacketType2["BINARY_ACK"] = 6] = "BINARY_ACK";
1931
+ })(PacketType || (PacketType = {}));
1932
+ var Encoder = class {
1933
+ /**
1934
+ * Encoder constructor
1935
+ *
1936
+ * @param {function} replacer - custom replacer to pass down to JSON.parse
1937
+ */
1938
+ constructor(replacer) {
1939
+ this.replacer = replacer;
1940
+ }
1941
+ /**
1942
+ * Encode a packet as a single string if non-binary, or as a
1943
+ * buffer sequence, depending on packet type.
1944
+ *
1945
+ * @param {Object} obj - packet object
1946
+ */
1947
+ encode(obj) {
1948
+ if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
1949
+ if (hasBinary(obj)) {
1950
+ return this.encodeAsBinary({
1951
+ type: obj.type === PacketType.EVENT ? PacketType.BINARY_EVENT : PacketType.BINARY_ACK,
1952
+ nsp: obj.nsp,
1953
+ data: obj.data,
1954
+ id: obj.id
1955
+ });
1956
+ }
1957
+ }
1958
+ return [this.encodeAsString(obj)];
1959
+ }
1960
+ /**
1961
+ * Encode packet as string.
1962
+ */
1963
+ encodeAsString(obj) {
1964
+ let str = "" + obj.type;
1965
+ if (obj.type === PacketType.BINARY_EVENT || obj.type === PacketType.BINARY_ACK) {
1966
+ str += obj.attachments + "-";
1967
+ }
1968
+ if (obj.nsp && "/" !== obj.nsp) {
1969
+ str += obj.nsp + ",";
1970
+ }
1971
+ if (null != obj.id) {
1972
+ str += obj.id;
1973
+ }
1974
+ if (null != obj.data) {
1975
+ str += JSON.stringify(obj.data, this.replacer);
1976
+ }
1977
+ return str;
1978
+ }
1979
+ /**
1980
+ * Encode packet as 'buffer sequence' by removing blobs, and
1981
+ * deconstructing packet into object with placeholders and
1982
+ * a list of buffers.
1983
+ */
1984
+ encodeAsBinary(obj) {
1985
+ const deconstruction = deconstructPacket(obj);
1986
+ const pack = this.encodeAsString(deconstruction.packet);
1987
+ const buffers = deconstruction.buffers;
1988
+ buffers.unshift(pack);
1989
+ return buffers;
1990
+ }
1991
+ };
1992
+ var Decoder = class _Decoder extends Emitter {
1993
+ /**
1994
+ * Decoder constructor
1995
+ *
1996
+ * @param {function} reviver - custom reviver to pass down to JSON.stringify
1997
+ */
1998
+ constructor(reviver) {
1999
+ super();
2000
+ this.reviver = reviver;
2001
+ }
2002
+ /**
2003
+ * Decodes an encoded packet string into packet JSON.
2004
+ *
2005
+ * @param {String} obj - encoded packet
2006
+ */
2007
+ add(obj) {
2008
+ let packet;
2009
+ if (typeof obj === "string") {
2010
+ if (this.reconstructor) {
2011
+ throw new Error("got plaintext data when reconstructing a packet");
2012
+ }
2013
+ packet = this.decodeString(obj);
2014
+ const isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
2015
+ if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
2016
+ packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
2017
+ this.reconstructor = new BinaryReconstructor(packet);
2018
+ if (packet.attachments === 0) {
2019
+ super.emitReserved("decoded", packet);
2020
+ }
2021
+ } else {
2022
+ super.emitReserved("decoded", packet);
2023
+ }
2024
+ } else if (isBinary(obj) || obj.base64) {
2025
+ if (!this.reconstructor) {
2026
+ throw new Error("got binary data when not reconstructing a packet");
2027
+ } else {
2028
+ packet = this.reconstructor.takeBinaryData(obj);
2029
+ if (packet) {
2030
+ this.reconstructor = null;
2031
+ super.emitReserved("decoded", packet);
2032
+ }
2033
+ }
2034
+ } else {
2035
+ throw new Error("Unknown type: " + obj);
2036
+ }
2037
+ }
2038
+ /**
2039
+ * Decode a packet String (JSON data)
2040
+ *
2041
+ * @param {String} str
2042
+ * @return {Object} packet
2043
+ */
2044
+ decodeString(str) {
2045
+ let i = 0;
2046
+ const p = {
2047
+ type: Number(str.charAt(0))
2048
+ };
2049
+ if (PacketType[p.type] === void 0) {
2050
+ throw new Error("unknown packet type " + p.type);
2051
+ }
2052
+ if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) {
2053
+ const start = i + 1;
2054
+ while (str.charAt(++i) !== "-" && i != str.length) {
2055
+ }
2056
+ const buf = str.substring(start, i);
2057
+ if (buf != Number(buf) || str.charAt(i) !== "-") {
2058
+ throw new Error("Illegal attachments");
2059
+ }
2060
+ p.attachments = Number(buf);
2061
+ }
2062
+ if ("/" === str.charAt(i + 1)) {
2063
+ const start = i + 1;
2064
+ while (++i) {
2065
+ const c = str.charAt(i);
2066
+ if ("," === c)
2067
+ break;
2068
+ if (i === str.length)
2069
+ break;
2070
+ }
2071
+ p.nsp = str.substring(start, i);
2072
+ } else {
2073
+ p.nsp = "/";
2074
+ }
2075
+ const next = str.charAt(i + 1);
2076
+ if ("" !== next && Number(next) == next) {
2077
+ const start = i + 1;
2078
+ while (++i) {
2079
+ const c = str.charAt(i);
2080
+ if (null == c || Number(c) != c) {
2081
+ --i;
2082
+ break;
2083
+ }
2084
+ if (i === str.length)
2085
+ break;
2086
+ }
2087
+ p.id = Number(str.substring(start, i + 1));
2088
+ }
2089
+ if (str.charAt(++i)) {
2090
+ const payload = this.tryParse(str.substr(i));
2091
+ if (_Decoder.isPayloadValid(p.type, payload)) {
2092
+ p.data = payload;
2093
+ } else {
2094
+ throw new Error("invalid payload");
2095
+ }
2096
+ }
2097
+ return p;
2098
+ }
2099
+ tryParse(str) {
2100
+ try {
2101
+ return JSON.parse(str, this.reviver);
2102
+ } catch (e) {
2103
+ return false;
2104
+ }
2105
+ }
2106
+ static isPayloadValid(type, payload) {
2107
+ switch (type) {
2108
+ case PacketType.CONNECT:
2109
+ return isObject(payload);
2110
+ case PacketType.DISCONNECT:
2111
+ return payload === void 0;
2112
+ case PacketType.CONNECT_ERROR:
2113
+ return typeof payload === "string" || isObject(payload);
2114
+ case PacketType.EVENT:
2115
+ case PacketType.BINARY_EVENT:
2116
+ return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS.indexOf(payload[0]) === -1);
2117
+ case PacketType.ACK:
2118
+ case PacketType.BINARY_ACK:
2119
+ return Array.isArray(payload);
2120
+ }
2121
+ }
2122
+ /**
2123
+ * Deallocates a parser's resources
2124
+ */
2125
+ destroy() {
2126
+ if (this.reconstructor) {
2127
+ this.reconstructor.finishedReconstruction();
2128
+ this.reconstructor = null;
2129
+ }
2130
+ }
19
2131
  };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
2132
+ var BinaryReconstructor = class {
2133
+ constructor(packet) {
2134
+ this.packet = packet;
2135
+ this.buffers = [];
2136
+ this.reconPack = packet;
2137
+ }
2138
+ /**
2139
+ * Method to be called when binary data received from connection
2140
+ * after a BINARY_EVENT packet.
2141
+ *
2142
+ * @param {Buffer | ArrayBuffer} binData - the raw binary data received
2143
+ * @return {null | Object} returns null if more binary data is expected or
2144
+ * a reconstructed packet object if all buffers have been received.
2145
+ */
2146
+ takeBinaryData(binData) {
2147
+ this.buffers.push(binData);
2148
+ if (this.buffers.length === this.reconPack.attachments) {
2149
+ const packet = reconstructPacket(this.reconPack, this.buffers);
2150
+ this.finishedReconstruction();
2151
+ return packet;
2152
+ }
2153
+ return null;
2154
+ }
2155
+ /**
2156
+ * Cleans up binary packet reconstruction variables.
2157
+ */
2158
+ finishedReconstruction() {
2159
+ this.reconPack = null;
2160
+ this.buffers = [];
25
2161
  }
26
- return to;
27
2162
  };
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/errors.ts
31
- var ErrorCode, EstuaryError;
32
- var init_errors = __esm({
33
- "src/errors.ts"() {
34
- ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
35
- ErrorCode2["CONNECTION_FAILED"] = "CONNECTION_FAILED";
36
- ErrorCode2["AUTH_FAILED"] = "AUTH_FAILED";
37
- ErrorCode2["CONNECTION_TIMEOUT"] = "CONNECTION_TIMEOUT";
38
- ErrorCode2["QUOTA_EXCEEDED"] = "QUOTA_EXCEEDED";
39
- ErrorCode2["VOICE_NOT_SUPPORTED"] = "VOICE_NOT_SUPPORTED";
40
- ErrorCode2["VOICE_ALREADY_ACTIVE"] = "VOICE_ALREADY_ACTIVE";
41
- ErrorCode2["VOICE_NOT_ACTIVE"] = "VOICE_NOT_ACTIVE";
42
- ErrorCode2["LIVEKIT_UNAVAILABLE"] = "LIVEKIT_UNAVAILABLE";
43
- ErrorCode2["MICROPHONE_DENIED"] = "MICROPHONE_DENIED";
44
- ErrorCode2["NOT_CONNECTED"] = "NOT_CONNECTED";
45
- ErrorCode2["REST_ERROR"] = "REST_ERROR";
46
- ErrorCode2["UNKNOWN"] = "UNKNOWN";
47
- return ErrorCode2;
48
- })(ErrorCode || {});
49
- EstuaryError = class extends Error {
50
- code;
51
- details;
52
- constructor(code, message, details) {
53
- super(message);
54
- this.name = "EstuaryError";
55
- this.code = code;
56
- this.details = details;
57
- }
58
- };
2163
+ function isNamespaceValid(nsp) {
2164
+ return typeof nsp === "string";
2165
+ }
2166
+ var isInteger = Number.isInteger || function(value2) {
2167
+ return typeof value2 === "number" && isFinite(value2) && Math.floor(value2) === value2;
2168
+ };
2169
+ function isAckIdValid(id) {
2170
+ return id === void 0 || isInteger(id);
2171
+ }
2172
+ function isObject(value2) {
2173
+ return Object.prototype.toString.call(value2) === "[object Object]";
2174
+ }
2175
+ function isDataValid(type, payload) {
2176
+ switch (type) {
2177
+ case PacketType.CONNECT:
2178
+ return payload === void 0 || isObject(payload);
2179
+ case PacketType.DISCONNECT:
2180
+ return payload === void 0;
2181
+ case PacketType.EVENT:
2182
+ return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS.indexOf(payload[0]) === -1);
2183
+ case PacketType.ACK:
2184
+ return Array.isArray(payload);
2185
+ case PacketType.CONNECT_ERROR:
2186
+ return typeof payload === "string" || isObject(payload);
2187
+ default:
2188
+ return false;
59
2189
  }
60
- });
2190
+ }
2191
+ function isPacketValid(packet) {
2192
+ return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data);
2193
+ }
61
2194
 
62
- // src/voice/websocket-voice.ts
63
- var websocket_voice_exports = {};
64
- __export(websocket_voice_exports, {
65
- WebSocketVoiceManager: () => WebSocketVoiceManager
66
- });
67
- function resample(input, fromRate, toRate) {
68
- const ratio = fromRate / toRate;
69
- const outputLength = Math.round(input.length / ratio);
70
- const output = new Float32Array(outputLength);
71
- for (let i = 0; i < outputLength; i++) {
72
- const srcIndex = i * ratio;
73
- const low = Math.floor(srcIndex);
74
- const high = Math.min(low + 1, input.length - 1);
75
- const frac = srcIndex - low;
76
- output[i] = input[low] * (1 - frac) + input[high] * frac;
77
- }
78
- return output;
2195
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/on.js
2196
+ function on(obj, ev, fn) {
2197
+ obj.on(ev, fn);
2198
+ return function subDestroy() {
2199
+ obj.off(ev, fn);
2200
+ };
79
2201
  }
80
- function float32ToInt16(float32) {
81
- const int16 = new Int16Array(float32.length);
82
- for (let i = 0; i < float32.length; i++) {
83
- const clamped = Math.max(-1, Math.min(1, float32[i]));
84
- int16[i] = clamped < 0 ? clamped * 32768 : clamped * 32767;
2202
+
2203
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/socket.js
2204
+ var RESERVED_EVENTS2 = Object.freeze({
2205
+ connect: 1,
2206
+ connect_error: 1,
2207
+ disconnect: 1,
2208
+ disconnecting: 1,
2209
+ // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
2210
+ newListener: 1,
2211
+ removeListener: 1
2212
+ });
2213
+ var Socket2 = class extends Emitter {
2214
+ /**
2215
+ * `Socket` constructor.
2216
+ */
2217
+ constructor(io, nsp, opts) {
2218
+ super();
2219
+ this.connected = false;
2220
+ this.recovered = false;
2221
+ this.receiveBuffer = [];
2222
+ this.sendBuffer = [];
2223
+ this._queue = [];
2224
+ this._queueSeq = 0;
2225
+ this.ids = 0;
2226
+ this.acks = {};
2227
+ this.flags = {};
2228
+ this.io = io;
2229
+ this.nsp = nsp;
2230
+ if (opts && opts.auth) {
2231
+ this.auth = opts.auth;
2232
+ }
2233
+ this._opts = Object.assign({}, opts);
2234
+ if (this.io._autoConnect)
2235
+ this.open();
85
2236
  }
86
- return int16;
87
- }
88
- function uint8ArrayToBase64(bytes) {
89
- if (typeof btoa === "function") {
90
- let binary = "";
91
- for (let i = 0; i < bytes.length; i++) {
92
- binary += String.fromCharCode(bytes[i]);
2237
+ /**
2238
+ * Whether the socket is currently disconnected
2239
+ *
2240
+ * @example
2241
+ * const socket = io();
2242
+ *
2243
+ * socket.on("connect", () => {
2244
+ * console.log(socket.disconnected); // false
2245
+ * });
2246
+ *
2247
+ * socket.on("disconnect", () => {
2248
+ * console.log(socket.disconnected); // true
2249
+ * });
2250
+ */
2251
+ get disconnected() {
2252
+ return !this.connected;
2253
+ }
2254
+ /**
2255
+ * Subscribe to open, close and packet events
2256
+ *
2257
+ * @private
2258
+ */
2259
+ subEvents() {
2260
+ if (this.subs)
2261
+ return;
2262
+ const io = this.io;
2263
+ this.subs = [
2264
+ on(io, "open", this.onopen.bind(this)),
2265
+ on(io, "packet", this.onpacket.bind(this)),
2266
+ on(io, "error", this.onerror.bind(this)),
2267
+ on(io, "close", this.onclose.bind(this))
2268
+ ];
2269
+ }
2270
+ /**
2271
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects.
2272
+ *
2273
+ * @example
2274
+ * const socket = io();
2275
+ *
2276
+ * console.log(socket.active); // true
2277
+ *
2278
+ * socket.on("disconnect", (reason) => {
2279
+ * if (reason === "io server disconnect") {
2280
+ * // the disconnection was initiated by the server, you need to manually reconnect
2281
+ * console.log(socket.active); // false
2282
+ * }
2283
+ * // else the socket will automatically try to reconnect
2284
+ * console.log(socket.active); // true
2285
+ * });
2286
+ */
2287
+ get active() {
2288
+ return !!this.subs;
2289
+ }
2290
+ /**
2291
+ * "Opens" the socket.
2292
+ *
2293
+ * @example
2294
+ * const socket = io({
2295
+ * autoConnect: false
2296
+ * });
2297
+ *
2298
+ * socket.connect();
2299
+ */
2300
+ connect() {
2301
+ if (this.connected)
2302
+ return this;
2303
+ this.subEvents();
2304
+ if (!this.io["_reconnecting"])
2305
+ this.io.open();
2306
+ if ("open" === this.io._readyState)
2307
+ this.onopen();
2308
+ return this;
2309
+ }
2310
+ /**
2311
+ * Alias for {@link connect()}.
2312
+ */
2313
+ open() {
2314
+ return this.connect();
2315
+ }
2316
+ /**
2317
+ * Sends a `message` event.
2318
+ *
2319
+ * This method mimics the WebSocket.send() method.
2320
+ *
2321
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
2322
+ *
2323
+ * @example
2324
+ * socket.send("hello");
2325
+ *
2326
+ * // this is equivalent to
2327
+ * socket.emit("message", "hello");
2328
+ *
2329
+ * @return self
2330
+ */
2331
+ send(...args) {
2332
+ args.unshift("message");
2333
+ this.emit.apply(this, args);
2334
+ return this;
2335
+ }
2336
+ /**
2337
+ * Override `emit`.
2338
+ * If the event is in `events`, it's emitted normally.
2339
+ *
2340
+ * @example
2341
+ * socket.emit("hello", "world");
2342
+ *
2343
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
2344
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
2345
+ *
2346
+ * // with an acknowledgement from the server
2347
+ * socket.emit("hello", "world", (val) => {
2348
+ * // ...
2349
+ * });
2350
+ *
2351
+ * @return self
2352
+ */
2353
+ emit(ev, ...args) {
2354
+ var _a, _b, _c;
2355
+ if (RESERVED_EVENTS2.hasOwnProperty(ev)) {
2356
+ throw new Error('"' + ev.toString() + '" is a reserved event name');
2357
+ }
2358
+ args.unshift(ev);
2359
+ if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
2360
+ this._addToQueue(args);
2361
+ return this;
93
2362
  }
94
- return btoa(binary);
2363
+ const packet = {
2364
+ type: PacketType.EVENT,
2365
+ data: args
2366
+ };
2367
+ packet.options = {};
2368
+ packet.options.compress = this.flags.compress !== false;
2369
+ if ("function" === typeof args[args.length - 1]) {
2370
+ const id = this.ids++;
2371
+ const ack = args.pop();
2372
+ this._registerAckCallback(id, ack);
2373
+ packet.id = id;
2374
+ }
2375
+ const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
2376
+ const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
2377
+ const discardPacket = this.flags.volatile && !isTransportWritable;
2378
+ if (discardPacket) ; else if (isConnected) {
2379
+ this.notifyOutgoingListeners(packet);
2380
+ this.packet(packet);
2381
+ } else {
2382
+ this.sendBuffer.push(packet);
2383
+ }
2384
+ this.flags = {};
2385
+ return this;
95
2386
  }
96
- return Buffer.from(bytes).toString("base64");
97
- }
98
- var WebSocketVoiceManager;
99
- var init_websocket_voice = __esm({
100
- "src/voice/websocket-voice.ts"() {
101
- init_errors();
102
- WebSocketVoiceManager = class {
103
- socketManager;
104
- sampleRate;
105
- logger;
106
- audioContext = null;
107
- mediaStream = null;
108
- scriptProcessor = null;
109
- sourceNode = null;
110
- _isMuted = false;
111
- _isActive = false;
112
- constructor(socketManager, sampleRate, logger) {
113
- this.socketManager = socketManager;
114
- this.sampleRate = sampleRate;
115
- this.logger = logger;
116
- }
117
- get isMuted() {
118
- return this._isMuted;
119
- }
120
- get isActive() {
121
- return this._isActive;
122
- }
123
- async start() {
124
- if (this._isActive) {
125
- throw new EstuaryError("VOICE_ALREADY_ACTIVE" /* VOICE_ALREADY_ACTIVE */, "Voice is already active");
2387
+ /**
2388
+ * @private
2389
+ */
2390
+ _registerAckCallback(id, ack) {
2391
+ var _a;
2392
+ const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
2393
+ if (timeout === void 0) {
2394
+ this.acks[id] = ack;
2395
+ return;
2396
+ }
2397
+ const timer = this.io.setTimeoutFn(() => {
2398
+ delete this.acks[id];
2399
+ for (let i = 0; i < this.sendBuffer.length; i++) {
2400
+ if (this.sendBuffer[i].id === id) {
2401
+ this.sendBuffer.splice(i, 1);
126
2402
  }
127
- if (typeof AudioContext === "undefined" && typeof globalThis.webkitAudioContext === "undefined") {
128
- throw new EstuaryError("VOICE_NOT_SUPPORTED" /* VOICE_NOT_SUPPORTED */, "AudioContext is not available in this environment");
2403
+ }
2404
+ ack.call(this, new Error("operation has timed out"));
2405
+ }, timeout);
2406
+ const fn = (...args) => {
2407
+ this.io.clearTimeoutFn(timer);
2408
+ ack.apply(this, args);
2409
+ };
2410
+ fn.withError = true;
2411
+ this.acks[id] = fn;
2412
+ }
2413
+ /**
2414
+ * Emits an event and waits for an acknowledgement
2415
+ *
2416
+ * @example
2417
+ * // without timeout
2418
+ * const response = await socket.emitWithAck("hello", "world");
2419
+ *
2420
+ * // with a specific timeout
2421
+ * try {
2422
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
2423
+ * } catch (err) {
2424
+ * // the server did not acknowledge the event in the given delay
2425
+ * }
2426
+ *
2427
+ * @return a Promise that will be fulfilled when the server acknowledges the event
2428
+ */
2429
+ emitWithAck(ev, ...args) {
2430
+ return new Promise((resolve, reject) => {
2431
+ const fn = (arg1, arg2) => {
2432
+ return arg1 ? reject(arg1) : resolve(arg2);
2433
+ };
2434
+ fn.withError = true;
2435
+ args.push(fn);
2436
+ this.emit(ev, ...args);
2437
+ });
2438
+ }
2439
+ /**
2440
+ * Add the packet to the queue.
2441
+ * @param args
2442
+ * @private
2443
+ */
2444
+ _addToQueue(args) {
2445
+ let ack;
2446
+ if (typeof args[args.length - 1] === "function") {
2447
+ ack = args.pop();
2448
+ }
2449
+ const packet = {
2450
+ id: this._queueSeq++,
2451
+ tryCount: 0,
2452
+ pending: false,
2453
+ args,
2454
+ flags: Object.assign({ fromQueue: true }, this.flags)
2455
+ };
2456
+ args.push((err, ...responseArgs) => {
2457
+ if (packet !== this._queue[0]) ;
2458
+ const hasError = err !== null;
2459
+ if (hasError) {
2460
+ if (packet.tryCount > this._opts.retries) {
2461
+ this._queue.shift();
2462
+ if (ack) {
2463
+ ack(err);
2464
+ }
129
2465
  }
130
- let stream;
131
- try {
132
- stream = await navigator.mediaDevices.getUserMedia({
133
- audio: { sampleRate: this.sampleRate, channelCount: 1 }
134
- });
135
- } catch (err) {
136
- throw new EstuaryError(
137
- "MICROPHONE_DENIED" /* MICROPHONE_DENIED */,
138
- "Microphone access denied",
139
- err
140
- );
2466
+ } else {
2467
+ this._queue.shift();
2468
+ if (ack) {
2469
+ ack(null, ...responseArgs);
141
2470
  }
142
- this.mediaStream = stream;
143
- const AudioCtx = globalThis.AudioContext || globalThis.webkitAudioContext;
144
- this.audioContext = new AudioCtx({ sampleRate: this.sampleRate });
145
- this.sourceNode = this.audioContext.createMediaStreamSource(stream);
146
- this.scriptProcessor = this.audioContext.createScriptProcessor(4096, 1, 1);
147
- const nativeRate = this.audioContext.sampleRate;
148
- const targetRate = this.sampleRate;
149
- this.scriptProcessor.onaudioprocess = (event) => {
150
- if (this._isMuted) return;
151
- const inputData = event.inputBuffer.getChannelData(0);
152
- let pcmFloat;
153
- if (nativeRate !== targetRate) {
154
- pcmFloat = resample(inputData, nativeRate, targetRate);
155
- } else {
156
- pcmFloat = inputData;
157
- }
158
- const pcm16 = float32ToInt16(pcmFloat);
159
- const base64 = uint8ArrayToBase64(new Uint8Array(pcm16.buffer));
160
- try {
161
- this.socketManager.emitEvent("stream_audio", { audio: base64 });
162
- } catch {
163
- }
164
- };
165
- this.sourceNode.connect(this.scriptProcessor);
166
- this.scriptProcessor.connect(this.audioContext.destination);
167
- this._isActive = true;
168
- this.socketManager.emitEvent("start_voice");
169
- this.logger.debug("WebSocket voice started");
170
2471
  }
171
- async stop() {
172
- if (!this._isActive) return;
173
- try {
174
- this.socketManager.emitEvent("stop_voice");
175
- } catch {
2472
+ packet.pending = false;
2473
+ return this._drainQueue();
2474
+ });
2475
+ this._queue.push(packet);
2476
+ this._drainQueue();
2477
+ }
2478
+ /**
2479
+ * Send the first packet of the queue, and wait for an acknowledgement from the server.
2480
+ * @param force - whether to resend a packet that has not been acknowledged yet
2481
+ *
2482
+ * @private
2483
+ */
2484
+ _drainQueue(force = false) {
2485
+ if (!this.connected || this._queue.length === 0) {
2486
+ return;
2487
+ }
2488
+ const packet = this._queue[0];
2489
+ if (packet.pending && !force) {
2490
+ return;
2491
+ }
2492
+ packet.pending = true;
2493
+ packet.tryCount++;
2494
+ this.flags = packet.flags;
2495
+ this.emit.apply(this, packet.args);
2496
+ }
2497
+ /**
2498
+ * Sends a packet.
2499
+ *
2500
+ * @param packet
2501
+ * @private
2502
+ */
2503
+ packet(packet) {
2504
+ packet.nsp = this.nsp;
2505
+ this.io._packet(packet);
2506
+ }
2507
+ /**
2508
+ * Called upon engine `open`.
2509
+ *
2510
+ * @private
2511
+ */
2512
+ onopen() {
2513
+ if (typeof this.auth == "function") {
2514
+ this.auth((data) => {
2515
+ this._sendConnectPacket(data);
2516
+ });
2517
+ } else {
2518
+ this._sendConnectPacket(this.auth);
2519
+ }
2520
+ }
2521
+ /**
2522
+ * Sends a CONNECT packet to initiate the Socket.IO session.
2523
+ *
2524
+ * @param data
2525
+ * @private
2526
+ */
2527
+ _sendConnectPacket(data) {
2528
+ this.packet({
2529
+ type: PacketType.CONNECT,
2530
+ data: this._pid ? Object.assign({ pid: this._pid, offset: this._lastOffset }, data) : data
2531
+ });
2532
+ }
2533
+ /**
2534
+ * Called upon engine or manager `error`.
2535
+ *
2536
+ * @param err
2537
+ * @private
2538
+ */
2539
+ onerror(err) {
2540
+ if (!this.connected) {
2541
+ this.emitReserved("connect_error", err);
2542
+ }
2543
+ }
2544
+ /**
2545
+ * Called upon engine `close`.
2546
+ *
2547
+ * @param reason
2548
+ * @param description
2549
+ * @private
2550
+ */
2551
+ onclose(reason, description) {
2552
+ this.connected = false;
2553
+ delete this.id;
2554
+ this.emitReserved("disconnect", reason, description);
2555
+ this._clearAcks();
2556
+ }
2557
+ /**
2558
+ * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
2559
+ * the server.
2560
+ *
2561
+ * @private
2562
+ */
2563
+ _clearAcks() {
2564
+ Object.keys(this.acks).forEach((id) => {
2565
+ const isBuffered = this.sendBuffer.some((packet) => String(packet.id) === id);
2566
+ if (!isBuffered) {
2567
+ const ack = this.acks[id];
2568
+ delete this.acks[id];
2569
+ if (ack.withError) {
2570
+ ack.call(this, new Error("socket has been disconnected"));
176
2571
  }
177
- this.cleanup();
178
- this._isActive = false;
179
- this._isMuted = false;
180
- this.logger.debug("WebSocket voice stopped");
181
2572
  }
182
- toggleMute() {
183
- if (!this._isActive || !this.mediaStream) return;
184
- this._isMuted = !this._isMuted;
185
- for (const track of this.mediaStream.getAudioTracks()) {
186
- track.enabled = !this._isMuted;
2573
+ });
2574
+ }
2575
+ /**
2576
+ * Called with socket packet.
2577
+ *
2578
+ * @param packet
2579
+ * @private
2580
+ */
2581
+ onpacket(packet) {
2582
+ const sameNamespace = packet.nsp === this.nsp;
2583
+ if (!sameNamespace)
2584
+ return;
2585
+ switch (packet.type) {
2586
+ case PacketType.CONNECT:
2587
+ if (packet.data && packet.data.sid) {
2588
+ this.onconnect(packet.data.sid, packet.data.pid);
2589
+ } else {
2590
+ this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
187
2591
  }
188
- this.logger.debug("Mute toggled:", this._isMuted);
189
- }
190
- dispose() {
191
- this.cleanup();
192
- this._isActive = false;
193
- this._isMuted = false;
2592
+ break;
2593
+ case PacketType.EVENT:
2594
+ case PacketType.BINARY_EVENT:
2595
+ this.onevent(packet);
2596
+ break;
2597
+ case PacketType.ACK:
2598
+ case PacketType.BINARY_ACK:
2599
+ this.onack(packet);
2600
+ break;
2601
+ case PacketType.DISCONNECT:
2602
+ this.ondisconnect();
2603
+ break;
2604
+ case PacketType.CONNECT_ERROR:
2605
+ this.destroy();
2606
+ const err = new Error(packet.data.message);
2607
+ err.data = packet.data.data;
2608
+ this.emitReserved("connect_error", err);
2609
+ break;
2610
+ }
2611
+ }
2612
+ /**
2613
+ * Called upon a server event.
2614
+ *
2615
+ * @param packet
2616
+ * @private
2617
+ */
2618
+ onevent(packet) {
2619
+ const args = packet.data || [];
2620
+ if (null != packet.id) {
2621
+ args.push(this.ack(packet.id));
2622
+ }
2623
+ if (this.connected) {
2624
+ this.emitEvent(args);
2625
+ } else {
2626
+ this.receiveBuffer.push(Object.freeze(args));
2627
+ }
2628
+ }
2629
+ emitEvent(args) {
2630
+ if (this._anyListeners && this._anyListeners.length) {
2631
+ const listeners = this._anyListeners.slice();
2632
+ for (const listener of listeners) {
2633
+ listener.apply(this, args);
194
2634
  }
195
- cleanup() {
196
- if (this.scriptProcessor) {
197
- this.scriptProcessor.onaudioprocess = null;
198
- this.scriptProcessor.disconnect();
199
- this.scriptProcessor = null;
200
- }
201
- if (this.sourceNode) {
202
- this.sourceNode.disconnect();
203
- this.sourceNode = null;
204
- }
205
- if (this.mediaStream) {
206
- for (const track of this.mediaStream.getTracks()) {
207
- track.stop();
208
- }
209
- this.mediaStream = null;
2635
+ }
2636
+ super.emit.apply(this, args);
2637
+ if (this._pid && args.length && typeof args[args.length - 1] === "string") {
2638
+ this._lastOffset = args[args.length - 1];
2639
+ }
2640
+ }
2641
+ /**
2642
+ * Produces an ack callback to emit with an event.
2643
+ *
2644
+ * @private
2645
+ */
2646
+ ack(id) {
2647
+ const self2 = this;
2648
+ let sent = false;
2649
+ return function(...args) {
2650
+ if (sent)
2651
+ return;
2652
+ sent = true;
2653
+ self2.packet({
2654
+ type: PacketType.ACK,
2655
+ id,
2656
+ data: args
2657
+ });
2658
+ };
2659
+ }
2660
+ /**
2661
+ * Called upon a server acknowledgement.
2662
+ *
2663
+ * @param packet
2664
+ * @private
2665
+ */
2666
+ onack(packet) {
2667
+ const ack = this.acks[packet.id];
2668
+ if (typeof ack !== "function") {
2669
+ return;
2670
+ }
2671
+ delete this.acks[packet.id];
2672
+ if (ack.withError) {
2673
+ packet.data.unshift(null);
2674
+ }
2675
+ ack.apply(this, packet.data);
2676
+ }
2677
+ /**
2678
+ * Called upon server connect.
2679
+ *
2680
+ * @private
2681
+ */
2682
+ onconnect(id, pid) {
2683
+ this.id = id;
2684
+ this.recovered = pid && this._pid === pid;
2685
+ this._pid = pid;
2686
+ this.connected = true;
2687
+ this.emitBuffered();
2688
+ this._drainQueue(true);
2689
+ this.emitReserved("connect");
2690
+ }
2691
+ /**
2692
+ * Emit buffered events (received and emitted).
2693
+ *
2694
+ * @private
2695
+ */
2696
+ emitBuffered() {
2697
+ this.receiveBuffer.forEach((args) => this.emitEvent(args));
2698
+ this.receiveBuffer = [];
2699
+ this.sendBuffer.forEach((packet) => {
2700
+ this.notifyOutgoingListeners(packet);
2701
+ this.packet(packet);
2702
+ });
2703
+ this.sendBuffer = [];
2704
+ }
2705
+ /**
2706
+ * Called upon server disconnect.
2707
+ *
2708
+ * @private
2709
+ */
2710
+ ondisconnect() {
2711
+ this.destroy();
2712
+ this.onclose("io server disconnect");
2713
+ }
2714
+ /**
2715
+ * Called upon forced client/server side disconnections,
2716
+ * this method ensures the manager stops tracking us and
2717
+ * that reconnections don't get triggered for this.
2718
+ *
2719
+ * @private
2720
+ */
2721
+ destroy() {
2722
+ if (this.subs) {
2723
+ this.subs.forEach((subDestroy) => subDestroy());
2724
+ this.subs = void 0;
2725
+ }
2726
+ this.io["_destroy"](this);
2727
+ }
2728
+ /**
2729
+ * Disconnects the socket manually. In that case, the socket will not try to reconnect.
2730
+ *
2731
+ * If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
2732
+ *
2733
+ * @example
2734
+ * const socket = io();
2735
+ *
2736
+ * socket.on("disconnect", (reason) => {
2737
+ * // console.log(reason); prints "io client disconnect"
2738
+ * });
2739
+ *
2740
+ * socket.disconnect();
2741
+ *
2742
+ * @return self
2743
+ */
2744
+ disconnect() {
2745
+ if (this.connected) {
2746
+ this.packet({ type: PacketType.DISCONNECT });
2747
+ }
2748
+ this.destroy();
2749
+ if (this.connected) {
2750
+ this.onclose("io client disconnect");
2751
+ }
2752
+ return this;
2753
+ }
2754
+ /**
2755
+ * Alias for {@link disconnect()}.
2756
+ *
2757
+ * @return self
2758
+ */
2759
+ close() {
2760
+ return this.disconnect();
2761
+ }
2762
+ /**
2763
+ * Sets the compress flag.
2764
+ *
2765
+ * @example
2766
+ * socket.compress(false).emit("hello");
2767
+ *
2768
+ * @param compress - if `true`, compresses the sending data
2769
+ * @return self
2770
+ */
2771
+ compress(compress) {
2772
+ this.flags.compress = compress;
2773
+ return this;
2774
+ }
2775
+ /**
2776
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
2777
+ * ready to send messages.
2778
+ *
2779
+ * @example
2780
+ * socket.volatile.emit("hello"); // the server may or may not receive it
2781
+ *
2782
+ * @returns self
2783
+ */
2784
+ get volatile() {
2785
+ this.flags.volatile = true;
2786
+ return this;
2787
+ }
2788
+ /**
2789
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
2790
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
2791
+ *
2792
+ * @example
2793
+ * socket.timeout(5000).emit("my-event", (err) => {
2794
+ * if (err) {
2795
+ * // the server did not acknowledge the event in the given delay
2796
+ * }
2797
+ * });
2798
+ *
2799
+ * @returns self
2800
+ */
2801
+ timeout(timeout) {
2802
+ this.flags.timeout = timeout;
2803
+ return this;
2804
+ }
2805
+ /**
2806
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2807
+ * callback.
2808
+ *
2809
+ * @example
2810
+ * socket.onAny((event, ...args) => {
2811
+ * console.log(`got ${event}`);
2812
+ * });
2813
+ *
2814
+ * @param listener
2815
+ */
2816
+ onAny(listener) {
2817
+ this._anyListeners = this._anyListeners || [];
2818
+ this._anyListeners.push(listener);
2819
+ return this;
2820
+ }
2821
+ /**
2822
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2823
+ * callback. The listener is added to the beginning of the listeners array.
2824
+ *
2825
+ * @example
2826
+ * socket.prependAny((event, ...args) => {
2827
+ * console.log(`got event ${event}`);
2828
+ * });
2829
+ *
2830
+ * @param listener
2831
+ */
2832
+ prependAny(listener) {
2833
+ this._anyListeners = this._anyListeners || [];
2834
+ this._anyListeners.unshift(listener);
2835
+ return this;
2836
+ }
2837
+ /**
2838
+ * Removes the listener that will be fired when any event is emitted.
2839
+ *
2840
+ * @example
2841
+ * const catchAllListener = (event, ...args) => {
2842
+ * console.log(`got event ${event}`);
2843
+ * }
2844
+ *
2845
+ * socket.onAny(catchAllListener);
2846
+ *
2847
+ * // remove a specific listener
2848
+ * socket.offAny(catchAllListener);
2849
+ *
2850
+ * // or remove all listeners
2851
+ * socket.offAny();
2852
+ *
2853
+ * @param listener
2854
+ */
2855
+ offAny(listener) {
2856
+ if (!this._anyListeners) {
2857
+ return this;
2858
+ }
2859
+ if (listener) {
2860
+ const listeners = this._anyListeners;
2861
+ for (let i = 0; i < listeners.length; i++) {
2862
+ if (listener === listeners[i]) {
2863
+ listeners.splice(i, 1);
2864
+ return this;
210
2865
  }
211
- if (this.audioContext) {
212
- this.audioContext.close().catch(() => {
213
- });
214
- this.audioContext = null;
2866
+ }
2867
+ } else {
2868
+ this._anyListeners = [];
2869
+ }
2870
+ return this;
2871
+ }
2872
+ /**
2873
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2874
+ * e.g. to remove listeners.
2875
+ */
2876
+ listenersAny() {
2877
+ return this._anyListeners || [];
2878
+ }
2879
+ /**
2880
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2881
+ * callback.
2882
+ *
2883
+ * Note: acknowledgements sent to the server are not included.
2884
+ *
2885
+ * @example
2886
+ * socket.onAnyOutgoing((event, ...args) => {
2887
+ * console.log(`sent event ${event}`);
2888
+ * });
2889
+ *
2890
+ * @param listener
2891
+ */
2892
+ onAnyOutgoing(listener) {
2893
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
2894
+ this._anyOutgoingListeners.push(listener);
2895
+ return this;
2896
+ }
2897
+ /**
2898
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
2899
+ * callback. The listener is added to the beginning of the listeners array.
2900
+ *
2901
+ * Note: acknowledgements sent to the server are not included.
2902
+ *
2903
+ * @example
2904
+ * socket.prependAnyOutgoing((event, ...args) => {
2905
+ * console.log(`sent event ${event}`);
2906
+ * });
2907
+ *
2908
+ * @param listener
2909
+ */
2910
+ prependAnyOutgoing(listener) {
2911
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
2912
+ this._anyOutgoingListeners.unshift(listener);
2913
+ return this;
2914
+ }
2915
+ /**
2916
+ * Removes the listener that will be fired when any event is emitted.
2917
+ *
2918
+ * @example
2919
+ * const catchAllListener = (event, ...args) => {
2920
+ * console.log(`sent event ${event}`);
2921
+ * }
2922
+ *
2923
+ * socket.onAnyOutgoing(catchAllListener);
2924
+ *
2925
+ * // remove a specific listener
2926
+ * socket.offAnyOutgoing(catchAllListener);
2927
+ *
2928
+ * // or remove all listeners
2929
+ * socket.offAnyOutgoing();
2930
+ *
2931
+ * @param [listener] - the catch-all listener (optional)
2932
+ */
2933
+ offAnyOutgoing(listener) {
2934
+ if (!this._anyOutgoingListeners) {
2935
+ return this;
2936
+ }
2937
+ if (listener) {
2938
+ const listeners = this._anyOutgoingListeners;
2939
+ for (let i = 0; i < listeners.length; i++) {
2940
+ if (listener === listeners[i]) {
2941
+ listeners.splice(i, 1);
2942
+ return this;
215
2943
  }
216
2944
  }
217
- };
2945
+ } else {
2946
+ this._anyOutgoingListeners = [];
2947
+ }
2948
+ return this;
218
2949
  }
219
- });
220
-
221
- // src/voice/livekit-voice.ts
222
- var livekit_voice_exports = {};
223
- __export(livekit_voice_exports, {
224
- LiveKitVoiceManager: () => LiveKitVoiceManager
225
- });
226
- var LiveKitVoiceManager;
227
- var init_livekit_voice = __esm({
228
- "src/voice/livekit-voice.ts"() {
229
- init_errors();
230
- LiveKitVoiceManager = class {
231
- socketManager;
232
- logger;
233
- room = null;
234
- // livekit-client Room (dynamically imported)
235
- _isMuted = false;
236
- _isActive = false;
237
- constructor(socketManager, logger) {
238
- this.socketManager = socketManager;
239
- this.logger = logger;
2950
+ /**
2951
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
2952
+ * e.g. to remove listeners.
2953
+ */
2954
+ listenersAnyOutgoing() {
2955
+ return this._anyOutgoingListeners || [];
2956
+ }
2957
+ /**
2958
+ * Notify the listeners for each packet sent
2959
+ *
2960
+ * @param packet
2961
+ *
2962
+ * @private
2963
+ */
2964
+ notifyOutgoingListeners(packet) {
2965
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
2966
+ const listeners = this._anyOutgoingListeners.slice();
2967
+ for (const listener of listeners) {
2968
+ listener.apply(this, packet.data);
240
2969
  }
241
- get isMuted() {
242
- return this._isMuted;
2970
+ }
2971
+ }
2972
+ };
2973
+
2974
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/contrib/backo2.js
2975
+ function Backoff(opts) {
2976
+ opts = opts || {};
2977
+ this.ms = opts.min || 100;
2978
+ this.max = opts.max || 1e4;
2979
+ this.factor = opts.factor || 2;
2980
+ this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
2981
+ this.attempts = 0;
2982
+ }
2983
+ Backoff.prototype.duration = function() {
2984
+ var ms = this.ms * Math.pow(this.factor, this.attempts++);
2985
+ if (this.jitter) {
2986
+ var rand = Math.random();
2987
+ var deviation = Math.floor(rand * this.jitter * ms);
2988
+ ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
2989
+ }
2990
+ return Math.min(ms, this.max) | 0;
2991
+ };
2992
+ Backoff.prototype.reset = function() {
2993
+ this.attempts = 0;
2994
+ };
2995
+ Backoff.prototype.setMin = function(min) {
2996
+ this.ms = min;
2997
+ };
2998
+ Backoff.prototype.setMax = function(max) {
2999
+ this.max = max;
3000
+ };
3001
+ Backoff.prototype.setJitter = function(jitter) {
3002
+ this.jitter = jitter;
3003
+ };
3004
+
3005
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/manager.js
3006
+ var Manager = class extends Emitter {
3007
+ constructor(uri, opts) {
3008
+ var _a;
3009
+ super();
3010
+ this.nsps = {};
3011
+ this.subs = [];
3012
+ if (uri && "object" === typeof uri) {
3013
+ opts = uri;
3014
+ uri = void 0;
3015
+ }
3016
+ opts = opts || {};
3017
+ opts.path = opts.path || "/socket.io";
3018
+ this.opts = opts;
3019
+ installTimerFunctions(this, opts);
3020
+ this.reconnection(opts.reconnection !== false);
3021
+ this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
3022
+ this.reconnectionDelay(opts.reconnectionDelay || 1e3);
3023
+ this.reconnectionDelayMax(opts.reconnectionDelayMax || 5e3);
3024
+ this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
3025
+ this.backoff = new Backoff({
3026
+ min: this.reconnectionDelay(),
3027
+ max: this.reconnectionDelayMax(),
3028
+ jitter: this.randomizationFactor()
3029
+ });
3030
+ this.timeout(null == opts.timeout ? 2e4 : opts.timeout);
3031
+ this._readyState = "closed";
3032
+ this.uri = uri;
3033
+ const _parser = opts.parser || esm_exports;
3034
+ this.encoder = new _parser.Encoder();
3035
+ this.decoder = new _parser.Decoder();
3036
+ this._autoConnect = opts.autoConnect !== false;
3037
+ if (this._autoConnect)
3038
+ this.open();
3039
+ }
3040
+ reconnection(v) {
3041
+ if (!arguments.length)
3042
+ return this._reconnection;
3043
+ this._reconnection = !!v;
3044
+ if (!v) {
3045
+ this.skipReconnect = true;
3046
+ }
3047
+ return this;
3048
+ }
3049
+ reconnectionAttempts(v) {
3050
+ if (v === void 0)
3051
+ return this._reconnectionAttempts;
3052
+ this._reconnectionAttempts = v;
3053
+ return this;
3054
+ }
3055
+ reconnectionDelay(v) {
3056
+ var _a;
3057
+ if (v === void 0)
3058
+ return this._reconnectionDelay;
3059
+ this._reconnectionDelay = v;
3060
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
3061
+ return this;
3062
+ }
3063
+ randomizationFactor(v) {
3064
+ var _a;
3065
+ if (v === void 0)
3066
+ return this._randomizationFactor;
3067
+ this._randomizationFactor = v;
3068
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
3069
+ return this;
3070
+ }
3071
+ reconnectionDelayMax(v) {
3072
+ var _a;
3073
+ if (v === void 0)
3074
+ return this._reconnectionDelayMax;
3075
+ this._reconnectionDelayMax = v;
3076
+ (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
3077
+ return this;
3078
+ }
3079
+ timeout(v) {
3080
+ if (!arguments.length)
3081
+ return this._timeout;
3082
+ this._timeout = v;
3083
+ return this;
3084
+ }
3085
+ /**
3086
+ * Starts trying to reconnect if reconnection is enabled and we have not
3087
+ * started reconnecting yet
3088
+ *
3089
+ * @private
3090
+ */
3091
+ maybeReconnectOnOpen() {
3092
+ if (!this._reconnecting && this._reconnection && this.backoff.attempts === 0) {
3093
+ this.reconnect();
3094
+ }
3095
+ }
3096
+ /**
3097
+ * Sets the current transport `socket`.
3098
+ *
3099
+ * @param {Function} fn - optional, callback
3100
+ * @return self
3101
+ * @public
3102
+ */
3103
+ open(fn) {
3104
+ if (~this._readyState.indexOf("open"))
3105
+ return this;
3106
+ this.engine = new Socket(this.uri, this.opts);
3107
+ const socket = this.engine;
3108
+ const self2 = this;
3109
+ this._readyState = "opening";
3110
+ this.skipReconnect = false;
3111
+ const openSubDestroy = on(socket, "open", function() {
3112
+ self2.onopen();
3113
+ fn && fn();
3114
+ });
3115
+ const onError = (err) => {
3116
+ this.cleanup();
3117
+ this._readyState = "closed";
3118
+ this.emitReserved("error", err);
3119
+ if (fn) {
3120
+ fn(err);
3121
+ } else {
3122
+ this.maybeReconnectOnOpen();
243
3123
  }
244
- get isActive() {
245
- return this._isActive;
3124
+ };
3125
+ const errorSub = on(socket, "error", onError);
3126
+ if (false !== this._timeout) {
3127
+ const timeout = this._timeout;
3128
+ const timer = this.setTimeoutFn(() => {
3129
+ openSubDestroy();
3130
+ onError(new Error("timeout"));
3131
+ socket.close();
3132
+ }, timeout);
3133
+ if (this.opts.autoUnref) {
3134
+ timer.unref();
246
3135
  }
247
- async start() {
248
- if (this._isActive) {
249
- throw new EstuaryError("VOICE_ALREADY_ACTIVE" /* VOICE_ALREADY_ACTIVE */, "Voice is already active");
250
- }
251
- let Room;
252
- let RoomEvent;
253
- let Track;
254
- try {
255
- const lk = await import('livekit-client');
256
- Room = lk.Room;
257
- RoomEvent = lk.RoomEvent;
258
- Track = lk.Track;
259
- } catch {
260
- throw new EstuaryError(
261
- "LIVEKIT_UNAVAILABLE" /* LIVEKIT_UNAVAILABLE */,
262
- "livekit-client package is not installed"
263
- );
264
- }
265
- const tokenData = await this.requestToken();
266
- this.room = new Room({
267
- adaptiveStream: true,
268
- dynacast: true,
269
- audioCaptureDefaults: {
270
- echoCancellation: true,
271
- noiseSuppression: true,
272
- autoGainControl: true
273
- }
274
- });
275
- this.room.on(RoomEvent.TrackSubscribed, (track, _publication, participant) => {
276
- if (track.kind === Track.Kind.Audio) {
277
- this.logger.debug("Bot audio track subscribed from", participant.identity);
278
- const audioElement = track.attach();
279
- audioElement.autoplay = true;
280
- audioElement.style.display = "none";
281
- if (typeof document !== "undefined") {
282
- document.body.appendChild(audioElement);
283
- }
284
- audioElement.play().catch(() => {
285
- });
286
- }
287
- });
288
- this.room.on(RoomEvent.TrackUnsubscribed, (track) => {
289
- if (track.kind === Track.Kind.Audio) {
290
- track.detach().forEach((el) => el.remove());
291
- }
292
- });
293
- this.room.on(RoomEvent.Disconnected, () => {
294
- this.logger.debug("LiveKit room disconnected");
295
- this._isActive = false;
296
- });
297
- try {
298
- await this.room.connect(tokenData.url, tokenData.token);
299
- this.logger.debug("Connected to LiveKit room:", tokenData.room);
300
- } catch (err) {
301
- this.room = null;
302
- throw new EstuaryError(
303
- "CONNECTION_FAILED" /* CONNECTION_FAILED */,
304
- "Failed to connect to LiveKit room",
305
- err
306
- );
307
- }
308
- try {
309
- await this.room.localParticipant.setMicrophoneEnabled(true);
310
- this.logger.debug("Microphone enabled");
311
- } catch (err) {
312
- this.room.disconnect();
313
- this.room = null;
314
- throw new EstuaryError(
315
- "MICROPHONE_DENIED" /* MICROPHONE_DENIED */,
316
- "Failed to enable microphone",
317
- err
318
- );
319
- }
320
- this.socketManager.emitEvent("livekit_join", { room: tokenData.room });
321
- this._isActive = true;
322
- this.logger.debug("LiveKit voice started");
3136
+ this.subs.push(() => {
3137
+ this.clearTimeoutFn(timer);
3138
+ });
3139
+ }
3140
+ this.subs.push(openSubDestroy);
3141
+ this.subs.push(errorSub);
3142
+ return this;
3143
+ }
3144
+ /**
3145
+ * Alias for open()
3146
+ *
3147
+ * @return self
3148
+ * @public
3149
+ */
3150
+ connect(fn) {
3151
+ return this.open(fn);
3152
+ }
3153
+ /**
3154
+ * Called upon transport open.
3155
+ *
3156
+ * @private
3157
+ */
3158
+ onopen() {
3159
+ this.cleanup();
3160
+ this._readyState = "open";
3161
+ this.emitReserved("open");
3162
+ const socket = this.engine;
3163
+ this.subs.push(
3164
+ on(socket, "ping", this.onping.bind(this)),
3165
+ on(socket, "data", this.ondata.bind(this)),
3166
+ on(socket, "error", this.onerror.bind(this)),
3167
+ on(socket, "close", this.onclose.bind(this)),
3168
+ // @ts-ignore
3169
+ on(this.decoder, "decoded", this.ondecoded.bind(this))
3170
+ );
3171
+ }
3172
+ /**
3173
+ * Called upon a ping.
3174
+ *
3175
+ * @private
3176
+ */
3177
+ onping() {
3178
+ this.emitReserved("ping");
3179
+ }
3180
+ /**
3181
+ * Called with data.
3182
+ *
3183
+ * @private
3184
+ */
3185
+ ondata(data) {
3186
+ try {
3187
+ this.decoder.add(data);
3188
+ } catch (e) {
3189
+ this.onclose("parse error", e);
3190
+ }
3191
+ }
3192
+ /**
3193
+ * Called when parser fully decodes a packet.
3194
+ *
3195
+ * @private
3196
+ */
3197
+ ondecoded(packet) {
3198
+ nextTick(() => {
3199
+ this.emitReserved("packet", packet);
3200
+ }, this.setTimeoutFn);
3201
+ }
3202
+ /**
3203
+ * Called upon socket error.
3204
+ *
3205
+ * @private
3206
+ */
3207
+ onerror(err) {
3208
+ this.emitReserved("error", err);
3209
+ }
3210
+ /**
3211
+ * Creates a new socket for the given `nsp`.
3212
+ *
3213
+ * @return {Socket}
3214
+ * @public
3215
+ */
3216
+ socket(nsp, opts) {
3217
+ let socket = this.nsps[nsp];
3218
+ if (!socket) {
3219
+ socket = new Socket2(this, nsp, opts);
3220
+ this.nsps[nsp] = socket;
3221
+ } else if (this._autoConnect && !socket.active) {
3222
+ socket.connect();
3223
+ }
3224
+ return socket;
3225
+ }
3226
+ /**
3227
+ * Called upon a socket close.
3228
+ *
3229
+ * @param socket
3230
+ * @private
3231
+ */
3232
+ _destroy(socket) {
3233
+ const nsps = Object.keys(this.nsps);
3234
+ for (const nsp of nsps) {
3235
+ const socket2 = this.nsps[nsp];
3236
+ if (socket2.active) {
3237
+ return;
323
3238
  }
324
- async stop() {
325
- if (!this._isActive) return;
326
- try {
327
- this.socketManager.emitEvent("livekit_leave");
328
- } catch {
329
- }
330
- if (this.room) {
331
- for (const [, publication] of this.room.localParticipant.trackPublications) {
332
- if (publication.track) {
333
- publication.track.stop();
334
- }
3239
+ }
3240
+ this._close();
3241
+ }
3242
+ /**
3243
+ * Writes a packet.
3244
+ *
3245
+ * @param packet
3246
+ * @private
3247
+ */
3248
+ _packet(packet) {
3249
+ const encodedPackets = this.encoder.encode(packet);
3250
+ for (let i = 0; i < encodedPackets.length; i++) {
3251
+ this.engine.write(encodedPackets[i], packet.options);
3252
+ }
3253
+ }
3254
+ /**
3255
+ * Clean up transport subscriptions and packet buffer.
3256
+ *
3257
+ * @private
3258
+ */
3259
+ cleanup() {
3260
+ this.subs.forEach((subDestroy) => subDestroy());
3261
+ this.subs.length = 0;
3262
+ this.decoder.destroy();
3263
+ }
3264
+ /**
3265
+ * Close the current socket.
3266
+ *
3267
+ * @private
3268
+ */
3269
+ _close() {
3270
+ this.skipReconnect = true;
3271
+ this._reconnecting = false;
3272
+ this.onclose("forced close");
3273
+ }
3274
+ /**
3275
+ * Alias for close()
3276
+ *
3277
+ * @private
3278
+ */
3279
+ disconnect() {
3280
+ return this._close();
3281
+ }
3282
+ /**
3283
+ * Called when:
3284
+ *
3285
+ * - the low-level engine is closed
3286
+ * - the parser encountered a badly formatted packet
3287
+ * - all sockets are disconnected
3288
+ *
3289
+ * @private
3290
+ */
3291
+ onclose(reason, description) {
3292
+ var _a;
3293
+ this.cleanup();
3294
+ (_a = this.engine) === null || _a === void 0 ? void 0 : _a.close();
3295
+ this.backoff.reset();
3296
+ this._readyState = "closed";
3297
+ this.emitReserved("close", reason, description);
3298
+ if (this._reconnection && !this.skipReconnect) {
3299
+ this.reconnect();
3300
+ }
3301
+ }
3302
+ /**
3303
+ * Attempt a reconnection.
3304
+ *
3305
+ * @private
3306
+ */
3307
+ reconnect() {
3308
+ if (this._reconnecting || this.skipReconnect)
3309
+ return this;
3310
+ const self2 = this;
3311
+ if (this.backoff.attempts >= this._reconnectionAttempts) {
3312
+ this.backoff.reset();
3313
+ this.emitReserved("reconnect_failed");
3314
+ this._reconnecting = false;
3315
+ } else {
3316
+ const delay = this.backoff.duration();
3317
+ this._reconnecting = true;
3318
+ const timer = this.setTimeoutFn(() => {
3319
+ if (self2.skipReconnect)
3320
+ return;
3321
+ this.emitReserved("reconnect_attempt", self2.backoff.attempts);
3322
+ if (self2.skipReconnect)
3323
+ return;
3324
+ self2.open((err) => {
3325
+ if (err) {
3326
+ self2._reconnecting = false;
3327
+ self2.reconnect();
3328
+ this.emitReserved("reconnect_error", err);
3329
+ } else {
3330
+ self2.onreconnect();
335
3331
  }
336
- this.room.disconnect();
337
- this.room = null;
338
- }
339
- this._isActive = false;
340
- this._isMuted = false;
341
- this.logger.debug("LiveKit voice stopped");
342
- }
343
- toggleMute() {
344
- if (!this._isActive || !this.room) return;
345
- this._isMuted = !this._isMuted;
346
- this.room.localParticipant.setMicrophoneEnabled(!this._isMuted);
347
- this.logger.debug("Mute toggled:", this._isMuted);
348
- }
349
- dispose() {
350
- if (this.room) {
351
- this.room.disconnect();
352
- this.room = null;
353
- }
354
- this._isActive = false;
355
- this._isMuted = false;
356
- }
357
- requestToken() {
358
- return new Promise((resolve, reject) => {
359
- const timeout = setTimeout(() => {
360
- this.socketManager.onLiveKitToken(() => {
361
- });
362
- reject(new EstuaryError(
363
- "CONNECTION_TIMEOUT" /* CONNECTION_TIMEOUT */,
364
- "Timed out waiting for LiveKit token"
365
- ));
366
- }, 1e4);
367
- this.socketManager.onLiveKitToken((data) => {
368
- clearTimeout(timeout);
369
- resolve(data);
370
- });
371
- this.socketManager.emitEvent("livekit_token");
372
3332
  });
3333
+ }, delay);
3334
+ if (this.opts.autoUnref) {
3335
+ timer.unref();
373
3336
  }
374
- };
3337
+ this.subs.push(() => {
3338
+ this.clearTimeoutFn(timer);
3339
+ });
3340
+ }
3341
+ }
3342
+ /**
3343
+ * Called upon successful reconnect.
3344
+ *
3345
+ * @private
3346
+ */
3347
+ onreconnect() {
3348
+ const attempt = this.backoff.attempts;
3349
+ this._reconnecting = false;
3350
+ this.backoff.reset();
3351
+ this.emitReserved("reconnect", attempt);
3352
+ }
3353
+ };
3354
+
3355
+ // ../node_modules/.pnpm/socket.io-client@4.8.3/node_modules/socket.io-client/build/esm/index.js
3356
+ var cache = {};
3357
+ function lookup2(uri, opts) {
3358
+ if (typeof uri === "object") {
3359
+ opts = uri;
3360
+ uri = void 0;
375
3361
  }
3362
+ opts = opts || {};
3363
+ const parsed = url(uri, opts.path || "/socket.io");
3364
+ const source = parsed.source;
3365
+ const id = parsed.id;
3366
+ const path = parsed.path;
3367
+ const sameNamespace = cache[id] && path in cache[id]["nsps"];
3368
+ const newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;
3369
+ let io;
3370
+ if (newConnection) {
3371
+ io = new Manager(source, opts);
3372
+ } else {
3373
+ if (!cache[id]) {
3374
+ cache[id] = new Manager(source, opts);
3375
+ }
3376
+ io = cache[id];
3377
+ }
3378
+ if (parsed.query && !opts.query) {
3379
+ opts.query = parsed.queryKey;
3380
+ }
3381
+ return io.socket(parsed.path, opts);
3382
+ }
3383
+ Object.assign(lookup2, {
3384
+ Manager,
3385
+ Socket: Socket2,
3386
+ io: lookup2,
3387
+ connect: lookup2
376
3388
  });
377
3389
 
378
3390
  // src/utils/event-emitter.ts
@@ -434,9 +3446,6 @@ var TypedEventEmitter = class {
434
3446
  }
435
3447
  };
436
3448
 
437
- // src/connection/socket-manager.ts
438
- init_errors();
439
-
440
3449
  // src/types.ts
441
3450
  var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
442
3451
  ConnectionState2["Disconnected"] = "disconnected";
@@ -461,7 +3470,8 @@ function toBotResponse(wire) {
461
3470
  partial: wire.partial,
462
3471
  messageId: wire.message_id,
463
3472
  chunkIndex: wire.chunk_index,
464
- isInterjection: wire.is_interjection
3473
+ isInterjection: wire.is_interjection,
3474
+ tokenStream: wire.token_stream
465
3475
  };
466
3476
  }
467
3477
  function toBotVoice(wire) {
@@ -555,9 +3565,9 @@ var SocketManager = class extends TypedEventEmitter {
555
3565
  }
556
3566
  this.setConnectionState("connecting" /* Connecting */);
557
3567
  this.reconnectAttempt = 0;
558
- const url = `${this.config.serverUrl}/sdk`;
559
- this.logger.debug("Connecting to", url);
560
- this.socket = io(url, {
3568
+ const url2 = `${this.config.serverUrl}/sdk`;
3569
+ this.logger.debug("Connecting to", url2);
3570
+ this.socket = lookup2(url2, {
561
3571
  transports: ["websocket"],
562
3572
  timeout: 1e4,
563
3573
  reconnection: false,
@@ -726,37 +3736,34 @@ var SocketManager = class extends TypedEventEmitter {
726
3736
  };
727
3737
 
728
3738
  // src/voice/voice-manager.ts
729
- function createVoiceManager(transport, socketManager, sampleRate, logger) {
3739
+ async function createVoiceManager(transport, socketManager, sampleRate, logger) {
730
3740
  if (transport === "websocket") {
731
- const { WebSocketVoiceManager: WebSocketVoiceManager2 } = (init_websocket_voice(), __toCommonJS(websocket_voice_exports));
732
- return new WebSocketVoiceManager2(socketManager, sampleRate, logger);
3741
+ const { WebSocketVoiceManager } = await import('./websocket-voice-A4CK3UTM.mjs');
3742
+ return new WebSocketVoiceManager(socketManager, sampleRate, logger);
733
3743
  }
734
3744
  if (transport === "livekit") {
735
3745
  try {
736
- __require.resolve("livekit-client");
737
- const { LiveKitVoiceManager: LiveKitVoiceManager2 } = (init_livekit_voice(), __toCommonJS(livekit_voice_exports));
738
- return new LiveKitVoiceManager2(socketManager, logger);
3746
+ const { LiveKitVoiceManager } = await import('./livekit-voice-2WOL2XRV.mjs');
3747
+ return new LiveKitVoiceManager(socketManager, logger);
739
3748
  } catch {
740
3749
  logger.warn("livekit-client not installed, falling back to WebSocket voice");
741
- const { WebSocketVoiceManager: WebSocketVoiceManager2 } = (init_websocket_voice(), __toCommonJS(websocket_voice_exports));
742
- return new WebSocketVoiceManager2(socketManager, sampleRate, logger);
3750
+ const { WebSocketVoiceManager } = await import('./websocket-voice-A4CK3UTM.mjs');
3751
+ return new WebSocketVoiceManager(socketManager, sampleRate, logger);
743
3752
  }
744
3753
  }
745
3754
  if (transport === "auto") {
746
3755
  try {
747
- __require.resolve("livekit-client");
748
- const { LiveKitVoiceManager: LiveKitVoiceManager2 } = (init_livekit_voice(), __toCommonJS(livekit_voice_exports));
749
- return new LiveKitVoiceManager2(socketManager, logger);
3756
+ const { LiveKitVoiceManager } = await import('./livekit-voice-2WOL2XRV.mjs');
3757
+ return new LiveKitVoiceManager(socketManager, logger);
750
3758
  } catch {
751
- const { WebSocketVoiceManager: WebSocketVoiceManager2 } = (init_websocket_voice(), __toCommonJS(websocket_voice_exports));
752
- return new WebSocketVoiceManager2(socketManager, sampleRate, logger);
3759
+ const { WebSocketVoiceManager } = await import('./websocket-voice-A4CK3UTM.mjs');
3760
+ return new WebSocketVoiceManager(socketManager, sampleRate, logger);
753
3761
  }
754
3762
  }
755
3763
  return null;
756
3764
  }
757
3765
 
758
3766
  // src/rest/rest-client.ts
759
- init_errors();
760
3767
  var RestClient = class {
761
3768
  baseUrl;
762
3769
  apiKey;
@@ -765,39 +3772,39 @@ var RestClient = class {
765
3772
  this.apiKey = apiKey;
766
3773
  }
767
3774
  async get(path, params) {
768
- const url = this.buildUrl(path, params);
769
- return this.request(url, { method: "GET" });
3775
+ const url2 = this.buildUrl(path, params);
3776
+ return this.request(url2, { method: "GET" });
770
3777
  }
771
3778
  async post(path, body) {
772
- const url = this.buildUrl(path);
3779
+ const url2 = this.buildUrl(path);
773
3780
  const init = { method: "POST" };
774
3781
  if (body !== void 0) {
775
3782
  init.headers = { "Content-Type": "application/json" };
776
3783
  init.body = JSON.stringify(body);
777
3784
  }
778
- return this.request(url, init);
3785
+ return this.request(url2, init);
779
3786
  }
780
3787
  async delete(path, params) {
781
- const url = this.buildUrl(path, params);
782
- return this.request(url, { method: "DELETE" });
3788
+ const url2 = this.buildUrl(path, params);
3789
+ return this.request(url2, { method: "DELETE" });
783
3790
  }
784
3791
  dispose() {
785
3792
  }
786
3793
  buildUrl(path, params) {
787
- const url = new URL(path, this.baseUrl);
3794
+ const url2 = new URL(path, this.baseUrl);
788
3795
  if (params) {
789
- for (const [key, value] of Object.entries(params)) {
790
- if (value !== void 0) {
791
- url.searchParams.set(key, String(value));
3796
+ for (const [key, value2] of Object.entries(params)) {
3797
+ if (value2 !== void 0) {
3798
+ url2.searchParams.set(key, String(value2));
792
3799
  }
793
3800
  }
794
3801
  }
795
- return url.toString();
3802
+ return url2.toString();
796
3803
  }
797
- async request(url, init) {
3804
+ async request(url2, init) {
798
3805
  const headers = new Headers(init.headers);
799
3806
  headers.set("X-API-Key", this.apiKey);
800
- const response = await fetch(url, { ...init, headers });
3807
+ const response = await fetch(url2, { ...init, headers });
801
3808
  if (!response.ok) {
802
3809
  let detail;
803
3810
  try {
@@ -983,7 +3990,6 @@ var Logger = class {
983
3990
  };
984
3991
 
985
3992
  // src/client.ts
986
- init_errors();
987
3993
  var DEFAULT_SAMPLE_RATE = 16e3;
988
3994
  var EstuaryClient = class extends TypedEventEmitter {
989
3995
  config;
@@ -1074,7 +4080,7 @@ var EstuaryClient = class extends TypedEventEmitter {
1074
4080
  }
1075
4081
  const transport = this.config.voiceTransport ?? "auto";
1076
4082
  const sampleRate = this.config.audioSampleRate ?? DEFAULT_SAMPLE_RATE;
1077
- this.voiceManager = createVoiceManager(transport, this.socketManager, sampleRate, this.logger);
4083
+ this.voiceManager = await createVoiceManager(transport, this.socketManager, sampleRate, this.logger);
1078
4084
  if (!this.voiceManager) {
1079
4085
  throw new EstuaryError("VOICE_NOT_SUPPORTED" /* VOICE_NOT_SUPPORTED */, "No voice transport available");
1080
4086
  }
@@ -1153,9 +4159,6 @@ var EstuaryClient = class extends TypedEventEmitter {
1153
4159
  }
1154
4160
  };
1155
4161
 
1156
- // src/index.ts
1157
- init_errors();
1158
-
1159
- export { ConnectionState, ErrorCode, EstuaryClient, EstuaryError };
4162
+ export { ConnectionState, EstuaryClient };
1160
4163
  //# sourceMappingURL=index.mjs.map
1161
4164
  //# sourceMappingURL=index.mjs.map