mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat: add mainland acceleration preview
This commit is contained in:
1 parent
45584810a2
commit
b82c4fe0af
11 files changed
+494
-21
No files matched your search
@@ -93,7 +93,7 @@ export function useVoiceWebSocket() {
|
||||
const serverEvents = reactive<ServerEvent[]>([]);
|
||||
const pokeNotifications = reactive<{ id: string; invokerId: number; invokerUid: string; invokerName: string; message: string; timestamp: number }[]>([]);
|
||||
let connectionSequence = 0;
|
||||
let lastConnection: { target: string; channel: string; nickname: string; serverPassword: string; identity?: string; rememberIdentity: boolean } | null = null;
|
||||
let lastConnection: { target: string; channel: string; nickname: string; serverPassword: string; identity?: string; rememberIdentity: boolean; accelerated: boolean } | null = null;
|
||||
let latencyProbeSequence = 0;
|
||||
const pendingLatencyProbes = new Map<string, { startedAt: number; resolve: (result: LatencyProbeResult | null) => void; timer: ReturnType<typeof setTimeout> }>();
|
||||
let webrtcPeer: RTCPeerConnection | null = null;
|
||||
@@ -1088,9 +1088,9 @@ export function useVoiceWebSocket() {
|
||||
clearRemotePlayback(clientId);
|
||||
}
|
||||
|
||||
function connect(target: string, channel: string, nickname: string, serverPassword = "", identity = "", rememberIdentity = false, inviteToken = ""): void {
|
||||
function connect(target: string, channel: string, nickname: string, serverPassword = "", identity = "", rememberIdentity = false, inviteToken = "", accelerated = false): void {
|
||||
disconnect(true);
|
||||
lastConnection = { target, channel, nickname, serverPassword, ...(identity ? { identity } : {}), rememberIdentity };
|
||||
lastConnection = { target, channel, nickname, serverPassword, ...(identity ? { identity } : {}), rememberIdentity, accelerated };
|
||||
identityMaterial.value = identity;
|
||||
const sequence = ++connectionSequence;
|
||||
state.error = "";
|
||||
@@ -1099,15 +1099,15 @@ export function useVoiceWebSocket() {
|
||||
state.reconnecting = false;
|
||||
state.reconnectAttempt = 0;
|
||||
state.reconnectFailed = false;
|
||||
void openTicketedConnection(sequence, target, channel, nickname, serverPassword, inviteToken);
|
||||
void openTicketedConnection(sequence, target, channel, nickname, serverPassword, inviteToken, accelerated);
|
||||
}
|
||||
|
||||
async function openTicketedConnection(sequence: number, target: string, channel: string, nickname: string, serverPassword: string, inviteToken: string): Promise<void> {
|
||||
async function openTicketedConnection(sequence: number, target: string, channel: string, nickname: string, serverPassword: string, inviteToken: string, accelerated: boolean): Promise<void> {
|
||||
try {
|
||||
const response = await fetch("/api/join-ticket", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", accept: "application/json" },
|
||||
body: JSON.stringify({ target, nickname, channel, serverPassword, ...(inviteToken ? { invite: inviteToken } : {}), ...(lastConnection?.rememberIdentity && lastConnection.identity ? { identity: lastConnection.identity } : {}), ...(lastConnection?.rememberIdentity ? { rememberIdentity: true } : {}) }),
|
||||
body: JSON.stringify({ target, nickname, channel, serverPassword, ...(inviteToken ? { invite: inviteToken } : {}), ...(accelerated ? { accelerated: true } : {}), ...(lastConnection?.rememberIdentity && lastConnection.identity ? { identity: lastConnection.identity } : {}), ...(lastConnection?.rememberIdentity ? { rememberIdentity: true } : {}) }),
|
||||
});
|
||||
const result = await response.json().catch(() => ({})) as { ticket?: unknown; code?: unknown };
|
||||
if (!response.ok || typeof result.ticket !== "string") {
|
||||
@@ -1168,6 +1168,7 @@ export function useVoiceWebSocket() {
|
||||
function joinTicketReason(code: string): string {
|
||||
if (code === "NOT_INITIALIZED") return "WebSpeak 尚未完成首次配置";
|
||||
if (code === "TARGET_NOT_ALLOWED") return "此 TeamSpeak 服务器地址不允许连接";
|
||||
if (code === "ACCELERATION_UNAVAILABLE") return "大陆节点智能加速尚未在当前网关配置";
|
||||
if (code === "INVALID_NICKNAME") return "请输入有效的昵称";
|
||||
if (code === "INVITE_INVALID") return "邀请链接已失效或已被撤销";
|
||||
return "连接服务器失败,请检查邀请链接或服务器状态";
|
||||
@@ -1498,7 +1499,7 @@ export function useVoiceWebSocket() {
|
||||
|
||||
function reconnectNow(): void {
|
||||
if (!lastConnection || state.connecting) return;
|
||||
connect(lastConnection.target, lastConnection.channel, lastConnection.nickname, lastConnection.serverPassword, lastConnection.rememberIdentity ? identityMaterial.value || lastConnection.identity : "", lastConnection.rememberIdentity);
|
||||
connect(lastConnection.target, lastConnection.channel, lastConnection.nickname, lastConnection.serverPassword, lastConnection.rememberIdentity ? identityMaterial.value || lastConnection.identity : "", lastConnection.rememberIdentity, "", lastConnection.accelerated);
|
||||
}
|
||||
|
||||
function setMicrophoneMuted(muted: boolean): void {
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<label class="field-label" for="server-port"><span>{{ t('serverPort') }}</span><div class="field-wrap"><Icon name="hash" :size="17" /><input id="server-port" v-model="serverPort" inputmode="numeric" type="text" maxlength="5" :placeholder="t('serverPortPlaceholder')" /></div></label>
|
||||
</div>
|
||||
<p v-if="accessMode === 'open'" class="field-hint">{{ t('serverAddressHint') }}</p>
|
||||
<label v-if="accelerationAvailable" class="acceleration-choice"><input v-model="accelerationEnabled" type="checkbox" /><span><strong>{{ t('mainlandAcceleration') }}</strong><small>{{ t('mainlandAccelerationHint') }}</small></span></label>
|
||||
<div v-if="accessMode === 'open' && (favoriteServers.length || recentServers.length)" class="local-servers">
|
||||
<div v-if="favoriteServers.length" class="local-server-group"><span>{{ t('favoriteServers') }}</span><button v-for="favorite in favoriteServers" :key="favorite.id" type="button" @click="selectLocalServer(favorite.address, favorite.nickname)">{{ favorite.label }}</button></div>
|
||||
<div v-if="recentServers.length" class="local-server-group"><span>{{ t('recentServers') }}</span><button v-for="recent in recentServers" :key="recent.id" type="button" @click="selectLocalServer(recent.address, recent.nickname)">{{ recent.address }}</button></div>
|
||||
@@ -378,7 +379,9 @@ const initialized = ref(false);
|
||||
const siteName = ref("WebSpeak");
|
||||
const welcomeTextZh = ref("");
|
||||
const welcomeTextEn = ref("");
|
||||
const appVersion = ref("0.1.2");
|
||||
const appVersion = ref("0.2.0-preview");
|
||||
const accelerationAvailable = ref(false);
|
||||
const accelerationEnabled = ref(false);
|
||||
const browserError = ref("");
|
||||
const serverConfigLoading = ref(true);
|
||||
const memberQuery = ref("");
|
||||
@@ -454,6 +457,8 @@ const translations: Record<string, Record<string, string>> = {
|
||||
serverPort: "语音端口",
|
||||
serverPortPlaceholder: "9987",
|
||||
serverAddressHint: "这是网关服务器连接的 TeamSpeak 地址和端口,不是浏览器直接连接地址。",
|
||||
mainlandAcceleration: "大陆节点智能加速",
|
||||
mainlandAccelerationHint: "通过已配置的大陆节点转发,适合境外连接不稳定或被拒绝的服务器。",
|
||||
nickname: "你的昵称",
|
||||
nicknamePlaceholder: "例如:Alex Rivera",
|
||||
targetChannel: "目标频道",
|
||||
@@ -711,6 +716,8 @@ const translations: Record<string, Record<string, string>> = {
|
||||
serverPort: "Voice port",
|
||||
serverPortPlaceholder: "9987",
|
||||
serverAddressHint: "This is the TeamSpeak address and port reached by the gateway, not a direct browser connection.",
|
||||
mainlandAcceleration: "Mainland node acceleration",
|
||||
mainlandAccelerationHint: "Route this connection through the configured mainland relay for servers that reject or slow overseas traffic.",
|
||||
nickname: "Your nickname",
|
||||
nicknamePlaceholder: "e.g. Alex Rivera",
|
||||
targetChannel: "Target channel",
|
||||
@@ -971,6 +978,8 @@ translations.de = {
|
||||
serverPort: "Sprachport",
|
||||
serverPortPlaceholder: "9987",
|
||||
serverAddressHint: "Dies ist die TeamSpeak-Adresse und der Port, die vom Gateway erreicht werden – keine direkte Browseradresse.",
|
||||
mainlandAcceleration: "Beschleunigung über einen Festlandknoten",
|
||||
mainlandAccelerationHint: "Leitet diese Verbindung über das konfigurierte Festland-Relay – für Server mit instabilen oder abgelehnten Auslandsverbindungen.",
|
||||
nickname: "Dein Name",
|
||||
nicknamePlaceholder: "z. B. Alex Rivera",
|
||||
targetChannel: "Zielkanal",
|
||||
@@ -1560,7 +1569,7 @@ function doConnect() {
|
||||
serverPort.value = serverPort.value.trim();
|
||||
}
|
||||
selectedChannelId.value = "";
|
||||
connect(currentServerTarget(), channel.value.trim(), nickname.value, accessMode.value === "open" ? serverPassword.value : "", rememberIdentity.value ? identityMaterial.value : "", rememberIdentity.value, inviteToken);
|
||||
connect(currentServerTarget(), channel.value.trim(), nickname.value, accessMode.value === "open" ? serverPassword.value : "", rememberIdentity.value ? identityMaterial.value : "", rememberIdentity.value, inviteToken, accelerationEnabled.value);
|
||||
}
|
||||
|
||||
function doDisconnect() {
|
||||
@@ -1671,13 +1680,15 @@ async function loadPublicConfig() {
|
||||
try {
|
||||
const response = await fetch("/api/public-config", { headers: { accept: "application/json" } });
|
||||
if (!response.ok) return;
|
||||
const config = await response.json() as { version?: unknown; initialized?: unknown; siteName?: unknown; welcomeText?: unknown; welcomeTextEn?: unknown; accessMode?: unknown; target?: unknown };
|
||||
const config = await response.json() as { version?: unknown; initialized?: unknown; siteName?: unknown; welcomeText?: unknown; welcomeTextEn?: unknown; accessMode?: unknown; target?: unknown; accelerationAvailable?: unknown };
|
||||
if (typeof config.version === "string" && config.version.trim()) appVersion.value = config.version.trim();
|
||||
initialized.value = config.initialized === true;
|
||||
if (typeof config.siteName === "string" && config.siteName.trim()) siteName.value = config.siteName.trim();
|
||||
if (typeof config.welcomeText === "string") welcomeTextZh.value = config.welcomeText;
|
||||
if (typeof config.welcomeTextEn === "string") welcomeTextEn.value = config.welcomeTextEn;
|
||||
accessMode.value = config.accessMode === "open" ? "open" : "fixed";
|
||||
accelerationAvailable.value = config.accelerationAvailable === true;
|
||||
if (!accelerationAvailable.value) accelerationEnabled.value = false;
|
||||
const hasInviteTarget = query.has("server") || query.has("target") || query.has("tsHost") || query.has("tsPort");
|
||||
if (!hasInviteTarget && typeof config.target === "string" && config.target.trim()) {
|
||||
const target = splitTeamSpeakTarget(config.target);
|
||||
@@ -2110,11 +2121,18 @@ function stopWhisperTalk(): void {
|
||||
.reconnect-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
|
||||
.reconnect-actions .secondary-button { min-height: 34px; padding-inline: 13px; }
|
||||
.remember-identity { display: flex; align-items: flex-start; gap: 9px; margin-top: 8px; color: #465650; cursor: pointer; }
|
||||
.acceleration-choice { display: flex; align-items: flex-start; gap: 9px; margin: 8px 0 2px; padding: 10px 11px; color: #245f58; background: #edf9f5; border: 1px solid #c4e9df; border-radius: 10px; cursor: pointer; }
|
||||
.acceleration-choice input { width: 16px; height: 16px; flex: 0 0 auto; margin: 1px 0 0; accent-color: #087d74; }
|
||||
.acceleration-choice strong, .acceleration-choice small { display: block; }
|
||||
.acceleration-choice strong { font-size: 11px; font-weight: 800; }
|
||||
.acceleration-choice small { margin-top: 3px; color: #6b8c85; font-size: 10px; line-height: 1.45; }
|
||||
.remember-identity input { width: 16px; height: 16px; flex: 0 0 auto; margin: 1px 0 0; accent-color: #087d74; }
|
||||
.remember-identity strong, .remember-identity small { display: block; }
|
||||
.remember-identity strong { font-size: 11px; font-weight: 700; }
|
||||
.remember-identity small { margin-top: 3px; color: #8b9994; font-size: 10px; line-height: 1.4; }
|
||||
.identity-warning { margin: 8px 0 0; color: #9a6a32; font-size: 10px; line-height: 1.45; }
|
||||
:global(html[data-theme="dark"] .acceleration-choice) { color: #b8eee3; background: #183530; border-color: #2b645b; }
|
||||
:global(html[data-theme="dark"] .acceleration-choice small) { color: #91b9b0; }
|
||||
.local-servers { display: grid; gap: 8px; margin: 1px 0 5px; }
|
||||
.local-server-group { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
|
||||
.local-server-group > span { width: 100%; color: #87958f; font-size: 10px; font-weight: 700; }
|
||||
|
||||
Reference in new issue
Block a user