mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
fix: show invalid nickname connection errors
This commit is contained in:
1 parent
d13b3207a9
commit
ef3e65ea0b
5 files changed
+22
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
export type WebSpeakErrorCode =
|
||||
| "invalid_target"
|
||||
| "invalid_nickname"
|
||||
| "host_not_found"
|
||||
| "unreachable"
|
||||
| "connection_refused"
|
||||
@@ -12,6 +13,7 @@ export type WebSpeakErrorCode =
|
||||
|
||||
export type ClientConnectionFailureCode =
|
||||
| "INVALID_TARGET"
|
||||
| "INVALID_NICKNAME"
|
||||
| "HOST_NOT_FOUND"
|
||||
| "UNREACHABLE"
|
||||
| "CONNECTION_REFUSED"
|
||||
@@ -60,6 +62,9 @@ export function normalizeTeamSpeakError(error: unknown): WebSpeakError {
|
||||
if (/password|authenticate|authentication|not authorized|invalid.*(credential|password)/.test(text)) {
|
||||
return new WebSpeakError("authentication_failed", "TeamSpeak authentication failed", false, error, diagnostics);
|
||||
}
|
||||
if (/invalid parameter size|nickname.{0,20}(length|size)|(?:length|size).{0,20}nickname|id[=: ]1541/.test(text)) {
|
||||
return new WebSpeakError("invalid_nickname", "TeamSpeak nickname length is invalid", false, error, diagnostics);
|
||||
}
|
||||
if (/enotfound|eai_again|host not found|name or service not known|dns/.test(text)) {
|
||||
return new WebSpeakError("host_not_found", "TeamSpeak server hostname could not be resolved", true, error, diagnostics);
|
||||
}
|
||||
@@ -87,6 +92,7 @@ export function clientConnectionFailureCode(error: WebSpeakError, serverPassword
|
||||
}
|
||||
const mapping: Record<WebSpeakErrorCode, ClientConnectionFailureCode> = {
|
||||
invalid_target: "INVALID_TARGET",
|
||||
invalid_nickname: "INVALID_NICKNAME",
|
||||
host_not_found: "HOST_NOT_FOUND",
|
||||
unreachable: "UNREACHABLE",
|
||||
connection_refused: "CONNECTION_REFUSED",
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TSClient } from "./ts-client.js";
|
||||
import type { TeamSpeakProtocol } from "./teamspeak-adapter.js";
|
||||
|
||||
export type ProbeErrorCode =
|
||||
| "INVALID_NICKNAME"
|
||||
| "HOST_NOT_FOUND"
|
||||
| "UNREACHABLE"
|
||||
| "CONNECTION_REFUSED"
|
||||
@@ -104,6 +105,7 @@ export function toProbeError(error: unknown, password = ""): TeamSpeakProbeError
|
||||
}
|
||||
const mapping: Record<WebSpeakErrorCode, ProbeErrorCode> = {
|
||||
invalid_target: "INTERNAL_ERROR",
|
||||
invalid_nickname: "INVALID_NICKNAME",
|
||||
unreachable: "UNREACHABLE",
|
||||
host_not_found: "HOST_NOT_FOUND",
|
||||
connection_refused: "CONNECTION_REFUSED",
|
||||
|
||||
@@ -1153,7 +1153,7 @@ export function useVoiceWebSocket() {
|
||||
// Prefer the close code over the generic WebSocket error event. The
|
||||
// gateway uses a dedicated code when a remembered identity is already
|
||||
// active in another browser page.
|
||||
if (event.code !== 1000 && !state.reconnectFailed) {
|
||||
if (event.code !== 1000 && !state.reconnectFailed && !state.errorCode) {
|
||||
state.errorCode = closeErrorCode(event.code, event.reason);
|
||||
state.error = closeReason(event.code, event.reason);
|
||||
}
|
||||
@@ -1178,7 +1178,7 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
|
||||
function closeErrorCode(code: number, reason = ""): string {
|
||||
const known = new Set(["INVALID_TARGET", "HOST_NOT_FOUND", "UNREACHABLE", "CONNECTION_REFUSED", "CONNECTION_RESET", "TIMEOUT", "SERVER_PASSWORD_REQUIRED", "INVALID_SERVER_PASSWORD", "PROTOCOL_NEGOTIATION_FAILED", "SERVER_REJECTED", "CONNECTION_FAILED"]);
|
||||
const known = new Set(["INVALID_TARGET", "INVALID_NICKNAME", "HOST_NOT_FOUND", "UNREACHABLE", "CONNECTION_REFUSED", "CONNECTION_RESET", "TIMEOUT", "SERVER_PASSWORD_REQUIRED", "INVALID_SERVER_PASSWORD", "PROTOCOL_NEGOTIATION_FAILED", "SERVER_REJECTED", "CONNECTION_FAILED"]);
|
||||
if (known.has(reason)) return reason;
|
||||
if (code === 4002) return "INVALID_TARGET";
|
||||
if (code === 4004) return "SERVER_REJECTED";
|
||||
@@ -1189,6 +1189,7 @@ export function useVoiceWebSocket() {
|
||||
function connectionFailureMessage(code: string): string {
|
||||
const messages: Record<string, string> = {
|
||||
INVALID_TARGET: "TeamSpeak 服务器地址无效",
|
||||
INVALID_NICKNAME: "昵称长度不符合 TeamSpeak 服务器要求,请修改后重试",
|
||||
HOST_NOT_FOUND: "找不到 TeamSpeak 服务器主机名,请检查地址",
|
||||
UNREACHABLE: "无法到达 TeamSpeak 服务器,请检查网络或地址",
|
||||
CONNECTION_REFUSED: "TeamSpeak 服务器拒绝了连接,请检查端口和服务状态",
|
||||
@@ -1412,7 +1413,9 @@ export function useVoiceWebSocket() {
|
||||
state.connected = false;
|
||||
state.connecting = false;
|
||||
state.reconnecting = false;
|
||||
state.reconnectFailed = true;
|
||||
// This is the first connection attempt, not a failed reconnect. Keep
|
||||
// the user on the welcome form instead of showing an empty voice room.
|
||||
state.reconnectFailed = false;
|
||||
state.errorCode = typeof msg.code === "string" ? msg.code : "CONNECTION_FAILED";
|
||||
state.error = connectionFailureMessage(state.errorCode);
|
||||
whisperTargetIds.clear();
|
||||
|
||||
@@ -180,6 +180,7 @@ const copy = {
|
||||
invalidServerPasswordError: "服务器密码错误",
|
||||
protocolFailureError: "TeamSpeak 协议协商失败",
|
||||
serverRejectedError: "服务器拒绝连接",
|
||||
invalidNicknameError: "昵称长度不符合服务器要求",
|
||||
pingUnavailableError: "无法执行网络探测",
|
||||
accessAndIdentity: "访问与站点信息",
|
||||
advancedSettings: "高级参数",
|
||||
@@ -382,6 +383,7 @@ const copy = {
|
||||
invalidServerPasswordError: "Invalid server password",
|
||||
protocolFailureError: "TeamSpeak protocol negotiation failed",
|
||||
serverRejectedError: "Server rejected the connection",
|
||||
invalidNicknameError: "The nickname length does not meet the server requirements",
|
||||
pingUnavailableError: "Network probe unavailable",
|
||||
accessAndIdentity: "Access and site identity",
|
||||
advancedSettings: "Advanced settings",
|
||||
@@ -581,6 +583,7 @@ const germanCopy = {
|
||||
invalidServerPasswordError: "Falsches Serverpasswort",
|
||||
protocolFailureError: "Aushandlung des TeamSpeak-Protokolls fehlgeschlagen",
|
||||
serverRejectedError: "Server hat die Verbindung abgelehnt",
|
||||
invalidNicknameError: "Die Länge des Spitznamens entspricht nicht den Serveranforderungen",
|
||||
pingUnavailableError: "Netzwerkprüfung nicht verfügbar",
|
||||
accessAndIdentity: "Zugriff und Website-Informationen",
|
||||
advancedSettings: "Erweiterte Einstellungen",
|
||||
@@ -690,6 +693,7 @@ const testResultTitle = computed(() => {
|
||||
if (result.ok) return result.checkType === "network" ? tr("networkReachable") : tr("connectionReady");
|
||||
const names: Record<string, keyof typeof copy.zh> = {
|
||||
INVALID_TARGET: "serverAddress",
|
||||
INVALID_NICKNAME: "invalidNicknameError",
|
||||
HOST_NOT_FOUND: "hostNotFoundError",
|
||||
UNREACHABLE: "networkUnreachableError",
|
||||
CONNECTION_REFUSED: "connectionRefusedError",
|
||||
@@ -767,7 +771,8 @@ function connectionFailureText(code?: string) {
|
||||
SERVER_PASSWORD_REQUIRED: "serverPasswordRequiredError",
|
||||
INVALID_PASSWORD: "invalidServerPasswordError",
|
||||
INVALID_SERVER_PASSWORD: "invalidServerPasswordError",
|
||||
INVALID_TARGET: "serverAddress",
|
||||
INVALID_TARGET: "serverAddress",
|
||||
INVALID_NICKNAME: "invalidNicknameError",
|
||||
HOST_NOT_FOUND: "hostNotFoundError",
|
||||
UNREACHABLE: "networkUnreachableError",
|
||||
CONNECTION_REFUSED: "connectionRefusedError",
|
||||
|
||||
@@ -1279,6 +1279,7 @@ function localizedMessage(message: string) {
|
||||
"连接已断开": "The connection was closed",
|
||||
"此 TeamSpeak 身份已在另一个浏览器页面使用,请关闭另一条连接或取消“保持身份”后重试": "This TeamSpeak identity is already used by another browser page. Close that connection or clear ‘Remember identity’ and try again",
|
||||
"TeamSpeak 服务器地址无效": "The TeamSpeak server address is invalid",
|
||||
"昵称长度不符合 TeamSpeak 服务器要求,请修改后重试": "The nickname length does not meet the TeamSpeak server requirements. Change it and try again",
|
||||
"TeamSpeak 服务器连接失败": "Could not connect to the TeamSpeak server",
|
||||
"找不到 TeamSpeak 服务器主机名,请检查地址": "The TeamSpeak server hostname could not be resolved. Check the address",
|
||||
"无法到达 TeamSpeak 服务器,请检查网络或地址": "The TeamSpeak server is unreachable. Check the network or address",
|
||||
@@ -1329,6 +1330,7 @@ function localizedMessage(message: string) {
|
||||
"TeamSpeak 连接已断开": "Die TeamSpeak-Verbindung wurde getrennt",
|
||||
"连接已断开": "Die Verbindung wurde getrennt",
|
||||
"TeamSpeak 服务器地址无效": "Die TeamSpeak-Serveradresse ist ungültig",
|
||||
"昵称长度不符合 TeamSpeak 服务器要求,请修改后重试": "Die Länge des Spitznamens entspricht nicht den Anforderungen des TeamSpeak-Servers. Ändere ihn und versuche es erneut",
|
||||
"找不到 TeamSpeak 服务器主机名,请检查地址": "Der TeamSpeak-Servername konnte nicht aufgelöst werden. Prüfe die Adresse",
|
||||
"无法到达 TeamSpeak 服务器,请检查网络或地址": "Der TeamSpeak-Server ist nicht erreichbar. Prüfe Netzwerk und Adresse",
|
||||
"TeamSpeak 服务器拒绝了连接,请检查端口和服务状态": "Der TeamSpeak-Server hat die Verbindung abgelehnt. Prüfe Port und Serverstatus",
|
||||
|
||||
Reference in new issue
Block a user