fix: synchronize microphone mute state

This commit is contained in:
illusia committed 2026-09-18 17:06:30 +08:00
1 parent fae21ec086
commit bcf212738b
6 files changed
+35 -8

No files matched your search

+2 -2
View File
@@ -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"
+1 -1
View File
@@ -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",
+13 -3
View File
@@ -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<number, ClientInfo>();
private clients = new Map<number, DirectoryClientInfo>();
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 });
}
+9
View File
@@ -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<void> {
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<void> {
if (!this.client || !this.connected) return;
await tsClientMove(this.client, this.clientId, channelId, password);
+9 -1
View File
@@ -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") {
+1 -1
View File
@@ -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();
}