From ec034d2d6beb21c57643f1202dc011e141fa6061 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Tue, 28 Jul 2026 20:51:50 +0200 Subject: [PATCH] Add client poking (send and receive) Uses tsclientlib's existing MessageTarget::Poke support end to end: a poke button on each client row opens a small compose overlay (an optional message, like TeamSpeak's own poke), and incoming pokes show as a dismissible, auto-expiring banner. Co-Authored-By: Claude Sonnet 5 --- connector/src/main.rs | 28 +++++++++- gateway/src/index.ts | 4 ++ gateway/src/ts3/connection.ts | 7 +++ web/src/App.css | 97 +++++++++++++++++++++++++++++++++++ web/src/App.tsx | 80 +++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 2 deletions(-) diff --git a/connector/src/main.rs b/connector/src/main.rs index 7d77ac7..8ccbb1d 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -12,7 +12,7 @@ use tokio::io::{AsyncBufReadExt, BufReader}; use tsclientlib::audio::AudioHandler; use tsclientlib::events::Event as BookEvent; -use tsclientlib::messages::c2s::OutSendTextMessagePart; +use tsclientlib::messages::c2s::{OutClientPokeRequestPart, OutSendTextMessagePart}; use tsclientlib::prelude::*; use tsclientlib::{ data, ChannelId, ClientId, Connection, DisconnectOptions, MessageHandle, MessageTarget, @@ -77,6 +77,10 @@ enum Event { /// frontend can group messages into one thread per partner. #[serde(rename = "privateMessage")] PrivateMessage { partner_id: u16, partner_name: String, from_self: bool, message: String }, + /// Someone poked us. Pokes can only be received here - the server doesn't + /// echo our own outgoing pokes back to us, unlike text messages. + #[serde(rename = "poke")] + Poke { from: String, message: String }, /// Mixed, decoded PCM audio ready to play: 16-bit signed little-endian, /// stereo, 48kHz, base64-encoded. #[serde(rename = "audioOut")] @@ -346,6 +350,24 @@ async fn run(args: Args) -> Result<()> { }, None => emit(&Event::Error { message: "Malformed pm command".into() }), } + } else if let Some(rest) = l.strip_prefix("poke ") { + // Unlike chat, a poke's message is optional - a plain poke with no + // text is a normal thing to send in TeamSpeak. + let rest = rest.trim(); + let (id, message) = rest.split_once(' ').unwrap_or((rest, "")); + match id.parse::() { + Ok(id) => { + let part = + OutClientPokeRequestPart { client_id: ClientId(id), message: Cow::Borrowed(message) }; + match part.send_with_result(&mut con) { + Ok(handle) => { + pending_messages.insert(handle, "Poke".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } + Err(_) => emit(&Event::Error { message: format!("Invalid client id: {id}") }), + } } else if let Some(b64) = l.strip_prefix("audio ") { match base64::engine::general_purpose::STANDARD.decode(b64.trim()) { Ok(bytes) => { @@ -425,7 +447,9 @@ async fn run(args: Args) -> Result<()> { }); } } - _ => {} + MessageTarget::Poke(_) => { + emit(&Event::Poke { from: invoker.name.clone(), message: message.clone() }); + } } } } diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 17ad33f..08af384 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -42,6 +42,10 @@ wss.on("connection", (socket: WebSocket) => { await connection?.sendPrivateMessage(msg.clientId, msg.message); break; } + case "sendPoke": { + await connection?.sendPoke(msg.clientId, msg.message ?? ""); + break; + } case "sendAudio": { await connection?.sendAudio(msg.pcm); break; diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 1f1d46f..6149c8c 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -34,6 +34,7 @@ export type Ts3ConnectionEvent = | { type: "chatMessage"; from: string; message: string } | { type: "serverMessage"; from: string; message: string } | { type: "privateMessage"; partnerId: number; partnerName: string; fromSelf: boolean; message: string } + | { type: "poke"; from: string; message: string } | { type: "audioOut"; pcm: string } | { type: "talkers"; clients: number[] } | { type: "disconnected"; reason: string } @@ -92,6 +93,7 @@ export class Ts3Connection { | { type: "chatMessage"; from: string; message: string } | { type: "serverMessage"; from: string; message: string } | { type: "privateMessage"; partner_id: number; partner_name: string; from_self: boolean; message: string } + | { type: "poke"; from: string; message: string } | { type: "audioOut"; pcm: string } | { type: "talkers"; clients: number[] } | { type: "disconnected"; reason: string } @@ -162,6 +164,11 @@ export class Ts3Connection { if (sanitized) this.child?.stdin.write(`pm ${clientId} ${sanitized}\n`); } + async sendPoke(clientId: number, message: string): Promise { + const sanitized = message.replace(/[\r\n]+/g, " ").trim(); + this.child?.stdin.write(`poke ${clientId} ${sanitized}\n`); + } + async sendAudio(pcmBase64: string): Promise { this.child?.stdin.write(`audio ${pcmBase64}\n`); } diff --git a/web/src/App.css b/web/src/App.css index 9153f60..026bf11 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -218,6 +218,25 @@ opacity: 0.85; } +.ts-poke-button { + margin-left: auto; + background: transparent; + border: none; + cursor: pointer; + font-size: 11px; + padding: 0 0.2rem; + opacity: 0; + transition: opacity 0.1s; +} + +.ts-client-row:hover .ts-poke-button { + opacity: 0.85; +} + +.ts-poke-button:hover { + opacity: 1 !important; +} + .ts-mic-on { background: color-mix(in srgb, #4caf50 30%, var(--button-bg-1)) !important; } @@ -363,3 +382,81 @@ .ts-connect-error button:hover { opacity: 1; } + +.ts-poke-compose-backdrop { + position: fixed; + inset: 0; + background: rgba(0, 0, 0, 0.35); + display: flex; + align-items: center; + justify-content: center; + z-index: 10; +} + +.ts-poke-compose { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.9rem 1.1rem; + background: var(--bg-toolbar-1); + border: 1px solid var(--border); + border-radius: 6px; + color: var(--text); + box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); +} + +.ts-poke-compose input { + background: var(--input-bg); + color: var(--input-text); + border: 1px solid var(--border); + border-radius: 3px; + padding: 0.3rem 0.5rem; + min-width: 220px; +} + +.ts-poke-compose button { + background: linear-gradient(var(--button-bg-1), var(--button-bg-2)); + border: 1px solid var(--border); + border-radius: 3px; + color: var(--text); + cursor: pointer; + padding: 0.3rem 0.7rem; +} + +.ts-poke-compose button:hover { + background: linear-gradient(var(--button-bg-hover-1), var(--button-bg-hover-2)); +} + +.ts-poke-notice { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + padding: 0.5rem 0.9rem; + background: #e8a53d; + color: #1a1a1a; + font-size: 13px; + animation: ts-poke-flash 0.4s ease-in-out 2; +} + +@keyframes ts-poke-flash { + 0%, 100% { + filter: brightness(1); + } + 50% { + filter: brightness(1.3); + } +} + +.ts-poke-notice button { + background: transparent; + border: none; + color: #1a1a1a; + cursor: pointer; + font-size: 13px; + opacity: 0.7; +} + +.ts-poke-notice button:hover { + opacity: 1; +} diff --git a/web/src/App.tsx b/web/src/App.tsx index fa1e2ff..61eec09 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -87,6 +87,7 @@ function ChannelTree({ talkers, onSelectChannel, onOpenPrivateChat, + onPokeClient, }: { channels: ChannelInfo[]; clients: ClientInfo[]; @@ -95,6 +96,7 @@ function ChannelTree({ talkers: Set; onSelectChannel: (channelId: number) => void; onOpenPrivateChat: (clientId: number, clientName: string) => void; + onPokeClient: (clientId: number, clientName: string) => void; }) { const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order); if (children.length === 0) return null; @@ -122,6 +124,18 @@ function ChannelTree({ {c.name} + {c.id !== ownClientId && ( + + )} ))} @@ -134,6 +148,7 @@ function ChannelTree({ talkers={talkers} onSelectChannel={onSelectChannel} onOpenPrivateChat={onOpenPrivateChat} + onPokeClient={onPokeClient} /> ))} @@ -160,6 +175,12 @@ interface PmThread { type ActiveTab = "channel" | "server" | number; +interface PokeNotice { + id: number; + from: string; + message: string; +} + function App() { const [host, setHost] = useState(() => localStorage.getItem(LAST_HOST_KEY) ?? "localhost"); const [nickname, setNickname] = useState(() => localStorage.getItem(LAST_NICKNAME_KEY) ?? "Claude Code"); @@ -176,6 +197,9 @@ function App() { const [serverChat, setServerChat] = useState([]); const [chatInput, setChatInput] = useState(""); const [pmThreads, setPmThreads] = useState>({}); + const [pokes, setPokes] = useState([]); + const [pokeTarget, setPokeTarget] = useState<{ id: number; name: string } | null>(null); + const [pokeMessage, setPokeMessage] = useState(""); const [activeTab, setActiveTab] = useState("channel"); const [theme, setTheme] = useState<"light" | "dark">(() => window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light" @@ -194,6 +218,7 @@ function App() { const micCaptureRef = useRef(null); const activeTabRef = useRef("channel"); const hasConnectedRef = useRef(false); + const pokeIdRef = useRef(0); useEffect(() => { chatEndRef.current?.scrollIntoView({ block: "nearest" }); @@ -313,6 +338,12 @@ function App() { case "talkers": setTalkers(new Set(data.clients)); break; + case "poke": { + const id = ++pokeIdRef.current; + setPokes((prev) => [...prev, { id, from: data.from, message: data.message }]); + setTimeout(() => setPokes((prev) => prev.filter((p) => p.id !== id)), 10000); + break; + } case "disconnected": hasConnectedRef.current = false; setConnecting(false); @@ -322,6 +353,7 @@ function App() { setChat([]); setServerChat([]); setPmThreads({}); + setPokes([]); setActiveTab("channel"); setTalkers(new Set()); stopMic(); @@ -425,6 +457,20 @@ function App() { setActiveTab(clientId); }; + const handlePokeClient = (clientId: number, clientName: string) => { + setPokeTarget({ id: clientId, name: clientName }); + setPokeMessage(""); + }; + + const handleSendPoke = () => { + if (!pokeTarget) return; + socketRef.current?.send( + JSON.stringify({ type: "sendPoke", clientId: pokeTarget.id, message: pokeMessage }) + ); + setPokeTarget(null); + setPokeMessage(""); + }; + const handleClosePrivateChat = (clientId: number) => { setPmThreads((prev) => { const next = { ...prev }; @@ -553,6 +599,39 @@ function App() { )} + {pokeTarget && ( +
setPokeTarget(null)}> +
e.stopPropagation()}> + + 👉 Poke {pokeTarget.name} + + setPokeMessage(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") handleSendPoke(); + if (e.key === "Escape") setPokeTarget(null); + }} + placeholder="Optional message..." + /> + + +
+
+ )} + + {pokes.map((poke) => ( +
+ + 👉 {poke.from} poked you{poke.message ? `: ${poke.message}` : ""} + + +
+ ))} +
{connected ? ( @@ -569,6 +648,7 @@ function App() { talkers={displayTalkers} onSelectChannel={handleSelectChannel} onOpenPrivateChat={handleOpenPrivateChat} + onPokeClient={handlePokeClient} /> ) : (