mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Merge upstream/main into GreenTeaSpeak main to resolve PR #4 conflicts.
Keep TeaSpeak/GTS multi-tab work while integrating channel-password prompts and the Pulse theme. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
3db5d90d89
7 files changed
+719
-20
No files matched your search
+156
-9
@@ -169,12 +169,13 @@ const DESIGN_THEME_KEY = "webspeak3:design-theme";
|
||||
const DESIGN_SELECTION_KEY = "webspeak3:design-selection";
|
||||
const CUSTOM_THEMES_KEY = "webspeak3:custom-themes";
|
||||
|
||||
type DesignTheme = "standard" | "nova" | "greenteaspeak";
|
||||
type DesignTheme = "standard" | "nova" | "greenteaspeak" | "pulse";
|
||||
|
||||
/** A user-authored theme package: a name, which built-in layout it behaves like
|
||||
* (Standard's plain chrome vs Nova's collapsed menu/splash vs GreenTeaSpeak shell),
|
||||
* and raw CSS that gets injected while it's active - free-form, so it can restyle
|
||||
* or even reflow the existing markup. */
|
||||
* (Standard's plain chrome, Nova's collapsed menu/splash, GreenTeaSpeak shell,
|
||||
* or Pulse's card/sidebar layout), and raw CSS that gets injected while it's
|
||||
* active - free-form, so it can restyle or even reflow the existing markup
|
||||
* (e.g. via flex `order`, `display:none`, overlays). */
|
||||
type CustomTheme = {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -183,7 +184,7 @@ type CustomTheme = {
|
||||
};
|
||||
|
||||
function isDesignTheme(value: string): value is DesignTheme {
|
||||
return value === "standard" || value === "nova" || value === "greenteaspeak";
|
||||
return value === "standard" || value === "nova" || value === "greenteaspeak" || value === "pulse";
|
||||
}
|
||||
|
||||
function loadDesignTheme(): DesignTheme {
|
||||
@@ -201,6 +202,7 @@ function resolveDesignThemeBase(selection: string, customThemes: CustomTheme[]):
|
||||
|
||||
function designThemeClassName(theme: DesignTheme): string {
|
||||
if (theme === "nova") return " ts-design-nova";
|
||||
if (theme === "pulse") return " ts-design-pulse";
|
||||
if (isGreenteaSpeakTheme(theme)) return " ts-design-greenteaspeak";
|
||||
return "";
|
||||
}
|
||||
@@ -208,6 +210,7 @@ function designThemeClassName(theme: DesignTheme): string {
|
||||
function designThemeLabel(theme: DesignTheme, t: (key: string) => string): string {
|
||||
if (theme === "nova") return t("design.theme.nova");
|
||||
if (theme === "greenteaspeak") return t("design.theme.greenteaspeak");
|
||||
if (theme === "pulse") return t("design.theme.pulse");
|
||||
return t("design.theme.standard");
|
||||
}
|
||||
|
||||
@@ -905,6 +908,46 @@ function ChannelTree({
|
||||
);
|
||||
}
|
||||
|
||||
/** Pulse-theme-only: a row of avatar tiles for everyone in the player's current
|
||||
* channel, with a highlighted ring on whoever is currently talking - the
|
||||
* "who's speaking" strip from the reference client's connected view. Purely
|
||||
* derived from state ChannelTree already has (own channel + `talkers`), no
|
||||
* new backend data needed. */
|
||||
function SpeakingNowBar({
|
||||
clients,
|
||||
talkers,
|
||||
ownClientId,
|
||||
}: {
|
||||
clients: ClientInfo[];
|
||||
talkers: Set<number>;
|
||||
ownClientId: number | null;
|
||||
}) {
|
||||
const own = clients.find((c) => c.id === ownClientId);
|
||||
if (!own) return null;
|
||||
const channelClients = clients.filter((c) => c.channel === own.channel);
|
||||
if (channelClients.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="ts-speaking-now">
|
||||
{channelClients.map((c) => (
|
||||
<div
|
||||
key={c.id}
|
||||
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>
|
||||
<span className="ts-speaking-now-name">{c.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InfoPanel({
|
||||
selected,
|
||||
host,
|
||||
@@ -1349,6 +1392,59 @@ function ConnectDialog({
|
||||
);
|
||||
}
|
||||
|
||||
function ChannelPasswordDialog({
|
||||
channelName,
|
||||
wrongPassword,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
}: {
|
||||
channelName: string;
|
||||
wrongPassword: boolean;
|
||||
onSubmit: (password: string) => void;
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const [password, setPassword] = useState("");
|
||||
const backdrop = { onClick: onCancel };
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-channel-password-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("channelPasswordDialog.title")}</span>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
<p>
|
||||
{wrongPassword ? t("channelPasswordDialog.wrongPassword") : t("channelPasswordDialog.prompt")}
|
||||
{channelName ? ` (${channelName})` : ""}
|
||||
</p>
|
||||
<label className="ts-dialog-field ts-dialog-field-grow">
|
||||
<input
|
||||
type="password"
|
||||
autoFocus
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") onSubmit(password);
|
||||
if (e.key === "Escape") onCancel();
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button type="button" onClick={onCancel}>
|
||||
{t("channelPasswordDialog.cancel")}
|
||||
</button>
|
||||
<button type="button" onClick={() => onSubmit(password)}>
|
||||
{t("channelPasswordDialog.submit")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function FavoritesDialog({
|
||||
favorites,
|
||||
prefillNew,
|
||||
@@ -4038,6 +4134,7 @@ function DesignPanel({
|
||||
name: t("design.theme.greenteaspeak"),
|
||||
desc: t("design.theme.greenteaspeak.desc"),
|
||||
},
|
||||
{ id: "pulse", name: t("design.theme.pulse"), desc: t("design.theme.pulse.desc") },
|
||||
];
|
||||
|
||||
const handleSaveEditing = () => {
|
||||
@@ -4101,6 +4198,7 @@ function DesignPanel({
|
||||
<option value="standard">{t("design.theme.standard")}</option>
|
||||
<option value="nova">{t("design.theme.nova")}</option>
|
||||
<option value="greenteaspeak">{t("design.theme.greenteaspeak")}</option>
|
||||
<option value="pulse">{t("design.theme.pulse")}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="ts-options-field">
|
||||
@@ -4800,6 +4898,13 @@ function AppInner() {
|
||||
() => localStorage.getItem(LAST_PRIVILEGE_KEY) ?? ""
|
||||
);
|
||||
const [serverType, setServerType] = useState<ServerType>(loadServerType);
|
||||
// Prompt shown when switching into a password-protected channel mid-session
|
||||
// (the initial-connect "default channel" password above is a separate field).
|
||||
const [channelPasswordPrompt, setChannelPasswordPrompt] = useState<{
|
||||
channelId: number;
|
||||
channelName: string;
|
||||
wrongPassword: boolean;
|
||||
} | null>(null);
|
||||
const [connectDialogOpen, setConnectDialogOpen] = useState(false);
|
||||
const [connectDialogExpanded, setConnectDialogExpanded] = useState(false);
|
||||
const [log, setLog] = useState<LogEntry[]>([]);
|
||||
@@ -5018,6 +5123,9 @@ function AppInner() {
|
||||
const [recording, setRecording] = useState(false);
|
||||
const whisperLogIdRef = useRef(0);
|
||||
const prevWhisperTargetsRef = useRef<{ channels: Set<number>; clients: Set<number> } | null>(null);
|
||||
// Channel passwords entered this session, so re-entering a channel already
|
||||
// unlocked doesn't prompt again. In-memory only - cleared on disconnect.
|
||||
const channelPasswordCacheRef = useRef<Map<number, string>>(new Map());
|
||||
|
||||
const logClient = (level: LogLevel, category: string, message: string) => {
|
||||
const entry: ClientLogEntry = { id: ++logIdRef.current, timestamp: Date.now(), category, level, message };
|
||||
@@ -5316,6 +5424,8 @@ function AppInner() {
|
||||
setConnected(false);
|
||||
setConnecting(false);
|
||||
setConnectError(null);
|
||||
setChannelPasswordPrompt(null);
|
||||
channelPasswordCacheRef.current.clear();
|
||||
setChannels([]);
|
||||
setClients([]);
|
||||
setOwnClientId(null);
|
||||
@@ -5694,12 +5804,27 @@ function AppInner() {
|
||||
case "disconnected": {
|
||||
const wasConnected = hasConnectedRef.current;
|
||||
cleanDisconnectRef.current = true;
|
||||
setChannelPasswordPrompt(null);
|
||||
channelPasswordCacheRef.current.clear();
|
||||
appendLog({ text: `Disconnected: ${data.reason}`, kind: "info" });
|
||||
logClient("info", "Connection", `Disconnected: ${data.reason}`);
|
||||
if (wasConnected) void playSound("disconnect");
|
||||
removeSession(sessionId, { skipSocketClose: true });
|
||||
break;
|
||||
}
|
||||
case "channelPasswordRequired": {
|
||||
// A cached password just got rejected (channel password changed,
|
||||
// or was wrong) - drop it so the next auto-switch doesn't reuse it.
|
||||
channelPasswordCacheRef.current.delete(data.channelId);
|
||||
setChannelPasswordPrompt((prev) => ({
|
||||
channelId: data.channelId,
|
||||
// `channels` here can be stale (this handler's closure is fixed at
|
||||
// connect time) - the dialog falls back to showing just the id.
|
||||
channelName: channels.find((c) => c.id === data.channelId)?.name ?? "",
|
||||
wrongPassword: prev?.channelId === data.channelId,
|
||||
}));
|
||||
break;
|
||||
}
|
||||
case "error":
|
||||
logClient("error", "Connection", data.message);
|
||||
if (hasConnectedRef.current) {
|
||||
@@ -6447,11 +6572,11 @@ function AppInner() {
|
||||
audioPlayerRef.current?.playTestTone();
|
||||
};
|
||||
|
||||
const handleSwitchChannel = (channelId: number) => {
|
||||
const handleSwitchChannel = (channelId: number, channelPassword?: string) => {
|
||||
const id = Number(channelId);
|
||||
if (!Number.isFinite(id)) return;
|
||||
// Prefer server-reported own client id — nickname match breaks when the
|
||||
// server renames us (Guest → Guest1) or another client shares our nick.
|
||||
// Prefer server-reported own client id - nickname match breaks when the
|
||||
// server renames us (Guest -> Guest1) or another client shares our nick.
|
||||
const me =
|
||||
ownClientId != null
|
||||
? clients.find((c) => c.id === ownClientId)
|
||||
@@ -6462,9 +6587,19 @@ function AppInner() {
|
||||
appendLog({ text: t("tree.joinNotConnected"), kind: "error" });
|
||||
return;
|
||||
}
|
||||
socket.send(JSON.stringify({ type: "switchChannel", channelId: id }));
|
||||
const password = channelPassword ?? channelPasswordCacheRef.current.get(id);
|
||||
socket.send(JSON.stringify({ type: "switchChannel", channelId: id, channelPassword: password }));
|
||||
};
|
||||
|
||||
const handleChannelPasswordSubmit = (password: string) => {
|
||||
if (!channelPasswordPrompt) return;
|
||||
channelPasswordCacheRef.current.set(channelPasswordPrompt.channelId, password);
|
||||
handleSwitchChannel(channelPasswordPrompt.channelId, password);
|
||||
setChannelPasswordPrompt(null);
|
||||
};
|
||||
|
||||
const handleChannelPasswordCancel = () => setChannelPasswordPrompt(null);
|
||||
|
||||
const handleSelectItem = (item: SelectedItem) => setSelected(item);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -7839,6 +7974,15 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{channelPasswordPrompt && (
|
||||
<ChannelPasswordDialog
|
||||
channelName={channelPasswordPrompt.channelName}
|
||||
wrongPassword={channelPasswordPrompt.wrongPassword}
|
||||
onSubmit={handleChannelPasswordSubmit}
|
||||
onCancel={handleChannelPasswordCancel}
|
||||
/>
|
||||
)}
|
||||
|
||||
{inviteFriendOpen && (
|
||||
<InviteFriendDialog
|
||||
host={host}
|
||||
@@ -8590,6 +8734,9 @@ function AppInner() {
|
||||
<div className="ts-resize-handle-horizontal" onMouseDown={startUpperResize} />
|
||||
|
||||
<div className="ts-chat-panel">
|
||||
{connected && designTheme === "pulse" && (
|
||||
<SpeakingNowBar clients={clients} talkers={displayTalkers} ownClientId={ownClient?.id ?? null} />
|
||||
)}
|
||||
<div className="ts-chat-messages">
|
||||
{activeTab === "channel"
|
||||
? chat.map((entry, i) => (
|
||||
|
||||
Reference in new issue
Block a user