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 });
}