@tiktool/live 2.7.1 → 2.9.0

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,3 +1,1254 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __commonJS = (cb, mod) => function __require2() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+
12
+ // ../../../node_modules/ms/index.js
13
+ var require_ms = __commonJS({
14
+ "../../../node_modules/ms/index.js"(exports, module) {
15
+ "use strict";
16
+ var s = 1e3;
17
+ var m = s * 60;
18
+ var h = m * 60;
19
+ var d = h * 24;
20
+ var w = d * 7;
21
+ var y = d * 365.25;
22
+ module.exports = function(val, options) {
23
+ options = options || {};
24
+ var type = typeof val;
25
+ if (type === "string" && val.length > 0) {
26
+ return parse(val);
27
+ } else if (type === "number" && isFinite(val)) {
28
+ return options.long ? fmtLong(val) : fmtShort(val);
29
+ }
30
+ throw new Error(
31
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
32
+ );
33
+ };
34
+ function parse(str) {
35
+ str = String(str);
36
+ if (str.length > 100) {
37
+ return;
38
+ }
39
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
40
+ str
41
+ );
42
+ if (!match) {
43
+ return;
44
+ }
45
+ var n = parseFloat(match[1]);
46
+ var type = (match[2] || "ms").toLowerCase();
47
+ switch (type) {
48
+ case "years":
49
+ case "year":
50
+ case "yrs":
51
+ case "yr":
52
+ case "y":
53
+ return n * y;
54
+ case "weeks":
55
+ case "week":
56
+ case "w":
57
+ return n * w;
58
+ case "days":
59
+ case "day":
60
+ case "d":
61
+ return n * d;
62
+ case "hours":
63
+ case "hour":
64
+ case "hrs":
65
+ case "hr":
66
+ case "h":
67
+ return n * h;
68
+ case "minutes":
69
+ case "minute":
70
+ case "mins":
71
+ case "min":
72
+ case "m":
73
+ return n * m;
74
+ case "seconds":
75
+ case "second":
76
+ case "secs":
77
+ case "sec":
78
+ case "s":
79
+ return n * s;
80
+ case "milliseconds":
81
+ case "millisecond":
82
+ case "msecs":
83
+ case "msec":
84
+ case "ms":
85
+ return n;
86
+ default:
87
+ return void 0;
88
+ }
89
+ }
90
+ function fmtShort(ms) {
91
+ var msAbs = Math.abs(ms);
92
+ if (msAbs >= d) {
93
+ return Math.round(ms / d) + "d";
94
+ }
95
+ if (msAbs >= h) {
96
+ return Math.round(ms / h) + "h";
97
+ }
98
+ if (msAbs >= m) {
99
+ return Math.round(ms / m) + "m";
100
+ }
101
+ if (msAbs >= s) {
102
+ return Math.round(ms / s) + "s";
103
+ }
104
+ return ms + "ms";
105
+ }
106
+ function fmtLong(ms) {
107
+ var msAbs = Math.abs(ms);
108
+ if (msAbs >= d) {
109
+ return plural(ms, msAbs, d, "day");
110
+ }
111
+ if (msAbs >= h) {
112
+ return plural(ms, msAbs, h, "hour");
113
+ }
114
+ if (msAbs >= m) {
115
+ return plural(ms, msAbs, m, "minute");
116
+ }
117
+ if (msAbs >= s) {
118
+ return plural(ms, msAbs, s, "second");
119
+ }
120
+ return ms + " ms";
121
+ }
122
+ function plural(ms, msAbs, n, name) {
123
+ var isPlural = msAbs >= n * 1.5;
124
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
125
+ }
126
+ }
127
+ });
128
+
129
+ // ../../../node_modules/debug/src/common.js
130
+ var require_common = __commonJS({
131
+ "../../../node_modules/debug/src/common.js"(exports, module) {
132
+ "use strict";
133
+ function setup(env) {
134
+ createDebug.debug = createDebug;
135
+ createDebug.default = createDebug;
136
+ createDebug.coerce = coerce;
137
+ createDebug.disable = disable;
138
+ createDebug.enable = enable;
139
+ createDebug.enabled = enabled;
140
+ createDebug.humanize = require_ms();
141
+ createDebug.destroy = destroy;
142
+ Object.keys(env).forEach((key) => {
143
+ createDebug[key] = env[key];
144
+ });
145
+ createDebug.names = [];
146
+ createDebug.skips = [];
147
+ createDebug.formatters = {};
148
+ function selectColor(namespace) {
149
+ let hash = 0;
150
+ for (let i = 0; i < namespace.length; i++) {
151
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
152
+ hash |= 0;
153
+ }
154
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
155
+ }
156
+ createDebug.selectColor = selectColor;
157
+ function createDebug(namespace) {
158
+ let prevTime;
159
+ let enableOverride = null;
160
+ let namespacesCache;
161
+ let enabledCache;
162
+ function debug(...args) {
163
+ if (!debug.enabled) {
164
+ return;
165
+ }
166
+ const self = debug;
167
+ const curr = Number(/* @__PURE__ */ new Date());
168
+ const ms = curr - (prevTime || curr);
169
+ self.diff = ms;
170
+ self.prev = prevTime;
171
+ self.curr = curr;
172
+ prevTime = curr;
173
+ args[0] = createDebug.coerce(args[0]);
174
+ if (typeof args[0] !== "string") {
175
+ args.unshift("%O");
176
+ }
177
+ let index = 0;
178
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
179
+ if (match === "%%") {
180
+ return "%";
181
+ }
182
+ index++;
183
+ const formatter = createDebug.formatters[format];
184
+ if (typeof formatter === "function") {
185
+ const val = args[index];
186
+ match = formatter.call(self, val);
187
+ args.splice(index, 1);
188
+ index--;
189
+ }
190
+ return match;
191
+ });
192
+ createDebug.formatArgs.call(self, args);
193
+ const logFn = self.log || createDebug.log;
194
+ logFn.apply(self, args);
195
+ }
196
+ debug.namespace = namespace;
197
+ debug.useColors = createDebug.useColors();
198
+ debug.color = createDebug.selectColor(namespace);
199
+ debug.extend = extend;
200
+ debug.destroy = createDebug.destroy;
201
+ Object.defineProperty(debug, "enabled", {
202
+ enumerable: true,
203
+ configurable: false,
204
+ get: () => {
205
+ if (enableOverride !== null) {
206
+ return enableOverride;
207
+ }
208
+ if (namespacesCache !== createDebug.namespaces) {
209
+ namespacesCache = createDebug.namespaces;
210
+ enabledCache = createDebug.enabled(namespace);
211
+ }
212
+ return enabledCache;
213
+ },
214
+ set: (v) => {
215
+ enableOverride = v;
216
+ }
217
+ });
218
+ if (typeof createDebug.init === "function") {
219
+ createDebug.init(debug);
220
+ }
221
+ return debug;
222
+ }
223
+ function extend(namespace, delimiter) {
224
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
225
+ newDebug.log = this.log;
226
+ return newDebug;
227
+ }
228
+ function enable(namespaces) {
229
+ createDebug.save(namespaces);
230
+ createDebug.namespaces = namespaces;
231
+ createDebug.names = [];
232
+ createDebug.skips = [];
233
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
234
+ for (const ns of split) {
235
+ if (ns[0] === "-") {
236
+ createDebug.skips.push(ns.slice(1));
237
+ } else {
238
+ createDebug.names.push(ns);
239
+ }
240
+ }
241
+ }
242
+ function matchesTemplate(search, template) {
243
+ let searchIndex = 0;
244
+ let templateIndex = 0;
245
+ let starIndex = -1;
246
+ let matchIndex = 0;
247
+ while (searchIndex < search.length) {
248
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
249
+ if (template[templateIndex] === "*") {
250
+ starIndex = templateIndex;
251
+ matchIndex = searchIndex;
252
+ templateIndex++;
253
+ } else {
254
+ searchIndex++;
255
+ templateIndex++;
256
+ }
257
+ } else if (starIndex !== -1) {
258
+ templateIndex = starIndex + 1;
259
+ matchIndex++;
260
+ searchIndex = matchIndex;
261
+ } else {
262
+ return false;
263
+ }
264
+ }
265
+ while (templateIndex < template.length && template[templateIndex] === "*") {
266
+ templateIndex++;
267
+ }
268
+ return templateIndex === template.length;
269
+ }
270
+ function disable() {
271
+ const namespaces = [
272
+ ...createDebug.names,
273
+ ...createDebug.skips.map((namespace) => "-" + namespace)
274
+ ].join(",");
275
+ createDebug.enable("");
276
+ return namespaces;
277
+ }
278
+ function enabled(name) {
279
+ for (const skip of createDebug.skips) {
280
+ if (matchesTemplate(name, skip)) {
281
+ return false;
282
+ }
283
+ }
284
+ for (const ns of createDebug.names) {
285
+ if (matchesTemplate(name, ns)) {
286
+ return true;
287
+ }
288
+ }
289
+ return false;
290
+ }
291
+ function coerce(val) {
292
+ if (val instanceof Error) {
293
+ return val.stack || val.message;
294
+ }
295
+ return val;
296
+ }
297
+ function destroy() {
298
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
299
+ }
300
+ createDebug.enable(createDebug.load());
301
+ return createDebug;
302
+ }
303
+ module.exports = setup;
304
+ }
305
+ });
306
+
307
+ // ../../../node_modules/debug/src/browser.js
308
+ var require_browser = __commonJS({
309
+ "../../../node_modules/debug/src/browser.js"(exports, module) {
310
+ "use strict";
311
+ exports.formatArgs = formatArgs;
312
+ exports.save = save;
313
+ exports.load = load;
314
+ exports.useColors = useColors;
315
+ exports.storage = localstorage();
316
+ exports.destroy = /* @__PURE__ */ (() => {
317
+ let warned = false;
318
+ return () => {
319
+ if (!warned) {
320
+ warned = true;
321
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
322
+ }
323
+ };
324
+ })();
325
+ exports.colors = [
326
+ "#0000CC",
327
+ "#0000FF",
328
+ "#0033CC",
329
+ "#0033FF",
330
+ "#0066CC",
331
+ "#0066FF",
332
+ "#0099CC",
333
+ "#0099FF",
334
+ "#00CC00",
335
+ "#00CC33",
336
+ "#00CC66",
337
+ "#00CC99",
338
+ "#00CCCC",
339
+ "#00CCFF",
340
+ "#3300CC",
341
+ "#3300FF",
342
+ "#3333CC",
343
+ "#3333FF",
344
+ "#3366CC",
345
+ "#3366FF",
346
+ "#3399CC",
347
+ "#3399FF",
348
+ "#33CC00",
349
+ "#33CC33",
350
+ "#33CC66",
351
+ "#33CC99",
352
+ "#33CCCC",
353
+ "#33CCFF",
354
+ "#6600CC",
355
+ "#6600FF",
356
+ "#6633CC",
357
+ "#6633FF",
358
+ "#66CC00",
359
+ "#66CC33",
360
+ "#9900CC",
361
+ "#9900FF",
362
+ "#9933CC",
363
+ "#9933FF",
364
+ "#99CC00",
365
+ "#99CC33",
366
+ "#CC0000",
367
+ "#CC0033",
368
+ "#CC0066",
369
+ "#CC0099",
370
+ "#CC00CC",
371
+ "#CC00FF",
372
+ "#CC3300",
373
+ "#CC3333",
374
+ "#CC3366",
375
+ "#CC3399",
376
+ "#CC33CC",
377
+ "#CC33FF",
378
+ "#CC6600",
379
+ "#CC6633",
380
+ "#CC9900",
381
+ "#CC9933",
382
+ "#CCCC00",
383
+ "#CCCC33",
384
+ "#FF0000",
385
+ "#FF0033",
386
+ "#FF0066",
387
+ "#FF0099",
388
+ "#FF00CC",
389
+ "#FF00FF",
390
+ "#FF3300",
391
+ "#FF3333",
392
+ "#FF3366",
393
+ "#FF3399",
394
+ "#FF33CC",
395
+ "#FF33FF",
396
+ "#FF6600",
397
+ "#FF6633",
398
+ "#FF9900",
399
+ "#FF9933",
400
+ "#FFCC00",
401
+ "#FFCC33"
402
+ ];
403
+ function useColors() {
404
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
405
+ return true;
406
+ }
407
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
408
+ return false;
409
+ }
410
+ let m;
411
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
412
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
413
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
414
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
415
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
416
+ }
417
+ function formatArgs(args) {
418
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
419
+ if (!this.useColors) {
420
+ return;
421
+ }
422
+ const c = "color: " + this.color;
423
+ args.splice(1, 0, c, "color: inherit");
424
+ let index = 0;
425
+ let lastC = 0;
426
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
427
+ if (match === "%%") {
428
+ return;
429
+ }
430
+ index++;
431
+ if (match === "%c") {
432
+ lastC = index;
433
+ }
434
+ });
435
+ args.splice(lastC, 0, c);
436
+ }
437
+ exports.log = console.debug || console.log || (() => {
438
+ });
439
+ function save(namespaces) {
440
+ try {
441
+ if (namespaces) {
442
+ exports.storage.setItem("debug", namespaces);
443
+ } else {
444
+ exports.storage.removeItem("debug");
445
+ }
446
+ } catch (error) {
447
+ }
448
+ }
449
+ function load() {
450
+ let r;
451
+ try {
452
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
453
+ } catch (error) {
454
+ }
455
+ if (!r && typeof process !== "undefined" && "env" in process) {
456
+ r = process.env.DEBUG;
457
+ }
458
+ return r;
459
+ }
460
+ function localstorage() {
461
+ try {
462
+ return localStorage;
463
+ } catch (error) {
464
+ }
465
+ }
466
+ module.exports = require_common()(exports);
467
+ var { formatters } = module.exports;
468
+ formatters.j = function(v) {
469
+ try {
470
+ return JSON.stringify(v);
471
+ } catch (error) {
472
+ return "[UnexpectedJSONParseError]: " + error.message;
473
+ }
474
+ };
475
+ }
476
+ });
477
+
478
+ // ../../../../node_modules/has-flag/index.js
479
+ var require_has_flag = __commonJS({
480
+ "../../../../node_modules/has-flag/index.js"(exports, module) {
481
+ "use strict";
482
+ module.exports = (flag, argv = process.argv) => {
483
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
484
+ const position = argv.indexOf(prefix + flag);
485
+ const terminatorPosition = argv.indexOf("--");
486
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
487
+ };
488
+ }
489
+ });
490
+
491
+ // ../../../../node_modules/supports-color/index.js
492
+ var require_supports_color = __commonJS({
493
+ "../../../../node_modules/supports-color/index.js"(exports, module) {
494
+ "use strict";
495
+ var os = __require("os");
496
+ var tty = __require("tty");
497
+ var hasFlag = require_has_flag();
498
+ var { env } = process;
499
+ var forceColor;
500
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
501
+ forceColor = 0;
502
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
503
+ forceColor = 1;
504
+ }
505
+ if ("FORCE_COLOR" in env) {
506
+ if (env.FORCE_COLOR === "true") {
507
+ forceColor = 1;
508
+ } else if (env.FORCE_COLOR === "false") {
509
+ forceColor = 0;
510
+ } else {
511
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
512
+ }
513
+ }
514
+ function translateLevel(level) {
515
+ if (level === 0) {
516
+ return false;
517
+ }
518
+ return {
519
+ level,
520
+ hasBasic: true,
521
+ has256: level >= 2,
522
+ has16m: level >= 3
523
+ };
524
+ }
525
+ function supportsColor(haveStream, streamIsTTY) {
526
+ if (forceColor === 0) {
527
+ return 0;
528
+ }
529
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
530
+ return 3;
531
+ }
532
+ if (hasFlag("color=256")) {
533
+ return 2;
534
+ }
535
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
536
+ return 0;
537
+ }
538
+ const min = forceColor || 0;
539
+ if (env.TERM === "dumb") {
540
+ return min;
541
+ }
542
+ if (process.platform === "win32") {
543
+ const osRelease = os.release().split(".");
544
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
545
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
546
+ }
547
+ return 1;
548
+ }
549
+ if ("CI" in env) {
550
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
551
+ return 1;
552
+ }
553
+ return min;
554
+ }
555
+ if ("TEAMCITY_VERSION" in env) {
556
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
557
+ }
558
+ if (env.COLORTERM === "truecolor") {
559
+ return 3;
560
+ }
561
+ if ("TERM_PROGRAM" in env) {
562
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
563
+ switch (env.TERM_PROGRAM) {
564
+ case "iTerm.app":
565
+ return version >= 3 ? 3 : 2;
566
+ case "Apple_Terminal":
567
+ return 2;
568
+ }
569
+ }
570
+ if (/-256(color)?$/i.test(env.TERM)) {
571
+ return 2;
572
+ }
573
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
574
+ return 1;
575
+ }
576
+ if ("COLORTERM" in env) {
577
+ return 1;
578
+ }
579
+ return min;
580
+ }
581
+ function getSupportLevel(stream) {
582
+ const level = supportsColor(stream, stream && stream.isTTY);
583
+ return translateLevel(level);
584
+ }
585
+ module.exports = {
586
+ supportsColor: getSupportLevel,
587
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
588
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
589
+ };
590
+ }
591
+ });
592
+
593
+ // ../../../node_modules/debug/src/node.js
594
+ var require_node = __commonJS({
595
+ "../../../node_modules/debug/src/node.js"(exports, module) {
596
+ "use strict";
597
+ var tty = __require("tty");
598
+ var util = __require("util");
599
+ exports.init = init;
600
+ exports.log = log;
601
+ exports.formatArgs = formatArgs;
602
+ exports.save = save;
603
+ exports.load = load;
604
+ exports.useColors = useColors;
605
+ exports.destroy = util.deprecate(
606
+ () => {
607
+ },
608
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
609
+ );
610
+ exports.colors = [6, 2, 3, 4, 5, 1];
611
+ try {
612
+ const supportsColor = require_supports_color();
613
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
614
+ exports.colors = [
615
+ 20,
616
+ 21,
617
+ 26,
618
+ 27,
619
+ 32,
620
+ 33,
621
+ 38,
622
+ 39,
623
+ 40,
624
+ 41,
625
+ 42,
626
+ 43,
627
+ 44,
628
+ 45,
629
+ 56,
630
+ 57,
631
+ 62,
632
+ 63,
633
+ 68,
634
+ 69,
635
+ 74,
636
+ 75,
637
+ 76,
638
+ 77,
639
+ 78,
640
+ 79,
641
+ 80,
642
+ 81,
643
+ 92,
644
+ 93,
645
+ 98,
646
+ 99,
647
+ 112,
648
+ 113,
649
+ 128,
650
+ 129,
651
+ 134,
652
+ 135,
653
+ 148,
654
+ 149,
655
+ 160,
656
+ 161,
657
+ 162,
658
+ 163,
659
+ 164,
660
+ 165,
661
+ 166,
662
+ 167,
663
+ 168,
664
+ 169,
665
+ 170,
666
+ 171,
667
+ 172,
668
+ 173,
669
+ 178,
670
+ 179,
671
+ 184,
672
+ 185,
673
+ 196,
674
+ 197,
675
+ 198,
676
+ 199,
677
+ 200,
678
+ 201,
679
+ 202,
680
+ 203,
681
+ 204,
682
+ 205,
683
+ 206,
684
+ 207,
685
+ 208,
686
+ 209,
687
+ 214,
688
+ 215,
689
+ 220,
690
+ 221
691
+ ];
692
+ }
693
+ } catch (error) {
694
+ }
695
+ exports.inspectOpts = Object.keys(process.env).filter((key) => {
696
+ return /^debug_/i.test(key);
697
+ }).reduce((obj, key) => {
698
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
699
+ return k.toUpperCase();
700
+ });
701
+ let val = process.env[key];
702
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
703
+ val = true;
704
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
705
+ val = false;
706
+ } else if (val === "null") {
707
+ val = null;
708
+ } else {
709
+ val = Number(val);
710
+ }
711
+ obj[prop] = val;
712
+ return obj;
713
+ }, {});
714
+ function useColors() {
715
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
716
+ }
717
+ function formatArgs(args) {
718
+ const { namespace: name, useColors: useColors2 } = this;
719
+ if (useColors2) {
720
+ const c = this.color;
721
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
722
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
723
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
724
+ args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
725
+ } else {
726
+ args[0] = getDate() + name + " " + args[0];
727
+ }
728
+ }
729
+ function getDate() {
730
+ if (exports.inspectOpts.hideDate) {
731
+ return "";
732
+ }
733
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
734
+ }
735
+ function log(...args) {
736
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
737
+ }
738
+ function save(namespaces) {
739
+ if (namespaces) {
740
+ process.env.DEBUG = namespaces;
741
+ } else {
742
+ delete process.env.DEBUG;
743
+ }
744
+ }
745
+ function load() {
746
+ return process.env.DEBUG;
747
+ }
748
+ function init(debug) {
749
+ debug.inspectOpts = {};
750
+ const keys = Object.keys(exports.inspectOpts);
751
+ for (let i = 0; i < keys.length; i++) {
752
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
753
+ }
754
+ }
755
+ module.exports = require_common()(exports);
756
+ var { formatters } = module.exports;
757
+ formatters.o = function(v) {
758
+ this.inspectOpts.colors = this.useColors;
759
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
760
+ };
761
+ formatters.O = function(v) {
762
+ this.inspectOpts.colors = this.useColors;
763
+ return util.inspect(v, this.inspectOpts);
764
+ };
765
+ }
766
+ });
767
+
768
+ // ../../../node_modules/debug/src/index.js
769
+ var require_src = __commonJS({
770
+ "../../../node_modules/debug/src/index.js"(exports, module) {
771
+ "use strict";
772
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
773
+ module.exports = require_browser();
774
+ } else {
775
+ module.exports = require_node();
776
+ }
777
+ }
778
+ });
779
+
780
+ // ../../../node_modules/agent-base/dist/helpers.js
781
+ var require_helpers = __commonJS({
782
+ "../../../node_modules/agent-base/dist/helpers.js"(exports) {
783
+ "use strict";
784
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
785
+ if (k2 === void 0) k2 = k;
786
+ var desc = Object.getOwnPropertyDescriptor(m, k);
787
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
788
+ desc = { enumerable: true, get: function() {
789
+ return m[k];
790
+ } };
791
+ }
792
+ Object.defineProperty(o, k2, desc);
793
+ }) : (function(o, m, k, k2) {
794
+ if (k2 === void 0) k2 = k;
795
+ o[k2] = m[k];
796
+ }));
797
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
798
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
799
+ }) : function(o, v) {
800
+ o["default"] = v;
801
+ });
802
+ var __importStar = exports && exports.__importStar || function(mod) {
803
+ if (mod && mod.__esModule) return mod;
804
+ var result = {};
805
+ if (mod != null) {
806
+ for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
807
+ }
808
+ __setModuleDefault(result, mod);
809
+ return result;
810
+ };
811
+ Object.defineProperty(exports, "__esModule", { value: true });
812
+ exports.req = exports.json = exports.toBuffer = void 0;
813
+ var http2 = __importStar(__require("http"));
814
+ var https2 = __importStar(__require("https"));
815
+ async function toBuffer(stream) {
816
+ let length = 0;
817
+ const chunks = [];
818
+ for await (const chunk of stream) {
819
+ length += chunk.length;
820
+ chunks.push(chunk);
821
+ }
822
+ return Buffer.concat(chunks, length);
823
+ }
824
+ exports.toBuffer = toBuffer;
825
+ async function json(stream) {
826
+ const buf = await toBuffer(stream);
827
+ const str = buf.toString("utf8");
828
+ try {
829
+ return JSON.parse(str);
830
+ } catch (_err) {
831
+ const err = _err;
832
+ err.message += ` (input: ${str})`;
833
+ throw err;
834
+ }
835
+ }
836
+ exports.json = json;
837
+ function req(url, opts = {}) {
838
+ const href = typeof url === "string" ? url : url.href;
839
+ const req2 = (href.startsWith("https:") ? https2 : http2).request(url, opts);
840
+ const promise = new Promise((resolve, reject) => {
841
+ req2.once("response", resolve).once("error", reject).end();
842
+ });
843
+ req2.then = promise.then.bind(promise);
844
+ return req2;
845
+ }
846
+ exports.req = req;
847
+ }
848
+ });
849
+
850
+ // ../../../node_modules/agent-base/dist/index.js
851
+ var require_dist = __commonJS({
852
+ "../../../node_modules/agent-base/dist/index.js"(exports) {
853
+ "use strict";
854
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
855
+ if (k2 === void 0) k2 = k;
856
+ var desc = Object.getOwnPropertyDescriptor(m, k);
857
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
858
+ desc = { enumerable: true, get: function() {
859
+ return m[k];
860
+ } };
861
+ }
862
+ Object.defineProperty(o, k2, desc);
863
+ }) : (function(o, m, k, k2) {
864
+ if (k2 === void 0) k2 = k;
865
+ o[k2] = m[k];
866
+ }));
867
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
868
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
869
+ }) : function(o, v) {
870
+ o["default"] = v;
871
+ });
872
+ var __importStar = exports && exports.__importStar || function(mod) {
873
+ if (mod && mod.__esModule) return mod;
874
+ var result = {};
875
+ if (mod != null) {
876
+ for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
877
+ }
878
+ __setModuleDefault(result, mod);
879
+ return result;
880
+ };
881
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
882
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
883
+ };
884
+ Object.defineProperty(exports, "__esModule", { value: true });
885
+ exports.Agent = void 0;
886
+ var net = __importStar(__require("net"));
887
+ var http2 = __importStar(__require("http"));
888
+ var https_1 = __require("https");
889
+ __exportStar(require_helpers(), exports);
890
+ var INTERNAL = /* @__PURE__ */ Symbol("AgentBaseInternalState");
891
+ var Agent = class extends http2.Agent {
892
+ constructor(opts) {
893
+ super(opts);
894
+ this[INTERNAL] = {};
895
+ }
896
+ /**
897
+ * Determine whether this is an `http` or `https` request.
898
+ */
899
+ isSecureEndpoint(options) {
900
+ if (options) {
901
+ if (typeof options.secureEndpoint === "boolean") {
902
+ return options.secureEndpoint;
903
+ }
904
+ if (typeof options.protocol === "string") {
905
+ return options.protocol === "https:";
906
+ }
907
+ }
908
+ const { stack } = new Error();
909
+ if (typeof stack !== "string")
910
+ return false;
911
+ return stack.split("\n").some((l) => l.indexOf("(https.js:") !== -1 || l.indexOf("node:https:") !== -1);
912
+ }
913
+ // In order to support async signatures in `connect()` and Node's native
914
+ // connection pooling in `http.Agent`, the array of sockets for each origin
915
+ // has to be updated synchronously. This is so the length of the array is
916
+ // accurate when `addRequest()` is next called. We achieve this by creating a
917
+ // fake socket and adding it to `sockets[origin]` and incrementing
918
+ // `totalSocketCount`.
919
+ incrementSockets(name) {
920
+ if (this.maxSockets === Infinity && this.maxTotalSockets === Infinity) {
921
+ return null;
922
+ }
923
+ if (!this.sockets[name]) {
924
+ this.sockets[name] = [];
925
+ }
926
+ const fakeSocket = new net.Socket({ writable: false });
927
+ this.sockets[name].push(fakeSocket);
928
+ this.totalSocketCount++;
929
+ return fakeSocket;
930
+ }
931
+ decrementSockets(name, socket) {
932
+ if (!this.sockets[name] || socket === null) {
933
+ return;
934
+ }
935
+ const sockets = this.sockets[name];
936
+ const index = sockets.indexOf(socket);
937
+ if (index !== -1) {
938
+ sockets.splice(index, 1);
939
+ this.totalSocketCount--;
940
+ if (sockets.length === 0) {
941
+ delete this.sockets[name];
942
+ }
943
+ }
944
+ }
945
+ // In order to properly update the socket pool, we need to call `getName()` on
946
+ // the core `https.Agent` if it is a secureEndpoint.
947
+ getName(options) {
948
+ const secureEndpoint = this.isSecureEndpoint(options);
949
+ if (secureEndpoint) {
950
+ return https_1.Agent.prototype.getName.call(this, options);
951
+ }
952
+ return super.getName(options);
953
+ }
954
+ createSocket(req, options, cb) {
955
+ const connectOpts = {
956
+ ...options,
957
+ secureEndpoint: this.isSecureEndpoint(options)
958
+ };
959
+ const name = this.getName(connectOpts);
960
+ const fakeSocket = this.incrementSockets(name);
961
+ Promise.resolve().then(() => this.connect(req, connectOpts)).then((socket) => {
962
+ this.decrementSockets(name, fakeSocket);
963
+ if (socket instanceof http2.Agent) {
964
+ try {
965
+ return socket.addRequest(req, connectOpts);
966
+ } catch (err) {
967
+ return cb(err);
968
+ }
969
+ }
970
+ this[INTERNAL].currentSocket = socket;
971
+ super.createSocket(req, options, cb);
972
+ }, (err) => {
973
+ this.decrementSockets(name, fakeSocket);
974
+ cb(err);
975
+ });
976
+ }
977
+ createConnection() {
978
+ const socket = this[INTERNAL].currentSocket;
979
+ this[INTERNAL].currentSocket = void 0;
980
+ if (!socket) {
981
+ throw new Error("No socket was returned in the `connect()` function");
982
+ }
983
+ return socket;
984
+ }
985
+ get defaultPort() {
986
+ return this[INTERNAL].defaultPort ?? (this.protocol === "https:" ? 443 : 80);
987
+ }
988
+ set defaultPort(v) {
989
+ if (this[INTERNAL]) {
990
+ this[INTERNAL].defaultPort = v;
991
+ }
992
+ }
993
+ get protocol() {
994
+ return this[INTERNAL].protocol ?? (this.isSecureEndpoint() ? "https:" : "http:");
995
+ }
996
+ set protocol(v) {
997
+ if (this[INTERNAL]) {
998
+ this[INTERNAL].protocol = v;
999
+ }
1000
+ }
1001
+ };
1002
+ exports.Agent = Agent;
1003
+ }
1004
+ });
1005
+
1006
+ // ../../../node_modules/https-proxy-agent/dist/parse-proxy-response.js
1007
+ var require_parse_proxy_response = __commonJS({
1008
+ "../../../node_modules/https-proxy-agent/dist/parse-proxy-response.js"(exports) {
1009
+ "use strict";
1010
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1011
+ return mod && mod.__esModule ? mod : { "default": mod };
1012
+ };
1013
+ Object.defineProperty(exports, "__esModule", { value: true });
1014
+ exports.parseProxyResponse = void 0;
1015
+ var debug_1 = __importDefault(require_src());
1016
+ var debug = (0, debug_1.default)("https-proxy-agent:parse-proxy-response");
1017
+ function parseProxyResponse(socket) {
1018
+ return new Promise((resolve, reject) => {
1019
+ let buffersLength = 0;
1020
+ const buffers = [];
1021
+ function read() {
1022
+ const b = socket.read();
1023
+ if (b)
1024
+ ondata(b);
1025
+ else
1026
+ socket.once("readable", read);
1027
+ }
1028
+ function cleanup() {
1029
+ socket.removeListener("end", onend);
1030
+ socket.removeListener("error", onerror);
1031
+ socket.removeListener("readable", read);
1032
+ }
1033
+ function onend() {
1034
+ cleanup();
1035
+ debug("onend");
1036
+ reject(new Error("Proxy connection ended before receiving CONNECT response"));
1037
+ }
1038
+ function onerror(err) {
1039
+ cleanup();
1040
+ debug("onerror %o", err);
1041
+ reject(err);
1042
+ }
1043
+ function ondata(b) {
1044
+ buffers.push(b);
1045
+ buffersLength += b.length;
1046
+ const buffered = Buffer.concat(buffers, buffersLength);
1047
+ const endOfHeaders = buffered.indexOf("\r\n\r\n");
1048
+ if (endOfHeaders === -1) {
1049
+ debug("have not received end of HTTP headers yet...");
1050
+ read();
1051
+ return;
1052
+ }
1053
+ const headerParts = buffered.slice(0, endOfHeaders).toString("ascii").split("\r\n");
1054
+ const firstLine = headerParts.shift();
1055
+ if (!firstLine) {
1056
+ socket.destroy();
1057
+ return reject(new Error("No header received from proxy CONNECT response"));
1058
+ }
1059
+ const firstLineParts = firstLine.split(" ");
1060
+ const statusCode = +firstLineParts[1];
1061
+ const statusText = firstLineParts.slice(2).join(" ");
1062
+ const headers = {};
1063
+ for (const header of headerParts) {
1064
+ if (!header)
1065
+ continue;
1066
+ const firstColon = header.indexOf(":");
1067
+ if (firstColon === -1) {
1068
+ socket.destroy();
1069
+ return reject(new Error(`Invalid header from proxy CONNECT response: "${header}"`));
1070
+ }
1071
+ const key = header.slice(0, firstColon).toLowerCase();
1072
+ const value = header.slice(firstColon + 1).trimStart();
1073
+ const current = headers[key];
1074
+ if (typeof current === "string") {
1075
+ headers[key] = [current, value];
1076
+ } else if (Array.isArray(current)) {
1077
+ current.push(value);
1078
+ } else {
1079
+ headers[key] = value;
1080
+ }
1081
+ }
1082
+ debug("got proxy server response: %o %o", firstLine, headers);
1083
+ cleanup();
1084
+ resolve({
1085
+ connect: {
1086
+ statusCode,
1087
+ statusText,
1088
+ headers
1089
+ },
1090
+ buffered
1091
+ });
1092
+ }
1093
+ socket.on("error", onerror);
1094
+ socket.on("end", onend);
1095
+ read();
1096
+ });
1097
+ }
1098
+ exports.parseProxyResponse = parseProxyResponse;
1099
+ }
1100
+ });
1101
+
1102
+ // ../../../node_modules/https-proxy-agent/dist/index.js
1103
+ var require_dist2 = __commonJS({
1104
+ "../../../node_modules/https-proxy-agent/dist/index.js"(exports) {
1105
+ "use strict";
1106
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
1107
+ if (k2 === void 0) k2 = k;
1108
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1109
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1110
+ desc = { enumerable: true, get: function() {
1111
+ return m[k];
1112
+ } };
1113
+ }
1114
+ Object.defineProperty(o, k2, desc);
1115
+ }) : (function(o, m, k, k2) {
1116
+ if (k2 === void 0) k2 = k;
1117
+ o[k2] = m[k];
1118
+ }));
1119
+ var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
1120
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1121
+ }) : function(o, v) {
1122
+ o["default"] = v;
1123
+ });
1124
+ var __importStar = exports && exports.__importStar || function(mod) {
1125
+ if (mod && mod.__esModule) return mod;
1126
+ var result = {};
1127
+ if (mod != null) {
1128
+ for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1129
+ }
1130
+ __setModuleDefault(result, mod);
1131
+ return result;
1132
+ };
1133
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1134
+ return mod && mod.__esModule ? mod : { "default": mod };
1135
+ };
1136
+ Object.defineProperty(exports, "__esModule", { value: true });
1137
+ exports.HttpsProxyAgent = void 0;
1138
+ var net = __importStar(__require("net"));
1139
+ var tls = __importStar(__require("tls"));
1140
+ var assert_1 = __importDefault(__require("assert"));
1141
+ var debug_1 = __importDefault(require_src());
1142
+ var agent_base_1 = require_dist();
1143
+ var url_1 = __require("url");
1144
+ var parse_proxy_response_1 = require_parse_proxy_response();
1145
+ var debug = (0, debug_1.default)("https-proxy-agent");
1146
+ var setServernameFromNonIpHost = (options) => {
1147
+ if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
1148
+ return {
1149
+ ...options,
1150
+ servername: options.host
1151
+ };
1152
+ }
1153
+ return options;
1154
+ };
1155
+ var HttpsProxyAgent = class extends agent_base_1.Agent {
1156
+ constructor(proxy, opts) {
1157
+ super(opts);
1158
+ this.options = { path: void 0 };
1159
+ this.proxy = typeof proxy === "string" ? new url_1.URL(proxy) : proxy;
1160
+ this.proxyHeaders = opts?.headers ?? {};
1161
+ debug("Creating new HttpsProxyAgent instance: %o", this.proxy.href);
1162
+ const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, "");
1163
+ const port = this.proxy.port ? parseInt(this.proxy.port, 10) : this.proxy.protocol === "https:" ? 443 : 80;
1164
+ this.connectOpts = {
1165
+ // Attempt to negotiate http/1.1 for proxy servers that support http/2
1166
+ ALPNProtocols: ["http/1.1"],
1167
+ ...opts ? omit(opts, "headers") : null,
1168
+ host,
1169
+ port
1170
+ };
1171
+ }
1172
+ /**
1173
+ * Called when the node-core HTTP client library is creating a
1174
+ * new HTTP request.
1175
+ */
1176
+ async connect(req, opts) {
1177
+ const { proxy } = this;
1178
+ if (!opts.host) {
1179
+ throw new TypeError('No "host" provided');
1180
+ }
1181
+ let socket;
1182
+ if (proxy.protocol === "https:") {
1183
+ debug("Creating `tls.Socket`: %o", this.connectOpts);
1184
+ socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
1185
+ } else {
1186
+ debug("Creating `net.Socket`: %o", this.connectOpts);
1187
+ socket = net.connect(this.connectOpts);
1188
+ }
1189
+ const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
1190
+ const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
1191
+ let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
1192
+ `;
1193
+ if (proxy.username || proxy.password) {
1194
+ const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
1195
+ headers["Proxy-Authorization"] = `Basic ${Buffer.from(auth).toString("base64")}`;
1196
+ }
1197
+ headers.Host = `${host}:${opts.port}`;
1198
+ if (!headers["Proxy-Connection"]) {
1199
+ headers["Proxy-Connection"] = this.keepAlive ? "Keep-Alive" : "close";
1200
+ }
1201
+ for (const name of Object.keys(headers)) {
1202
+ payload += `${name}: ${headers[name]}\r
1203
+ `;
1204
+ }
1205
+ const proxyResponsePromise = (0, parse_proxy_response_1.parseProxyResponse)(socket);
1206
+ socket.write(`${payload}\r
1207
+ `);
1208
+ const { connect, buffered } = await proxyResponsePromise;
1209
+ req.emit("proxyConnect", connect);
1210
+ this.emit("proxyConnect", connect, req);
1211
+ if (connect.statusCode === 200) {
1212
+ req.once("socket", resume);
1213
+ if (opts.secureEndpoint) {
1214
+ debug("Upgrading socket connection to TLS");
1215
+ return tls.connect({
1216
+ ...omit(setServernameFromNonIpHost(opts), "host", "path", "port"),
1217
+ socket
1218
+ });
1219
+ }
1220
+ return socket;
1221
+ }
1222
+ socket.destroy();
1223
+ const fakeSocket = new net.Socket({ writable: false });
1224
+ fakeSocket.readable = true;
1225
+ req.once("socket", (s) => {
1226
+ debug("Replaying proxy buffer for failed request");
1227
+ (0, assert_1.default)(s.listenerCount("data") > 0);
1228
+ s.push(buffered);
1229
+ s.push(null);
1230
+ });
1231
+ return fakeSocket;
1232
+ }
1233
+ };
1234
+ HttpsProxyAgent.protocols = ["http", "https"];
1235
+ exports.HttpsProxyAgent = HttpsProxyAgent;
1236
+ function resume(socket) {
1237
+ socket.resume();
1238
+ }
1239
+ function omit(obj, ...keys) {
1240
+ const ret = {};
1241
+ let key;
1242
+ for (key in obj) {
1243
+ if (!keys.includes(key)) {
1244
+ ret[key] = obj[key];
1245
+ }
1246
+ }
1247
+ return ret;
1248
+ }
1249
+ }
1250
+ });
1251
+
1
1252
  // src/client.ts
2
1253
  import { EventEmitter } from "events";
3
1254
  import * as http from "http";
@@ -396,27 +1647,41 @@ function parseWebcastMessage(method, payload) {
396
1647
  // Proto: WebcastLinkMicBattle { repeated WebcastLinkMicBattleItems battleUsers=10 }
397
1648
  // battleUsers → { battleGroup=2 → { LinkUser user=1 } }
398
1649
  case "WebcastLinkMicBattle": {
399
- const battleId = String(getInt(f, 1) || "");
400
- const status = getInt(f, 2) || 1;
1650
+ const battleId = String(getInt(f, 4) || getInt(f, 1) || "");
1651
+ let status = getInt(f, 7);
1652
+ if (!status) {
1653
+ const fallback = getInt(f, 2);
1654
+ status = fallback > 0 && fallback < 100 ? fallback : 1;
1655
+ }
401
1656
  const battleDuration = getInt(f, 3);
402
1657
  const teams = [];
403
- const battleUserBufs = getAllBytes(f, 10);
404
- for (const bub of battleUserBufs) {
1658
+ const hostBufs = getAllBytes(f, 14);
1659
+ for (const hb of hostBufs) {
405
1660
  try {
406
- const bf = decodeProto(bub);
407
- const groupBuf = getBytes(bf, 2);
408
- if (groupBuf) {
409
- const gf = decodeProto(groupBuf);
410
- const linkUserBuf = getBytes(gf, 1);
411
- if (linkUserBuf) {
412
- const user = parseUser(linkUserBuf);
413
- teams.push({
414
- hostUserId: user.id,
415
- score: 0,
416
- users: [{ user, score: 0 }]
417
- });
1661
+ const hf = decodeProto(hb);
1662
+ const hostUserId = String(getInt(hf, 1) || "");
1663
+ const teamTotalScore = getInt(hf, 3);
1664
+ const users = [];
1665
+ const containerBuf = getBytes(hf, 4);
1666
+ if (containerBuf) {
1667
+ const cf = decodeProto(containerBuf);
1668
+ const userBufs = getAllBytes(cf, 1);
1669
+ for (const ub of userBufs) {
1670
+ try {
1671
+ const uf = decodeProto(ub);
1672
+ users.push({
1673
+ user: {
1674
+ id: String(getInt(uf, 1) || ""),
1675
+ nickname: getStr(uf, 3) || "",
1676
+ uniqueId: getStr(uf, 3) || ""
1677
+ },
1678
+ score: getInt(uf, 2)
1679
+ });
1680
+ } catch {
1681
+ }
418
1682
  }
419
1683
  }
1684
+ teams.push({ hostUserId, score: teamTotalScore, users });
420
1685
  } catch {
421
1686
  }
422
1687
  }
@@ -429,15 +1694,42 @@ function parseWebcastMessage(method, payload) {
429
1694
  }
430
1695
  }
431
1696
  }
1697
+ if (teams.length === 0) {
1698
+ const battleUserBufs = getAllBytes(f, 10);
1699
+ for (const bub of battleUserBufs) {
1700
+ try {
1701
+ const bf = decodeProto(bub);
1702
+ const groupBuf = getBytes(bf, 2);
1703
+ if (groupBuf) {
1704
+ const gf = decodeProto(groupBuf);
1705
+ const linkUserBuf = getBytes(gf, 1);
1706
+ if (linkUserBuf) {
1707
+ const user = parseUser(linkUserBuf);
1708
+ teams.push({
1709
+ hostUserId: user.id,
1710
+ score: 0,
1711
+ users: [{ user, score: 0 }]
1712
+ });
1713
+ }
1714
+ }
1715
+ } catch {
1716
+ }
1717
+ }
1718
+ }
432
1719
  return { ...base, type: "battle", battleId, status, battleDuration, teams };
433
1720
  }
434
- // Proto: WebcastLinkMicArmies { msg_header=1, session_id=2, repeated battleItems=3, status=7,
435
- // battle_config=18 { session_id=1, start_time_ms=2, duration_s=3 }, battle_id=17 }
436
- // battleItems → { hostUserId=1, repeated battleGroups=2 }
437
- // battleGroups → { repeated users=1, int32 points=2 }
1721
+ // Proto: WebcastLinkMicArmies { msg_header=1, matchId=2, session_id=4, startedAtMs=5,
1722
+ // serverTsMs=6, repeated battleItems=3, status=7, sessionTag=17,
1723
+ // battle_config=18 { session_id=1, start_time_ms=2, duration_s=3 },
1724
+ // repeated hosts=14 { hostUserId=1, teamTotalScore=3, teamIdx=5,
1725
+ // userContainer=4 { repeated users=1 { userId=1, score=2, nickname=3 } } }
438
1726
  case "WebcastLinkMicArmies": {
439
- const battleId = getStr(f, 17) || String(getInt(f, 2) || "");
1727
+ const sessionTag = getStr(f, 17);
1728
+ const matchId = getIntStr(f, 2);
1729
+ const sessionId = getIntStr(f, 4);
1730
+ const battleId = sessionTag || matchId;
440
1731
  const battleStatus = getInt(f, 7);
1732
+ const serverTsMs = getInt(f, 6);
441
1733
  const teams = [];
442
1734
  const itemBufs = getAllBytes(f, 3);
443
1735
  for (const ib of itemBufs) {
@@ -457,6 +1749,10 @@ function parseWebcastMessage(method, payload) {
457
1749
  } catch {
458
1750
  }
459
1751
  }
1752
+ let secsRemaining = 0;
1753
+ if (battleStartMs > 0 && battleDurationSeconds > 0 && serverTsMs > 0) {
1754
+ secsRemaining = Math.max(0, battleDurationSeconds - Math.floor((serverTsMs - battleStartMs) / 1e3));
1755
+ }
460
1756
  let endTimeMs = 0;
461
1757
  let timeLeftSeconds = 0;
462
1758
  if (battleStartMs > 0 && battleDurationSeconds > 0) {
@@ -464,6 +1760,36 @@ function parseWebcastMessage(method, payload) {
464
1760
  const elapsedMs = Date.now() - battleStartMs;
465
1761
  timeLeftSeconds = Math.max(0, battleDurationSeconds - Math.floor(elapsedMs / 1e3));
466
1762
  }
1763
+ const hosts = [];
1764
+ const hostBufs = getAllBytes(f, 14);
1765
+ for (const hb of hostBufs) {
1766
+ try {
1767
+ const hf = decodeProto(hb);
1768
+ const hostUserId = getIntStr(hf, 1);
1769
+ const teamTotalScore = getInt(hf, 3);
1770
+ const teamIdx = getInt(hf, 5);
1771
+ const contributors = [];
1772
+ const containerBuf = getBytes(hf, 4);
1773
+ if (containerBuf) {
1774
+ const cf = decodeProto(containerBuf);
1775
+ const userBufs = getAllBytes(cf, 1);
1776
+ for (const ub of userBufs) {
1777
+ try {
1778
+ const uf = decodeProto(ub);
1779
+ contributors.push({
1780
+ userId: getIntStr(uf, 1),
1781
+ score: getInt(uf, 2),
1782
+ nickname: getStr(uf, 3) || ""
1783
+ });
1784
+ } catch {
1785
+ }
1786
+ }
1787
+ contributors.sort((a, b) => b.score - a.score);
1788
+ }
1789
+ hosts.push({ hostUserId, teamTotalScore, teamIdx, contributors });
1790
+ } catch {
1791
+ }
1792
+ }
467
1793
  return {
468
1794
  ...base,
469
1795
  type: "battleArmies",
@@ -473,7 +1799,162 @@ function parseWebcastMessage(method, payload) {
473
1799
  battleStartMs,
474
1800
  battleDurationSeconds,
475
1801
  timeLeftSeconds,
476
- endTimeMs
1802
+ endTimeMs,
1803
+ matchId,
1804
+ sessionId,
1805
+ serverTsMs,
1806
+ sessionTag,
1807
+ durationSec: battleDurationSeconds,
1808
+ secsRemaining,
1809
+ hosts
1810
+ };
1811
+ }
1812
+ // Proto: WebcastLinkMicBattleItemCard
1813
+ // #2 battleId
1814
+ // #3 cardType (2=gloves/crit, 3=mist, 4=match_guide, 10=x2?, 11=x3, ...)
1815
+ // #5/#6/#7/#14 inner (location varies with cardType — scan numerically):
1816
+ // #1.{
1817
+ // #1 effectKey
1818
+ // #2 icon block { #1 repeated CDN urls, #2 iconKey, #5 accentColor }
1819
+ // #3 activatedAtSec (unix seconds)
1820
+ // #4 sender block: #1 sub { #1 userId, #2 nickname, #3 avatar block, #4 uniqueId }
1821
+ // #5 durationSec
1822
+ // #8 senderUserId (new boosters)
1823
+ // #11 endsAtSec
1824
+ // #12 senderUserId (old gloves/mist)
1825
+ // }
1826
+ // #3 comment template msg → #2 commentText
1827
+ case "WebcastLinkMicBattleItemCard": {
1828
+ const battleId = getIntStr(f, 2);
1829
+ const cardType = getInt(f, 3);
1830
+ let inner = null;
1831
+ for (const fn of [5, 6, 7, 14, 15, 16, 8, 9, 10, 11, 12, 13]) {
1832
+ const buf = getBytes(f, fn);
1833
+ if (buf) {
1834
+ inner = decodeProto(buf);
1835
+ break;
1836
+ }
1837
+ }
1838
+ let effectKey = "";
1839
+ let effect = "unknown";
1840
+ let multiplier = 0;
1841
+ let activatedAtSec = 0;
1842
+ let durationSec = 0;
1843
+ let endsAtSec = 0;
1844
+ let senderUserId = "";
1845
+ let senderNickname = "";
1846
+ let senderUniqueId = "";
1847
+ let senderAvatarUrl = "";
1848
+ let commentTemplate = "";
1849
+ let iconUrl = "";
1850
+ let iconKey = "";
1851
+ let accentColor = "";
1852
+ if (inner) {
1853
+ let nameBuf = getBytes(inner, 1);
1854
+ let nf = nameBuf ? decodeProto(nameBuf) : [];
1855
+ let probedKey = nf.length ? getStr(nf, 1) || "" : "";
1856
+ if (!probedKey) {
1857
+ const altBuf = getBytes(inner, 3);
1858
+ if (altBuf) {
1859
+ const altFields = decodeProto(altBuf);
1860
+ const altKey = getStr(altFields, 1) || "";
1861
+ if (altKey) {
1862
+ nameBuf = altBuf;
1863
+ nf = altFields;
1864
+ probedKey = altKey;
1865
+ }
1866
+ }
1867
+ }
1868
+ if (nameBuf && nf.length) {
1869
+ effectKey = probedKey;
1870
+ if (effectKey === "pm_mt_boost_crit_name") effect = "hammer";
1871
+ else if (effectKey === "pm_mt_boost_glove_name" || effectKey === "pm_mt_boost_gloves_name") effect = "gloves";
1872
+ else if (effectKey === "pm_mt_boost_mist_name") effect = "mist";
1873
+ else if (effectKey === "pm_mt_match_guide_gotPowerUps") effect = "match_guide";
1874
+ else if (effectKey.includes("userSentBooster_no2") || effectKey.includes("gotPowerUp_panel_no2")) {
1875
+ effect = "booster_x2";
1876
+ multiplier = 2;
1877
+ } else if (effectKey.includes("userSentBooster_no3") || effectKey.includes("gotPowerUp_panel_no3")) {
1878
+ effect = "booster_x3";
1879
+ multiplier = 3;
1880
+ } else if (effectKey.includes("thunder")) effect = "thunder";
1881
+ else if (effectKey.includes("extra_time") || effectKey.includes("extra_round")) effect = "extra_time";
1882
+ else if (effectKey) effect = effectKey;
1883
+ activatedAtSec = getInt(nf, 3);
1884
+ durationSec = getInt(nf, 5);
1885
+ endsAtSec = getInt(nf, 11) || getInt(nf, 7);
1886
+ senderUserId = getIntStr(nf, 12);
1887
+ if (senderUserId === "0") senderUserId = getIntStr(nf, 8);
1888
+ if (senderUserId === "0") senderUserId = getStr(nf, 13) || getStr(nf, 9) || "";
1889
+ const iconBuf = getBytes(nf, 2);
1890
+ if (iconBuf) {
1891
+ const icf = decodeProto(iconBuf);
1892
+ const urlBufs = getAllBytes(icf, 1);
1893
+ for (const ub of urlBufs) {
1894
+ const candidate = ub.toString("utf-8");
1895
+ if (candidate.includes("://")) {
1896
+ iconUrl = candidate;
1897
+ break;
1898
+ }
1899
+ }
1900
+ iconKey = getStr(icf, 2) || "";
1901
+ accentColor = getStr(icf, 5) || "";
1902
+ }
1903
+ const senderOuter = getBytes(nf, 4);
1904
+ if (senderOuter) {
1905
+ const sf = decodeProto(senderOuter);
1906
+ const sub = getBytes(sf, 1);
1907
+ if (sub) {
1908
+ const su = decodeProto(sub);
1909
+ const nickBuf = getBytes(su, 2);
1910
+ if (nickBuf) {
1911
+ try {
1912
+ senderNickname = nickBuf.toString("utf-8");
1913
+ } catch {
1914
+ }
1915
+ }
1916
+ senderUniqueId = getStr(su, 4) || "";
1917
+ if (!senderUserId || senderUserId === "0") senderUserId = getIntStr(su, 1);
1918
+ const avBuf = getBytes(su, 3);
1919
+ if (avBuf) {
1920
+ const af = decodeProto(avBuf);
1921
+ const urlBufs = getAllBytes(af, 1);
1922
+ for (const ub of urlBufs) {
1923
+ const candidate = ub.toString("utf-8");
1924
+ if (candidate.includes("://")) {
1925
+ senderAvatarUrl = candidate;
1926
+ break;
1927
+ }
1928
+ }
1929
+ }
1930
+ }
1931
+ }
1932
+ }
1933
+ const commentBuf = getBytes(inner, 3);
1934
+ if (commentBuf) {
1935
+ const cf = decodeProto(commentBuf);
1936
+ commentTemplate = getStr(cf, 2) || "";
1937
+ }
1938
+ }
1939
+ return {
1940
+ ...base,
1941
+ type: "battleItemCard",
1942
+ battleId,
1943
+ cardType,
1944
+ effect,
1945
+ effectKey,
1946
+ multiplier,
1947
+ senderUserId,
1948
+ senderNickname,
1949
+ senderUniqueId,
1950
+ senderAvatarUrl,
1951
+ activatedAtSec,
1952
+ durationSec,
1953
+ endsAtSec,
1954
+ commentTemplate,
1955
+ iconUrl,
1956
+ iconKey,
1957
+ accentColor
477
1958
  };
478
1959
  }
479
1960
  // Proto: WebcastSubNotifyMessage { User user=2, ... subMonth=3 }
@@ -582,10 +2063,12 @@ function parseWebcastResponse(payload) {
582
2063
  // src/client.ts
583
2064
  var DEFAULT_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
584
2065
  var DEFAULT_SIGN_SERVER = "https://api.tik.tools";
585
- function httpGet(url, headers) {
2066
+ function httpGet(url, headers, agent) {
586
2067
  return new Promise((resolve, reject) => {
587
2068
  const mod = url.startsWith("https") ? https : http;
588
- const req = mod.get(url, { headers }, (res) => {
2069
+ const opts = { headers };
2070
+ if (agent) opts.agent = agent;
2071
+ const req = mod.get(url, opts, (res) => {
589
2072
  const chunks = [];
590
2073
  const enc = res.headers["content-encoding"];
591
2074
  const stream = enc === "gzip" || enc === "br" ? res.pipe(enc === "br" ? zlib.createBrotliDecompress() : zlib.createGunzip()) : res;
@@ -635,6 +2118,7 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
635
2118
  debug;
636
2119
  _presetRoomId;
637
2120
  _presetSessionId;
2121
+ proxyUrl;
638
2122
  constructor(options) {
639
2123
  super();
640
2124
  this.setMaxListeners(20);
@@ -648,6 +2132,22 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
648
2132
  this.debug = options.debug ?? false;
649
2133
  this._presetRoomId = options.roomId || "";
650
2134
  this._presetSessionId = options.sessionId || "";
2135
+ this.proxyUrl = options.proxy || "";
2136
+ }
2137
+ /**
2138
+ * Build an HttpsProxyAgent when `proxy` option is set, else undefined.
2139
+ * Lazy-required so users without proxy don't pay the dependency cost.
2140
+ */
2141
+ getProxyAgent() {
2142
+ if (!this.proxyUrl) return void 0;
2143
+ try {
2144
+ const { HttpsProxyAgent } = require_dist2();
2145
+ return new HttpsProxyAgent(this.proxyUrl);
2146
+ } catch (e) {
2147
+ throw new Error(
2148
+ `proxy option requires 'https-proxy-agent' package. Install it: npm i https-proxy-agent`
2149
+ );
2150
+ }
651
2151
  }
652
2152
  async connect() {
653
2153
  if (this._destroyed) throw new Error("Client has been destroyed. Create a new instance.");
@@ -676,13 +2176,13 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
676
2176
  preSignedCookies = credData.data.cookies || "";
677
2177
  preSignedUA = credData.data.user_agent || DEFAULT_UA;
678
2178
  ttwid = "__presigned__";
679
- console.log(`[TikTokLive] \u2705 Got pre-signed URL from sign server`);
2179
+ console.log(`[TikTokLive] \xE2\u0153\u2026 Got pre-signed URL from sign server`);
680
2180
  } else {
681
- console.log(`[TikTokLive] \u26A0\uFE0F ws_credentials bad response: ${JSON.stringify(credData).substring(0, 120)}`);
2181
+ console.log(`[TikTokLive] \xE2\u0161\xA0\xEF\xB8\x8F ws_credentials bad response: ${JSON.stringify(credData).substring(0, 120)}`);
682
2182
  }
683
2183
  }
684
2184
  } catch (e) {
685
- console.log(`[TikTokLive] \u274C ws_credentials failed: ${e.message}`);
2185
+ console.log(`[TikTokLive] \xE2\x9D\u0152 ws_credentials failed: ${e.message}`);
686
2186
  }
687
2187
  if (!ttwid) {
688
2188
  console.log(`[TikTokLive] Fallback: direct TikTok fetch for ttwid...`);
@@ -690,16 +2190,16 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
690
2190
  const resp = await httpGet(`https://www.tiktok.com/@${this.uniqueId}/live`, {
691
2191
  "User-Agent": DEFAULT_UA,
692
2192
  "Accept": "text/html"
693
- });
2193
+ }, this.getProxyAgent());
694
2194
  for (const sc of [resp.headers["set-cookie"] || []].flat()) {
695
2195
  if (typeof sc === "string" && sc.startsWith("ttwid=")) {
696
2196
  ttwid = sc.split(";")[0].split("=").slice(1).join("=");
697
2197
  break;
698
2198
  }
699
2199
  }
