@tiktool/live 2.5.1 → 2.6.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,1277 +1,4 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
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');
12
- });
13
- var __commonJS = (cb, mod) => function __require2() {
14
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
-
33
- // ../node_modules/ms/index.js
34
- var require_ms = __commonJS({
35
- "../node_modules/ms/index.js"(exports, module) {
36
- "use strict";
37
- var s = 1e3;
38
- var m = s * 60;
39
- var h = m * 60;
40
- var d = h * 24;
41
- var w = d * 7;
42
- var y = d * 365.25;
43
- module.exports = function(val, options) {
44
- options = options || {};
45
- var type = typeof val;
46
- if (type === "string" && val.length > 0) {
47
- return parse(val);
48
- } else if (type === "number" && isFinite(val)) {
49
- return options.long ? fmtLong(val) : fmtShort(val);
50
- }
51
- throw new Error(
52
- "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
53
- );
54
- };
55
- function parse(str) {
56
- str = String(str);
57
- if (str.length > 100) {
58
- return;
59
- }
60
- 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(
61
- str
62
- );
63
- if (!match) {
64
- return;
65
- }
66
- var n = parseFloat(match[1]);
67
- var type = (match[2] || "ms").toLowerCase();
68
- switch (type) {
69
- case "years":
70
- case "year":
71
- case "yrs":
72
- case "yr":
73
- case "y":
74
- return n * y;
75
- case "weeks":
76
- case "week":
77
- case "w":
78
- return n * w;
79
- case "days":
80
- case "day":
81
- case "d":
82
- return n * d;
83
- case "hours":
84
- case "hour":
85
- case "hrs":
86
- case "hr":
87
- case "h":
88
- return n * h;
89
- case "minutes":
90
- case "minute":
91
- case "mins":
92
- case "min":
93
- case "m":
94
- return n * m;
95
- case "seconds":
96
- case "second":
97
- case "secs":
98
- case "sec":
99
- case "s":
100
- return n * s;
101
- case "milliseconds":
102
- case "millisecond":
103
- case "msecs":
104
- case "msec":
105
- case "ms":
106
- return n;
107
- default:
108
- return void 0;
109
- }
110
- }
111
- function fmtShort(ms) {
112
- var msAbs = Math.abs(ms);
113
- if (msAbs >= d) {
114
- return Math.round(ms / d) + "d";
115
- }
116
- if (msAbs >= h) {
117
- return Math.round(ms / h) + "h";
118
- }
119
- if (msAbs >= m) {
120
- return Math.round(ms / m) + "m";
121
- }
122
- if (msAbs >= s) {
123
- return Math.round(ms / s) + "s";
124
- }
125
- return ms + "ms";
126
- }
127
- function fmtLong(ms) {
128
- var msAbs = Math.abs(ms);
129
- if (msAbs >= d) {
130
- return plural(ms, msAbs, d, "day");
131
- }
132
- if (msAbs >= h) {
133
- return plural(ms, msAbs, h, "hour");
134
- }
135
- if (msAbs >= m) {
136
- return plural(ms, msAbs, m, "minute");
137
- }
138
- if (msAbs >= s) {
139
- return plural(ms, msAbs, s, "second");
140
- }
141
- return ms + " ms";
142
- }
143
- function plural(ms, msAbs, n, name) {
144
- var isPlural = msAbs >= n * 1.5;
145
- return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
146
- }
147
- }
148
- });
149
-
150
- // ../node_modules/debug/src/common.js
151
- var require_common = __commonJS({
152
- "../node_modules/debug/src/common.js"(exports, module) {
153
- "use strict";
154
- function setup(env) {
155
- createDebug.debug = createDebug;
156
- createDebug.default = createDebug;
157
- createDebug.coerce = coerce;
158
- createDebug.disable = disable;
159
- createDebug.enable = enable;
160
- createDebug.enabled = enabled;
161
- createDebug.humanize = require_ms();
162
- createDebug.destroy = destroy;
163
- Object.keys(env).forEach((key) => {
164
- createDebug[key] = env[key];
165
- });
166
- createDebug.names = [];
167
- createDebug.skips = [];
168
- createDebug.formatters = {};
169
- function selectColor(namespace) {
170
- let hash = 0;
171
- for (let i = 0; i < namespace.length; i++) {
172
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
173
- hash |= 0;
174
- }
175
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
176
- }
177
- createDebug.selectColor = selectColor;
178
- function createDebug(namespace) {
179
- let prevTime;
180
- let enableOverride = null;
181
- let namespacesCache;
182
- let enabledCache;
183
- function debug(...args) {
184
- if (!debug.enabled) {
185
- return;
186
- }
187
- const self = debug;
188
- const curr = Number(/* @__PURE__ */ new Date());
189
- const ms = curr - (prevTime || curr);
190
- self.diff = ms;
191
- self.prev = prevTime;
192
- self.curr = curr;
193
- prevTime = curr;
194
- args[0] = createDebug.coerce(args[0]);
195
- if (typeof args[0] !== "string") {
196
- args.unshift("%O");
197
- }
198
- let index = 0;
199
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
200
- if (match === "%%") {
201
- return "%";
202
- }
203
- index++;
204
- const formatter = createDebug.formatters[format];
205
- if (typeof formatter === "function") {
206
- const val = args[index];
207
- match = formatter.call(self, val);
208
- args.splice(index, 1);
209
- index--;
210
- }
211
- return match;
212
- });
213
- createDebug.formatArgs.call(self, args);
214
- const logFn = self.log || createDebug.log;
215
- logFn.apply(self, args);
216
- }
217
- debug.namespace = namespace;
218
- debug.useColors = createDebug.useColors();
219
- debug.color = createDebug.selectColor(namespace);
220
- debug.extend = extend;
221
- debug.destroy = createDebug.destroy;
222
- Object.defineProperty(debug, "enabled", {
223
- enumerable: true,
224
- configurable: false,
225
- get: () => {
226
- if (enableOverride !== null) {
227
- return enableOverride;
228
- }
229
- if (namespacesCache !== createDebug.namespaces) {
230
- namespacesCache = createDebug.namespaces;
231
- enabledCache = createDebug.enabled(namespace);
232
- }
233
- return enabledCache;
234
- },
235
- set: (v) => {
236
- enableOverride = v;
237
- }
238
- });
239
- if (typeof createDebug.init === "function") {
240
- createDebug.init(debug);
241
- }
242
- return debug;
243
- }
244
- function extend(namespace, delimiter) {
245
- const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
246
- newDebug.log = this.log;
247
- return newDebug;
248
- }
249
- function enable(namespaces) {
250
- createDebug.save(namespaces);
251
- createDebug.namespaces = namespaces;
252
- createDebug.names = [];
253
- createDebug.skips = [];
254
- const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
255
- for (const ns of split) {
256
- if (ns[0] === "-") {
257
- createDebug.skips.push(ns.slice(1));
258
- } else {
259
- createDebug.names.push(ns);
260
- }
261
- }
262
- }
263
- function matchesTemplate(search, template) {
264
- let searchIndex = 0;
265
- let templateIndex = 0;
266
- let starIndex = -1;
267
- let matchIndex = 0;
268
- while (searchIndex < search.length) {
269
- if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
270
- if (template[templateIndex] === "*") {
271
- starIndex = templateIndex;
272
- matchIndex = searchIndex;
273
- templateIndex++;
274
- } else {
275
- searchIndex++;
276
- templateIndex++;
277
- }
278
- } else if (starIndex !== -1) {
279
- templateIndex = starIndex + 1;
280
- matchIndex++;
281
- searchIndex = matchIndex;
282
- } else {
283
- return false;
284
- }
285
- }
286
- while (templateIndex < template.length && template[templateIndex] === "*") {
287
- templateIndex++;
288
- }
289
- return templateIndex === template.length;
290
- }
291
- function disable() {
292
- const namespaces = [
293
- ...createDebug.names,
294
- ...createDebug.skips.map((namespace) => "-" + namespace)
295
- ].join(",");
296
- createDebug.enable("");
297
- return namespaces;
298
- }
299
- function enabled(name) {
300
- for (const skip of createDebug.skips) {
301
- if (matchesTemplate(name, skip)) {
302
- return false;
303
- }
304
- }
305
- for (const ns of createDebug.names) {
306
- if (matchesTemplate(name, ns)) {
307
- return true;
308
- }
309
- }
310
- return false;
311
- }
312
- function coerce(val) {
313
- if (val instanceof Error) {
314
- return val.stack || val.message;
315
- }
316
- return val;
317
- }
318
- function destroy() {
319
- console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
320
- }
321
- createDebug.enable(createDebug.load());
322
- return createDebug;
323
- }
324
- module.exports = setup;
325
- }
326
- });
327
-
328
- // ../node_modules/debug/src/browser.js
329
- var require_browser = __commonJS({
330
- "../node_modules/debug/src/browser.js"(exports, module) {
331
- "use strict";
332
- exports.formatArgs = formatArgs;
333
- exports.save = save;
334
- exports.load = load;
335
- exports.useColors = useColors;
336
- exports.storage = localstorage();
337
- exports.destroy = /* @__PURE__ */ (() => {
338
- let warned = false;
339
- return () => {
340
- if (!warned) {
341
- warned = true;
342
- console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
343
- }
344
- };
345
- })();
346
- exports.colors = [
347
- "#0000CC",
348
- "#0000FF",
349
- "#0033CC",
350
- "#0033FF",
351
- "#0066CC",
352
- "#0066FF",
353
- "#0099CC",
354
- "#0099FF",
355
- "#00CC00",
356
- "#00CC33",
357
- "#00CC66",
358
- "#00CC99",
359
- "#00CCCC",
360
- "#00CCFF",
361
- "#3300CC",
362
- "#3300FF",
363
- "#3333CC",
364
- "#3333FF",
365
- "#3366CC",
366
- "#3366FF",
367
- "#3399CC",
368
- "#3399FF",
369
- "#33CC00",
370
- "#33CC33",
371
- "#33CC66",
372
- "#33CC99",
373
- "#33CCCC",
374
- "#33CCFF",
375
- "#6600CC",
376
- "#6600FF",
377
- "#6633CC",
378
- "#6633FF",
379
- "#66CC00",
380
- "#66CC33",
381
- "#9900CC",
382
- "#9900FF",
383
- "#9933CC",
384
- "#9933FF",
385
- "#99CC00",
386
- "#99CC33",
387
- "#CC0000",
388
- "#CC0033",
389
- "#CC0066",
390
- "#CC0099",
391
- "#CC00CC",
392
- "#CC00FF",
393
- "#CC3300",
394
- "#CC3333",
395
- "#CC3366",
396
- "#CC3399",
397
- "#CC33CC",
398
- "#CC33FF",
399
- "#CC6600",
400
- "#CC6633",
401
- "#CC9900",
402
- "#CC9933",
403
- "#CCCC00",
404
- "#CCCC33",
405
- "#FF0000",
406
- "#FF0033",
407
- "#FF0066",
408
- "#FF0099",
409
- "#FF00CC",
410
- "#FF00FF",
411
- "#FF3300",
412
- "#FF3333",
413
- "#FF3366",
414
- "#FF3399",
415
- "#FF33CC",
416
- "#FF33FF",
417
- "#FF6600",
418
- "#FF6633",
419
- "#FF9900",
420
- "#FF9933",
421
- "#FFCC00",
422
- "#FFCC33"
423
- ];
424
- function useColors() {
425
- if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
426
- return true;
427
- }
428
- if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
429
- return false;
430
- }
431
- let m;
432
- return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
433
- typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
434
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
435
- 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
436
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
437
- }
438
- function formatArgs(args) {
439
- args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
440
- if (!this.useColors) {
441
- return;
442
- }
443
- const c = "color: " + this.color;
444
- args.splice(1, 0, c, "color: inherit");
445
- let index = 0;
446
- let lastC = 0;
447
- args[0].replace(/%[a-zA-Z%]/g, (match) => {
448
- if (match === "%%") {
449
- return;
450
- }
451
- index++;
452
- if (match === "%c") {
453
- lastC = index;
454
- }
455
- });
456
- args.splice(lastC, 0, c);
457
- }
458
- exports.log = console.debug || console.log || (() => {
459
- });
460
- function save(namespaces) {
461
- try {
462
- if (namespaces) {
463
- exports.storage.setItem("debug", namespaces);
464
- } else {
465
- exports.storage.removeItem("debug");
466
- }
467
- } catch (error) {
468
- }
469
- }
470
- function load() {
471
- let r;
472
- try {
473
- r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
474
- } catch (error) {
475
- }
476
- if (!r && typeof process !== "undefined" && "env" in process) {
477
- r = process.env.DEBUG;
478
- }
479
- return r;
480
- }
481
- function localstorage() {
482
- try {
483
- return localStorage;
484
- } catch (error) {
485
- }
486
- }
487
- module.exports = require_common()(exports);
488
- var { formatters } = module.exports;
489
- formatters.j = function(v) {
490
- try {
491
- return JSON.stringify(v);
492
- } catch (error) {
493
- return "[UnexpectedJSONParseError]: " + error.message;
494
- }
495
- };
496
- }
497
- });
498
-
499
- // ../../node_modules/has-flag/index.js
500
- var require_has_flag = __commonJS({
501
- "../../node_modules/has-flag/index.js"(exports, module) {
502
- "use strict";
503
- module.exports = (flag, argv = process.argv) => {
504
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
505
- const position = argv.indexOf(prefix + flag);
506
- const terminatorPosition = argv.indexOf("--");
507
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
508
- };
509
- }
510
- });
511
-
512
- // ../../node_modules/supports-color/index.js
513
- var require_supports_color = __commonJS({
514
- "../../node_modules/supports-color/index.js"(exports, module) {
515
- "use strict";
516
- var os = __require("os");
517
- var tty = __require("tty");
518
- var hasFlag = require_has_flag();
519
- var { env } = process;
520
- var forceColor;
521
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
522
- forceColor = 0;
523
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
524
- forceColor = 1;
525
- }
526
- if ("FORCE_COLOR" in env) {
527
- if (env.FORCE_COLOR === "true") {
528
- forceColor = 1;
529
- } else if (env.FORCE_COLOR === "false") {
530
- forceColor = 0;
531
- } else {
532
- forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
533
- }
534
- }
535
- function translateLevel(level) {
536
- if (level === 0) {
537
- return false;
538
- }
539
- return {
540
- level,
541
- hasBasic: true,
542
- has256: level >= 2,
543
- has16m: level >= 3
544
- };
545
- }
546
- function supportsColor(haveStream, streamIsTTY) {
547
- if (forceColor === 0) {
548
- return 0;
549
- }
550
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
551
- return 3;
552
- }
553
- if (hasFlag("color=256")) {
554
- return 2;
555
- }
556
- if (haveStream && !streamIsTTY && forceColor === void 0) {
557
- return 0;
558
- }
559
- const min = forceColor || 0;
560
- if (env.TERM === "dumb") {
561
- return min;
562
- }
563
- if (process.platform === "win32") {
564
- const osRelease = os.release().split(".");
565
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
566
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
567
- }
568
- return 1;
569
- }
570
- if ("CI" in env) {
571
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
572
- return 1;
573
- }
574
- return min;
575
- }
576
- if ("TEAMCITY_VERSION" in env) {
577
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
578
- }
579
- if (env.COLORTERM === "truecolor") {
580
- return 3;
581
- }
582
- if ("TERM_PROGRAM" in env) {
583
- const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
584
- switch (env.TERM_PROGRAM) {
585
- case "iTerm.app":
586
- return version >= 3 ? 3 : 2;
587
- case "Apple_Terminal":
588
- return 2;
589
- }
590
- }
591
- if (/-256(color)?$/i.test(env.TERM)) {
592
- return 2;
593
- }
594
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
595
- return 1;
596
- }
597
- if ("COLORTERM" in env) {
598
- return 1;
599
- }
600
- return min;
601
- }
602
- function getSupportLevel(stream) {
603
- const level = supportsColor(stream, stream && stream.isTTY);
604
- return translateLevel(level);
605
- }
606
- module.exports = {
607
- supportsColor: getSupportLevel,
608
- stdout: translateLevel(supportsColor(true, tty.isatty(1))),
609
- stderr: translateLevel(supportsColor(true, tty.isatty(2)))
610
- };
611
- }
612
- });
613
-
614
- // ../node_modules/debug/src/node.js
615
- var require_node = __commonJS({
616
- "../node_modules/debug/src/node.js"(exports, module) {
617
- "use strict";
618
- var tty = __require("tty");
619
- var util = __require("util");
620
- exports.init = init;
621
- exports.log = log;
622
- exports.formatArgs = formatArgs;
623
- exports.save = save;
624
- exports.load = load;
625
- exports.useColors = useColors;
626
- exports.destroy = util.deprecate(
627
- () => {
628
- },
629
- "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
630
- );
631
- exports.colors = [6, 2, 3, 4, 5, 1];
632
- try {
633
- const supportsColor = require_supports_color();
634
- if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
635
- exports.colors = [
636
- 20,
637
- 21,
638
- 26,
639
- 27,
640
- 32,
641
- 33,
642
- 38,
643
- 39,
644
- 40,
645
- 41,
646
- 42,
647
- 43,
648
- 44,
649
- 45,
650
- 56,
651
- 57,
652
- 62,
653
- 63,
654
- 68,
655
- 69,
656
- 74,
657
- 75,
658
- 76,
659
- 77,
660
- 78,
661
- 79,
662
- 80,
663
- 81,
664
- 92,
665
- 93,
666
- 98,
667
- 99,
668
- 112,
669
- 113,
670
- 128,
671
- 129,
672
- 134,
673
- 135,
674
- 148,
675
- 149,
676
- 160,
677
- 161,
678
- 162,
679
- 163,
680
- 164,
681
- 165,
682
- 166,
683
- 167,
684
- 168,
685
- 169,
686
- 170,
687
- 171,
688
- 172,
689
- 173,
690
- 178,
691
- 179,
692
- 184,
693
- 185,
694
- 196,
695
- 197,
696
- 198,
697
- 199,
698
- 200,
699
- 201,
700
- 202,
701
- 203,
702
- 204,
703
- 205,
704
- 206,
705
- 207,
706
- 208,
707
- 209,
708
- 214,
709
- 215,
710
- 220,
711
- 221
712
- ];
713
- }
714
- } catch (error) {
715
- }
716
- exports.inspectOpts = Object.keys(process.env).filter((key) => {
717
- return /^debug_/i.test(key);
718
- }).reduce((obj, key) => {
719
- const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
720
- return k.toUpperCase();
721
- });
722
- let val = process.env[key];
723
- if (/^(yes|on|true|enabled)$/i.test(val)) {
724
- val = true;
725
- } else if (/^(no|off|false|disabled)$/i.test(val)) {
726
- val = false;
727
- } else if (val === "null") {
728
- val = null;
729
- } else {
730
- val = Number(val);
731
- }
732
- obj[prop] = val;
733
- return obj;
734
- }, {});
735
- function useColors() {
736
- return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
737
- }
738
- function formatArgs(args) {
739
- const { namespace: name, useColors: useColors2 } = this;
740
- if (useColors2) {
741
- const c = this.color;
742
- const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
743
- const prefix = ` ${colorCode};1m${name} \x1B[0m`;
744
- args[0] = prefix + args[0].split("\n").join("\n" + prefix);
745
- args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
746
- } else {
747
- args[0] = getDate() + name + " " + args[0];
748
- }
749
- }
750
- function getDate() {
751
- if (exports.inspectOpts.hideDate) {
752
- return "";
753
- }
754
- return (/* @__PURE__ */ new Date()).toISOString() + " ";
755
- }
756
- function log(...args) {
757
- return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
758
- }
759
- function save(namespaces) {
760
- if (namespaces) {
761
- process.env.DEBUG = namespaces;
762
- } else {
763
- delete process.env.DEBUG;
764
- }
765
- }
766
- function load() {
767
- return process.env.DEBUG;
768
- }
769
- function init(debug) {
770
- debug.inspectOpts = {};
771
- const keys = Object.keys(exports.inspectOpts);
772
- for (let i = 0; i < keys.length; i++) {
773
- debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
774
- }
775
- }
776
- module.exports = require_common()(exports);
777
- var { formatters } = module.exports;
778
- formatters.o = function(v) {
779
- this.inspectOpts.colors = this.useColors;
780
- return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
781
- };
782
- formatters.O = function(v) {
783
- this.inspectOpts.colors = this.useColors;
784
- return util.inspect(v, this.inspectOpts);
785
- };
786
- }
787
- });
788
-
789
- // ../node_modules/debug/src/index.js
790
- var require_src = __commonJS({
791
- "../node_modules/debug/src/index.js"(exports, module) {
792
- "use strict";
793
- if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
794
- module.exports = require_browser();
795
- } else {
796
- module.exports = require_node();
797
- }
798
- }
799
- });
800
-
801
- // ../node_modules/agent-base/dist/helpers.js
802
- var require_helpers = __commonJS({
803
- "../node_modules/agent-base/dist/helpers.js"(exports) {
804
- "use strict";
805
- var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
806
- if (k2 === void 0) k2 = k;
807
- var desc = Object.getOwnPropertyDescriptor(m, k);
808
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
809
- desc = { enumerable: true, get: function() {
810
- return m[k];
811
- } };
812
- }
813
- Object.defineProperty(o, k2, desc);
814
- }) : (function(o, m, k, k2) {
815
- if (k2 === void 0) k2 = k;
816
- o[k2] = m[k];
817
- }));
818
- var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
819
- Object.defineProperty(o, "default", { enumerable: true, value: v });
820
- }) : function(o, v) {
821
- o["default"] = v;
822
- });
823
- var __importStar = exports && exports.__importStar || function(mod) {
824
- if (mod && mod.__esModule) return mod;
825
- var result = {};
826
- if (mod != null) {
827
- for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
828
- }
829
- __setModuleDefault(result, mod);
830
- return result;
831
- };
832
- Object.defineProperty(exports, "__esModule", { value: true });
833
- exports.req = exports.json = exports.toBuffer = void 0;
834
- var http2 = __importStar(__require("http"));
835
- var https2 = __importStar(__require("https"));
836
- async function toBuffer(stream) {
837
- let length = 0;
838
- const chunks = [];
839
- for await (const chunk of stream) {
840
- length += chunk.length;
841
- chunks.push(chunk);
842
- }
843
- return Buffer.concat(chunks, length);
844
- }
845
- exports.toBuffer = toBuffer;
846
- async function json(stream) {
847
- const buf = await toBuffer(stream);
848
- const str = buf.toString("utf8");
849
- try {
850
- return JSON.parse(str);
851
- } catch (_err) {
852
- const err = _err;
853
- err.message += ` (input: ${str})`;
854
- throw err;
855
- }
856
- }
857
- exports.json = json;
858
- function req(url, opts = {}) {
859
- const href = typeof url === "string" ? url : url.href;
860
- const req2 = (href.startsWith("https:") ? https2 : http2).request(url, opts);
861
- const promise = new Promise((resolve, reject) => {
862
- req2.once("response", resolve).once("error", reject).end();
863
- });
864
- req2.then = promise.then.bind(promise);
865
- return req2;
866
- }
867
- exports.req = req;
868
- }
869
- });
870
-
871
- // ../node_modules/agent-base/dist/index.js
872
- var require_dist = __commonJS({
873
- "../node_modules/agent-base/dist/index.js"(exports) {
874
- "use strict";
875
- var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
876
- if (k2 === void 0) k2 = k;
877
- var desc = Object.getOwnPropertyDescriptor(m, k);
878
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
879
- desc = { enumerable: true, get: function() {
880
- return m[k];
881
- } };
882
- }
883
- Object.defineProperty(o, k2, desc);
884
- }) : (function(o, m, k, k2) {
885
- if (k2 === void 0) k2 = k;
886
- o[k2] = m[k];
887
- }));
888
- var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
889
- Object.defineProperty(o, "default", { enumerable: true, value: v });
890
- }) : function(o, v) {
891
- o["default"] = v;
892
- });
893
- var __importStar = exports && exports.__importStar || function(mod) {
894
- if (mod && mod.__esModule) return mod;
895
- var result = {};
896
- if (mod != null) {
897
- for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
898
- }
899
- __setModuleDefault(result, mod);
900
- return result;
901
- };
902
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
903
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
904
- };
905
- Object.defineProperty(exports, "__esModule", { value: true });
906
- exports.Agent = void 0;
907
- var net = __importStar(__require("net"));
908
- var http2 = __importStar(__require("http"));
909
- var https_1 = __require("https");
910
- __exportStar(require_helpers(), exports);
911
- var INTERNAL = /* @__PURE__ */ Symbol("AgentBaseInternalState");
912
- var Agent = class extends http2.Agent {
913
- constructor(opts) {
914
- super(opts);
915
- this[INTERNAL] = {};
916
- }
917
- /**
918
- * Determine whether this is an `http` or `https` request.
919
- */
920
- isSecureEndpoint(options) {
921
- if (options) {
922
- if (typeof options.secureEndpoint === "boolean") {
923
- return options.secureEndpoint;
924
- }
925
- if (typeof options.protocol === "string") {
926
- return options.protocol === "https:";
927
- }
928
- }
929
- const { stack } = new Error();
930
- if (typeof stack !== "string")
931
- return false;
932
- return stack.split("\n").some((l) => l.indexOf("(https.js:") !== -1 || l.indexOf("node:https:") !== -1);
933
- }
934
- // In order to support async signatures in `connect()` and Node's native
935
- // connection pooling in `http.Agent`, the array of sockets for each origin
936
- // has to be updated synchronously. This is so the length of the array is
937
- // accurate when `addRequest()` is next called. We achieve this by creating a
938
- // fake socket and adding it to `sockets[origin]` and incrementing
939
- // `totalSocketCount`.
940
- incrementSockets(name) {
941
- if (this.maxSockets === Infinity && this.maxTotalSockets === Infinity) {
942
- return null;
943
- }
944
- if (!this.sockets[name]) {
945
- this.sockets[name] = [];
946
- }
947
- const fakeSocket = new net.Socket({ writable: false });
948
- this.sockets[name].push(fakeSocket);
949
- this.totalSocketCount++;
950
- return fakeSocket;
951
- }
952
- decrementSockets(name, socket) {
953
- if (!this.sockets[name] || socket === null) {
954
- return;
955
- }
956
- const sockets = this.sockets[name];
957
- const index = sockets.indexOf(socket);
958
- if (index !== -1) {
959
- sockets.splice(index, 1);
960
- this.totalSocketCount--;
961
- if (sockets.length === 0) {
962
- delete this.sockets[name];
963
- }
964
- }
965
- }
966
- // In order to properly update the socket pool, we need to call `getName()` on
967
- // the core `https.Agent` if it is a secureEndpoint.
968
- getName(options) {
969
- const secureEndpoint = this.isSecureEndpoint(options);
970
- if (secureEndpoint) {
971
- return https_1.Agent.prototype.getName.call(this, options);
972
- }
973
- return super.getName(options);
974
- }
975
- createSocket(req, options, cb) {
976
- const connectOpts = {
977
- ...options,
978
- secureEndpoint: this.isSecureEndpoint(options)
979
- };
980
- const name = this.getName(connectOpts);
981
- const fakeSocket = this.incrementSockets(name);
982
- Promise.resolve().then(() => this.connect(req, connectOpts)).then((socket) => {
983
- this.decrementSockets(name, fakeSocket);
984
- if (socket instanceof http2.Agent) {
985
- try {
986
- return socket.addRequest(req, connectOpts);
987
- } catch (err) {
988
- return cb(err);
989
- }
990
- }
991
- this[INTERNAL].currentSocket = socket;
992
- super.createSocket(req, options, cb);
993
- }, (err) => {
994
- this.decrementSockets(name, fakeSocket);
995
- cb(err);
996
- });
997
- }
998
- createConnection() {
999
- const socket = this[INTERNAL].currentSocket;
1000
- this[INTERNAL].currentSocket = void 0;
1001
- if (!socket) {
1002
- throw new Error("No socket was returned in the `connect()` function");
1003
- }
1004
- return socket;
1005
- }
1006
- get defaultPort() {
1007
- return this[INTERNAL].defaultPort ?? (this.protocol === "https:" ? 443 : 80);
1008
- }
1009
- set defaultPort(v) {
1010
- if (this[INTERNAL]) {
1011
- this[INTERNAL].defaultPort = v;
1012
- }
1013
- }
1014
- get protocol() {
1015
- return this[INTERNAL].protocol ?? (this.isSecureEndpoint() ? "https:" : "http:");
1016
- }
1017
- set protocol(v) {
1018
- if (this[INTERNAL]) {
1019
- this[INTERNAL].protocol = v;
1020
- }
1021
- }
1022
- };
1023
- exports.Agent = Agent;
1024
- }
1025
- });
1026
-
1027
- // ../node_modules/https-proxy-agent/dist/parse-proxy-response.js
1028
- var require_parse_proxy_response = __commonJS({
1029
- "../node_modules/https-proxy-agent/dist/parse-proxy-response.js"(exports) {
1030
- "use strict";
1031
- var __importDefault = exports && exports.__importDefault || function(mod) {
1032
- return mod && mod.__esModule ? mod : { "default": mod };
1033
- };
1034
- Object.defineProperty(exports, "__esModule", { value: true });
1035
- exports.parseProxyResponse = void 0;
1036
- var debug_1 = __importDefault(require_src());
1037
- var debug = (0, debug_1.default)("https-proxy-agent:parse-proxy-response");
1038
- function parseProxyResponse(socket) {
1039
- return new Promise((resolve, reject) => {
1040
- let buffersLength = 0;
1041
- const buffers = [];
1042
- function read() {
1043
- const b = socket.read();
1044
- if (b)
1045
- ondata(b);
1046
- else
1047
- socket.once("readable", read);
1048
- }
1049
- function cleanup() {
1050
- socket.removeListener("end", onend);
1051
- socket.removeListener("error", onerror);
1052
- socket.removeListener("readable", read);
1053
- }
1054
- function onend() {
1055
- cleanup();
1056
- debug("onend");
1057
- reject(new Error("Proxy connection ended before receiving CONNECT response"));
1058
- }
1059
- function onerror(err) {
1060
- cleanup();
1061
- debug("onerror %o", err);
1062
- reject(err);
1063
- }
1064
- function ondata(b) {
1065
- buffers.push(b);
1066
- buffersLength += b.length;
1067
- const buffered = Buffer.concat(buffers, buffersLength);
1068
- const endOfHeaders = buffered.indexOf("\r\n\r\n");
1069
- if (endOfHeaders === -1) {
1070
- debug("have not received end of HTTP headers yet...");
1071
- read();
1072
- return;
1073
- }
1074
- const headerParts = buffered.slice(0, endOfHeaders).toString("ascii").split("\r\n");
1075
- const firstLine = headerParts.shift();
1076
- if (!firstLine) {
1077
- socket.destroy();
1078
- return reject(new Error("No header received from proxy CONNECT response"));
1079
- }
1080
- const firstLineParts = firstLine.split(" ");
1081
- const statusCode = +firstLineParts[1];
1082
- const statusText = firstLineParts.slice(2).join(" ");
1083
- const headers = {};
1084
- for (const header of headerParts) {
1085
- if (!header)
1086
- continue;
1087
- const firstColon = header.indexOf(":");
1088
- if (firstColon === -1) {
1089
- socket.destroy();
1090
- return reject(new Error(`Invalid header from proxy CONNECT response: "${header}"`));
1091
- }
1092
- const key = header.slice(0, firstColon).toLowerCase();
1093
- const value = header.slice(firstColon + 1).trimStart();
1094
- const current = headers[key];
1095
- if (typeof current === "string") {
1096
- headers[key] = [current, value];
1097
- } else if (Array.isArray(current)) {
1098
- current.push(value);
1099
- } else {
1100
- headers[key] = value;
1101
- }
1102
- }
1103
- debug("got proxy server response: %o %o", firstLine, headers);
1104
- cleanup();
1105
- resolve({
1106
- connect: {
1107
- statusCode,
1108
- statusText,
1109
- headers
1110
- },
1111
- buffered
1112
- });
1113
- }
1114
- socket.on("error", onerror);
1115
- socket.on("end", onend);
1116
- read();
1117
- });
1118
- }
1119
- exports.parseProxyResponse = parseProxyResponse;
1120
- }
1121
- });
1122
-
1123
- // ../node_modules/https-proxy-agent/dist/index.js
1124
- var require_dist2 = __commonJS({
1125
- "../node_modules/https-proxy-agent/dist/index.js"(exports) {
1126
- "use strict";
1127
- var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
1128
- if (k2 === void 0) k2 = k;
1129
- var desc = Object.getOwnPropertyDescriptor(m, k);
1130
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1131
- desc = { enumerable: true, get: function() {
1132
- return m[k];
1133
- } };
1134
- }
1135
- Object.defineProperty(o, k2, desc);
1136
- }) : (function(o, m, k, k2) {
1137
- if (k2 === void 0) k2 = k;
1138
- o[k2] = m[k];
1139
- }));
1140
- var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
1141
- Object.defineProperty(o, "default", { enumerable: true, value: v });
1142
- }) : function(o, v) {
1143
- o["default"] = v;
1144
- });
1145
- var __importStar = exports && exports.__importStar || function(mod) {
1146
- if (mod && mod.__esModule) return mod;
1147
- var result = {};
1148
- if (mod != null) {
1149
- for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1150
- }
1151
- __setModuleDefault(result, mod);
1152
- return result;
1153
- };
1154
- var __importDefault = exports && exports.__importDefault || function(mod) {
1155
- return mod && mod.__esModule ? mod : { "default": mod };
1156
- };
1157
- Object.defineProperty(exports, "__esModule", { value: true });
1158
- exports.HttpsProxyAgent = void 0;
1159
- var net = __importStar(__require("net"));
1160
- var tls = __importStar(__require("tls"));
1161
- var assert_1 = __importDefault(__require("assert"));
1162
- var debug_1 = __importDefault(require_src());
1163
- var agent_base_1 = require_dist();
1164
- var url_1 = __require("url");
1165
- var parse_proxy_response_1 = require_parse_proxy_response();
1166
- var debug = (0, debug_1.default)("https-proxy-agent");
1167
- var setServernameFromNonIpHost = (options) => {
1168
- if (options.servername === void 0 && options.host && !net.isIP(options.host)) {
1169
- return {
1170
- ...options,
1171
- servername: options.host
1172
- };
1173
- }
1174
- return options;
1175
- };
1176
- var HttpsProxyAgent2 = class extends agent_base_1.Agent {
1177
- constructor(proxy, opts) {
1178
- super(opts);
1179
- this.options = { path: void 0 };
1180
- this.proxy = typeof proxy === "string" ? new url_1.URL(proxy) : proxy;
1181
- this.proxyHeaders = opts?.headers ?? {};
1182
- debug("Creating new HttpsProxyAgent instance: %o", this.proxy.href);
1183
- const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, "");
1184
- const port = this.proxy.port ? parseInt(this.proxy.port, 10) : this.proxy.protocol === "https:" ? 443 : 80;
1185
- this.connectOpts = {
1186
- // Attempt to negotiate http/1.1 for proxy servers that support http/2
1187
- ALPNProtocols: ["http/1.1"],
1188
- ...opts ? omit(opts, "headers") : null,
1189
- host,
1190
- port
1191
- };
1192
- }
1193
- /**
1194
- * Called when the node-core HTTP client library is creating a
1195
- * new HTTP request.
1196
- */
1197
- async connect(req, opts) {
1198
- const { proxy } = this;
1199
- if (!opts.host) {
1200
- throw new TypeError('No "host" provided');
1201
- }
1202
- let socket;
1203
- if (proxy.protocol === "https:") {
1204
- debug("Creating `tls.Socket`: %o", this.connectOpts);
1205
- socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
1206
- } else {
1207
- debug("Creating `net.Socket`: %o", this.connectOpts);
1208
- socket = net.connect(this.connectOpts);
1209
- }
1210
- const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
1211
- const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
1212
- let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r
1213
- `;
1214
- if (proxy.username || proxy.password) {
1215
- const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
1216
- headers["Proxy-Authorization"] = `Basic ${Buffer.from(auth).toString("base64")}`;
1217
- }
1218
- headers.Host = `${host}:${opts.port}`;
1219
- if (!headers["Proxy-Connection"]) {
1220
- headers["Proxy-Connection"] = this.keepAlive ? "Keep-Alive" : "close";
1221
- }
1222
- for (const name of Object.keys(headers)) {
1223
- payload += `${name}: ${headers[name]}\r
1224
- `;
1225
- }
1226
- const proxyResponsePromise = (0, parse_proxy_response_1.parseProxyResponse)(socket);
1227
- socket.write(`${payload}\r
1228
- `);
1229
- const { connect, buffered } = await proxyResponsePromise;
1230
- req.emit("proxyConnect", connect);
1231
- this.emit("proxyConnect", connect, req);
1232
- if (connect.statusCode === 200) {
1233
- req.once("socket", resume);
1234
- if (opts.secureEndpoint) {
1235
- debug("Upgrading socket connection to TLS");
1236
- return tls.connect({
1237
- ...omit(setServernameFromNonIpHost(opts), "host", "path", "port"),
1238
- socket
1239
- });
1240
- }
1241
- return socket;
1242
- }
1243
- socket.destroy();
1244
- const fakeSocket = new net.Socket({ writable: false });
1245
- fakeSocket.readable = true;
1246
- req.once("socket", (s) => {
1247
- debug("Replaying proxy buffer for failed request");
1248
- (0, assert_1.default)(s.listenerCount("data") > 0);
1249
- s.push(buffered);
1250
- s.push(null);
1251
- });
1252
- return fakeSocket;
1253
- }
1254
- };
1255
- HttpsProxyAgent2.protocols = ["http", "https"];
1256
- exports.HttpsProxyAgent = HttpsProxyAgent2;
1257
- function resume(socket) {
1258
- socket.resume();
1259
- }
1260
- function omit(obj, ...keys) {
1261
- const ret = {};
1262
- let key;
1263
- for (key in obj) {
1264
- if (!keys.includes(key)) {
1265
- ret[key] = obj[key];
1266
- }
1267
- }
1268
- return ret;
1269
- }
1270
- }
1271
- });
1272
-
1273
1
  // src/client.ts
1274
- var import_https_proxy_agent = __toESM(require_dist2());
1275
2
  import { EventEmitter } from "events";
1276
3
  import * as http from "http";
1277
4
  import * as https from "https";
@@ -1519,10 +246,24 @@ function parseUser(data) {
1519
246
  }
1520
247
  }
1521
248
  const badges = [];
1522
- const badgeBuf = getBytes(f, 64);
1523
- if (badgeBuf) {
249
+ let payGrade;
250
+ const badgeBufs = getAllBytes(f, 64);
251
+ for (const badgeBuf of badgeBufs) {
1524
252
  try {
1525
253
  const badgeFields = decodeProto(badgeBuf);
254
+ const badgeCategory = getInt(badgeFields, 2);
255
+ const badgeSubCat = getInt(badgeFields, 3);
256
+ if (badgeCategory === 20 && badgeSubCat === 8 && !payGrade) {
257
+ const privBuf = getBytes(badgeFields, 12);
258
+ if (privBuf) {
259
+ const privFields = decodeProto(privBuf);
260
+ const levelStr = getStr(privFields, 5);
261
+ if (levelStr) {
262
+ const level = parseInt(levelStr, 10);
263
+ if (level > 0) payGrade = level;
264
+ }
265
+ }
266
+ }
1526
267
  const badgeItems = getAllBytes(badgeFields, 21);
1527
268
  for (const bi of badgeItems) {
1528
269
  const bf = decodeProto(bi);
@@ -1537,7 +278,8 @@ function parseUser(data) {
1537
278
  nickname,
1538
279
  uniqueId: uniqueId || nickname || id,
1539
280
  profilePictureUrl: profilePicture,
1540
- badges: badges.length > 0 ? badges : void 0
281
+ badges: badges.length > 0 ? badges : void 0,
282
+ payGrade
1541
283
  };
1542
284
  }
1543
285
  function parseBattleTeamFromArmies(itemBuf) {
@@ -1787,9 +529,27 @@ function parseWebcastMessage(method, payload) {
1787
529
  return { ...base, type: "battle", battleId, status, battleDuration, teams, battleSettings };
1788
530
  }
1789
531
  case "WebcastLinkMicArmies": {
1790
- const battleId = getIntStr(f, 1) || "";
532
+ const battleId = getIntStr(f, 2) || getIntStr(f, 1) || "";
1791
533
  const battleStatus = getInt(f, 7);
1792
534
  const teams = [];
535
+ let battleSettings;
536
+ const settingsBuf18 = getBytes(f, 18);
537
+ if (settingsBuf18) {
538
+ try {
539
+ const sf = decodeProto(settingsBuf18);
540
+ const startTimeMs = getInt(sf, 2);
541
+ const duration = getInt(sf, 3);
542
+ const endTimeMs = getInt(sf, 10);
543
+ battleSettings = {
544
+ startTimeMs: startTimeMs || void 0,
545
+ duration: duration || void 0,
546
+ endTimeMs: endTimeMs || void 0
547
+ };
548
+ } catch {
549
+ }
550
+ }
551
+ const scoreUpdateTime = getInt(f, 5);
552
+ const giftSentTime = getInt(f, 6);
1793
553
  const itemBufs = getAllBytes(f, 3);
1794
554
  for (const ib of itemBufs) {
1795
555
  try {
@@ -1802,7 +562,10 @@ function parseWebcastMessage(method, payload) {
1802
562
  type: "battleArmies",
1803
563
  battleId,
1804
564
  teams,
1805
- status: battleStatus
565
+ status: battleStatus,
566
+ battleSettings,
567
+ scoreUpdateTime,
568
+ giftSentTime
1806
569
  };
1807
570
  }
1808
571
  case "WebcastSubNotifyMessage": {
@@ -2101,6 +864,8 @@ var TikTokLive = class extends EventEmitter {
2101
864
  _sessionId;
2102
865
  _ttTargetIdc;
2103
866
  proxyAgent;
867
+ _presetRoomId;
868
+ _presetTtwid;
2104
869
  constructor(options) {
2105
870
  super();
2106
871
  this.uniqueId = options.uniqueId.replace(/^@/, "");
@@ -2113,48 +878,54 @@ var TikTokLive = class extends EventEmitter {
2113
878
  this.debug = options.debug ?? false;
2114
879
  this._sessionId = options.sessionId;
2115
880
  this._ttTargetIdc = options.ttTargetIdc;
2116
- if (options.proxyUrl) {
2117
- this.proxyAgent = new import_https_proxy_agent.HttpsProxyAgent(options.proxyUrl);
881
+ if (options.agent) {
882
+ this.proxyAgent = options.agent;
2118
883
  }
884
+ this._presetRoomId = options.roomId;
885
+ this._presetTtwid = options.ttwid;
2119
886
  }
2120
887
  async connect() {
2121
888
  this.intentionalClose = false;
2122
- const resp = await httpGet(`https://www.tiktok.com/@${this.uniqueId}/live`, {
2123
- "User-Agent": DEFAULT_UA,
2124
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
2125
- "Accept-Encoding": "gzip, deflate, br",
2126
- "Accept-Language": "en-US,en;q=0.9"
2127
- }, this.proxyAgent);
2128
- let ttwid = "";
2129
- for (const sc of [resp.headers["set-cookie"] || []].flat()) {
2130
- if (typeof sc === "string" && sc.startsWith("ttwid=")) {
2131
- ttwid = sc.split(";")[0].split("=").slice(1).join("=");
2132
- break;
2133
- }
2134
- }
2135
- if (!ttwid) throw new Error("Failed to obtain session cookie");
2136
- const html = resp.body.toString();
2137
- let roomId = "";
889
+ let ttwid = this._presetTtwid || "";
890
+ let roomId = this._presetRoomId || "";
2138
891
  let ownerUserId = "";
