@tiktool/live 2.12.2 → 2.13.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/README.md +31 -30
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +146 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -475,6 +475,121 @@ var require_browser = __commonJS({
|
|
|
475
475
|
}
|
|
476
476
|
});
|
|
477
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
|
+
|
|
478
593
|
// node_modules/debug/src/node.js
|
|
479
594
|
var require_node = __commonJS({
|
|
480
595
|
"node_modules/debug/src/node.js"(exports, module) {
|
|
@@ -494,7 +609,7 @@ var require_node = __commonJS({
|
|
|
494
609
|
);
|
|
495
610
|
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
496
611
|
try {
|
|
497
|
-
const supportsColor =
|
|
612
|
+
const supportsColor = require_supports_color();
|
|
498
613
|
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
499
614
|
exports.colors = [
|
|
500
615
|
20,
|
|
@@ -1483,12 +1598,18 @@ function parseWebcastMessage(method, payload) {
|
|
|
1483
1598
|
}
|
|
1484
1599
|
}
|
|
1485
1600
|
let toUserId = "";
|
|
1601
|
+
const receiverBuf = getBytes(f, 8);
|
|
1602
|
+
if (receiverBuf) {
|
|
1603
|
+
const r = parseUser(receiverBuf);
|
|
1604
|
+
if (r.id && r.id !== "0") toUserId = r.id;
|
|
1605
|
+
}
|
|
1486
1606
|
const extraBuf = getBytes(f, 23);
|
|
1487
|
-
if (extraBuf) {
|
|
1488
|
-
const
|
|
1489
|
-
toUserId =
|
|
1607
|
+
if (!toUserId && extraBuf) {
|
|
1608
|
+
const id = getIntStr(decodeProto(extraBuf), 8);
|
|
1609
|
+
if (id !== "0") toUserId = id;
|
|
1490
1610
|
}
|
|
1491
|
-
const
|
|
1611
|
+
const rawGroup = getIntStr(f, 11);
|
|
1612
|
+
const groupId = getStr(f, 11) || (rawGroup !== "0" ? rawGroup : "");
|
|
1492
1613
|
return {
|
|
1493
1614
|
...base,
|
|
1494
1615
|
type: "gift",
|
|
@@ -1500,7 +1621,9 @@ function parseWebcastMessage(method, payload) {
|
|
|
1500
1621
|
repeatEnd,
|
|
1501
1622
|
combo: repeatCount > 1 && !repeatEnd,
|
|
1502
1623
|
giftType,
|
|
1503
|
-
groupId
|
|
1624
|
+
groupId,
|
|
1625
|
+
toUserId,
|
|
1626
|
+
receiverUserId: toUserId
|
|
1504
1627
|
};
|
|
1505
1628
|
}
|
|
1506
1629
|
// Proto: WebcastSocialMessage { User user=2, WebcastMessageEvent event=1 }
|
|
@@ -1526,7 +1649,7 @@ function parseWebcastMessage(method, payload) {
|
|
|
1526
1649
|
// Proto: WebcastRoomUserSeqMessage { int32 viewerCount=3 }
|
|
1527
1650
|
case "WebcastRoomUserSeqMessage": {
|
|
1528
1651
|
const viewerCount = getInt(f, 3) || getInt(f, 2);
|
|
1529
|
-
const totalViewers = getInt(f,
|
|
1652
|
+
const totalViewers = getInt(f, 7) || viewerCount;
|
|
1530
1653
|
return { ...base, type: "roomUserSeq", totalViewers, viewerCount };
|
|
1531
1654
|
}
|
|
1532
1655
|
// Proto: WebcastLinkMicBattle { repeated WebcastLinkMicBattleItems battleUsers=10 }
|
|
@@ -2040,6 +2163,11 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
|
|
|
2040
2163
|
if (this._destroyed) throw new Error("Client has been destroyed. Create a new instance.");
|
|
2041
2164
|
this.intentionalClose = false;
|
|
2042
2165
|
if (this.mode === "relayed") {
|
|
2166
|
+
if (this._presetRoomId) {
|
|
2167
|
+
console.warn(
|
|
2168
|
+
`[TikTokLive] roomId=${this._presetRoomId} is ignored in mode:'relayed' - the managed relay resolves the room itself. Use mode:'direct' with roomId to pin an exact room (resolve it first via /webcast/bulk_live_check).`
|
|
2169
|
+
);
|
|
2170
|
+
}
|
|
2043
2171
|
return this._connectRelayed();
|
|
2044
2172
|
}
|
|
2045
2173
|
let ttwid = this._presetSessionId;
|
|
@@ -2475,6 +2603,9 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
|
|
|
2475
2603
|
}
|
|
2476
2604
|
this.emit("event", evt);
|
|
2477
2605
|
this.emit(evt.type, evt);
|
|
2606
|
+
if (evt.type === "control" && evt.action === 3) {
|
|
2607
|
+
this.emit("streamEnd", { type: "streamEnd", uniqueId: this.uniqueId, reason: "creator_offline" });
|
|
2608
|
+
}
|
|
2478
2609
|
}
|
|
2479
2610
|
}
|
|
2480
2611
|
} catch {
|
|
@@ -2484,8 +2615,12 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
|
|
|
2484
2615
|
* Resolve unknown host user IDs via the sign server API.
|
|
2485
2616
|
* Caches results and re-emits the battleArmies event with enriched hostUser data.
|
|
2486
2617
|
*/
|
|
2618
|
+
// Set once the sign server refuses host resolution for this key (tier below
|
|
2619
|
+
// Basic answers 403). Before this, every battle frame retried and filled the
|
|
2620
|
+
// customer's API log with 403s they never asked for.
|
|
2621
|
+
_hostResolveUnavailable = false;
|
|
2487
2622
|
async resolveHostUsers(userIds, originalEvt) {
|
|
2488
|
-
const toResolve = userIds.filter((id) => !this._pendingHostResolves.has(id));
|
|
2623
|
+
const toResolve = this._hostResolveUnavailable ? [] : userIds.filter((id) => !this._pendingHostResolves.has(id));
|
|
2489
2624
|
if (toResolve.length === 0) {
|
|
2490
2625
|
this.emit("event", originalEvt);
|
|
2491
2626
|
this.emit(originalEvt.type, originalEvt);
|
|
@@ -2503,7 +2638,9 @@ var TikTokLive = class _TikTokLive extends EventEmitter {
|
|
|
2503
2638
|
body: JSON.stringify({ user_ids: toResolve }),
|
|
2504
2639
|
signal: AbortSignal.timeout(5e3)
|
|
2505
2640
|
});
|
|
2506
|
-
if (res.
|
|
2641
|
+
if (res.status === 401 || res.status === 403) {
|
|
2642
|
+
this._hostResolveUnavailable = true;
|
|
2643
|
+
} else if (res.ok) {
|
|
2507
2644
|
const json = await res.json();
|
|
2508
2645
|
if (json.data) {
|
|
2509
2646
|
for (const [uid, info] of Object.entries(json.data)) {
|