M002: harden session lifecycle and directory sync

This commit is contained in:
illusia committed 2026-09-01 16:52:26 +08:00
1 parent 4a5d1ca0da
commit 8c7a940de5
11 files changed
+615 -153

No files matched your search

+21 -5
View File
@@ -461,7 +461,7 @@ export function useVoiceWebSocket() {
state.error = "TeamSpeak 连接已断开";
break;
case "error":
state.error = String(msg.message || "操作失败");
state.error = protocolErrorMessage(String(msg.error?.code || ""), String(msg.error?.message || msg.message || "操作失败"));
break;
}
}
@@ -474,18 +474,18 @@ export function useVoiceWebSocket() {
playAudioFrame(clientId, data.slice(3));
}
function sendCmd(command: Record<string, unknown>): void {
if (ws.value?.readyState === WebSocket.OPEN) ws.value.send(JSON.stringify(command));
function sendCmd(type: string, payload: Record<string, unknown> = {}): void {
if (ws.value?.readyState === WebSocket.OPEN) ws.value.send(JSON.stringify({ type, payload }));
}
function switchChannel(channelId: string): void {
sendCmd({ type: "switchChannel", channelId });
sendCmd("switchChannel", { channelId });
}
function sendTextMessage(message: string): void {
const trimmed = message.trim();
if (!trimmed || trimmed.length > 500) return;
sendCmd({ type: "sendTextMessage", message: trimmed });
sendCmd("sendTextMessage", { message: trimmed });
chatMessages.push({
id: `self-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
invokerName: "你",
@@ -508,6 +508,22 @@ export function useVoiceWebSocket() {
state.error = "";
}
function protocolErrorMessage(code: string, fallback: string): string {
const messages: Record<string, string> = {
INVALID_JSON: "消息格式无效",
INVALID_MESSAGE: "消息格式无效",
INVALID_REQUEST_ID: "请求标识无效",
UNKNOWN_MESSAGE_TYPE: "不支持的操作",
INVALID_PAYLOAD: "操作参数无效",
INVALID_CHANNEL_ID: "频道标识无效",
INVALID_TEXT_MESSAGE: "文字消息无效",
INVALID_AUDIO_FRAME: "音频帧格式无效",
SESSION_NOT_READY: "TeamSpeak 会话尚未就绪",
CHANNEL_SWITCH_FAILED: "频道切换失败",
};
return messages[code] || fallback;
}
function setVolume(clientId: number, volume: number): void {
const normalized = Math.max(0, Math.min(4, volume));
volumes[clientId] = normalized;
+9
View File
@@ -555,6 +555,15 @@ function localizedMessage(message: string) {
"WebSpeak 尚未配置 TeamSpeak 目标。": "The WebSpeak TeamSpeak target has not been configured",
"此 TeamSpeak 服务器地址不允许连接": "This TeamSpeak server address is not allowed",
"请输入有效的昵称": "Enter a valid nickname",
"消息格式无效": "The message format is invalid",
"请求标识无效": "The request id is invalid",
"不支持的操作": "This operation is not supported",
"操作参数无效": "The operation payload is invalid",
"频道标识无效": "The channel id is invalid",
"文字消息无效": "The text message is invalid",
"音频帧格式无效": "The audio frame is invalid",
"TeamSpeak 会话尚未就绪": "The TeamSpeak session is not ready",
"频道切换失败": "Channel switch failed",
};
if (exact[message]) return exact[message];
if (message.startsWith("麦克风访问失败:")) return `Microphone access failed: ${message.slice(8)}`;