mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(plugins): add GitHub store and scoped collaborative panels
This commit is contained in:
1 parent
b9fccb8757
commit
ce681f749d
40 files changed
+1370
-5
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { reactive, ref, shallowRef } from "vue";
|
||||
import { createAdminRequests } from "../services/admin-requests.js";
|
||||
import { isAdminRequestCancelled, type AdminApi } from "../services/admin-api.js";
|
||||
import { parsePluginPackage, PLUGIN_LIMIT_BYTES, type InstalledPlugin, type PluginCatalog, type PluginStoreEntry } from "../../../src/shared/plugins.js";
|
||||
|
||||
export function useAdminPlugins(api: AdminApi) {
|
||||
const installed = shallowRef<InstalledPlugin[]>([]), catalog = shallowRef<PluginCatalog | null>(null);
|
||||
const busy = ref(false), error = ref(''), requests = createAdminRequests();
|
||||
const drafts = reactive<Record<string, { enabled: boolean; scope: 'server'|'instance'; targets: string; config: string }>>({});
|
||||
function apply(records: InstalledPlugin[]) {
|
||||
installed.value = records;
|
||||
for (const record of records) if (!drafts[record.manifest.id]) drafts[record.manifest.id] = {
|
||||
enabled: record.settings.enabled, scope: record.settings.scope, targets: record.settings.targets.join('\n'), config: JSON.stringify(record.settings.config, null, 2),
|
||||
};
|
||||
for (const id of Object.keys(drafts)) if (!records.some(r => r.manifest.id === id)) delete drafts[id];
|
||||
}
|
||||
async function work(run: (signal: AbortSignal, current: () => boolean) => Promise<void>) {
|
||||
if (busy.value) return;
|
||||
const request = requests.begin('plugins'); busy.value = true; error.value = '';
|
||||
const timer = setTimeout(() => { if (request.isCurrent()) { error.value='PLUGIN_TIMEOUT'; requests.cancel('plugins'); busy.value=false; } }, 90_000);
|
||||
try { await run(request.signal, request.isCurrent); }
|
||||
catch (e) { if (request.isCurrent() && !isAdminRequestCancelled(e)) error.value = e instanceof Error ? e.message : 'PLUGIN_FAILED'; }
|
||||
finally { clearTimeout(timer); if (request.isCurrent()) busy.value = false; request.finish(); }
|
||||
}
|
||||
function load() { return work(async (signal, current) => {
|
||||
const result = await api.plugins(signal); if (current()) apply(result.plugins);
|
||||
// Installed packages remain manageable even when GitHub is unavailable.
|
||||
const store = await api.pluginStore(signal); if (current()) catalog.value = store;
|
||||
}); }
|
||||
async function install(entry: PluginStoreEntry) {
|
||||
return work(async (signal, current) => {
|
||||
const result = await api.installPlugin({ id: entry.id, revision: entry.revision, installedRevision: installed.value.find(p => p.manifest.id === entry.id)?.revision ?? null }, signal);
|
||||
if (current()) { delete drafts[entry.id]; apply([...installed.value.filter(p => p.manifest.id !== entry.id), result.plugin]); }
|
||||
});
|
||||
}
|
||||
function save(record: InstalledPlugin) {
|
||||
return work(async (signal, current) => {
|
||||
const draft = drafts[record.manifest.id], captured = JSON.stringify(draft);
|
||||
const settings = { enabled: draft.enabled, scope: draft.scope, targets: draft.targets.split(/\r?\n/).map(t => t.trim()).filter(Boolean), config: JSON.parse(draft.config) };
|
||||
const result = await api.configurePlugin(record.manifest.id, record.revision, settings, signal);
|
||||
if (current()) { if (JSON.stringify(drafts[record.manifest.id]) === captured) delete drafts[record.manifest.id]; apply(installed.value.map(p => p.manifest.id === record.manifest.id ? result.plugin : p)); }
|
||||
});
|
||||
}
|
||||
function remove(record: InstalledPlugin) { return work(async (signal, current) => { await api.removePlugin(record.manifest.id, record.revision, signal); if (current()) apply(installed.value.filter(p => p.manifest.id !== record.manifest.id)); }); }
|
||||
function upload(file: File) { return work(async (signal, current) => {
|
||||
if (file.size > PLUGIN_LIMIT_BYTES) throw new Error('PLUGIN_TOO_LARGE');
|
||||
const pack = parsePluginPackage(JSON.parse(await file.text())); if (!current()) return;
|
||||
const result = await api.uploadPlugin(pack, installed.value.find(p => p.manifest.id === pack.manifest.id)?.revision ?? null, signal);
|
||||
if (current()) { delete drafts[pack.manifest.id]; apply([...installed.value.filter(p => p.manifest.id !== pack.manifest.id), result.plugin]); }
|
||||
}); }
|
||||
function cancelRequests() { requests.reset(); busy.value = false; }
|
||||
function reset() { cancelRequests(); installed.value = []; catalog.value = null; error.value = ''; for (const id of Object.keys(drafts)) delete drafts[id]; }
|
||||
return { installed, catalog, busy, error, drafts, load, install, save, remove, upload, cancelRequests, reset };
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { createAccompaniment, type AccompanimentErrorCode } from "../voice/accom
|
||||
import { createWebRtcTransport } from "../voice/webrtc-transport.js";
|
||||
import { createVoiceConnection } from "../voice/connection.js";
|
||||
import { createVoiceCommands } from "../voice/commands.js";
|
||||
import { createPluginTransport } from "../services/plugin-transport.js";
|
||||
import { createVoiceSessionState } from "../voice/session-state.js";
|
||||
import { applySavedMemberVolumes } from "../voice/member-volume-preferences.js";
|
||||
import { createAudioDiagnostics, type AudioPermission, type VoiceAudioStatusSample } from "../voice/audio-diagnostics.js";
|
||||
@@ -200,6 +201,7 @@ export function useVoiceWebSocket() {
|
||||
const ws = shallowRef<WebSocket | null>(null);
|
||||
const serverInfo = shallowRef<VoiceServerInfo | null>(null);
|
||||
const state = reactive<VoiceState>({ connected: false, connecting: false, reconnecting: false, reconnectAttempt: 0, reconnectFailed: false, tsClientId: 0, error: "", errorCode: "", microphoneError: "", microphoneErrorCode: "", audioNotice: "", audioNoticeCode: "", channelSwitchedChannelId: "" });
|
||||
const plugins = createPluginTransport(() => ws.value, () => state.connected);
|
||||
const sessionState = createVoiceSessionState({
|
||||
selfId: () => state.tsClientId,
|
||||
onMemberRemoved(id) {
|
||||
@@ -1023,6 +1025,7 @@ export function useVoiceWebSocket() {
|
||||
|
||||
/** All ways a session ends release the same owned media and pending work. */
|
||||
function releaseSessionResources(sendScreenStop = false): void {
|
||||
plugins.reset();
|
||||
chatGeneration++;
|
||||
inputDeviceGeneration++;
|
||||
outputDeviceGeneration++;
|
||||
@@ -1043,6 +1046,7 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
|
||||
function handleMessage(raw: unknown): void {
|
||||
if (plugins.receive(raw)) return;
|
||||
const msg = parseServerMessage(raw);
|
||||
if (!msg || screenShare.handleMessage(msg) || sessionState.receive(msg)) return;
|
||||
switch (msg.type) {
|
||||
@@ -1416,6 +1420,7 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
|
||||
return {
|
||||
plugins,
|
||||
...screenShare.api,
|
||||
ws,
|
||||
state,
|
||||
|
||||
Reference in new issue
Block a user