mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 20:12:52 +08:00
fix: synchronize microphone mute state
This commit is contained in:
1 parent
fae21ec086
commit
bcf212738b
6 files changed
+35
-8
No files matched your search
Generated
+2
-2
@@ -10,7 +10,7 @@
|
|||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "^0.10.0",
|
"@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",
|
"express": "^5.2.1",
|
||||||
"pino": "^10.3.1",
|
"pino": "^10.3.1",
|
||||||
"werift": "0.24.4",
|
"werift": "0.24.4",
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/@echosixhiya/teamspeak-client": {
|
"node_modules/@echosixhiya/teamspeak-client": {
|
||||||
"version": "0.2.4",
|
"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",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/curves": "^2.0.1"
|
"@noble/curves": "^2.0.1"
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "^0.10.0",
|
"@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",
|
"express": "^5.2.1",
|
||||||
"pino": "^10.3.1",
|
"pino": "^10.3.1",
|
||||||
"werift": "0.24.4",
|
"werift": "0.24.4",
|
||||||
|
|||||||
@@ -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";
|
import type { TSDirectorySnapshot } from "./ts-client.js";
|
||||||
|
|
||||||
type DirectoryDelta =
|
type DirectoryDelta =
|
||||||
| { type: "clientEnter"; info: ClientInfo }
|
| { type: "clientEnter"; info: ClientInfo }
|
||||||
| { type: "clientLeave"; id: number }
|
| { 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
|
* Merges staged welcome snapshots with events received while the snapshot is
|
||||||
@@ -14,7 +15,7 @@ type DirectoryDelta =
|
|||||||
*/
|
*/
|
||||||
export class DirectorySynchronizer {
|
export class DirectorySynchronizer {
|
||||||
private snapshot: TSDirectorySnapshot | null = null;
|
private snapshot: TSDirectorySnapshot | null = null;
|
||||||
private clients = new Map<number, ClientInfo>();
|
private clients = new Map<number, DirectoryClientInfo>();
|
||||||
private pending: DirectoryDelta[] = [];
|
private pending: DirectoryDelta[] = [];
|
||||||
|
|
||||||
get ready(): boolean {
|
get ready(): boolean {
|
||||||
@@ -43,6 +44,10 @@ export class DirectorySynchronizer {
|
|||||||
this.applyOrQueue({ type: "clientMoved", id, channelID });
|
this.applyOrQueue({ type: "clientMoved", id, channelID });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyClientUpdated(info: DirectoryClientInfo): void {
|
||||||
|
this.applyOrQueue({ type: "clientUpdated", info });
|
||||||
|
}
|
||||||
|
|
||||||
getSnapshot(): TSDirectorySnapshot | null {
|
getSnapshot(): TSDirectorySnapshot | null {
|
||||||
if (!this.snapshot) return null;
|
if (!this.snapshot) return null;
|
||||||
return {
|
return {
|
||||||
@@ -74,6 +79,11 @@ export class DirectorySynchronizer {
|
|||||||
this.clients.delete(delta.id);
|
this.clients.delete(delta.id);
|
||||||
return;
|
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);
|
const current = this.clients.get(delta.id);
|
||||||
if (current) this.clients.set(delta.id, { ...current, channelID: delta.channelID });
|
if (current) this.clients.set(delta.id, { ...current, channelID: delta.channelID });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,6 +240,10 @@ export class TSClient extends EventEmitter {
|
|||||||
if (info.id === this.clientId && info.targetChannelID !== 0n) this.preferredChannelId = info.targetChannelID;
|
if (info.id === this.clientId && info.targetChannelID !== 0n) this.preferredChannelId = info.targetChannelID;
|
||||||
this.emit("clientMoved", info);
|
this.emit("clientMoved", info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on("clientUpdated", (event) => {
|
||||||
|
this.emit("clientUpdated", event.info);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendVoice(data: Buffer, codec: number = 4): void {
|
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}`);
|
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> {
|
async switchChannel(channelId: bigint, password?: string): Promise<void> {
|
||||||
if (!this.client || !this.connected) return;
|
if (!this.client || !this.connected) return;
|
||||||
await tsClientMove(this.client, this.clientId, channelId, password);
|
await tsClientMove(this.client, this.clientId, channelId, password);
|
||||||
|
|||||||
@@ -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) => {
|
tsClient.on("voiceData", (data: TSVoiceData) => {
|
||||||
const receivedAt = Date.now();
|
const receivedAt = Date.now();
|
||||||
if (entry!.audio.tsReceiveLastAt !== null) entry!.audio.tsReceiveMaxGapMs = Math.max(entry!.audio.tsReceiveMaxGapMs, receivedAt - entry!.audio.tsReceiveLastAt);
|
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;
|
entry.whisperActive = active;
|
||||||
sendJson({ type: "whisperTargets", targetIds: [...entry.whisperTargetIds], active: entry.whisperActive });
|
sendJson({ type: "whisperTargets", targetIds: [...entry.whisperTargetIds], active: entry.whisperActive });
|
||||||
} else if (command.type === "setMicrophoneMuted") {
|
} 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") {
|
} else if (command.type === "setAccompanimentActive") {
|
||||||
entry.webrtc?.setAccompanimentActive(command.payload.active as boolean);
|
entry.webrtc?.setAccompanimentActive(command.payload.active as boolean);
|
||||||
} else if (command.type === "setMemberVolume") {
|
} else if (command.type === "setMemberVolume") {
|
||||||
|
|||||||
@@ -1878,7 +1878,7 @@ export function useVoiceWebSocket() {
|
|||||||
accumLen = 0;
|
accumLen = 0;
|
||||||
if (webrtcActive.value) micStream?.getAudioTracks().forEach((track) => { track.enabled = !muted; });
|
if (webrtcActive.value) micStream?.getAudioTracks().forEach((track) => { track.enabled = !muted; });
|
||||||
if (webrtcMixMicGain) webrtcMixMicGain.gain.value = muted ? 0 : inputVolume.value;
|
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);
|
if (muted && state.tsClientId) clearSpeaking(state.tsClientId);
|
||||||
void saveAudioPreferences();
|
void saveAudioPreferences();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user