feat: 添加直播聊天功能与相关配置

- 在 LiveChatPanel.vue 中实现直播间聊天功能,支持发送和接收消息。
- 新增 useChat.js 组合式 API,管理聊天逻辑与状态。
- 更新 Live.vue 控制面板,集成聊天组件并优化直播状态显示。
- 更新 package.json 和 pnpm-lock.yaml,添加 @tencentcloud/chat 和 hls.js 依赖。
This commit is contained in:
Ryan Ran
2026-07-07 16:40:09 +08:00
parent 548335b658
commit 709d114986
9 changed files with 1113 additions and 65 deletions

View File

@@ -0,0 +1,44 @@
import { getSetting } from "@/api/index";
/** @type {Record<string, any> | null} */
let cachedSetting = null;
/** @type {Promise<Record<string, any> | null> | null} */
let fetchingPromise = null;
/** 获取直播配置(带缓存) */
export async function fetchLiveSetting(force = false) {
if (!force && cachedSetting) {
return cachedSetting;
}
if (!force && fetchingPromise) {
return fetchingPromise;
}
fetchingPromise = (async () => {
try {
const res = await getSetting("LIVE_SETTING");
if (res?.success && res?.result) {
cachedSetting = res.result;
return cachedSetting;
}
console.warn("获取直播配置失败", res);
return null;
} catch (error) {
console.error("获取直播配置异常:", error);
return null;
} finally {
fetchingPromise = null;
}
})();
return fetchingPromise;
}
/** 解析 IM SDK AppID */
export function resolveSdkAppId(setting) {
if (!setting?.imSdkAppid) {
return 0;
}
const id = Number(setting.imSdkAppid);
return Number.isNaN(id) ? 0 : id;
}