Add whisper (targeted voice to channels/clients)

Connector: a new "whisper <channelIds>;<clientIds>" stdin command sets
persistent whisper targets; outgoing audio then goes out as
AudioData::C2SWhisper instead of the normal C2S broadcast until
"unwhisper" clears it. Gateway relays a setWhisperTargets message the
same way.

Frontend: a toolbar toggle lists channels as checkboxes, and the
client context menu gets an "add/remove as whisper target" entry;
selecting any target switches all subsequent outgoing voice to
whisper mode.

Verified against the real test server: setting a channel target and
sending a frame produced no connector error, and clearing targets
resumed normal voice cleanly.
This commit is contained in:
Moepchi committed 2026-08-02 14:41:54 +02:00
1 parent 7217bc146a
commit 5858631e6d
5 files changed
+184 -7

No files matched your search

+33 -5
View File
@@ -445,6 +445,11 @@ async fn run(args: Args) -> Result<()> {
// `send_with_result()` for text messages gets us a `MessageResult` event we
// can surface as a visible error instead of the message just vanishing.
let mut pending_messages: HashMap<MessageHandle, String> = HashMap::new();
// When non-empty, outgoing voice is whispered to just these channels/clients
// instead of being sent to the current channel - set via the "whisper "
// stdin command, cleared via "unwhisper".
let mut whisper_channels: Vec<u64> = Vec::new();
let mut whisper_clients: Vec<u16> = Vec::new();
enum LoopOutcome {
StdinLine(std::io::Result<Option<String>>),
@@ -582,6 +587,17 @@ async fn run(args: Args) -> Result<()> {
if let Err(e) = part.send(&mut con) {
emit(&Event::Error { message: e.to_string() });
}
} else if let Some(rest) = l.strip_prefix("whisper ") {
// Format: "whisper <channelId,channelId,...>;<clientId,clientId,...>"
// (either side may be empty, e.g. "whisper 5;" or "whisper ;12,13").
let mut parts = rest.splitn(2, ';');
let channels_part = parts.next().unwrap_or("");
let clients_part = parts.next().unwrap_or("");
whisper_channels = channels_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
whisper_clients = clients_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
} else if l == "unwhisper" {
whisper_channels.clear();
whisper_clients.clear();
} else if let Some(b64) = l.strip_prefix("audio ") {
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
Ok(bytes) => {
@@ -593,11 +609,23 @@ async fn run(args: Args) -> Result<()> {
let mut opus_output = [0u8; 1275];
match opus_encoder.encode_float(&samples, &mut opus_output) {
Ok(len) => {
let packet = OutAudio::new(&AudioData::C2S {
id: 0,
codec: CodecType::OpusVoice,
data: &opus_output[..len],
});
let has_whisper_targets =
!whisper_channels.is_empty() || !whisper_clients.is_empty();
let packet = if has_whisper_targets {
OutAudio::new(&AudioData::C2SWhisper {
id: 0,
codec: CodecType::OpusVoice,
channels: whisper_channels.clone(),
clients: whisper_clients.clone(),
data: &opus_output[..len],
})
} else {
OutAudio::new(&AudioData::C2S {
id: 0,
codec: CodecType::OpusVoice,
data: &opus_output[..len],
})
};
if let Err(e) = con.send_audio(packet) {
emit(&Event::Error { message: e.to_string() });
}
+4
View File
@@ -114,6 +114,10 @@ wss.on("connection", (socket: WebSocket) => {
await connection?.setOutputMuted(msg.muted);
break;
}
case "setWhisperTargets": {
await connection?.setWhisperTargets(msg.channelIds ?? [], msg.clientIds ?? []);
break;
}
case "disconnect": {
await connection?.disconnect(msg.message ?? "");
break;
+10
View File
@@ -268,6 +268,16 @@ export class Ts3Connection {
this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`);
}
/** Empty channelIds/clientIds clears whisper mode, returning outgoing
* voice to the normal current-channel broadcast. */
async setWhisperTargets(channelIds: number[], clientIds: number[]): Promise<void> {
if (channelIds.length === 0 && clientIds.length === 0) {
this.child?.stdin.write("unwhisper\n");
} else {
this.child?.stdin.write(`whisper ${channelIds.join(",")};${clientIds.join(",")}\n`);
}
}
async disconnect(message = ""): Promise<void> {
if (this.child && !this.child.killed) {
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
+125
View File
@@ -1477,6 +1477,10 @@ function AppInner() {
isSelf: boolean;
} | null>(null);
const clientContextMenuRef = useRef<HTMLDivElement>(null);
const [whisperChannelIds, setWhisperChannelIds] = useState<Set<number>>(new Set());
const [whisperClientIds, setWhisperClientIds] = useState<Set<number>>(new Set());
const [whisperMenuOpen, setWhisperMenuOpen] = useState(false);
const whisperMenuRef = useRef<HTMLDivElement | null>(null);
const [activeTab, setActiveTab] = useState<ActiveTab>("channel");
const [theme, setTheme] = useState<"light" | "dark">(() =>
window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"
@@ -2033,6 +2037,40 @@ function AppInner() {
};
}, [clientContextMenu]);
useEffect(() => {
if (!connected) {
setWhisperChannelIds(new Set());
setWhisperClientIds(new Set());
}
}, [connected]);
useEffect(() => {
if (!connected) return;
socketRef.current?.send(
JSON.stringify({
type: "setWhisperTargets",
channelIds: [...whisperChannelIds],
clientIds: [...whisperClientIds],
})
);
}, [whisperChannelIds, whisperClientIds, connected]);
useEffect(() => {
if (!whisperMenuOpen) return;
const onPointerDown = (e: MouseEvent) => {
if (!whisperMenuRef.current?.contains(e.target as Node)) setWhisperMenuOpen(false);
};
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === "Escape") setWhisperMenuOpen(false);
};
window.addEventListener("mousedown", onPointerDown);
window.addEventListener("keydown", onKeyDown);
return () => {
window.removeEventListener("mousedown", onPointerDown);
window.removeEventListener("keydown", onKeyDown);
};
}, [whisperMenuOpen]);
useEffect(() => {
if (!extrasMenuOpen) return;
const onPointerDown = (e: MouseEvent) => {
@@ -2215,6 +2253,29 @@ function AppInner() {
setPokeMessage("");
};
const toggleWhisperChannel = (channelId: number) => {
setWhisperChannelIds((prev) => {
const next = new Set(prev);
if (next.has(channelId)) next.delete(channelId);
else next.add(channelId);
return next;
});
};
const toggleWhisperClient = (clientId: number) => {
setWhisperClientIds((prev) => {
const next = new Set(prev);
if (next.has(clientId)) next.delete(clientId);
else next.add(clientId);
return next;
});
};
const clearWhisperTargets = () => {
setWhisperChannelIds(new Set());
setWhisperClientIds(new Set());
};
const handleClientContextMenu = (
e: React.MouseEvent,
clientId: number,
@@ -2500,6 +2561,54 @@ function AppInner() {
)}
</div>
<span className="ts-toolbar-sep" />
<div className="ts-toolbar-away" ref={whisperMenuRef}>
<button
className={`ts-icon-button${whisperChannelIds.size > 0 || whisperClientIds.size > 0 ? " ts-away-on" : ""}`}
onClick={() => setWhisperMenuOpen((v) => !v)}
disabled={!connected}
title={t("toolbar.whisper")}
>
🤫
</button>
{whisperMenuOpen && (
<div className="ts-menu ts-menu-away">
<div className="ts-context-menu-title">{t("whisper.channels")}</div>
{channels.map((ch) => (
<label key={ch.id} className="ts-menu-item">
<input
type="checkbox"
checked={whisperChannelIds.has(ch.id)}
onChange={() => toggleWhisperChannel(ch.id)}
/>
<span className="ts-menu-item-label">{ch.name}</span>
</label>
))}
{whisperClientIds.size > 0 && (
<>
<div className="ts-menu-separator" />
<div className="ts-context-menu-title">{t("whisper.clients")}</div>
{[...whisperClientIds].map((id) => (
<button key={id} className="ts-menu-item" onClick={() => toggleWhisperClient(id)}>
<span className="ts-menu-item-icon">✕</span>
<span className="ts-menu-item-label">
{clients.find((c) => c.id === id)?.name ?? id}
</span>
</button>
))}
</>
)}
{(whisperChannelIds.size > 0 || whisperClientIds.size > 0) && (
<>
<div className="ts-menu-separator" />
<button className="ts-menu-item" onClick={clearWhisperTargets}>
<span className="ts-menu-item-label">{t("whisper.clearAll")}</span>
</button>
</>
)}
</div>
)}
</div>
<span className="ts-toolbar-sep" />
<button
className={`ts-icon-button${micOn && !inputMuted ? " ts-mic-on" : ""}${micOn && inputMuted ? " ts-muted-on" : ""}`}
onClick={handleToggleMic}
@@ -2722,6 +2831,22 @@ function AppInner() {
<span className="ts-menu-item-icon">📋</span>
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
</button>
{!clientContextMenu.isSelf && (
<button
className="ts-menu-item"
onClick={() => {
toggleWhisperClient(clientContextMenu.clientId);
setClientContextMenu(null);
}}
>
<span className="ts-menu-item-icon">🤫</span>
<span className="ts-menu-item-label">
{whisperClientIds.has(clientContextMenu.clientId)
? t("clientContext.removeWhisperTarget")
: t("clientContext.addWhisperTarget")}
</span>
</button>
)}
<div className="ts-menu-separator" />
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
<span className="ts-menu-item-icon">🏷️</span>
+12 -2
View File
@@ -38,12 +38,15 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.extras.startRecording": "Aufnahme starten",
"menu.extras.startMultitrackRecording": "Start Multitrack Recording",
"menu.extras.stopRecording": "Aufnahme beenden",
"menu.extras.installOverwolf": "Overwolf installieren",
"menu.extras.options": "Optionen",
"toolbar.setAway": "Als abwesend markieren",
"toolbar.backOnline": "Wieder online",
"toolbar.awayOptions": "Abwesenheitsoptionen",
"toolbar.whisper": "Whisper-Ziele",
"whisper.channels": "Channels",
"whisper.clients": "Clients",
"whisper.clearAll": "Alle Whisper-Ziele entfernen",
"toolbar.micEnable": "Mikrofon aktivieren",
"toolbar.micMute": "Mikrofon stummschalten",
"toolbar.micUnmute": "Mikrofon aktivieren (unmute)",
@@ -209,6 +212,8 @@ const translations: Record<Lang, Record<string, string>> = {
"clientContext.privateChat": "Privater Chat",
"clientContext.poke": "Anstupsen",
"clientContext.copyName": "Namen kopieren",
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
"clientContext.removeWhisperTarget": "Als Whisper-Ziel entfernen",
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
"clientContext.assignServerGroup": "Server-Gruppe zuweisen",
"clientContext.kick": "Vom Server kicken",
@@ -277,12 +282,15 @@ const translations: Record<Lang, Record<string, string>> = {
"menu.extras.startRecording": "Start Recording",
"menu.extras.startMultitrackRecording": "Start Multitrack Recording",
"menu.extras.stopRecording": "Stop Recording",
"menu.extras.installOverwolf": "Install Overwolf",
"menu.extras.options": "Options",
"toolbar.setAway": "Set away",
"toolbar.backOnline": "Back online",
"toolbar.awayOptions": "Away options",
"toolbar.whisper": "Whisper targets",
"whisper.channels": "Channels",
"whisper.clients": "Clients",
"whisper.clearAll": "Clear all whisper targets",
"toolbar.micEnable": "Enable microphone",
"toolbar.micMute": "Mute microphone",
"toolbar.micUnmute": "Unmute microphone",
@@ -448,6 +456,8 @@ const translations: Record<Lang, Record<string, string>> = {
"clientContext.privateChat": "Private chat",
"clientContext.poke": "Poke",
"clientContext.copyName": "Copy name",
"clientContext.addWhisperTarget": "Add as whisper target",
"clientContext.removeWhisperTarget": "Remove as whisper target",
"clientContext.assignChannelGroup": "Assign channel group",
"clientContext.assignServerGroup": "Assign server group",
"clientContext.kick": "Kick from server",