2139
- const sigiMatch = html.match(/id="SIGI_STATE"[^>]*>([^<]+)/);
2140
- if (sigiMatch) {
2141
- try {
2142
- const json = JSON.parse(sigiMatch[1]);
2143
- const jsonStr = JSON.stringify(json);
2144
- const m = jsonStr.match(/"roomId"\s*:\s*"(\d+)"/);
2145
- if (m) roomId = m[1];
2146
- const ownerUser = json?.LiveRoom?.liveRoomUserInfo?.user;
2147
- if (ownerUser?.id) {
2148
- ownerUserId = String(ownerUser.id);
892
+ let clusterRegion = "";
893
+ if (!roomId || !ttwid) {
894
+ const targetUrl = `https://www.tiktok.com/@${this.uniqueId}/live`;
895
+ const resp = await httpGet(targetUrl, {
896
+ "User-Agent": DEFAULT_UA,
897
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
898
+ "Accept-Encoding": "gzip, deflate, br",
899
+ "Accept-Language": "en-US,en;q=0.9"
900
+ }, this.proxyAgent);
901
+ for (const sc of [resp.headers["set-cookie"] || []].flat()) {
902
+ if (typeof sc === "string" && sc.startsWith("ttwid=")) {
903
+ ttwid = sc.split(";")[0].split("=").slice(1).join("=");
904
+ break;
905
+ }
906
+ }
907
+ if (!ttwid) throw new Error("Failed to obtain session cookie");
908
+ const html = resp.body.toString();
909
+ const sigiMatch = html.match(/id="SIGI_STATE"[^>]*>([^<]+)/);
910
+ if (sigiMatch) {
911
+ try {
912
+ const json = JSON.parse(sigiMatch[1]);
913
+ const jsonStr = JSON.stringify(json);
914
+ const m = jsonStr.match(/"roomId"\s*:\s*"(\d+)"/);
915
+ if (m) roomId = m[1];
916
+ const ownerUser = json?.LiveRoom?.liveRoomUserInfo?.user;
917
+ if (ownerUser?.id) {
918
+ ownerUserId = String(ownerUser.id);
919
+ }
920
+ } catch {
2149
921
  }
2150
- } catch {
2151
922
  }
923
+ if (!roomId) throw new Error(`User @${this.uniqueId} is not currently live`);
924
+ const crMatch = html.match(/"clusterRegion"\s*:\s*"([^"]+)"/);
925
+ clusterRegion = crMatch ? crMatch[1] : "";
2152
926
  }
2153
- if (!roomId) throw new Error(`User @${this.uniqueId} is not currently live`);
2154
927
  this._roomId = roomId;
2155
928
  this._ownerUserId = ownerUserId;
2156
- const crMatch = html.match(/"clusterRegion"\s*:\s*"([^"]+)"/);
2157
- const clusterRegion = crMatch ? crMatch[1] : "";
2158
929
  const wsHost = getWsHost(clusterRegion);
2159
930
  const wsParams = new URLSearchParams({
2160
931
  version_code: "270000",
@@ -2208,9 +979,10 @@ var TikTokLive = class extends EventEmitter {
2208
979
  wsUrl = rawWsUrl.replace(/^https:\/\//, "wss://");
2209
980
  }
2210
981
  return new Promise((resolve, reject) => {
2211
- let cookieHeader = `ttwid=${ttwid}`;
982
+ let cookieHeader = ttwid ? `ttwid=${ttwid}` : "";
2212
983
  if (this._sessionId) {
2213
- cookieHeader += `; sessionid=${this._sessionId}; sessionid_ss=${this._sessionId}; sid_tt=${this._sessionId}`;
984
+ const sessionCookies = `sessionid=${this._sessionId}; sessionid_ss=${this._sessionId}; sid_tt=${this._sessionId}`;
985
+ cookieHeader = cookieHeader ? `${cookieHeader}; ${sessionCookies}` : sessionCookies;
2214
986
  if (this._ttTargetIdc) {
2215
987
  cookieHeader += `; tt-target-idc=${this._ttTargetIdc}`;
2216
988
  }