700
- console.log(`[TikTokLive] Direct fetch ttwid: ${ttwid ? "\u2705" : "\u274C none"}`);
2200
+ console.log(`[TikTokLive] Direct fetch ttwid: ${ttwid ? "\xE2\u0153\u2026" : "\xE2\x9D\u0152 none"}`);
701
2201
  } catch (e) {
702
- console.log(`[TikTokLive] \u274C Direct TikTok fetch failed: ${e.message}`);
2202
+ console.log(`[TikTokLive] \xE2\x9D\u0152 Direct TikTok fetch failed: ${e.message}`);
703
2203
  }
704
2204
  }
705
2205
  } else {
@@ -715,13 +2215,13 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
715
2215
  const roomData = await roomResp.json();
716
2216
  if (roomData.status_code === 0 && roomData.data?.room_id) {
717
2217
  roomId = roomData.data.room_id;
718
- console.log(`[TikTokLive] \u2705 Got roomId from sign server: ${roomId}`);
2218
+ console.log(`[TikTokLive] \xE2\u0153\u2026 Got roomId from sign server: ${roomId}`);
719
2219
  } else {
720
- console.log(`[TikTokLive] \u26A0\uFE0F room_id response: ${JSON.stringify(roomData).substring(0, 120)}`);
2220
+ console.log(`[TikTokLive] \xE2\u0161\xA0\xEF\xB8\x8F room_id response: ${JSON.stringify(roomData).substring(0, 120)}`);
721
2221
  }
722
2222
  }
