@bilicli/live-full
Version:
Bili-Live danmu client
1,094 lines (1,072 loc) • 44 kB
JavaScript
// src/index.ts
import { render } from "@temir/core";
import { h } from "vue";
// vue:./App.vue
import { defineComponent as _defineComponent13 } from "vue";
import { createVNode as _createVNode13, unref as _unref13, withCtx as _withCtx13, renderList as _renderList2, Fragment as _Fragment3, openBlock as _openBlock13, createElementBlock as _createElementBlock3, createBlock as _createBlock13, createCommentVNode as _createCommentVNode6 } from "vue";
import { provide, onMounted, ref as ref3 } from "vue";
import { startListen } from "blive-message-listener";
import { TBox as TBox13 } from "@temir/core";
// src/utils/getInfo.ts
import { $fetch } from "ohmyfetch";
var getRoomInfo = async (roomId) => {
const url = `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomId}`;
const response = await $fetch(url);
return response.code === 0 ? response.data : null;
};
// src/utils/readline.ts
import readline from "readline";
var listenQuitCommand = () => {
let rl = readline.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
readline.emitKeypressEvents(process.stdin, rl);
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
function keypressHandler(str, key) {
if (str === "" || str === "\x1B" || key && key.ctrl && key.name === "c") {
return process.exit();
}
const name = key == null ? void 0 : key.name;
if (name === "q") {
return process.exit();
}
}
process.stdin.on("keypress", keypressHandler);
};
// vue:./components/CliHeader.vue
import { defineComponent as _defineComponent } from "vue";
import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, unref as _unref, withCtx as _withCtx, createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode } from "vue";
import { TBox, TText } from "@temir/core";
var __sfc_main = /* @__PURE__ */ _defineComponent({
props: {
roomInfo: { type: null, required: true }
},
setup(__props) {
const { roomInfo } = __props;
return (_ctx, _cache) => {
return _openBlock(), _createBlock(_unref(TBox), {
width: "100%",
"padding-left": 1,
"padding-right": 2,
"border-style": "single",
"justify-content": "space-between"
}, {
default: _withCtx(() => [
_createVNode(_unref(TBox), null, {
default: _withCtx(() => [
__props.roomInfo ? (_openBlock(), _createBlock(_unref(TBox), { key: 0 }, {
default: _withCtx(() => [
_createVNode(_unref(TText), {
color: "green",
bold: ""
}, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(__props.roomInfo.short_id || __props.roomInfo.room_id), 1)
]),
_: 1
}),
_createVNode(_unref(TBox), { "margin-x": 1 }, {
default: _withCtx(() => [
_createVNode(_unref(TText), { color: "green" }, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(`(${__props.roomInfo.parent_area_name}\xB7${__props.roomInfo.area_name})`), 1)
]),
_: 1
})
]),
_: 1
}),
_createVNode(_unref(TText), null, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(__props.roomInfo.title), 1)
]),
_: 1
})
]),
_: 1
})) : _createCommentVNode("v-if", true)
]),
_: 1
})
]),
_: 1
});
};
}
});
var CliHeader_default = __sfc_main;
// vue:./components/CliFooter.vue
import { defineComponent as _defineComponent4 } from "vue";
import { openBlock as _openBlock4, createBlock as _createBlock4, createCommentVNode as _createCommentVNode3, unref as _unref4, withCtx as _withCtx4, createVNode as _createVNode4, createTextVNode as _createTextVNode4, toDisplayString as _toDisplayString4, Fragment as _Fragment, createElementBlock as _createElementBlock } from "vue";
import { ref, watch } from "vue";
import { TBox as TBox4, TText as TText4 } from "@temir/core";
import dayjs from "dayjs";
// vue:./msgCom/UserActionMsgCom.vue
import { defineComponent as _defineComponent3 } from "vue";
import { createVNode as _createVNode3, toDisplayString as _toDisplayString3, createTextVNode as _createTextVNode3, unref as _unref3, withCtx as _withCtx3, openBlock as _openBlock3, createBlock as _createBlock3 } from "vue";
import { TBox as TBox3, TText as TText3 } from "@temir/core";
// vue:../UserName.vue
import { defineComponent as _defineComponent2 } from "vue";
import { unref as _unref2, toDisplayString as _toDisplayString2, createTextVNode as _createTextVNode2, withCtx as _withCtx2, createVNode as _createVNode2, openBlock as _openBlock2, createBlock as _createBlock2, createCommentVNode as _createCommentVNode2 } from "vue";
import { inject, computed } from "vue";
import { TBox as TBox2, TText as TText2 } from "@temir/core";
// src/utils/format.ts
var addSpace = (str) => {
return " " + str + " ";
};
var getGuardColor = (level = 0) => {
const colorDict = ["#967E76", "#FF7C28", "#E17AFF", "#00D1F1"];
return colorDict[level];
};
// vue:../UserName.vue
var __sfc_main2 = /* @__PURE__ */ _defineComponent2({
props: {
userInfo: { type: null, required: true }
},
setup(__props) {
const { userInfo } = __props;
const options = inject("options");
const badgeColor = computed(() => {
var _a;
if ((_a = userInfo.badge) == null ? void 0 : _a.anchor.is_same_room) {
return userInfo.badge.color;
}
return "#666666";
});
return (_ctx, _cache) => {
return _openBlock2(), _createBlock2(_unref2(TBox2), { "flex-shrink": 0 }, {
default: _withCtx2(() => {
var _a;
return [
_createVNode2(_unref2(TBox2), null, {
default: _withCtx2(() => [
_unref2(options).badge && __props.userInfo.badge && __props.userInfo.badge.active ? (_openBlock2(), _createBlock2(_unref2(TBox2), {
key: 0,
"margin-right": 1
}, {
default: _withCtx2(() => [
_createVNode2(_unref2(TText2), {
"background-color": _unref2(badgeColor),
"flex-shrink": 0
}, {
default: _withCtx2(() => [
_createTextVNode2(_toDisplayString2(_unref2(addSpace)(__props.userInfo.badge.name)), 1)
]),
_: 1
}, 8, ["background-color"]),
_createVNode2(_unref2(TText2), {
color: _unref2(badgeColor),
"background-color": "#ffffff"
}, {
default: _withCtx2(() => [
_createTextVNode2(_toDisplayString2(_unref2(addSpace)(__props.userInfo.badge.level.toString())), 1)
]),
_: 1
}, 8, ["color"])
]),
_: 1
})) : _createCommentVNode2("v-if", true)
]),
_: 1
}),
_createVNode2(_unref2(TText2), { "background-color": "blue" }, {
default: _withCtx2(() => {
var _a2;
return [
_createTextVNode2(_toDisplayString2(_unref2(options).rank && ((_a2 = __props.userInfo.identity) == null ? void 0 : _a2.rank) ? ` \u699C${__props.userInfo.identity.rank} ` : ""), 1)
];
}),
_: 1
}),
_createVNode2(_unref2(TText2), { "background-color": "red" }, {
default: _withCtx2(() => {
var _a2;
return [
_createTextVNode2(_toDisplayString2(((_a2 = __props.userInfo.identity) == null ? void 0 : _a2.room_admin) ? "\u623F" : ""), 1)
];
}),
_: 1
}),
_createVNode2(_unref2(TText2), {
bold: "",
color: _unref2(getGuardColor)((_a = __props.userInfo.identity) == null ? void 0 : _a.guard_level)
}, {
default: _withCtx2(() => [
_createTextVNode2(_toDisplayString2(__props.userInfo.uname), 1)
]),
_: 1
}, 8, ["color"]),
_createVNode2(_unref2(TText2), null, {
default: _withCtx2(() => [
_createTextVNode2(": ")
]),
_: 1
})
];
}),
_: 1
});
};
}
});
var UserName_default = __sfc_main2;
// vue:./msgCom/UserActionMsgCom.vue
var __sfc_main3 = /* @__PURE__ */ _defineComponent3({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
const typeDict = {
enter: "\u8FDB\u5165",
follow: "\u5173\u6CE8",
share: "\u5206\u4EAB",
unknown: "-"
};
return (_ctx, _cache) => {
return _openBlock3(), _createBlock3(_unref3(TBox3), null, {
default: _withCtx3(() => [
_createVNode3(_unref3(TBox3), null, {
default: _withCtx3(() => [
_createVNode3(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode3(_unref3(TText3), null, {
default: _withCtx3(() => [
_createTextVNode3(_toDisplayString3(typeDict[__props.msg.action]), 1)
]),
_: 1
}),
_createVNode3(_unref3(TText3), null, {
default: _withCtx3(() => [
_createTextVNode3("\u76F4\u64AD\u95F4")
]),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var UserActionMsgCom_default = __sfc_main3;
// vue:./components/CliFooter.vue
var __sfc_main4 = /* @__PURE__ */ _defineComponent4({
props: {
newestWatcher: { type: null, required: true },
liveStatus: { type: Object, required: true },
watchers: { type: Number, required: true },
attention: { type: Number, required: true }
},
setup(__props) {
const props = __props;
const watchersHighlight = ref(false);
const attentionHighlight = ref(false);
const timer = ref(0);
const timeText = ref(" ");
watch(() => [props.liveStatus.isLive, props.liveStatus.startTime], () => {
if (!props.liveStatus.isLive) {
clearInterval(timer.value);
return;
}
timer.value = 0;
clearInterval(timer.value);
timer.value = setInterval(() => {
const liveSeconds = dayjs().diff(props.liveStatus.startTime, "second");
timeText.value = formatSeconds(liveSeconds);
}, 1e3);
});
watch(() => props.watchers, () => {
watchersHighlight.value = true;
setTimeout(() => {
watchersHighlight.value = false;
}, 1e3);
});
watch(() => props.attention, () => {
attentionHighlight.value = true;
setTimeout(() => {
attentionHighlight.value = false;
}, 1e3);
});
const formatSeconds = (seconds) => {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds - hours * 3600) / 60);
const secs = seconds - hours * 3600 - minutes * 60;
const formatH = hours ? `${hours}` : "";
const formatM = hours ? minutes < 10 ? `0${minutes}` : `${minutes}` : `${minutes}`;
const formatS = secs < 10 ? `0${secs}` : `${secs}`;
return `${formatH ? `${formatH}:` : ""}${formatM}:${formatS}`;
};
return (_ctx, _cache) => {
return _openBlock4(), _createBlock4(_unref4(TBox4), {
width: "100%",
"padding-left": 1,
"padding-right": 2,
"border-style": "single",
"justify-content": "space-between"
}, {
default: _withCtx4(() => [
_createVNode4(_unref4(TBox4), null, {
default: _withCtx4(() => [
props.newestWatcher ? (_openBlock4(), _createBlock4(UserActionMsgCom_default, {
msg: props.newestWatcher.body,
key: props.newestWatcher.id
}, null, 8, ["msg"])) : _createCommentVNode3("v-if", true)
]),
_: 1
}),
_createVNode4(_unref4(TBox4), null, {
default: _withCtx4(() => [
_createVNode4(_unref4(TBox4), null, {
default: _withCtx4(() => [
__props.liveStatus ? (_openBlock4(), _createBlock4(_unref4(TBox4), { key: 0 }, {
default: _withCtx4(() => [
_createVNode4(_unref4(TBox4), null, {
default: _withCtx4(() => [
__props.liveStatus.isLive ? (_openBlock4(), _createBlock4(_unref4(TText4), { key: 0 }, {
default: _withCtx4(() => [
_createTextVNode4("\u{1F534}")
]),
_: 1
})) : (_openBlock4(), _createBlock4(_unref4(TText4), { key: 1 }, {
default: _withCtx4(() => [
_createTextVNode4("\u26AB\uFE0F")
]),
_: 1
}))
]),
_: 1
}),
_createVNode4(_unref4(TBox4), null, {
default: _withCtx4(() => [
__props.liveStatus.startTime ? (_openBlock4(), _createElementBlock(_Fragment, { key: 0 }, [
_createVNode4(_unref4(TText4), null, {
default: _withCtx4(() => [
_createTextVNode4(_toDisplayString4(timeText.value), 1)
]),
_: 1
}),
_createVNode4(_unref4(TText4), null, {
default: _withCtx4(() => [
_createTextVNode4(" (Start at " + _toDisplayString4(_unref4(dayjs)(__props.liveStatus.startTime).format("HH:mm")) + ") ", 1)
]),
_: 1
})
], 64)) : _createCommentVNode3("v-if", true)
]),
_: 1
})
]),
_: 1
})) : _createCommentVNode3("v-if", true)
]),
_: 1
}),
_createVNode4(_unref4(TText4), {
"background-color": watchersHighlight.value ? "green" : "black"
}, {
default: _withCtx4(() => [
_createTextVNode4(_toDisplayString4(` \u{1F440}${props.watchers} `), 1)
]),
_: 1
}, 8, ["background-color"]),
_createVNode4(_unref4(TText4), {
"background-color": attentionHighlight.value ? "green" : "black"
}, {
default: _withCtx4(() => [
_createTextVNode4(_toDisplayString4(` \u{1F525}${props.attention} `), 1)
]),
_: 1
}, 8, ["background-color"])
]),
_: 1
})
]),
_: 1
});
};
}
});
var CliFooter_default = __sfc_main4;
// vue:./components/TabSelector.vue
import { defineComponent as _defineComponent5 } from "vue";
import { renderList as _renderList, Fragment as _Fragment2, openBlock as _openBlock5, createElementBlock as _createElementBlock2, toDisplayString as _toDisplayString5, createTextVNode as _createTextVNode5, unref as _unref5, withCtx as _withCtx5, createVNode as _createVNode5, createBlock as _createBlock5 } from "vue";
import { ref as ref2 } from "vue";
import { TBox as TBox5 } from "@temir/core";
import { TTab, TTabs } from "@temir/tab";
var __sfc_main5 = /* @__PURE__ */ _defineComponent5({
emits: ["change"],
setup(__props, { emit }) {
const tabs = ["ALL", "\u5F39\u5E55", "SC", "\u793C\u7269", "\u4E0A\u8230", "\u7528\u6237"];
const activeIndex = ref2(0);
const handleTabChange = (index) => {
activeIndex.value = +index;
emit("change", parseInt(index));
};
return (_ctx, _cache) => {
return _openBlock5(), _createBlock5(_unref5(TBox5), null, {
default: _withCtx5(() => [
_createVNode5(_unref5(TTabs), {
"flex-direction": "column",
"on-change": handleTabChange
}, {
default: _withCtx5(() => [
(_openBlock5(), _createElementBlock2(_Fragment2, null, _renderList(tabs, (item) => {
return _createVNode5(_unref5(TTab), { key: item }, {
default: _withCtx5(() => [
_createTextVNode5(_toDisplayString5(item), 1)
]),
_: 2
}, 1024);
}), 64))
]),
_: 1
})
]),
_: 1
});
};
}
});
var TabSelector_default = __sfc_main5;
// vue:./components/MsgTime.vue
import { defineComponent as _defineComponent6 } from "vue";
import { unref as _unref6, toDisplayString as _toDisplayString6, createTextVNode as _createTextVNode6, withCtx as _withCtx6, createVNode as _createVNode6, openBlock as _openBlock6, createBlock as _createBlock6 } from "vue";
import { TBox as TBox6, TText as TText6 } from "@temir/core";
import dayjs2 from "dayjs";
var __sfc_main6 = /* @__PURE__ */ _defineComponent6({
props: {
timestamp: { type: Number, required: true }
},
setup(__props) {
const { timestamp } = __props;
return (_ctx, _cache) => {
return _openBlock6(), _createBlock6(_unref6(TBox6), { "margin-right": 1 }, {
default: _withCtx6(() => [
_createVNode6(_unref6(TText6), { color: "#666666" }, {
default: _withCtx6(() => [
_createTextVNode6(_toDisplayString6(_unref6(dayjs2)(__props.timestamp).format("HH:mm:ss")), 1)
]),
_: 1
})
]),
_: 1
});
};
}
});
var MsgTime_default = __sfc_main6;
// vue:./components/MsgType.vue
import { defineComponent as _defineComponent7 } from "vue";
import { toDisplayString as _toDisplayString7, createTextVNode as _createTextVNode7, unref as _unref7, withCtx as _withCtx7, createVNode as _createVNode7, openBlock as _openBlock7, createBlock as _createBlock7 } from "vue";
import { TBox as TBox7, TText as TText7 } from "@temir/core";
var __sfc_main7 = /* @__PURE__ */ _defineComponent7({
props: {
type: { type: String, required: true }
},
setup(__props) {
const { type } = __props;
const typeDict = {
DANMU_MSG: "\u5F39\u5E55",
SUPER_CHAT_MESSAGE: "SC",
SEND_GIFT: "\u793C\u7269",
GUARD_BUY: "\u4E0A\u8230",
INTERACT_WORD: "\u8FDB\u573A",
ENTRY_EFFECT: "\u8FDB\u573A"
};
return (_ctx, _cache) => {
return _openBlock7(), _createBlock7(_unref7(TBox7), { "margin-right": 1 }, {
default: _withCtx7(() => [
_createVNode7(_unref7(TText7), { color: "yellow" }, {
default: _withCtx7(() => [
_createTextVNode7("[" + _toDisplayString7(typeDict[__props.type]) + "]", 1)
]),
_: 1
})
]),
_: 1
});
};
}
});
var MsgType_default = __sfc_main7;
// vue:./components/msgCom/DanmuMsgCom.vue
import { defineComponent as _defineComponent8 } from "vue";
import { createVNode as _createVNode8, createTextVNode as _createTextVNode8, unref as _unref8, withCtx as _withCtx8, openBlock as _openBlock8, createBlock as _createBlock8, createCommentVNode as _createCommentVNode4, toDisplayString as _toDisplayString8 } from "vue";
import { TBox as TBox8, TText as TText8 } from "@temir/core";
var __sfc_main8 = /* @__PURE__ */ _defineComponent8({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
return (_ctx, _cache) => {
return _openBlock8(), _createBlock8(_unref8(TBox8), null, {
default: _withCtx8(() => [
_createVNode8(_unref8(TBox8), null, {
default: _withCtx8(() => [
_createVNode8(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode8(_unref8(TBox8), { "flex-glow": 1 }, {
default: _withCtx8(() => [
__props.msg.lottery ? (_openBlock8(), _createBlock8(_unref8(TText8), {
key: 0,
color: "yellow"
}, {
default: _withCtx8(() => [
_createTextVNode8("[\u62BD\u5956] ")
]),
_: 1
})) : _createCommentVNode4("v-if", true),
__props.msg.emoticon ? (_openBlock8(), _createBlock8(_unref8(TText8), {
key: 1,
color: "yellow"
}, {
default: _withCtx8(() => [
_createTextVNode8("[\u8868\u60C5] ")
]),
_: 1
})) : _createCommentVNode4("v-if", true),
_createVNode8(_unref8(TText8), null, {
default: _withCtx8(() => [
_createTextVNode8(_toDisplayString8(__props.msg.content), 1)
]),
_: 1
})
]),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var DanmuMsgCom_default = __sfc_main8;
// vue:./components/msgCom/SuperChatMsgCom.vue
import { defineComponent as _defineComponent9 } from "vue";
import { createVNode as _createVNode9, toDisplayString as _toDisplayString9, createTextVNode as _createTextVNode9, unref as _unref9, withCtx as _withCtx9, openBlock as _openBlock9, createBlock as _createBlock9 } from "vue";
import { TBox as TBox9, TText as TText9 } from "@temir/core";
var __sfc_main9 = /* @__PURE__ */ _defineComponent9({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
return (_ctx, _cache) => {
return _openBlock9(), _createBlock9(_unref9(TBox9), null, {
default: _withCtx9(() => [
_createVNode9(_unref9(TBox9), null, {
default: _withCtx9(() => [
_createVNode9(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode9(_unref9(TBox9), { "flex-glow": 1 }, {
default: _withCtx9(() => [
_createVNode9(_unref9(TText9), null, {
default: _withCtx9(() => [
_createTextVNode9("(\xA5" + _toDisplayString9(__props.msg.price) + ") ", 1)
]),
_: 1
}),
_createVNode9(_unref9(TText9), {
color: __props.msg.content_color
}, {
default: _withCtx9(() => [
_createTextVNode9(_toDisplayString9(__props.msg.content), 1)
]),
_: 1
}, 8, ["color"])
]),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var SuperChatMsgCom_default = __sfc_main9;
// vue:./components/msgCom/GiftMsgCom.vue
import { defineComponent as _defineComponent10 } from "vue";
import { createVNode as _createVNode10, createTextVNode as _createTextVNode10, unref as _unref10, withCtx as _withCtx10, toDisplayString as _toDisplayString10, openBlock as _openBlock10, createBlock as _createBlock10, createCommentVNode as _createCommentVNode5 } from "vue";
import { TBox as TBox10, TText as TText10 } from "@temir/core";
var __sfc_main10 = /* @__PURE__ */ _defineComponent10({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
return (_ctx, _cache) => {
return _openBlock10(), _createBlock10(_unref10(TBox10), null, {
default: _withCtx10(() => [
_createVNode10(_unref10(TBox10), null, {
default: _withCtx10(() => [
_createVNode10(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode10(_unref10(TBox10), null, {
default: _withCtx10(() => {
var _a;
return [
_createVNode10(_unref10(TText10), null, {
default: _withCtx10(() => [
_createTextVNode10("\u8D60\u9001\u4E86")
]),
_: 1
}),
_createVNode10(_unref10(TText10), null, {
default: _withCtx10(() => [
_createVNode10(_unref10(TText10), { color: "magenta" }, {
default: _withCtx10(() => [
_createTextVNode10(" (\xA5" + _toDisplayString10(__props.msg.price / 1e3) + ") ", 1)
]),
_: 1
}),
_createVNode10(_unref10(TText10), { color: "magenta" }, {
default: _withCtx10(() => [
_createTextVNode10(_toDisplayString10(__props.msg.gift_name), 1)
]),
_: 1
}),
_createVNode10(_unref10(TText10), null, {
default: _withCtx10(() => [
_createTextVNode10(" * " + _toDisplayString10(__props.msg.amount), 1)
]),
_: 1
})
]),
_: 1
}),
((_a = __props.msg.send_master) == null ? void 0 : _a.uname) ? (_openBlock10(), _createBlock10(_unref10(TText10), { key: 0 }, {
default: _withCtx10(() => [
_createVNode10(_unref10(TText10), null, {
default: _withCtx10(() => [
_createTextVNode10(" \u7ED9 ")
]),
_: 1
}),
_createVNode10(_unref10(TText10), {
color: "magenta",
dimColor: ""
}, {
default: _withCtx10(() => [
_createTextVNode10(_toDisplayString10(__props.msg.send_master.uname), 1)
]),
_: 1
})
]),
_: 1
})) : _createCommentVNode5("v-if", true)
];
}),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var GiftMsgCom_default = __sfc_main10;
// vue:./components/msgCom/GuardBuyMsgCom.vue
import { defineComponent as _defineComponent11 } from "vue";
import { createVNode as _createVNode11, toDisplayString as _toDisplayString11, createTextVNode as _createTextVNode11, unref as _unref11, withCtx as _withCtx11, openBlock as _openBlock11, createBlock as _createBlock11 } from "vue";
import { TBox as TBox11, TText as TText11 } from "@temir/core";
var __sfc_main11 = /* @__PURE__ */ _defineComponent11({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
return (_ctx, _cache) => {
return _openBlock11(), _createBlock11(_unref11(TBox11), null, {
default: _withCtx11(() => [
_createVNode11(_unref11(TBox11), null, {
default: _withCtx11(() => [
_createVNode11(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode11(_unref11(TBox11), null, {
default: _withCtx11(() => [
_createVNode11(_unref11(TText11), null, {
default: _withCtx11(() => [
_createTextVNode11("(\xA5" + _toDisplayString11(__props.msg.price / 1e3) + ") ", 1)
]),
_: 1
}),
_createVNode11(_unref11(TText11), {
bold: "",
color: _unref11(getGuardColor)(__props.msg.guard_level)
}, {
default: _withCtx11(() => [
_createTextVNode11(_toDisplayString11(__props.msg.gift_name), 1)
]),
_: 1
}, 8, ["color"])
]),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var GuardBuyMsgCom_default = __sfc_main11;
// vue:./components/msgCom/UserActionMsgCom.vue
import { defineComponent as _defineComponent12 } from "vue";
import { createVNode as _createVNode12, toDisplayString as _toDisplayString12, createTextVNode as _createTextVNode12, unref as _unref12, withCtx as _withCtx12, openBlock as _openBlock12, createBlock as _createBlock12 } from "vue";
import { TBox as TBox12, TText as TText12 } from "@temir/core";
var __sfc_main12 = /* @__PURE__ */ _defineComponent12({
props: {
msg: { type: null, required: true }
},
setup(__props) {
const { msg } = __props;
const typeDict = {
enter: "\u8FDB\u5165",
follow: "\u5173\u6CE8",
share: "\u5206\u4EAB",
unknown: "-"
};
return (_ctx, _cache) => {
return _openBlock12(), _createBlock12(_unref12(TBox12), null, {
default: _withCtx12(() => [
_createVNode12(_unref12(TBox12), null, {
default: _withCtx12(() => [
_createVNode12(UserName_default, {
userInfo: __props.msg.user
}, null, 8, ["userInfo"]),
_createVNode12(_unref12(TText12), null, {
default: _withCtx12(() => [
_createTextVNode12(_toDisplayString12(typeDict[__props.msg.action]), 1)
]),
_: 1
}),
_createVNode12(_unref12(TText12), null, {
default: _withCtx12(() => [
_createTextVNode12("\u76F4\u64AD\u95F4")
]),
_: 1
})
]),
_: 1
})
]),
_: 1
});
};
}
});
var UserActionMsgCom_default2 = __sfc_main12;
// vue:./App.vue
var __sfc_main13 = /* @__PURE__ */ _defineComponent13({
props: {
roomId: { type: Number, required: true },
roomInfo: { type: null, required: true },
options: { type: null, required: true }
},
setup(__props) {
const props = __props;
const currentRoomInfo = ref3(props.roomInfo);
const liveStatus = ref3({
isLive: false,
startTime: ""
});
const watchers = ref3(0);
const attention = ref3(0);
const selectedTab = ref3(0);
const contentHeight = process.stdout.rows - 9 || 14;
const allList = ref3([]);
const danmuList = ref3([]);
const superChatList = ref3([]);
const giftList = ref3([]);
const guardBuyList = ref3([]);
const userActionList = ref3([]);
provide("options", props.options);
onMounted(async () => {
listenQuitCommand();
const roomInfo = await getRoomInfo(props.roomId);
if (!roomInfo) {
console.log("\u623F\u95F4\u4E0D\u5B58\u5728");
return process.exit(1);
}
currentRoomInfo.value = roomInfo;
liveStatus.value = {
isLive: roomInfo.live_status === 1,
startTime: roomInfo.live_time
};
try {
const handler = {
onAttentionChange: ({ body }) => {
attention.value = body.attention;
},
onWatchedChange: ({ body }) => {
watchers.value = body.num;
},
onLiveStart: async ({ body }) => {
const roomInfo2 = await getRoomInfo(props.roomId);
if (roomInfo2) {
liveStatus.value = {
isLive: roomInfo2.live_status === 1,
startTime: roomInfo2.live_time
};
}
},
onLiveEnd: () => {
liveStatus.value.isLive = false;
},
onIncomeDanmu: (msg) => {
if (msg.body.lottery)
return;
allList.value.push(msg);
danmuList.value.push(msg);
},
onIncomeSuperChat: (msg) => {
allList.value.push(msg);
superChatList.value.push(msg);
},
onGift: (msg) => {
allList.value.push(msg);
giftList.value.push(msg);
},
onGuardBuy: (msg) => {
allList.value.push(msg);
guardBuyList.value.push(msg);
},
onUserAction: (msg) => {
userActionList.value.push(msg);
}
};
startListen(roomInfo.room_id, handler);
} catch (error) {
console.error(error);
}
});
const handleTabChange = (index) => {
selectedTab.value = index;
};
return (_ctx, _cache) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), {
"flex-direction": "column",
height: "100%"
}, {
default: _withCtx13(() => [
_createVNode13(CliHeader_default, { roomInfo: currentRoomInfo.value }, null, 8, ["roomInfo"]),
_createVNode13(_unref13(TBox13), { "flex-grow": 1 }, {
default: _withCtx13(() => [
_createVNode13(_unref13(TBox13), {
"flex-direction": "column",
"border-style": "single"
}, {
default: _withCtx13(() => [
_createVNode13(TabSelector_default, { onChange: handleTabChange })
]),
_: 1
}),
_createVNode13(_unref13(TBox13), {
"flex-grow": 1,
width: "100%",
height: _unref13(contentHeight) + 2,
"border-style": "single"
}, {
default: _withCtx13(() => [
selectedTab.value === 1 ? (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 0,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(danmuList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
(_openBlock13(), _createBlock13(DanmuMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"]))
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
})) : selectedTab.value === 2 ? (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 1,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(superChatList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
(_openBlock13(), _createBlock13(SuperChatMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"]))
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
})) : selectedTab.value === 3 ? (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 2,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(giftList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
(_openBlock13(), _createBlock13(GiftMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"]))
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
})) : selectedTab.value === 4 ? (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 3,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(guardBuyList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
(_openBlock13(), _createBlock13(GuardBuyMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"]))
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
})) : selectedTab.value === 5 ? (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 4,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(userActionList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
(_openBlock13(), _createBlock13(UserActionMsgCom_default2, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"]))
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
})) : (_openBlock13(), _createBlock13(_unref13(TBox13), {
key: 5,
"flex-direction": "column"
}, {
default: _withCtx13(() => [
(_openBlock13(true), _createElementBlock3(_Fragment3, null, _renderList2(allList.value.slice(-_unref13(contentHeight)), (msg) => {
return _openBlock13(), _createBlock13(_unref13(TBox13), { "flex-direction": "row" }, {
default: _withCtx13(() => [
_createVNode13(MsgTime_default, {
timestamp: msg.timestamp
}, null, 8, ["timestamp"]),
_createVNode13(MsgType_default, {
type: msg.type
}, null, 8, ["type"]),
msg.type === "DANMU_MSG" ? (_openBlock13(), _createBlock13(DanmuMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"])) : msg.type === "SUPER_CHAT_MESSAGE" ? (_openBlock13(), _createBlock13(SuperChatMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"])) : msg.type === "SEND_GIFT" ? (_openBlock13(), _createBlock13(GiftMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"])) : msg.type === "GUARD_BUY" ? (_openBlock13(), _createBlock13(GuardBuyMsgCom_default, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"])) : msg.type === "INTERACT_WORD" || msg.type === "ENTRY_EFFECT" ? (_openBlock13(), _createBlock13(UserActionMsgCom_default2, {
msg: msg.body,
key: msg.id
}, null, 8, ["msg"])) : _createCommentVNode6("v-if", true)
]),
_: 2
}, 1024);
}), 256))
]),
_: 1
}))
]),
_: 1
}, 8, ["height"])
]),
_: 1
}),
_createVNode13(CliFooter_default, {
liveStatus: liveStatus.value,
newestWatcher: userActionList.value[userActionList.value.length - 1],
watchers: watchers.value,
attention: attention.value
}, null, 8, ["liveStatus", "newestWatcher", "watchers", "attention"])
]),
_: 1
});
};
}
});
var App_default = __sfc_main13;
// src/index.ts
var startApp = async (roomId, options) => {
const roomInfo = await getRoomInfo(roomId);
if (!roomInfo) {
console.log("\u623F\u95F4\u4E0D\u5B58\u5728");
return process.exit(1);
}
const NewApp = {
render() {
return h(App_default, {
roomId,
roomInfo,
options
});
}
};
render(NewApp);
};
export {
startApp
};