diff --git a/package-lock.json b/package-lock.json index ecfbaec..05273a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "AGPL-3.0-only", "dependencies": { "@discordjs/opus": "^0.10.0", - "@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338", + "@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#95217066f61a1c7021d4744040283a78ece929f9", "express": "^5.2.1", "pino": "^10.3.1", "werift": "0.24.4", @@ -63,7 +63,7 @@ }, "node_modules/@echosixhiya/teamspeak-client": { "version": "0.2.4", - "resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338c7a83044dee0951c412ad91292b570215", + "resolved": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#95217066f61a1c7021d4744040283a78ece929f9", "license": "MIT", "dependencies": { "@noble/curves": "^2.0.1" diff --git a/package.json b/package.json index 8a26b03..22cfce7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@discordjs/opus": "^0.10.0", - "@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#a145338", + "@echosixhiya/teamspeak-client": "git+https://github.com/EchoSixHIYA/teamspeak-js.git#95217066f61a1c7021d4744040283a78ece929f9", "express": "^5.2.1", "pino": "^10.3.1", "werift": "0.24.4", diff --git a/src/server/directory-sync.ts b/src/server/directory-sync.ts index 0504d58..99e4e2b 100644 --- a/src/server/directory-sync.ts +++ b/src/server/directory-sync.ts @@ -1,10 +1,11 @@ -import type { ClientInfo } from "@echosixhiya/teamspeak-client"; +import type { ClientInfo, DirectoryClientInfo } from "@echosixhiya/teamspeak-client"; import type { TSDirectorySnapshot } from "./ts-client.js"; type DirectoryDelta = | { type: "clientEnter"; info: ClientInfo } | { type: "clientLeave"; id: number } - | { type: "clientMoved"; id: number; channelID: bigint }; + | { type: "clientMoved"; id: number; channelID: bigint } + | { type: "clientUpdated"; info: DirectoryClientInfo }; /** * Merges staged welcome snapshots with events received while the snapshot is @@ -14,7 +15,7 @@ type DirectoryDelta = */ export class DirectorySynchronizer { private snapshot: TSDirectorySnapshot | null = null; - private clients = new Map(); + private clients = new Map(); private pending: DirectoryDelta[] = []; get ready(): boolean { @@ -43,6 +44,10 @@ export class DirectorySynchronizer { this.applyOrQueue({ type: "clientMoved", id, channelID }); } + applyClientUpdated(info: DirectoryClientInfo): void { + this.applyOrQueue({ type: "clientUpdated", info }); + } + getSnapshot(): TSDirectorySnapshot | null { if (!this.snapshot) return null; return { @@ -74,6 +79,11 @@ export class DirectorySynchronizer { this.clients.delete(delta.id); return; } + if (delta.type === "clientUpdated") { + const current = this.clients.get(delta.info.id); + this.clients.set(delta.info.id, current ? { ...current, ...delta.info } : delta.info); + return; + } const current = this.clients.get(delta.id); if (current) this.clients.set(delta.id, { ...current, channelID: delta.channelID }); } diff --git a/src/server/ts-client.ts b/src/server/ts-client.ts index bf6e98c..c897ec7 100644 --- a/src/server/ts-client.ts +++ b/src/server/ts-client.ts @@ -240,6 +240,10 @@ export class TSClient extends EventEmitter { if (info.id === this.clientId && info.targetChannelID !== 0n) this.preferredChannelId = info.targetChannelID; this.emit("clientMoved", info); }); + + client.on("clientUpdated", (event) => { + this.emit("clientUpdated", event.info); + }); } sendVoice(data: Buffer, codec: number = 4): void { @@ -271,6 +275,11 @@ export class TSClient extends EventEmitter { await this.client.execCommand(`clientupdate client_away=${away ? 1 : 0} client_away_message=${escaped}`); } + async setInputMuted(muted: boolean): Promise { + if (!this.client || !this.connected) throw new Error("TeamSpeak session is not ready"); + await this.client.execCommand(`clientupdate client_input_muted=${muted ? 1 : 0}`); + } + async switchChannel(channelId: bigint, password?: string): Promise { if (!this.client || !this.connected) return; await tsClientMove(this.client, this.clientId, channelId, password); diff --git a/src/server/voice-bridge.ts b/src/server/voice-bridge.ts index 851b0ca..cbc2ab7 100644 --- a/src/server/voice-bridge.ts +++ b/src/server/voice-bridge.ts @@ -546,6 +546,12 @@ export class VoiceBridge { } }); + tsClient.on("clientUpdated", (info) => { + directory.applyClientUpdated(info); + refreshDirectory(); + if (tsReady && initialStateSent) sendJson({ type: "channelList", channels: entry!.channelTree }); + }); + tsClient.on("voiceData", (data: TSVoiceData) => { const receivedAt = Date.now(); if (entry!.audio.tsReceiveLastAt !== null) entry!.audio.tsReceiveMaxGapMs = Math.max(entry!.audio.tsReceiveMaxGapMs, receivedAt - entry!.audio.tsReceiveLastAt); @@ -1086,7 +1092,9 @@ async function handleCommand( entry.whisperActive = active; sendJson({ type: "whisperTargets", targetIds: [...entry.whisperTargetIds], active: entry.whisperActive }); } else if (command.type === "setMicrophoneMuted") { - entry.webrtc?.setMicrophoneMuted(command.payload.muted as boolean); + const muted = command.payload.muted as boolean; + await entry.tsClient.setInputMuted(muted); + entry.webrtc?.setMicrophoneMuted(muted); } else if (command.type === "setAccompanimentActive") { entry.webrtc?.setAccompanimentActive(command.payload.active as boolean); } else if (command.type === "setMemberVolume") { diff --git a/web/src/composables/useVoiceWebSocket.ts b/web/src/composables/useVoiceWebSocket.ts index 76b3284..5f0f131 100644 --- a/web/src/composables/useVoiceWebSocket.ts +++ b/web/src/composables/useVoiceWebSocket.ts @@ -1878,7 +1878,7 @@ export function useVoiceWebSocket() { accumLen = 0; if (webrtcActive.value) micStream?.getAudioTracks().forEach((track) => { track.enabled = !muted; }); if (webrtcMixMicGain) webrtcMixMicGain.gain.value = muted ? 0 : inputVolume.value; - if (webrtcActive.value) sendCmd("setMicrophoneMuted", { muted }); + sendCmd("setMicrophoneMuted", { muted }); if (muted && state.tsClientId) clearSpeaking(state.tsClientId); void saveAudioPreferences(); }