723
2223
  } catch (e) {
724
- console.log(`[TikTokLive] \u274C room_id request failed: ${e.message}`);
2224
+ console.log(`[TikTokLive] \xE2\x9D\u0152 room_id request failed: ${e.message}`);
725
2225
  }
726
2226
  if (roomId) {
727
2227
  try {
@@ -737,14 +2237,14 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
737
2237
  const m = credData.data.cookies.match(/ttwid=([^;]+)/);
738
2238
  if (m) {
739
2239
  ttwid = m[1];
740
- console.log(`[TikTokLive] \u2705 Got ttwid from sign server`);
741
- } else console.log(`[TikTokLive] \u26A0\uFE0F No ttwid in cookies: ${credData.data.cookies.substring(0, 60)}`);
2240
+ console.log(`[TikTokLive] \xE2\u0153\u2026 Got ttwid from sign server`);
2241
+ } else console.log(`[TikTokLive] \xE2\u0161\xA0\xEF\xB8\x8F No ttwid in cookies: ${credData.data.cookies.substring(0, 60)}`);
742
2242
  } else {
743
- console.log(`[TikTokLive] \u26A0\uFE0F No cookies in ws_credentials: ${JSON.stringify(credData).substring(0, 120)}`);
2243
+ console.log(`[TikTokLive] \xE2\u0161\xA0\xEF\xB8\x8F No cookies in ws_credentials: ${JSON.stringify(credData).substring(0, 120)}`);
744
2244
  }
