mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 01:12:49 +08:00
feat: show real TeamSpeak avatars
The connector now reports client_flag_avatar (the avatar's MD5) per client. The browser derives /avatar_<uid> from the UID and fetches it through the existing channel-0 file cache used for group icons, again whenever the hash changes. Only the own channel and the selected client are fetched, so a big server does not push every avatar through the gateway; avatars are capped at 512 KiB like icons. They replace the initials tile in the tree (Nova/Pulse), the speaking-now bar, and appear in the client info panel. Also fixes the Nova connect dialog staying open over an auto-connect: its "forced open while disconnected" effect ran after the auto-connect had closed it, and nothing closed it again once connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
7b3cb5ef09
commit
4b245d69d3
4 files changed
+124
-17
No files matched your search
+12
-1
@@ -38,6 +38,9 @@ const FRAME_SAMPLES: usize = 960;
|
||||
/// Upper bound for a file download relayed to the browser (see its use).
|
||||
const MAX_DOWNLOAD_BYTES: u64 = 25 << 20;
|
||||
const MAX_ICON_BYTES: u64 = 512 << 10;
|
||||
/// Avatars are fetched for everyone in the user's channel without asking;
|
||||
/// TS3 servers default to a 300 KiB avatar size limit.
|
||||
const MAX_AVATAR_BYTES: u64 = 512 << 10;
|
||||
const OUT_CHANNELS: usize = 2;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -118,6 +121,9 @@ struct ClientInfo {
|
||||
/// sends no stream command in that case, so the id has to be fetched with
|
||||
/// `requeststreaminfo`. Always `false` on servers that don't report it.
|
||||
is_streaming: bool,
|
||||
/// `client_flag_avatar`: MD5 of the client's avatar, empty without one. The
|
||||
/// file itself is `/avatar_<uid>` in channel 0, fetched by the browser.
|
||||
avatar_hash: String,
|
||||
}
|
||||
|
||||
/// Payload for the "streamsetup " stdin command - the `setupstream` args, which
|
||||
@@ -669,6 +675,7 @@ fn snapshot(con: &data::Connection) -> Event {
|
||||
has_talk_power,
|
||||
is_query: matches!(c.client_type, ClientType::Query { .. }),
|
||||
is_streaming: c.is_streaming.unwrap_or(false),
|
||||
avatar_hash: c.avatar_hash.clone(),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -2955,7 +2962,11 @@ async fn run(args: Args) -> Result<()> {
|
||||
let announced_size = result.size;
|
||||
// Group/server icons are fetched automatically, without the user
|
||||
// asking, so they get a far smaller budget than explicit downloads.
|
||||
let limit = if cid == 0 && path.starts_with("/icon_") { MAX_ICON_BYTES } else { MAX_DOWNLOAD_BYTES };
|
||||
let limit = match path.as_str() {
|
||||
p if cid == 0 && p.starts_with("/icon_") => MAX_ICON_BYTES,
|
||||
p if cid == 0 && p.starts_with("/avatar_") => MAX_AVATAR_BYTES,
|
||||
_ => MAX_DOWNLOAD_BYTES,
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
if announced_size > limit {
|
||||
emit(&Event::Error {
|
||||
|
||||
@@ -59,6 +59,8 @@ export interface ClientInfo {
|
||||
isQuery: boolean;
|
||||
/** Broadcasting a TS6 Stream/Call. The stream id is fetched separately. */
|
||||
isStreaming: boolean;
|
||||
/** MD5 of the avatar (`client_flag_avatar`), empty without one. */
|
||||
avatarHash: string;
|
||||
}
|
||||
|
||||
export interface GroupEntry {
|
||||
@@ -318,6 +320,7 @@ export class Ts3Connection {
|
||||
has_talk_power: boolean;
|
||||
is_query?: boolean;
|
||||
is_streaming?: boolean;
|
||||
avatar_hash?: string;
|
||||
}
|
||||
|
||||
interface RawChannelInfo {
|
||||
@@ -493,6 +496,7 @@ export class Ts3Connection {
|
||||
hasTalkPower: c.has_talk_power,
|
||||
isQuery: Boolean(c.is_query),
|
||||
isStreaming: Boolean(c.is_streaming),
|
||||
avatarHash: c.avatar_hash ?? "",
|
||||
})),
|
||||
ownClientId: event.own_client_id ?? 0,
|
||||
serverMaxClients: event.server_max_clients ?? 0,
|
||||
|
||||
@@ -1417,6 +1417,22 @@
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.ts-avatar-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
.ts-info-avatar {
|
||||
display: block;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
margin: 0.2rem 0 0.4rem;
|
||||
}
|
||||
|
||||
.ts-menu-volume input {
|
||||
flex: 1;
|
||||
min-width: 6rem;
|
||||
|
||||
+92
-16
@@ -647,6 +647,8 @@ interface ClientInfo {
|
||||
isStreaming?: boolean;
|
||||
/** ServerQuery client; filtered from the tree unless a favorite enables them. */
|
||||
isQuery?: boolean;
|
||||
/** MD5 of the avatar, empty without one; missing from gateways before v0.15. */
|
||||
avatarHash?: string;
|
||||
}
|
||||
|
||||
interface GroupEntry {
|
||||
@@ -1099,14 +1101,12 @@ function ChannelTree({
|
||||
<span className="ts-client-status-leading">
|
||||
<ClientStatusIcons client={c} />
|
||||
</span>
|
||||
<span
|
||||
<AvatarTile
|
||||
client={c}
|
||||
images={groupIconImages}
|
||||
className="ts-client-avatar"
|
||||
style={{
|
||||
background: c.id === ownClientId ? "var(--accent)" : clientAvatarColor(c.name),
|
||||
}}
|
||||
>
|
||||
{c.name.trim().charAt(0).toUpperCase() || "?"}
|
||||
</span>
|
||||
isSelf={c.id === ownClientId}
|
||||
/>
|
||||
{countryFlag(c.country) && <span title={c.country}>{countryFlag(c.country)}</span>}
|
||||
<span className="ts-tree-label">{c.name}</span>
|
||||
{c.away && c.awayMessage && (
|
||||
@@ -1180,10 +1180,12 @@ function SpeakingNowBar({
|
||||
clients,
|
||||
talkers,
|
||||
ownClientId,
|
||||
images,
|
||||
}: {
|
||||
clients: ClientInfo[];
|
||||
talkers: Set<number>;
|
||||
ownClientId: number | null;
|
||||
images: Record<string, string>;
|
||||
}) {
|
||||
const own = clients.find((c) => c.id === ownClientId);
|
||||
if (!own) return null;
|
||||
@@ -1198,12 +1200,7 @@ function SpeakingNowBar({
|
||||
className={`ts-speaking-now-tile${talkers.has(c.id) ? " ts-speaking-now-tile-active" : ""}`}
|
||||
title={c.name}
|
||||
>
|
||||
<span
|
||||
className="ts-speaking-now-avatar"
|
||||
style={{ background: c.id === ownClientId ? "var(--accent)" : clientAvatarColor(c.name) }}
|
||||
>
|
||||
{c.name.trim().charAt(0).toUpperCase() || "?"}
|
||||
</span>
|
||||
<AvatarTile client={c} images={images} className="ts-speaking-now-avatar" isSelf={c.id === ownClientId} />
|
||||
<span className="ts-speaking-now-name">{c.name}</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -1224,6 +1221,7 @@ function InfoPanel({
|
||||
channels,
|
||||
clients,
|
||||
serverGroups,
|
||||
images,
|
||||
onShowServerConnectionInfo,
|
||||
onEditServer,
|
||||
}: {
|
||||
@@ -1239,6 +1237,7 @@ function InfoPanel({
|
||||
channels: ChannelInfo[];
|
||||
clients: ClientInfo[];
|
||||
serverGroups: GroupEntry[] | null;
|
||||
images: Record<string, string>;
|
||||
onShowServerConnectionInfo: () => void;
|
||||
onEditServer: () => void;
|
||||
}) {
|
||||
@@ -1301,6 +1300,9 @@ function InfoPanel({
|
||||
/>
|
||||
<span>{client.name}</span>
|
||||
</div>
|
||||
{clientAvatarUrl(client, images) && (
|
||||
<img className="ts-info-avatar" src={clientAvatarUrl(client, images)!} alt="" />
|
||||
)}
|
||||
{client.country && (
|
||||
<div className="ts-info-row">
|
||||
<span>{t("info.country")}</span>{" "}
|
||||
@@ -3581,6 +3583,50 @@ function iconDataUrl(base64: string): string {
|
||||
return `data:${sniffImageMime(atob(base64))};base64,${base64}`;
|
||||
}
|
||||
|
||||
// TeamSpeak keeps a client's avatar as /avatar_<uid> in channel 0's files,
|
||||
// with the UID's decoded bytes spelled as one letter a-p per nibble.
|
||||
function avatarPath(uid: string): string | null {
|
||||
try {
|
||||
const letters = [...atob(uid)].map((ch) => {
|
||||
const b = ch.charCodeAt(0);
|
||||
return String.fromCharCode(97 + (b >> 4), 97 + (b & 15));
|
||||
});
|
||||
return letters.length ? `/avatar_${letters.join("")}` : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Data URL of a client's downloaded avatar, or null to fall back to initials. */
|
||||
function clientAvatarUrl(client: ClientInfo, images: Record<string, string>): string | null {
|
||||
const path = client.avatarHash ? avatarPath(client.uid) : null;
|
||||
const base64 = path ? images[path] : undefined;
|
||||
return base64 ? iconDataUrl(base64) : null;
|
||||
}
|
||||
|
||||
/** The initials tile, or the real avatar once it has been downloaded. */
|
||||
function AvatarTile({
|
||||
client,
|
||||
images,
|
||||
className,
|
||||
isSelf,
|
||||
}: {
|
||||
client: ClientInfo;
|
||||
images: Record<string, string>;
|
||||
className: string;
|
||||
isSelf: boolean;
|
||||
}) {
|
||||
const url = clientAvatarUrl(client, images);
|
||||
return (
|
||||
<span
|
||||
className={className}
|
||||
style={{ background: url ? undefined : isSelf ? "var(--accent)" : clientAvatarColor(client.name) }}
|
||||
>
|
||||
{url ? <img className="ts-avatar-img" src={url} alt="" /> : client.name.trim().charAt(0).toUpperCase() || "?"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// IDs below this are TeamSpeak's built-in default group icons - they ship
|
||||
// inside the official client and were never uploaded to the server's icon
|
||||
// filebase, so downloadFile() for them just hangs forever (nothing to send
|
||||
@@ -7282,6 +7328,7 @@ function AppInner() {
|
||||
case "connected":
|
||||
logClient("info", "Connection", `Connected to ${data.serverName}`);
|
||||
reconnectAttemptsRef.current.delete(sessionId);
|
||||
autoConnectPendingRef.current = false;
|
||||
hasConnectedRef.current = true;
|
||||
everConnectedRef.current.add(sessionId);
|
||||
setConnecting(false);
|
||||
@@ -8162,6 +8209,26 @@ function AppInner() {
|
||||
}
|
||||
}, [clients, serverGroups, serverIconImages]);
|
||||
|
||||
// Avatars share that cid-0 cache, keyed by path; the hash makes a changed
|
||||
// avatar download again. ponytail: only the own channel and the selected
|
||||
// client - a big server's every avatar would be megabytes through the
|
||||
// gateway; widen this if the tree designs ever need all of them.
|
||||
const requestedAvatarHashesRef = useRef(new Map<string, string>());
|
||||
useEffect(() => {
|
||||
if (!connected) requestedAvatarHashesRef.current.clear();
|
||||
}, [connected]);
|
||||
|
||||
useEffect(() => {
|
||||
const ownChannel = clients.find((c) => c.id === ownClientId)?.channel;
|
||||
for (const c of clients) {
|
||||
const wanted = c.channel === ownChannel || (selected?.type === "client" && selected.id === c.id);
|
||||
const path = wanted && c.avatarHash ? avatarPath(c.uid) : null;
|
||||
if (!path || requestedAvatarHashesRef.current.get(path) === c.avatarHash) continue;
|
||||
requestedAvatarHashesRef.current.set(path, c.avatarHash!);
|
||||
socketRef.current?.send(JSON.stringify({ type: "downloadFile", channelId: 0, path }));
|
||||
}
|
||||
}, [clients, ownClientId, selected]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!connected) {
|
||||
setWhisperChannelIds(new Set());
|
||||
@@ -8322,9 +8389,10 @@ function AppInner() {
|
||||
|
||||
// Nova-theme-only: the connect dialog IS the app until a connection exists -
|
||||
// it's forced open on load and after every disconnect, and closes itself the
|
||||
// moment a connection succeeds.
|
||||
// moment a connection succeeds (an auto-connect never went through the
|
||||
// dialog's own close, so this has to do it).
|
||||
useEffect(() => {
|
||||
if (designTheme === "nova" && !connected) setConnectDialogOpen(true);
|
||||
if (designTheme === "nova") setConnectDialogOpen(!connected);
|
||||
}, [designTheme, connected]);
|
||||
|
||||
// Overrides let a device/DSP-setting change take effect immediately, without
|
||||
@@ -9319,11 +9387,13 @@ function AppInner() {
|
||||
setServerIconsOpen(true);
|
||||
setServerIconEntries(null);
|
||||
setServerIconImages({});
|
||||
requestedAvatarHashesRef.current.clear();
|
||||
socketRef.current?.send(JSON.stringify({ type: "getFileList", channelId: 0, path: "/" }));
|
||||
};
|
||||
|
||||
const handleServerIconsRefresh = () => {
|
||||
setServerIconImages({});
|
||||
requestedAvatarHashesRef.current.clear();
|
||||
socketRef.current?.send(JSON.stringify({ type: "getFileList", channelId: 0, path: "/" }));
|
||||
};
|
||||
|
||||
@@ -11184,6 +11254,7 @@ function AppInner() {
|
||||
channels={channels}
|
||||
clients={treeClients}
|
||||
serverGroups={serverGroups}
|
||||
images={serverIconImages}
|
||||
onShowServerConnectionInfo={handleShowServerConnectionInfo}
|
||||
onEditServer={() => setServerEditOpen(true)}
|
||||
/>
|
||||
@@ -11195,7 +11266,12 @@ function AppInner() {
|
||||
|
||||
<div className="ts-chat-panel">
|
||||
{connected && designTheme === "pulse" && (
|
||||
<SpeakingNowBar clients={treeClients} talkers={displayTalkers} ownClientId={ownClient?.id ?? null} />
|
||||
<SpeakingNowBar
|
||||
clients={treeClients}
|
||||
talkers={displayTalkers}
|
||||
ownClientId={ownClient?.id ?? null}
|
||||
images={serverIconImages}
|
||||
/>
|
||||
)}
|
||||
<div className="ts-chat-messages">
|
||||
{activeTab === "channel"
|
||||
|
||||
Reference in new issue
Block a user