mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: add private expiring workspace invites and restore KAAK home
This commit is contained in:
1 parent
33ba062686
commit
72d7e6e013
39 files changed
+512
-53
No files matched your search
@@ -0,0 +1,54 @@
|
||||
<template>
|
||||
<div class="modal-backdrop workspace-invite-backdrop" data-ws-part="voice.invite.backdrop" @click.self="emit('close')">
|
||||
<section ref="dialog" class="channel-password-modal workspace-invite-dialog" data-ws-part="voice.invite.dialog" tabindex="-1" role="dialog" aria-modal="true" aria-labelledby="workspace-invite-title" @keydown="onDialogKeydown">
|
||||
<button class="qq-modal-close" type="button" :aria-label="t('close')" @click="emit('close')">×</button>
|
||||
<h2 id="workspace-invite-title">{{ t('workspaceInviteTitle') }}</h2>
|
||||
<p>{{ t('workspaceInviteLead') }}</p>
|
||||
<form class="channel-password-form" data-ws-part="voice.invite.form" @submit.prevent="generate">
|
||||
<label>{{ t('workspaceInviteExpiry') }}<input v-model.number="minutes" type="number" min="1" max="43200" required :disabled="busy" /></label>
|
||||
<label>{{ t('workspaceInviteServerPassword') }}<input v-model="serverPassword" type="password" maxlength="512" autocomplete="off" :disabled="busy" /></label>
|
||||
<label>{{ t('workspaceInvitePassword') }}<input v-model="password" type="password" maxlength="512" autocomplete="off" :disabled="busy" /></label>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<button class="primary-button" data-ws-part="voice.invite.create" type="submit" :disabled="busy">{{ t('workspaceInviteCreate') }}</button>
|
||||
</form>
|
||||
<div v-if="link" class="workspace-invite-result" aria-live="polite">
|
||||
<input :value="link" readonly :aria-label="t('workspaceInviteCopy')" @focus="($event.target as HTMLInputElement).select()" />
|
||||
<small>{{ t('workspaceInviteExpiresAt') }} {{ new Date(expiresAt).toLocaleString() }}</small>
|
||||
<button class="primary-button" data-ws-part="voice.invite.copy" type="button" @click="copy">{{ copied ? t('copiedToast') : t('workspaceInviteCopy') }}</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useDialogFocus } from "../../composables/useDialogFocus.js";
|
||||
const props = defineProps<{ t: (key: string) => string; create: (minutes: number, password: string, serverPassword: string) => Promise<{ token: string; expiresAt: number }> }>();
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
const dialog = ref<HTMLElement | null>(null);
|
||||
const { onDialogKeydown } = useDialogFocus(dialog, () => emit("close"));
|
||||
const minutes = ref(1440), password = ref(""), serverPassword = ref(""), busy = ref(false), error = ref(""), link = ref(""), expiresAt = ref(0), copied = ref(false);
|
||||
async function generate() {
|
||||
if (busy.value) return;
|
||||
busy.value = true; error.value = ""; link.value = ""; copied.value = false;
|
||||
try {
|
||||
const result = await props.create(minutes.value, password.value, serverPassword.value);
|
||||
const url = new URL("/", location.origin); url.searchParams.set("invite", result.token);
|
||||
link.value = url.toString(); expiresAt.value = result.expiresAt; password.value = ""; serverPassword.value = "";
|
||||
} catch { error.value = props.t("workspaceInviteError"); }
|
||||
finally { busy.value = false; }
|
||||
}
|
||||
async function copy() {
|
||||
try { await navigator.clipboard.writeText(link.value); copied.value = true; }
|
||||
catch { error.value = props.t("copyFailedToast"); }
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.workspace-invite-backdrop { z-index: 2147483000 !important; }
|
||||
.workspace-invite-dialog .primary-button { width: 100%; min-height: 44px; padding: 10px 16px; font: inherit; font-weight: 600; border-radius: 10px; }
|
||||
.workspace-invite-dialog { max-width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
|
||||
.workspace-invite-dialog h2 { color: inherit !important; }
|
||||
.workspace-invite-dialog p { line-height: 1.6; }
|
||||
.workspace-invite-dialog label, .workspace-invite-result { display: grid; gap: 10px; margin-block: 14px; }
|
||||
.workspace-invite-dialog input { box-sizing: border-box; width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid currentColor; border-radius: 10px; background: transparent; color: inherit; font: inherit; }
|
||||
.workspace-invite-result small { overflow-wrap: anywhere; }
|
||||
</style>
|
||||
@@ -1168,6 +1168,11 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "inviteCreated": {
|
||||
createdInvite = { token: msg.token, expiresAt: msg.expiresAt };
|
||||
commands.settle(msg.requestId ?? "");
|
||||
break;
|
||||
}
|
||||
case "commandCompleted": {
|
||||
const requestId = typeof msg.requestId === "string" ? msg.requestId : "";
|
||||
commands.settle(requestId);
|
||||
@@ -1205,6 +1210,14 @@ export function useVoiceWebSocket() {
|
||||
commands.send(type, payload);
|
||||
}
|
||||
|
||||
let createdInvite: { token: string; expiresAt: number } | null = null;
|
||||
async function createInvite(expiresInMinutes: number, channelPassword = "", serverPassword = ""): Promise<{ token: string; expiresAt: number }> {
|
||||
createdInvite = null;
|
||||
await sendCommandAndWait("createInvite", { expiresInMinutes, ...(channelPassword ? { channelPassword } : {}), ...(serverPassword ? { serverPassword } : {}) });
|
||||
if (!createdInvite) throw new Error("Invitation was not created");
|
||||
return createdInvite;
|
||||
}
|
||||
|
||||
function sendCommandAndWait<K extends ClientCommandType>(type: K, payload: ClientCommandPayloads[K], timeoutMs = 8_000): Promise<void> {
|
||||
return commands.sendAndWait(type, payload, timeoutMs);
|
||||
}
|
||||
@@ -1473,6 +1486,7 @@ export function useVoiceWebSocket() {
|
||||
playNotification,
|
||||
connect,
|
||||
reconnectNow,
|
||||
createInvite,
|
||||
disconnect,
|
||||
switchChannel,
|
||||
moveClient,
|
||||
|
||||
@@ -93,7 +93,7 @@ export function useWebClientConnection({
|
||||
const canJoin = computed(() => Boolean(
|
||||
initialized.value
|
||||
&& nickname.value.trim()
|
||||
&& (accessMode.value === "fixed" || (serverHost.value.trim() && isValidTeamSpeakPort(serverPort.value))),
|
||||
&& (inviteToken.value || accessMode.value === "fixed" || (serverHost.value.trim() && isValidTeamSpeakPort(serverPort.value))),
|
||||
));
|
||||
|
||||
watch(serverHost, (address, previousAddress) => {
|
||||
@@ -136,11 +136,11 @@ export function useWebClientConnection({
|
||||
resolvingServerPassword = true;
|
||||
void (async () => {
|
||||
try {
|
||||
const savedPassword = serverPassword.value ? "" : await loadStoredServerPassword(target);
|
||||
const savedPassword = inviteToken.value || serverPassword.value ? "" : await loadStoredServerPassword(target);
|
||||
if (attempt !== serverPasswordLookupAttempt || target !== currentServerTarget()) return;
|
||||
// A password entered while IndexedDB was being read takes precedence.
|
||||
const password = serverPassword.value || savedPassword;
|
||||
attemptedServerCredential = { target, password };
|
||||
const password = inviteToken.value ? "" : serverPassword.value || savedPassword;
|
||||
attemptedServerCredential = inviteToken.value ? null : { target, password };
|
||||
// Keep the in-memory value available for the existing reconnect flow.
|
||||
serverPassword.value = password;
|
||||
connect(
|
||||
@@ -257,6 +257,11 @@ export function useWebClientConnection({
|
||||
});
|
||||
watch(errorCode, (code) => {
|
||||
if (code !== "SERVER_PASSWORD_REQUIRED" && code !== "INVALID_SERVER_PASSWORD") return;
|
||||
if (inviteToken.value) {
|
||||
clearError();
|
||||
showToast(t("inviteCredentialFailure"));
|
||||
return;
|
||||
}
|
||||
if (attemptedServerCredential) void removeStoredServerPassword(attemptedServerCredential.target);
|
||||
attemptedServerCredential = null;
|
||||
serverPassword.value = "";
|
||||
|
||||
@@ -1699,6 +1699,12 @@ webClientTranslations.ja = {
|
||||
langSwitch: "中文",
|
||||
};
|
||||
|
||||
Object.assign(webClientTranslations.zh, {"workspaceInviteTitle": "邀请到当前频道", "workspaceInviteExpiry": "有效期(分钟,最长 30 天)", "workspaceInvitePassword": "频道密码(已在本次连接中输入过则无需再填)", "workspaceInviteCreate": "生成邀请链接", "workspaceInviteCopy": "复制链接", "workspaceInviteExpiresAt": "有效期至", "workspaceInviteLead": "链接持有者可加入此服务器和频道。连接凭据仅保留在服务端。", "workspaceInviteError": "生成失败,请检查频道密码或重试。", "workspaceInviteServerPassword": "服务器密码(仅在连接时未提供、受邀者又需要时填写)", "inviteCredentialFailure": "邀请中的连接凭据已失效,请联系创建者重新生成邀请。"});
|
||||
Object.assign(webClientTranslations.en, {"workspaceInviteTitle": "Invite to current channel", "workspaceInviteExpiry": "Expires in minutes (up to 30 days)", "workspaceInvitePassword": "Channel password (only if not entered during this session)", "workspaceInviteCreate": "Create invite link", "workspaceInviteCopy": "Copy link", "workspaceInviteExpiresAt": "Expires at", "workspaceInviteLead": "Anyone with this link can join this server and channel. Connection credentials stay on the server.", "workspaceInviteError": "Could not create invitation. Check the channel password or try again.", "workspaceInviteServerPassword": "Server password (only if not supplied when connecting and required by invitees)", "inviteCredentialFailure": "This invitation’s connection credentials no longer work. Ask its creator for a new link."});
|
||||
Object.assign(webClientTranslations.de, {"workspaceInviteTitle": "In aktuellen Kanal einladen", "workspaceInviteExpiry": "Gültigkeit in Minuten (bis zu 30 Tage)", "workspaceInvitePassword": "Kanalpasswort (falls in dieser Sitzung noch nicht eingegeben)", "workspaceInviteCreate": "Einladungslink erstellen", "workspaceInviteCopy": "Link kopieren", "workspaceInviteExpiresAt": "Gültig bis", "workspaceInviteLead": "Mit diesem Link kann man dem Server und Kanal beitreten. Zugangsdaten bleiben auf dem Server.", "workspaceInviteError": "Einladung fehlgeschlagen. Kanalpasswort prüfen oder erneut versuchen.", "workspaceInviteServerPassword": "Serverpasswort (nur falls bei der Verbindung nicht angegeben und für Gäste erforderlich)", "inviteCredentialFailure": "Die Zugangsdaten dieser Einladung funktionieren nicht mehr. Bitte den Ersteller um einen neuen Link."});
|
||||
Object.assign(webClientTranslations.ru, {"workspaceInviteTitle": "Пригласить в текущий канал", "workspaceInviteExpiry": "Срок в минутах (до 30 дней)", "workspaceInvitePassword": "Пароль канала (если ещё не вводился в этом сеансе)", "workspaceInviteCreate": "Создать приглашение", "workspaceInviteCopy": "Копировать ссылку", "workspaceInviteExpiresAt": "Действует до", "workspaceInviteLead": "Обладатель ссылки может войти на сервер и в канал. Данные доступа остаются на сервере.", "workspaceInviteError": "Не удалось создать приглашение. Проверьте пароль канала или повторите попытку.", "workspaceInviteServerPassword": "Пароль сервера (если он не вводился при подключении, но нужен гостям)", "inviteCredentialFailure": "Данные доступа в приглашении больше не действуют. Попросите автора создать новую ссылку."});
|
||||
Object.assign(webClientTranslations.ja, {"workspaceInviteTitle": "現在のチャンネルに招待", "workspaceInviteExpiry": "有効期間(分、最大30日)", "workspaceInvitePassword": "チャンネルのパスワード(この接続中に未入力の場合)", "workspaceInviteCreate": "招待リンクを作成", "workspaceInviteCopy": "リンクをコピー", "workspaceInviteExpiresAt": "有効期限", "workspaceInviteLead": "リンクを持つ人がこのサーバーとチャンネルに参加できます。接続の認証情報はサーバーにのみ保存されます。", "workspaceInviteError": "招待を作成できませんでした。パスワードを確認するか、もう一度お試しください。", "workspaceInviteServerPassword": "サーバーのパスワード(接続時に未入力で、招待者に必要な場合のみ)", "inviteCredentialFailure": "招待の認証情報が無効です。作成者に新しいリンクを依頼してください。"});
|
||||
|
||||
export function getInitialLanguage(): Language {
|
||||
const stored = localStorage.getItem("webspeak:language");
|
||||
if (stored === "zh" || stored === "en" || stored === "de" || stored === "ru" || stored === "ja") return stored;
|
||||
|
||||
@@ -46,7 +46,7 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
|
||||
{
|
||||
id: BUILTIN_KAAK_SKIN_ID,
|
||||
name: "KAAK",
|
||||
version: "3.1.127",
|
||||
version: "3.1.131",
|
||||
author: "WebSpeak Project",
|
||||
license: "AGPL-3.0-only",
|
||||
description: "A KOOK-inspired WebSpeak skin with a split-screen connection home, searchable server header, TeamSpeak banner, nested channel members, unified chat with local history, and a compact audio dock.",
|
||||
|
||||
@@ -486,8 +486,8 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
|
||||
const skin = await importSkinPack(file);
|
||||
assert.equal(skin.id, "community.kaak-voice");
|
||||
assert.equal(skin.version, "3.1.127");
|
||||
assert.deepEqual(skin.workspace, { apiVersion: 1, mode: "persistent" });
|
||||
assert.equal(skin.version, "3.1.131");
|
||||
assert.equal(skin.workspace, undefined);
|
||||
assert.equal(skin.minAppVersion, "0.2.8");
|
||||
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
|
||||
@@ -901,6 +901,8 @@
|
||||
@volume-input="onVolInput"
|
||||
/>
|
||||
|
||||
<WorkspaceInviteDialog v-if="inviteDialogOpen && voiceState.connected" :t="t" :create="createInvite" @close="inviteDialogOpen = false" />
|
||||
|
||||
<!-- Protected channel password modal -->
|
||||
<ChannelPasswordDialog
|
||||
v-if="channelPasswordDialog.open"
|
||||
@@ -1005,6 +1007,7 @@ import { useWebClientConnection } from "../composables/useWebClientConnection.js
|
||||
import { useWebClientMembers } from "../composables/useWebClientMembers.js";
|
||||
import PluginPanel from "../components/PluginPanel.vue";
|
||||
import InstanceAuthorization from '../components/InstanceAuthorization.vue';
|
||||
import WorkspaceInviteDialog from "../components/web-client/WorkspaceInviteDialog.vue";
|
||||
import { useVoiceWebSocket, type ChannelMember, type ChatMessage } from "../composables/useVoiceWebSocket.js";
|
||||
import { useWebClientScreenShare } from "../composables/useWebClientScreenShare.js";
|
||||
import { useWebClientPerformance } from "../composables/useWebClientPerformance.js";
|
||||
@@ -1108,6 +1111,7 @@ const {
|
||||
clearError,
|
||||
pluginSession,
|
||||
ws: pluginVoiceSocket,
|
||||
createInvite,
|
||||
measureVoiceAudioStatus,
|
||||
} = useVoiceWebSocket();
|
||||
const performance = useWebClientPerformance(computed(() => voiceState.connected), measureVoiceAudioStatus);
|
||||
@@ -2209,16 +2213,10 @@ function channelLabel(item: TreeChannel) {
|
||||
return `${" ".repeat(item.depth)}${item.name}`;
|
||||
}
|
||||
|
||||
const inviteDialogOpen = ref(false);
|
||||
watch(() => voiceState.connected, connected => { if (!connected) inviteDialogOpen.value = false; });
|
||||
function doShare() {
|
||||
const invite = new URL(location.href);
|
||||
invite.searchParams.delete("token");
|
||||
invite.searchParams.delete("target");
|
||||
invite.searchParams.delete("tsHost");
|
||||
invite.searchParams.delete("tsPort");
|
||||
invite.searchParams.delete("server");
|
||||
if (accessMode.value === "open" && serverHost.value.trim()) invite.searchParams.set("server", currentServerTarget());
|
||||
if (channel.value) invite.searchParams.set("channel", channel.value);
|
||||
navigator.clipboard?.writeText(invite.toString()).then(() => showToast(t("copiedToast")), () => showToast(t("copyFailedToast")));
|
||||
if (voiceState.connected) inviteDialogOpen.value = true;
|
||||
}
|
||||
|
||||
async function clearBrowserData(): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user