745
2245
  }
746
2246
  } catch (e) {
747
- console.log(`[TikTokLive] \u274C ws_credentials failed: ${e.message}`);
2247
+ console.log(`[TikTokLive] \xE2\x9D\u0152 ws_credentials failed: ${e.message}`);
748
2248
  }
749
2249
  }
750
2250
  if (!roomId || !ttwid) {
@@ -755,7 +2255,7 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
755
2255
  "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
756
2256
  "Accept-Encoding": "gzip, deflate, br",
757
2257
  "Accept-Language": "en-US,en;q=0.9"
758
- });
2258
+ }, this.getProxyAgent());
759
2259
  if (!ttwid) {
760
2260
  for (const sc of [resp.headers["set-cookie"] || []].flat()) {
761
2261
  if (typeof sc === "string" && sc.startsWith("ttwid=")) {
@@ -781,7 +2281,7 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
781
2281
  }
782
2282
  console.log(`[TikTokLive] Direct fetch result: roomId=${roomId || "none"}, ttwid=${ttwid ? "yes" : "none"}`);
783
2283
  } catch (e) {
784
- console.log(`[TikTokLive] \u274C Direct TikTok fetch failed: ${e.message}`);
2284
+ console.log(`[TikTokLive] \xE2\x9D\u0152 Direct TikTok fetch failed: ${e.message}`);
785
2285
  }
786
2286
  }
