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

+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") {