mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): expand schema v3 voice interactions
This commit is contained in:
1 parent
d505815f28
commit
849eb1a6d9
8 files changed
+282
-58
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { computed, defineComponent, Fragment, h, onUnmounted, reactive, ref, Teleport, watch, type PropType, type VNodeChild } from "vue";
|
||||
import {
|
||||
SKIN_PLUGIN_PERMISSIONS,
|
||||
SKIN_PLUGIN_REPEAT_LIMIT,
|
||||
parseSkinPluginDocument,
|
||||
type SkinPluginActionDefinition,
|
||||
type SkinPluginComponent,
|
||||
@@ -16,7 +17,9 @@ type HostAction = (args: Record<string, Scalar>, component: SkinPluginComponent)
|
||||
type HostWidget = () => VNodeChild;
|
||||
|
||||
const eventProps: Record<string, string> = {
|
||||
click: "onClick", dblclick: "onDblclick", change: "onChange", input: "onInput", submit: "onSubmit", keydown: "onKeydown",
|
||||
click: "onClick", dblclick: "onDblclick", change: "onChange", input: "onInput", submit: "onSubmit", keydown: "onKeydown", keyup: "onKeyup",
|
||||
contextmenu: "onContextmenu", focus: "onFocus", blur: "onBlur", pointerdown: "onPointerdown", pointerup: "onPointerup",
|
||||
pointerenter: "onPointerenter", pointerleave: "onPointerleave", dragstart: "onDragstart", dragover: "onDragover", drop: "onDrop",
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
@@ -118,6 +121,12 @@ export default defineComponent({
|
||||
if (typeof args.key === "string" && component.state && Object.hasOwn(component.state, args.key) && "value" in args) state[args.key] = args.value;
|
||||
return;
|
||||
}
|
||||
if (definition.type === "ui.toggleState") {
|
||||
if (typeof args.key === "string" && component.state && Object.hasOwn(component.state, args.key) && typeof state[args.key] === "boolean") {
|
||||
state[args.key] = !state[args.key];
|
||||
}
|
||||
return;
|
||||
}
|
||||
const handler = props.actions[definition.type];
|
||||
if (handler) void Promise.resolve(handler(args, component)).catch(() => undefined);
|
||||
}
|
||||
@@ -149,7 +158,8 @@ export default defineComponent({
|
||||
if (!skipRepeat && node.repeat) {
|
||||
const values = resolvePath(node.repeat.path, context, state);
|
||||
if (!Array.isArray(values)) return null;
|
||||
return h(Fragment, null, values.slice(0, 100).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, true)));
|
||||
const repeatLimit = props.document.schemaVersion >= 3 ? SKIN_PLUGIN_REPEAT_LIMIT : 100;
|
||||
return h(Fragment, null, values.slice(0, repeatLimit).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, true)));
|
||||
}
|
||||
if (node.when) {
|
||||
const value = resolvePath(node.when.path, context, state);
|
||||
@@ -174,7 +184,9 @@ export default defineComponent({
|
||||
if (!propName) continue;
|
||||
attrs[propName] = (event: Event) => {
|
||||
if (!event.isTrusted) return;
|
||||
if (eventName === "keydown" && event instanceof KeyboardEvent && event.key !== "Enter" && event.key !== " ") return;
|
||||
if ((eventName === "keydown" || eventName === "keyup") && event instanceof KeyboardEvent
|
||||
&& event.key !== "Enter" && event.key !== " " && event.key !== "Escape") return;
|
||||
if (eventName === "contextmenu" || eventName === "dragover") event.preventDefault();
|
||||
if (node.bindValue && eventName === "input" && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement)) {
|
||||
state[node.bindValue] = event.target instanceof HTMLInputElement && event.target.type === "checkbox" ? event.target.checked : event.target.value;
|
||||
} else if (node.bindValue && eventName === "change" && (event.target instanceof HTMLInputElement || event.target instanceof HTMLSelectElement || event.target instanceof HTMLTextAreaElement)) {
|
||||
|
||||
@@ -1507,6 +1507,34 @@ const skinPluginContext = computed(() => ({
|
||||
channelId: message.targetId ?? currentChannel.value?.id ?? "",
|
||||
})),
|
||||
},
|
||||
audio: {
|
||||
status: {
|
||||
microphoneMuted: microphoneMuted.value,
|
||||
outputMuted: outputMuted.value,
|
||||
},
|
||||
},
|
||||
whisper: {
|
||||
status: {
|
||||
active: whisperActive.value,
|
||||
targetCount: whisperTargetIds.size,
|
||||
},
|
||||
},
|
||||
screenShare: {
|
||||
status: {
|
||||
active: screenShareActive.value,
|
||||
starting: screenShareStarting.value,
|
||||
viewing: screenShareViewing.value,
|
||||
},
|
||||
streams: screenShareStreams.map((stream) => ({
|
||||
streamId: stream.streamId,
|
||||
source: stream.source,
|
||||
ownerClientId: stream.ownerClientId ?? 0,
|
||||
ownerNickname: stream.ownerNickname,
|
||||
name: stream.name,
|
||||
audio: stream.audio,
|
||||
viewerCount: stream.viewerCount,
|
||||
})),
|
||||
},
|
||||
}));
|
||||
|
||||
const skinPluginActions = {
|
||||
@@ -1531,6 +1559,31 @@ const skinPluginActions = {
|
||||
if (!text || text.length > 1000 || text.includes("\u0000")) return;
|
||||
void sendTextMessage(text, currentChannel.value.id);
|
||||
},
|
||||
"voice.toggleMicrophone": () => { if (voiceState.connected) toggleMicrophone(); },
|
||||
"voice.toggleOutputMute": () => { if (voiceState.connected) toggleOutputMute(); },
|
||||
"voice.setOutputVolume": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.volume !== "number" || !Number.isFinite(args.volume)) return;
|
||||
setOutputVolume(Math.max(0, Math.min(1, args.volume)));
|
||||
},
|
||||
"voice.disconnect": () => { if (voiceState.connected || voiceState.connecting) doDisconnect(); },
|
||||
"voice.setAway": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.away !== "boolean") return;
|
||||
const message = typeof args.message === "string" ? args.message.slice(0, 200) : "";
|
||||
setAway(args.away, message);
|
||||
},
|
||||
"voice.setWhisperActive": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.active !== "boolean") return;
|
||||
setWhisperActive(args.active);
|
||||
},
|
||||
"voice.startScreenShare": () => {
|
||||
if (voiceState.connected && !screenShareActive.value && !screenShareStarting.value) void startScreenShare();
|
||||
},
|
||||
"voice.stopScreenShare": () => { if (screenShareActive.value) stopScreenShare(); },
|
||||
"voice.joinScreenShare": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.streamId !== "string") return;
|
||||
if (screenShareStreams.some((stream) => stream.streamId === args.streamId)) joinScreenShare(args.streamId);
|
||||
},
|
||||
"voice.leaveScreenShare": () => { if (screenShareViewing.value) leaveScreenShare(); },
|
||||
};
|
||||
|
||||
const skinPluginWidgets = {
|
||||
|
||||
Reference in new issue
Block a user