787
2287
  }
@@ -844,8 +2344,10 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
844
2344
  const finalWsUrl = preSignedUrl ? preSignedUrl.replace(/^https:\/\//, "wss://") : wsUrl;
845
2345
  const finalHeaders = preSignedUrl ? { "User-Agent": preSignedUA, "Cookie": preSignedCookies, "Origin": "https://www.tiktok.com" } : { "User-Agent": DEFAULT_UA, "Cookie": `ttwid=${ttwid}`, "Origin": "https://www.tiktok.com" };
846
2346
  console.log(`[TikTokLive] Connecting WS: ${preSignedUrl ? "pre-signed URL" : "self-built URL"}`);
2347
+ const proxyAgent = this.getProxyAgent();
847
2348
  this.ws = new WebSocket(finalWsUrl, {
848
- headers: finalHeaders
2349
+ headers: finalHeaders,
2350
+ ...proxyAgent ? { agent: proxyAgent } : {}
849
2351
  });
850
2352
  this.ws.on("open", () => {
851
2353
  this._connected = true;
@@ -867,18 +2369,21 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
867
2369
  this.handleFrame(Buffer.from(rawData));
868
2370
  });
869
2371
  this.ws.on("close", (code, reason) => {
2372
+ const wasConnected = this._connected;
870
2373
  this._connected = false;
871
2374
  this.stopHeartbeat();
872
2375
  const reasonStr = reason?.toString() || "";
873
2376
  this.emit("disconnected", code, reasonStr);
874
- if (!this.intentionalClose && this.autoReconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
2377
+ if (wasConnected && !this.intentionalClose && this.autoReconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
875
2378
  this.reconnectAttempts++;
876
2379
  const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts - 1), 3e4);
877
2380
  setTimeout(() => this.connect().catch((e) => this.emit("error", e)), delay);
878
2381
  }
879
2382
  });
880
2383
  this.ws.on("error", (err) => {
881
- this.emit("error", err);
2384
+ if (this._connected) {
2385
+ this.emit("error", err);
2386
+ }
882
2387
  if (!this._connected) reject(err);
883
2388
  });
884
2389
  });
@@ -895,7 +2400,7 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
895
2400
  }
896
2401
  /**
897
2402
  * Fully destroy the client, releasing all resources and listeners.
898
- * After calling destroy(), the instance cannot be reused — create a new one.
2403
+ * After calling destroy(), the instance cannot be reused — create a new one.
899
2404
  */
900
2405
  destroy() {
901
2406
  this.disconnect();
@@ -920,7 +2425,7 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
920
2425
  /**
921
2426
  * Get live stream video URLs for a TikTok user.
922
2427
  * Returns FLV & HLS URLs segmented by quality (FULL_HD1, HD1, SD1, SD2).
923
- * This is a standalone method — no WebSocket connection required.
2428
+ * This is a standalone method — no WebSocket connection required.
924
2429
  *
925
2430
  * @example
926
2431
  * ```ts