mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(kaak): match KOOK audio device picker
This commit is contained in:
1 parent
70cc6c3bbf
commit
8e580e7e18
15 files changed
+408
-59
No files matched your search
@@ -0,0 +1,223 @@
|
||||
<template>
|
||||
<div
|
||||
ref="root"
|
||||
class="settings-device-select"
|
||||
data-ws-part="voice.audio-settings.device-select"
|
||||
>
|
||||
<button
|
||||
:id="id"
|
||||
ref="trigger"
|
||||
type="button"
|
||||
class="settings-select"
|
||||
role="combobox"
|
||||
aria-haspopup="listbox"
|
||||
:aria-label="label"
|
||||
:aria-expanded="open"
|
||||
:aria-controls="listboxId"
|
||||
:aria-activedescendant="open && activeIndex >= 0 ? optionId(activeIndex) : undefined"
|
||||
:disabled="disabled"
|
||||
data-ws-part="voice.audio-settings.device-select-trigger"
|
||||
@click="toggle"
|
||||
@keydown="onKeydown"
|
||||
>
|
||||
<span class="settings-select-label">{{ selectedOption?.label ?? "" }}</span>
|
||||
<span
|
||||
class="settings-select-chevron"
|
||||
aria-hidden="true"
|
||||
data-ws-part="voice.audio-settings.device-select-chevron"
|
||||
></span>
|
||||
</button>
|
||||
<Transition name="settings-select-menu">
|
||||
<ul
|
||||
v-if="open"
|
||||
:id="listboxId"
|
||||
class="settings-select-menu"
|
||||
role="listbox"
|
||||
:aria-label="label"
|
||||
:style="menuStyle"
|
||||
data-ws-part="voice.audio-settings.device-select-menu"
|
||||
>
|
||||
<li
|
||||
v-for="(option, index) in options"
|
||||
:id="optionId(index)"
|
||||
:key="index"
|
||||
class="settings-select-option"
|
||||
:class="{ active: index === activeIndex }"
|
||||
role="option"
|
||||
:aria-selected="option.value === modelValue"
|
||||
data-ws-part="voice.audio-settings.device-select-option"
|
||||
@pointermove="activeIndex = index"
|
||||
@click="select(option)"
|
||||
>
|
||||
{{ option.label }}
|
||||
</li>
|
||||
</ul>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type CSSProperties } from "vue";
|
||||
|
||||
export interface AudioDeviceOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
id: string;
|
||||
modelValue: string;
|
||||
options: readonly AudioDeviceOption[];
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
}>(), { disabled: false });
|
||||
const emit = defineEmits<{ change: [value: string] }>();
|
||||
|
||||
const root = ref<HTMLElement | null>(null);
|
||||
const trigger = ref<HTMLButtonElement | null>(null);
|
||||
const open = ref(false);
|
||||
const activeIndex = ref(-1);
|
||||
const menuStyle = ref<CSSProperties>({});
|
||||
const listboxId = computed(() => `${props.id}-listbox`);
|
||||
const selectedIndex = computed(() => props.options.findIndex(option => option.value === props.modelValue));
|
||||
const selectedOption = computed(() => props.options[selectedIndex.value] ?? props.options[0]);
|
||||
let typeahead = "";
|
||||
let typeaheadTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
function optionId(index: number): string {
|
||||
return `${listboxId.value}-option-${index}`;
|
||||
}
|
||||
|
||||
function updateMenuPosition(): void {
|
||||
const rect = trigger.value?.getBoundingClientRect();
|
||||
if (!rect || typeof window === "undefined") return;
|
||||
|
||||
const fullHeight = Math.min(240, props.options.length * 32 + 8);
|
||||
const below = Math.max(0, window.innerHeight - rect.bottom - 8);
|
||||
const above = Math.max(0, rect.top - 8);
|
||||
const opensAbove = below < fullHeight && above > below;
|
||||
const available = opensAbove ? above : below;
|
||||
const height = Math.min(fullHeight, Math.max(80, available));
|
||||
const top = opensAbove ? Math.max(8, rect.top - height - 4) : Math.min(rect.bottom + 4, window.innerHeight - height - 8);
|
||||
|
||||
menuStyle.value = {
|
||||
top: `${top}px`,
|
||||
left: `${rect.left}px`,
|
||||
width: `${rect.width}px`,
|
||||
maxHeight: `${height}px`,
|
||||
};
|
||||
}
|
||||
|
||||
function setOpen(next: boolean): void {
|
||||
if (props.disabled && next) return;
|
||||
if (next === open.value) return;
|
||||
if (next) activeIndex.value = Math.max(0, selectedIndex.value);
|
||||
open.value = next;
|
||||
if (next) void nextTick(() => {
|
||||
updateMenuPosition();
|
||||
scrollActiveIntoView();
|
||||
});
|
||||
}
|
||||
|
||||
function toggle(): void {
|
||||
setOpen(!open.value);
|
||||
}
|
||||
|
||||
function moveActive(delta: number): void {
|
||||
const count = props.options.length;
|
||||
if (!count) return;
|
||||
activeIndex.value = (activeIndex.value + delta + count) % count;
|
||||
scrollActiveIntoView();
|
||||
}
|
||||
|
||||
function scrollActiveIntoView(): void {
|
||||
void nextTick(() => {
|
||||
document.getElementById(optionId(activeIndex.value))?.scrollIntoView({ block: "nearest" });
|
||||
});
|
||||
}
|
||||
|
||||
function select(option: AudioDeviceOption): void {
|
||||
emit("change", option.value);
|
||||
setOpen(false);
|
||||
void nextTick(() => trigger.value?.focus());
|
||||
}
|
||||
|
||||
function typeaheadMatch(key: string): void {
|
||||
typeahead += key.toLocaleLowerCase();
|
||||
if (typeaheadTimeout) clearTimeout(typeaheadTimeout);
|
||||
typeaheadTimeout = setTimeout(() => { typeahead = ""; }, 700);
|
||||
|
||||
const start = Math.max(0, activeIndex.value + 1);
|
||||
const ordered = [...props.options.slice(start), ...props.options.slice(0, start)];
|
||||
const match = ordered.find(option => option.label.toLocaleLowerCase().startsWith(typeahead));
|
||||
if (match) {
|
||||
activeIndex.value = props.options.indexOf(match);
|
||||
scrollActiveIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
if (!open.value) {
|
||||
setOpen(true);
|
||||
return;
|
||||
}
|
||||
moveActive(event.key === "ArrowDown" ? 1 : -1);
|
||||
return;
|
||||
}
|
||||
if (event.key === "Home" || event.key === "End") {
|
||||
event.preventDefault();
|
||||
if (!open.value) setOpen(true);
|
||||
activeIndex.value = event.key === "Home" ? 0 : props.options.length - 1;
|
||||
scrollActiveIntoView();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
if (!open.value) setOpen(true);
|
||||
else if (props.options[activeIndex.value]) select(props.options[activeIndex.value]);
|
||||
return;
|
||||
}
|
||||
if (event.key === "Escape" && open.value) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
if (event.key === "Tab") {
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
if (event.key.length === 1 && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
||||
if (!open.value) setOpen(true);
|
||||
typeaheadMatch(event.key);
|
||||
}
|
||||
}
|
||||
|
||||
function onDocumentPointerDown(event: PointerEvent): void {
|
||||
if (!root.value?.contains(event.target as Node)) setOpen(false);
|
||||
}
|
||||
|
||||
function onWindowChange(): void {
|
||||
if (open.value) updateMenuPosition();
|
||||
}
|
||||
|
||||
watch(() => props.disabled, disabled => { if (disabled) setOpen(false); });
|
||||
watch(() => props.options, options => {
|
||||
if (activeIndex.value >= options.length) activeIndex.value = Math.max(0, options.length - 1);
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("pointerdown", onDocumentPointerDown, true);
|
||||
window.addEventListener("resize", onWindowChange);
|
||||
window.addEventListener("scroll", onWindowChange, true);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener("pointerdown", onDocumentPointerDown, true);
|
||||
window.removeEventListener("resize", onWindowChange);
|
||||
window.removeEventListener("scroll", onWindowChange, true);
|
||||
if (typeaheadTimeout) clearTimeout(typeaheadTimeout);
|
||||
});
|
||||
</script>
|
||||
@@ -35,20 +35,14 @@
|
||||
class="settings-label"
|
||||
for="input-device"
|
||||
>{{ t("microphone") }}</label
|
||||
><select
|
||||
><AudioDeviceSelect
|
||||
id="input-device"
|
||||
class="settings-select"
|
||||
:value="selectedInputDeviceId"
|
||||
:model-value="selectedInputDeviceId"
|
||||
:options="inputDeviceOptions"
|
||||
:label="t('microphone')"
|
||||
:disabled="!inputDevices.length"
|
||||
@change="onInputDeviceChange"
|
||||
><option value="">{{ t("defaultMicrophone") }}</option
|
||||
><option
|
||||
v-for="(device, index) in inputDevices"
|
||||
:key="device.deviceId || `microphone-${index}`"
|
||||
:value="device.deviceId"
|
||||
>{{ device.label || t("microphoneNumber", { index: index + 1 }) }}</option
|
||||
></select
|
||||
><p
|
||||
/><p
|
||||
v-if="audioSettingsError"
|
||||
class="settings-error"
|
||||
>{{ localizedMessage(audioSettingsError) }}</p
|
||||
@@ -160,21 +154,15 @@
|
||||
class="settings-label"
|
||||
for="output-device"
|
||||
>{{ t("outputDevice") }}</label
|
||||
><select
|
||||
><AudioDeviceSelect
|
||||
v-if="outputDeviceSupported"
|
||||
id="output-device"
|
||||
class="settings-select"
|
||||
:value="selectedOutputDeviceId"
|
||||
:model-value="selectedOutputDeviceId"
|
||||
:options="outputDeviceOptions"
|
||||
:label="t('outputDevice')"
|
||||
:disabled="!outputDevices.length"
|
||||
@change="onOutputDeviceChange"
|
||||
><option value="">{{ t("defaultOutput") }}</option
|
||||
><option
|
||||
v-for="(device, index) in outputDevices"
|
||||
:key="device.deviceId || `speaker-${index}`"
|
||||
:value="device.deviceId"
|
||||
>{{ device.label || t("speakerNumber", { index: index + 1 }) }}</option
|
||||
></select
|
||||
><p
|
||||
/><p
|
||||
v-else
|
||||
class="mode-note"
|
||||
><Icon
|
||||
@@ -241,8 +229,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, type CSSProperties } from "vue";
|
||||
import { computed, ref, type CSSProperties } from "vue";
|
||||
import Icon from "../Icon.vue";
|
||||
import AudioDeviceSelect from "./AudioDeviceSelect.vue";
|
||||
import { useDialogFocus } from "../../composables/useDialogFocus.js";
|
||||
import type { useVoiceWebSocket } from "../../composables/useVoiceWebSocket.js";
|
||||
import type { useWebClientAudioControls } from "../../composables/useWebClientAudioControls.js";
|
||||
@@ -325,4 +314,19 @@ const {
|
||||
meterBarHeight,
|
||||
toggleMicrophone,
|
||||
} = props.controls;
|
||||
|
||||
const inputDeviceOptions = computed(() => [
|
||||
{ value: "", label: props.t("defaultMicrophone") },
|
||||
...inputDevices.map((device, index) => ({
|
||||
value: device.deviceId,
|
||||
label: device.label || props.t("microphoneNumber", { index: index + 1 }),
|
||||
})),
|
||||
]);
|
||||
const outputDeviceOptions = computed(() => [
|
||||
{ value: "", label: props.t("defaultOutput") },
|
||||
...outputDevices.map((device, index) => ({
|
||||
value: device.deviceId,
|
||||
label: device.label || props.t("speakerNumber", { index: index + 1 }),
|
||||
})),
|
||||
]);
|
||||
</script>
|
||||
@@ -106,19 +106,21 @@ export function useWebClientAudioControls({
|
||||
setNotificationVolume(Number((event.target as HTMLInputElement).value) / 100);
|
||||
}
|
||||
|
||||
async function onInputDeviceChange(event: Event): Promise<void> {
|
||||
async function onInputDeviceChange(selection: Event | string): Promise<void> {
|
||||
const isCurrent = beginSettingsRequest();
|
||||
try {
|
||||
await setInputDevice((event.target as HTMLSelectElement).value);
|
||||
const deviceId = typeof selection === "string" ? selection : (selection.target as HTMLSelectElement).value;
|
||||
await setInputDevice(deviceId);
|
||||
} catch (error: unknown) {
|
||||
if (isCurrent()) settingsError.value = microphoneErrorMessage(error, "无法切换麦克风");
|
||||
}
|
||||
}
|
||||
|
||||
async function onOutputDeviceChange(event: Event): Promise<void> {
|
||||
async function onOutputDeviceChange(selection: Event | string): Promise<void> {
|
||||
const isCurrent = beginSettingsRequest();
|
||||
try {
|
||||
await setOutputDevice((event.target as HTMLSelectElement).value);
|
||||
const deviceId = typeof selection === "string" ? selection : (selection.target as HTMLSelectElement).value;
|
||||
await setOutputDevice(deviceId);
|
||||
} catch (error: unknown) {
|
||||
if (isCurrent()) settingsError.value = localizedMessage(error instanceof Error ? error.message : "无法切换扬声器");
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
|
||||
{
|
||||
id: BUILTIN_KAAK_SKIN_ID,
|
||||
name: "KAAK",
|
||||
version: "3.1.30",
|
||||
version: "3.1.31",
|
||||
author: "WebSpeak Project",
|
||||
license: "AGPL-3.0-only",
|
||||
description: "A KOOK-inspired voice-room workspace with collapsible voice groups and current voice-channel chat, TeamSpeak profile cards, and host-owned voice controls.",
|
||||
|
||||
@@ -464,7 +464,7 @@ 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.30");
|
||||
assert.equal(skin.version, "3.1.31");
|
||||
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
const home = skin.pluginData?.components.find((component) => component.page === "home");
|
||||
@@ -550,6 +550,9 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace.channel-row"]'));
|
||||
assert.match(skin.css, /channel-row"\]\[aria-current="true"\][\s\S]*?channel-join-hint[\s\S]*?display: none;/);
|
||||
assert.match(skin.css, /@keyframes ws-community-kaak-voice-kaak-channel-join-hint/);
|
||||
assert.match(skin.css, /--skin-kaak-font:[\s\S]*?PingFang SC/);
|
||||
assert.match(skin.css, /settings-select-menu[\s\S]*?background: #35373d/);
|
||||
assert.match(skin.css, /settings-select-option[\s\S]*?min-height: 32px/);
|
||||
assert.match(skin.css, /kaak-workspace\.voice-channel-group-toggle/);
|
||||
assert.match(skin.css, /kaak-workspace\.server-monogram"\]\[data-tone="0"\]/);
|
||||
assert.match(skin.css, /voice-stage-heading[\s\S]*?flex: 0 0 46px;/);
|
||||
|
||||
@@ -3183,7 +3183,6 @@
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
margin-bottom: 19px;
|
||||
padding: 0 13px;
|
||||
color: #394742;
|
||||
border: 1px solid #e0eae6;
|
||||
@@ -3194,13 +3193,93 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
:deep(.settings-device-select) {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-bottom: 19px;
|
||||
}
|
||||
|
||||
:deep(.settings-device-select > .settings-select) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
:deep(.settings-select-label) {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
:deep(.settings-select-chevron) {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
flex: 0 0 auto;
|
||||
margin: -3px 3px 0 12px;
|
||||
border: solid currentColor;
|
||||
border-width: 0 1.5px 1.5px 0;
|
||||
transform: rotate(45deg);
|
||||
transition: transform .2s ease;
|
||||
}
|
||||
|
||||
:deep(.settings-select[aria-expanded="true"] .settings-select-chevron) {
|
||||
transform: rotate(225deg);
|
||||
}
|
||||
|
||||
:deep(.settings-select-menu) {
|
||||
position: fixed;
|
||||
z-index: 24;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 4px 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
color: #394742;
|
||||
border: 1px solid #dfe7e3;
|
||||
border-radius: 8px;
|
||||
background: #f4f7f6;
|
||||
box-shadow: 0 10px 28px rgba(16, 30, 26, .22);
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
:deep(.settings-select-option) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 32px;
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
transition: background-color .12s ease;
|
||||
}
|
||||
|
||||
:deep(.settings-select-option:hover),
|
||||
:deep(.settings-select-option.active),
|
||||
:deep(.settings-select-option[aria-selected="true"]) {
|
||||
background: rgba(0, 106, 100, .1);
|
||||
}
|
||||
|
||||
:deep(.settings-select-menu-enter-active),
|
||||
:deep(.settings-select-menu-leave-active) {
|
||||
transition: opacity .14s ease, transform .14s ease;
|
||||
}
|
||||
|
||||
:deep(.settings-select-menu-enter-from),
|
||||
:deep(.settings-select-menu-leave-to) {
|
||||
opacity: 0;
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
:deep(.settings-select:focus) {
|
||||
border-color: #81d8d0;
|
||||
box-shadow: 0 0 0 2px rgba(129,216,208,.2);
|
||||
}
|
||||
|
||||
:deep(.settings-select:disabled) {
|
||||
cursor: wait;
|
||||
cursor: not-allowed;
|
||||
opacity: .65;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user