diff --git a/connector/src/main.rs b/connector/src/main.rs index ffc30d4..ff1cc8c 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -66,6 +66,7 @@ struct ClientInfo { output_muted: bool, input_hardware_enabled: bool, away: bool, + away_message: String, is_channel_commander: bool, } @@ -179,6 +180,7 @@ fn snapshot(con: &data::Connection) -> Event { output_muted: c.output_muted, input_hardware_enabled: c.input_hardware_enabled, away: c.away_message.is_some(), + away_message: c.away_message.clone().unwrap_or_default(), is_channel_commander: c.is_channel_commander, }) .collect(); @@ -406,6 +408,27 @@ async fn run(args: Args) -> Result<()> { } Err(_) => emit(&Event::Error { message: format!("Invalid client id: {id}") }), } + } else if l == "away" || l.starts_with("away ") { + let message = l.strip_prefix("away").unwrap_or("").trim(); + let part = con.get_state()?.client_update().set_away(Some(message)); + if let Err(e) = part.send(&mut con) { + emit(&Event::Error { message: e.to_string() }); + } + } else if l == "unaway" { + let part = con.get_state()?.client_update().set_away(None); + if let Err(e) = part.send(&mut con) { + emit(&Event::Error { message: e.to_string() }); + } + } else if let Some(rest) = l.strip_prefix("muteinput ") { + let part = con.get_state()?.client_update().set_input_muted(rest.trim() == "1"); + if let Err(e) = part.send(&mut con) { + emit(&Event::Error { message: e.to_string() }); + } + } else if let Some(rest) = l.strip_prefix("muteoutput ") { + let part = con.get_state()?.client_update().set_output_muted(rest.trim() == "1"); + if let Err(e) = part.send(&mut con) { + emit(&Event::Error { message: e.to_string() }); + } } else if let Some(b64) = l.strip_prefix("audio ") { match base64::engine::general_purpose::STANDARD.decode(b64.trim()) { Ok(bytes) => { diff --git a/gateway/src/index.ts b/gateway/src/index.ts index a6bb639..6c92036 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -51,6 +51,18 @@ wss.on("connection", (socket: WebSocket) => { await connection?.sendAudio(msg.pcm); break; } + case "setAway": { + await connection?.setAway(msg.away, msg.message ?? ""); + break; + } + case "setInputMuted": { + await connection?.setInputMuted(msg.muted); + break; + } + case "setOutputMuted": { + await connection?.setOutputMuted(msg.muted); + break; + } default: socket.send( JSON.stringify({ type: "error", message: `Unknown message type: ${msg.type}` }) diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 5214ebd..32cd1a9 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -29,6 +29,7 @@ export interface ClientInfo { outputMuted: boolean; inputHardwareEnabled: boolean; away: boolean; + awayMessage: string; isChannelCommander: boolean; } @@ -98,6 +99,7 @@ export class Ts3Connection { output_muted: boolean; input_hardware_enabled: boolean; away: boolean; + away_message: string; is_channel_commander: boolean; } @@ -163,6 +165,7 @@ export class Ts3Connection { outputMuted: c.output_muted, inputHardwareEnabled: c.input_hardware_enabled, away: c.away, + awayMessage: c.away_message, isChannelCommander: c.is_channel_commander, })), }); @@ -223,6 +226,23 @@ export class Ts3Connection { this.child?.stdin.write(`audio ${pcmBase64}\n`); } + async setAway(away: boolean, message: string): Promise { + if (away) { + const sanitized = message.replace(/[\r\n]+/g, " ").trim(); + this.child?.stdin.write(`away ${sanitized}\n`); + } else { + this.child?.stdin.write("unaway\n"); + } + } + + async setInputMuted(muted: boolean): Promise { + this.child?.stdin.write(`muteinput ${muted ? "1" : "0"}\n`); + } + + async setOutputMuted(muted: boolean): Promise { + this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`); + } + async disconnect(): Promise { if (this.child && !this.child.killed) { this.child.stdin.write("disconnect\n"); diff --git a/web/src/App.css b/web/src/App.css index 378245c..95f6026 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -136,6 +136,12 @@ color: var(--text-muted); } +.ts-menu-separator { + height: 1px; + margin: 0.25rem 0.3rem; + background: var(--border-soft); +} + .ts-toolbar { display: flex; flex-direction: column; @@ -454,6 +460,55 @@ background: color-mix(in srgb, #4caf50 30%, var(--button-bg-1)) !important; } +.ts-muted-on { + background: color-mix(in srgb, var(--log-error) 30%, var(--button-bg-1)) !important; +} + +.ts-client-away-message { + color: var(--text-muted); + font-style: italic; + font-size: 11px; +} + +.ts-toolbar-away { + position: relative; + display: flex; + align-items: center; +} + +.ts-icon-caret { + border: 1px solid var(--border); + border-left: none; + border-radius: 0 3px 3px 0; + background: linear-gradient(to bottom, var(--button-bg-1), var(--button-bg-2)); + color: var(--text); + padding: 0.25rem 0.3rem; + cursor: pointer; + font-size: 10px; + line-height: 1; +} + +.ts-icon-caret:hover:not(:disabled) { + background: linear-gradient(to bottom, var(--button-bg-hover-1), var(--button-bg-hover-2)); +} + +.ts-icon-caret:disabled { + opacity: 0.4; + cursor: default; +} + +.ts-toolbar-away .ts-icon-button { + border-radius: 3px 0 0 3px; +} + +.ts-away-on { + background: color-mix(in srgb, #e8a53d 30%, var(--button-bg-1)) !important; +} + +.ts-menu-away { + min-width: 220px; +} + /* Chat */ .ts-chat-panel { @@ -618,6 +673,116 @@ width: 480px; } +.ts-favorites-dialog { + width: 760px; +} + +.ts-away-dialog { + width: 420px; +} + +.ts-away-dialog .ts-dialog-row { + align-items: center; + justify-content: space-between; +} + +.ts-dialog-away-label { + font-size: 11px; + color: var(--text-muted); +} + +.ts-away-dialog .ts-dialog-field { + flex-direction: row; + align-items: center; + gap: 0.4rem; +} + +.ts-away-message-input { + border: 1px solid var(--border); + border-radius: 2px; + padding: 0.6rem; + font-size: 13px; + background: var(--input-bg); + color: var(--input-text); +} + +.ts-favorites-body { + display: flex; + gap: 0; +} + +.ts-favorites-list-col { + width: 220px; + flex-shrink: 0; + border-right: 1px solid var(--border-soft); + padding: 0.75rem; + display: flex; + flex-direction: column; + gap: 0.3rem; +} + +.ts-favorites-list-group-title { + font-size: 10px; + font-weight: 600; + text-transform: uppercase; + color: var(--text-muted); + margin-top: 0.4rem; +} + +.ts-favorites-list-group-title:first-child { + margin-top: 0; +} + +.ts-favorites-list-empty { + font-size: 11px; + font-style: italic; + color: var(--text-muted); +} + +.ts-favorites-list { + list-style: none; + margin: 0; + padding: 0; + overflow-y: auto; +} + +.ts-favorites-list-item { + padding: 0.3rem 0.4rem; + border-radius: 2px; + font-size: 12px; + cursor: pointer; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.ts-favorites-list-item:hover { + background: var(--row-hover); +} + +.ts-favorites-list-item-selected { + background: var(--row-hover); + outline: 1px solid var(--border); +} + +.ts-favorites-fields-col { + flex: 1; + display: flex; + flex-direction: column; + gap: 0.6rem; + padding: 0.75rem; +} + +.ts-favorites-profile-col { + width: 200px; + flex-shrink: 0; + border-left: 1px solid var(--border-soft); + padding: 0.75rem; + display: flex; + flex-direction: column; + gap: 0.6rem; +} + .ts-dialog-titlebar { display: flex; align-items: center; diff --git a/web/src/App.tsx b/web/src/App.tsx index b57a859..0e04bb6 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -13,6 +13,37 @@ const GATEWAY_URL = "ws://localhost:8080"; const LAST_HOST_KEY = "ts-web-client:last-host"; const LAST_NICKNAME_KEY = "ts-web-client:last-nickname"; +const FAVORITES_KEY = "ts-web-client:favorites"; + +interface Favorite { + id: string; + bookmarkName: string; + nickname: string; + host: string; + serverPassword: string; + defaultChannel: string; + defaultChannelPassword: string; +} + +function loadFavorites(): Favorite[] { + try { + const raw = localStorage.getItem(FAVORITES_KEY); + return raw ? (JSON.parse(raw) as Favorite[]) : []; + } catch { + return []; + } +} + +const AWAY_PRESETS_KEY = "ts-web-client:away-presets"; + +function loadAwayPresets(): string[] { + try { + const raw = localStorage.getItem(AWAY_PRESETS_KEY); + return raw ? (JSON.parse(raw) as string[]) : []; + } catch { + return []; + } +} type LogEntry = { text: string; kind: "info" | "error" }; @@ -37,6 +68,7 @@ interface ClientInfo { outputMuted: boolean; inputHardwareEnabled: boolean; away: boolean; + awayMessage: string; isChannelCommander: boolean; } @@ -141,6 +173,9 @@ function ChannelTree({ > {c.name} + {c.away && c.awayMessage && ( + ({c.awayMessage}) + )} {c.id !== ownClientId && ( + +
+
+
Synchronisierte Favoriten
+
Nicht angemeldet
+
Lokale Favoriten
+
    + {draft.map((f) => ( +
  • setSelectedId(f.id)} + > + {f.bookmarkName || "(unbenannt)"} +
  • + ))} +
+
+ +
+ + + + + + + +
+ +
+ + + + + + + + +
+
+
+
+ + + +
+
+ + + +
+
+ + + ); +} + +function AwayDialog({ + message, + presets, + onMessageChange, + onOk, + onSaveTemplate, + onCancel, +}: { + message: string; + presets: string[]; + onMessageChange: (v: string) => void; + onOk: () => void; + onSaveTemplate: () => void; + onCancel: () => void; +}) { + return ( +
+
e.stopPropagation()}> +
+ Abwesenheit-Nachricht setzen + +
+
+
+ Nachricht: + +
+ onMessageChange(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && onOk()} + /> +
+
+
+ + + +
+
+
+
+ ); +} + function App() { const [host, setHost] = useState(() => localStorage.getItem(LAST_HOST_KEY) ?? "localhost"); const [nickname, setNickname] = useState(() => localStorage.getItem(LAST_NICKNAME_KEY) ?? "Claude Code"); @@ -459,8 +771,19 @@ function App() { const [outputDeviceId, setOutputDeviceId] = useState(""); const [outputDeviceLabel, setOutputDeviceLabel] = useState("System default"); const [connectionsMenuOpen, setConnectionsMenuOpen] = useState(false); + const [favorites, setFavorites] = useState(() => loadFavorites()); + const [favoritesMenuOpen, setFavoritesMenuOpen] = useState(false); + const [favoritesDialogMode, setFavoritesDialogMode] = useState< + { kind: "add"; prefill: Omit } | { kind: "manage" } | null + >(null); + const [awayMenuOpen, setAwayMenuOpen] = useState(false); + const [awayDialogOpen, setAwayDialogOpen] = useState(false); + const [awayDialogMessage, setAwayDialogMessage] = useState(""); + const [awayPresets, setAwayPresets] = useState(() => loadAwayPresets()); const socketRef = useRef(null); const connectionsMenuRef = useRef(null); + const favoritesMenuRef = useRef(null); + const awayMenuRef = useRef(null); const chatEndRef = useRef(null); const audioContextRef = useRef(null); const audioPlayerRef = useRef(null); @@ -468,11 +791,19 @@ function App() { const activeTabRef = useRef("channel"); const hasConnectedRef = useRef(false); const pokeIdRef = useRef(0); + const inputMutedRef = useRef(false); + const outputMutedRef = useRef(false); useEffect(() => { chatEndRef.current?.scrollIntoView({ block: "nearest" }); }, [chat, serverChat, pmThreads, activeTab]); + useEffect(() => { + const own = clients.find((c) => c.name === nickname) ?? null; + inputMutedRef.current = own?.inputMuted ?? false; + outputMutedRef.current = own?.outputMuted ?? false; + }, [clients, nickname]); + useEffect(() => { if (micCaptureRef.current) micCaptureRef.current.threshold = vadThreshold; }, [vadThreshold]); @@ -545,7 +876,19 @@ function App() { setSelfActive(false); }; - const handleConnect = () => { + const handleConnect = (overrides?: { + host?: string; + nickname?: string; + serverPassword?: string; + channelPassword?: string; + defaultChannel?: string; + }) => { + const connectHost = overrides?.host ?? host; + const connectNickname = overrides?.nickname ?? nickname; + const connectServerPassword = overrides?.serverPassword ?? serverPassword; + const connectChannelPassword = overrides?.channelPassword ?? channelPassword; + const connectDefaultChannel = overrides?.defaultChannel ?? defaultChannel; + hasConnectedRef.current = false; setConnecting(true); setConnectError(null); @@ -562,11 +905,11 @@ function App() { socket.send( JSON.stringify({ type: "connect", - host, - nickname, - serverPassword: serverPassword || undefined, - channelPassword: channelPassword || undefined, - defaultChannel: defaultChannel || undefined, + host: connectHost, + nickname: connectNickname, + serverPassword: connectServerPassword || undefined, + channelPassword: connectChannelPassword || undefined, + defaultChannel: connectDefaultChannel || undefined, }) ); }; @@ -579,8 +922,8 @@ function App() { setConnecting(false); setConnectError(null); setConnected(true); - localStorage.setItem(LAST_HOST_KEY, host); - localStorage.setItem(LAST_NICKNAME_KEY, nickname); + localStorage.setItem(LAST_HOST_KEY, connectHost); + localStorage.setItem(LAST_NICKNAME_KEY, connectNickname); setServerName(data.serverName); setServerMaxClients(data.serverMaxClients); setServerVersion(data.serverVersion); @@ -620,7 +963,7 @@ function App() { }); break; case "audioOut": - audioPlayerRef.current?.playFrame(data.pcm); + if (!outputMutedRef.current) audioPlayerRef.current?.playFrame(data.pcm); break; case "talkers": setTalkers(new Set(data.clients)); @@ -682,6 +1025,66 @@ function App() { const handleDisconnect = () => socketRef.current?.close(); + const connectToFavorite = (f: Favorite) => { + setHost(f.host); + setNickname(f.nickname); + setServerPassword(f.serverPassword); + setChannelPassword(f.defaultChannelPassword); + setDefaultChannel(f.defaultChannel); + handleConnect({ + host: f.host, + nickname: f.nickname, + serverPassword: f.serverPassword, + channelPassword: f.defaultChannelPassword, + defaultChannel: f.defaultChannel, + }); + }; + + const saveFavorites = (next: Favorite[]) => { + setFavorites(next); + localStorage.setItem(FAVORITES_KEY, JSON.stringify(next)); + }; + + const openAddFavorite = () => { + setFavoritesDialogMode({ + kind: "add", + prefill: { + host, + nickname, + serverPassword, + defaultChannel, + defaultChannelPassword: channelPassword, + }, + }); + setFavoritesMenuOpen(false); + }; + + const openManageFavorites = () => { + setFavoritesDialogMode({ kind: "manage" }); + setFavoritesMenuOpen(false); + }; + + const sendAway = (away: boolean, message: string) => { + socketRef.current?.send(JSON.stringify({ type: "setAway", away, message })); + }; + + const handleSaveAwayTemplate = () => { + const trimmed = awayDialogMessage.trim(); + if (!trimmed) return; + setAwayPresets((prev) => { + if (prev.includes(trimmed)) return prev; + const next = [...prev, trimmed]; + localStorage.setItem(AWAY_PRESETS_KEY, JSON.stringify(next)); + return next; + }); + setAwayDialogOpen(false); + }; + + const handleConfirmAway = () => { + sendAway(true, awayDialogMessage); + setAwayDialogOpen(false); + }; + useEffect(() => { if (!connectionsMenuOpen) return; const onPointerDown = (e: MouseEvent) => { @@ -698,6 +1101,38 @@ function App() { }; }, [connectionsMenuOpen]); + useEffect(() => { + if (!favoritesMenuOpen) return; + const onPointerDown = (e: MouseEvent) => { + if (!favoritesMenuRef.current?.contains(e.target as Node)) setFavoritesMenuOpen(false); + }; + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") setFavoritesMenuOpen(false); + }; + window.addEventListener("mousedown", onPointerDown); + window.addEventListener("keydown", onKeyDown); + return () => { + window.removeEventListener("mousedown", onPointerDown); + window.removeEventListener("keydown", onKeyDown); + }; + }, [favoritesMenuOpen]); + + useEffect(() => { + if (!awayMenuOpen) return; + const onPointerDown = (e: MouseEvent) => { + if (!awayMenuRef.current?.contains(e.target as Node)) setAwayMenuOpen(false); + }; + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "Escape") setAwayMenuOpen(false); + }; + window.addEventListener("mousedown", onPointerDown); + window.addEventListener("keydown", onKeyDown); + return () => { + window.removeEventListener("mousedown", onPointerDown); + window.removeEventListener("keydown", onKeyDown); + }; + }, [awayMenuOpen]); + useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { if (!e.ctrlKey) return; @@ -707,33 +1142,42 @@ function App() { } else if (e.key.toLowerCase() === "d" && connected) { e.preventDefault(); handleDisconnect(); + } else if (e.key.toLowerCase() === "b") { + e.preventDefault(); + openAddFavorite(); } }; window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); - }, [connected, connecting]); + }, [connected, connecting, host, nickname, serverPassword, defaultChannel, channelPassword]); const handleToggleMic = async () => { - if (micOn) { - stopMic(); + if (!micOn) { + const audioContext = audioContextRef.current; + if (!audioContext) return; + try { + const mic = new MicCapture( + audioContext, + (pcm) => { + if (!inputMutedRef.current) socketRef.current?.send(JSON.stringify({ type: "sendAudio", pcm })); + }, + (active) => setSelfActive(active), + vadThreshold + ); + await mic.start(); + micCaptureRef.current = mic; + setMicOn(true); + refreshOutputDevices(); + } catch (error) { + appendLog({ text: `Microphone error: ${(error as Error).message}`, kind: "error" }); + } return; } - const audioContext = audioContextRef.current; - if (!audioContext) return; - try { - const mic = new MicCapture( - audioContext, - (pcm) => socketRef.current?.send(JSON.stringify({ type: "sendAudio", pcm })), - (active) => setSelfActive(active), - vadThreshold - ); - await mic.start(); - micCaptureRef.current = mic; - setMicOn(true); - refreshOutputDevices(); - } catch (error) { - appendLog({ text: `Microphone error: ${(error as Error).message}`, kind: "error" }); - } + socketRef.current?.send(JSON.stringify({ type: "setInputMuted", muted: !inputMutedRef.current })); + }; + + const handleToggleOutputMuted = () => { + socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current })); }; const handleOutputDeviceChange = async (deviceId: string, label?: string) => { @@ -802,6 +1246,9 @@ function App() { }; const ownClient = clients.find((c) => c.name === nickname) ?? null; + const isAway = ownClient?.away ?? false; + const inputMuted = ownClient?.inputMuted ?? false; + const outputMuted = ownClient?.outputMuted ?? false; const displayTalkers = selfActive && ownClient ? new Set(talkers).add(ownClient.id) : talkers; @@ -855,7 +1302,43 @@ function App() { )} - {["Favoriten", "Selbst", "Rechte", "Extras", "Hilfe"].map((item) => ( +
+ setFavoritesMenuOpen((v) => !v)} + > + Favoriten + + {favoritesMenuOpen && ( +
+ + + {favorites.length > 0 &&
} + {favorites.map((f) => ( + + ))} +
+ )} +
+ {["Selbst", "Rechte", "Extras", "Hilfe"].map((item) => ( {item} @@ -864,28 +1347,76 @@ function App() {
- {!connected ? ( +
- ) : ( - - )} + {awayMenuOpen && ( +
+ + + {awayPresets.length > 0 &&
} + {awayPresets.map((preset) => ( + + ))} +
+ )} +
+ + {hasNativeOutputPicker() ? ( ) : (