mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20d1944dc9 | ||
|
|
fd5a4cd6e0 | ||
|
|
701bd867fc | ||
|
|
b6448e65e8 | ||
|
|
bf85173a54 |
No files matched your search
@@ -80,7 +80,7 @@ not need to be installed on the same machine, modified, or operated by you.
|
|||||||
| 🌗 **Dark / light theme** | Clean, modern UI that adapts to your preference |
|
| 🌗 **Dark / light theme** | Clean, modern UI that adapts to your preference |
|
||||||
| 🔁 **Multi-join (server tabs)** | Several connections in parallel — one tab per server, like GreenTeaSpeak 2. Audio stays on the active tab |
|
| 🔁 **Multi-join (server tabs)** | Several connections in parallel — one tab per server, like GreenTeaSpeak 2. Audio stays on the active tab |
|
||||||
| 🔁 **Seamless reconnect** | Switch or add connections mid-session without tearing down unrelated tabs |
|
| 🔁 **Seamless reconnect** | Switch or add connections mid-session without tearing down unrelated tabs |
|
||||||
| 🍵 **GreenTeaSpeak theme** | Optional GTS-styled UI chrome (dark panels, gold menu bar, connection-tab strip) alongside the default look |
|
| 🍵 **GreenTeaSpeak support** | Connects to real GreenTeaSpeak servers (not just TS3/TS6/TeaSpeak), plus an optional GTS-styled UI chrome (dark panels, gold menu bar, connection-tab strip) alongside the default look |
|
||||||
|
|
||||||
## 🧱 Tech Stack
|
## 🧱 Tech Stack
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ gateway is required that speaks the real TS protocol on one side and
|
|||||||
WebSocket to the browser on the other.
|
WebSocket to the browser on the other.
|
||||||
|
|
||||||
```
|
```
|
||||||
Browser (web/) <--WebSocket--> Gateway (gateway/) <--stdin/stdout JSON--> Rust connector (connector/) <--TS3/TS6/TeaSpeak protocol--> Server
|
Browser (web/) <--WebSocket--> Gateway (gateway/) <--stdin/stdout JSON--> Rust connector (connector/) <--TS3/TS6/TeaSpeak/GreenTeaSpeak protocol--> Server
|
||||||
```
|
```
|
||||||
|
|
||||||
- **`web/`** — Vite + React frontend. TS3-lookalike UI: channel tree, chat
|
- **`web/`** — Vite + React frontend. TS3-lookalike UI: channel tree, chat
|
||||||
|
|||||||
+100
-13
@@ -17,9 +17,9 @@ use tsclientlib::messages::c2s::{
|
|||||||
OutChannelAddPermPart, OutChannelClientAddPermPart, OutChannelClientDelPermPart,
|
OutChannelAddPermPart, OutChannelClientAddPermPart, OutChannelClientDelPermPart,
|
||||||
OutChannelClientPermListRequestPart, OutChannelDelPermPart, OutChannelGroupAddPermPart,
|
OutChannelClientPermListRequestPart, OutChannelDelPermPart, OutChannelGroupAddPermPart,
|
||||||
OutChannelGroupDelPermPart, OutChannelGroupPermListRequestPart, OutChannelPermListRequestPart,
|
OutChannelGroupDelPermPart, OutChannelGroupPermListRequestPart, OutChannelPermListRequestPart,
|
||||||
OutClientAddPermPart, OutClientDelPermPart, OutClientPermListRequestPart, OutClientPokeRequestPart,
|
OutClientAddPermPart, OutClientDelPermPart, OutClientMovePart, OutClientPermListRequestPart,
|
||||||
OutCreateDirectoryPart, OutDeleteFilePart, OutFileListRequestPart, OutRenameFilePart,
|
OutClientPokeRequestPart, OutCreateDirectoryPart, OutDeleteFilePart, OutFileListRequestPart,
|
||||||
OutSendTextMessagePart, OutServerGroupAddPermPart, OutServerGroupDelPermPart,
|
OutRenameFilePart, OutSendTextMessagePart, OutServerGroupAddPermPart, OutServerGroupDelPermPart,
|
||||||
OutServerGroupPermListRequestPart,
|
OutServerGroupPermListRequestPart,
|
||||||
};
|
};
|
||||||
use tsclientlib::prelude::*;
|
use tsclientlib::prelude::*;
|
||||||
@@ -103,6 +103,9 @@ struct ClientInfo {
|
|||||||
/// haven't been individually granted talk power. Always `true` in a
|
/// haven't been individually granted talk power. Always `true` in a
|
||||||
/// non-moderated channel.
|
/// non-moderated channel.
|
||||||
has_talk_power: bool,
|
has_talk_power: bool,
|
||||||
|
/// ServerQuery client (`ClientType::Query`). Always included in the
|
||||||
|
/// snapshot; the UI hides these unless the user enables them per favorite.
|
||||||
|
is_query: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Payload for the "serveredit " stdin command - every field is optional so
|
/// Payload for the "serveredit " stdin command - every field is optional so
|
||||||
@@ -573,13 +576,13 @@ fn snapshot(con: &data::Connection) -> Event {
|
|||||||
has_password: ch.has_password.unwrap_or(false),
|
has_password: ch.has_password.unwrap_or(false),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
// Bookkeeping includes ServerQuery clients (`ClientType::Query`); hide them
|
// Bookkeeping includes ServerQuery clients (`ClientType::Query`). We always
|
||||||
// from the channel tree / client lists, and from the online-count fallback
|
// forward them (with `is_query`) so the UI can toggle visibility live from
|
||||||
// below too, so the number shown never counts a client the list doesn't.
|
// a favorite setting without reconnecting. Online counts below still exclude
|
||||||
|
// Query by default so the headline matches the default (hidden) tree.
|
||||||
let clients = con
|
let clients = con
|
||||||
.clients
|
.clients
|
||||||
.values()
|
.values()
|
||||||
.filter(|c| !matches!(c.client_type, ClientType::Query { .. }))
|
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
// A channel with no talk power requirement at all (the common
|
// A channel with no talk power requirement at all (the common
|
||||||
// case) is never moderated, so everyone can talk regardless of
|
// case) is never moderated, so everyone can talk regardless of
|
||||||
@@ -605,19 +608,20 @@ fn snapshot(con: &data::Connection) -> Event {
|
|||||||
channel_group: c.channel_group.0,
|
channel_group: c.channel_group.0,
|
||||||
server_groups: c.server_groups.iter().map(|g| g.0).collect(),
|
server_groups: c.server_groups.iter().map(|g| g.0).collect(),
|
||||||
has_talk_power,
|
has_talk_power,
|
||||||
|
is_query: matches!(c.client_type, ClientType::Query { .. }),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// Prefer server-reported counters (GTS/TS `virtualserver_*` via notifyserverupdated)
|
// Prefer server-reported counters (GTS/TS `virtualserver_*` via notifyserverupdated)
|
||||||
// but never under-report vs. the visible (non-Query) client set (stale
|
// but never under-report vs. the non-Query client set (stale optional_data
|
||||||
// optional_data after joins would otherwise freeze the InfoPanel left number).
|
// after joins would otherwise freeze the InfoPanel left number).
|
||||||
// `virtualserver_clientsonline` usually includes ServerQuery; subtract the
|
// `virtualserver_clientsonline` usually includes ServerQuery; subtract them
|
||||||
// Query clients we filtered from the list so the headline matches the tree.
|
// so the default (Query-hidden) headline matches the default tree.
|
||||||
let opt = con.server.optional_data.as_ref();
|
let opt = con.server.optional_data.as_ref();
|
||||||
let visible_channels = channels.len() as u64;
|
let visible_channels = channels.len() as u64;
|
||||||
let visible_clients_count = clients.len() as u16;
|
let query_count = clients.iter().filter(|c| c.is_query).count() as u16;
|
||||||
let query_count = (con.clients.len() as u16).saturating_sub(visible_clients_count);
|
let visible_clients_count = (clients.len() as u16).saturating_sub(query_count);
|
||||||
let server_clients_online = opt
|
let server_clients_online = opt
|
||||||
.map(|d| {
|
.map(|d| {
|
||||||
let without_query = d.client_count.saturating_sub(query_count);
|
let without_query = d.client_count.saturating_sub(query_count);
|
||||||
@@ -1094,6 +1098,72 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
}
|
}
|
||||||
Err(_) => emit(&Event::Error { message: format!("Invalid client id: {id}") }),
|
Err(_) => emit(&Event::Error { message: format!("Invalid client id: {id}") }),
|
||||||
}
|
}
|
||||||
|
} else if let Some(rest) = l.strip_prefix("moveclient ") {
|
||||||
|
// Move another client (or self) into a channel: clientmove clid=… cid=…
|
||||||
|
// Optional trailing base64 password, same as `switch`.
|
||||||
|
let mut move_args = rest.trim().splitn(3, ' ');
|
||||||
|
let clid_arg = move_args.next().unwrap_or("");
|
||||||
|
let cid_arg = move_args.next().unwrap_or("");
|
||||||
|
let password_arg = move_args.next();
|
||||||
|
match (clid_arg.parse::<u16>(), cid_arg.parse::<u64>()) {
|
||||||
|
(Ok(clid), Ok(cid)) => {
|
||||||
|
let password = password_arg.and_then(|p| {
|
||||||
|
base64::engine::general_purpose::STANDARD
|
||||||
|
.decode(p)
|
||||||
|
.ok()
|
||||||
|
.and_then(|bytes| String::from_utf8(bytes).ok())
|
||||||
|
});
|
||||||
|
let part = match con.get_state() {
|
||||||
|
Ok(state) => match state.clients.get(&ClientId(clid)) {
|
||||||
|
Some(client) => {
|
||||||
|
let mut part = client.client_move(ChannelId(cid));
|
||||||
|
match &password {
|
||||||
|
Some(pwd) => {
|
||||||
|
part = part.set_password(pwd);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
part.channel_password =
|
||||||
|
Some(std::borrow::Cow::Borrowed(""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(part)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// Still try with raw ids if the client left our view.
|
||||||
|
// Carry through the already-decoded password instead of
|
||||||
|
// dropping it - this path is also used for self-moves
|
||||||
|
// via drag-and-drop, which still need the password to
|
||||||
|
// reach the server when the target channel requires one.
|
||||||
|
Some(OutClientMovePart {
|
||||||
|
client_id: ClientId(clid),
|
||||||
|
channel_id: ChannelId(cid),
|
||||||
|
channel_password: Some(match &password {
|
||||||
|
Some(pwd) => Cow::Owned(pwd.clone()),
|
||||||
|
None => Cow::Borrowed(""),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
emit(&Event::Error {
|
||||||
|
message: format!("Move client failed: {e}"),
|
||||||
|
});
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Some(part) = part {
|
||||||
|
match part.send_with_result(&mut con) {
|
||||||
|
Ok(handle) => {
|
||||||
|
pending_messages.insert(handle, "Move client".into());
|
||||||
|
}
|
||||||
|
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => emit(&Event::Error {
|
||||||
|
message: format!("Malformed moveclient command: {rest}"),
|
||||||
|
}),
|
||||||
|
}
|
||||||
} else if l == "away" || l.starts_with("away ") {
|
} else if l == "away" || l.starts_with("away ") {
|
||||||
let message = l.strip_prefix("away").unwrap_or("").trim();
|
let message = l.strip_prefix("away").unwrap_or("").trim();
|
||||||
let part = con.get_state()?.client_update().set_away(Some(message));
|
let part = con.get_state()?.client_update().set_away(Some(message));
|
||||||
@@ -2292,6 +2362,23 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Ok(StreamItem::MessageEvent(msg))) => {
|
Some(Ok(StreamItem::MessageEvent(msg))) => {
|
||||||
|
// Defense in depth: TeaSpeak/GTS may surface notifyclientpoke as an
|
||||||
|
// unhandled MessageEvent if bookkeeping did not mark it handled.
|
||||||
|
if let InMessage::ClientPoke(poke) = &msg {
|
||||||
|
for part in poke.iter() {
|
||||||
|
emit(&Event::Poke {
|
||||||
|
from: part.invoker_name.clone(),
|
||||||
|
message: part.message.clone().unwrap_or_default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if let InMessage::ClientPokeNormal(poke) = &msg {
|
||||||
|
for part in poke.iter() {
|
||||||
|
emit(&Event::Poke {
|
||||||
|
from: part.invoker_name.clone(),
|
||||||
|
message: part.message.clone().unwrap_or_default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
if pending_server_log {
|
if pending_server_log {
|
||||||
if let InMessage::ServerLog(log) = &msg {
|
if let InMessage::ServerLog(log) = &msg {
|
||||||
let lines: Vec<String> = log.iter().map(|part| part.log.clone()).collect();
|
let lines: Vec<String> = log.iter().map(|part| part.log.clone()).collect();
|
||||||
|
|||||||
@@ -86,6 +86,36 @@ const server = createServer((req, res) => {
|
|||||||
|
|
||||||
const wss = new WebSocketServer({ server, path: "/ws" });
|
const wss = new WebSocketServer({ server, path: "/ws" });
|
||||||
|
|
||||||
|
// Heartbeat: a browser tab that loses its network mid-session (mobile
|
||||||
|
// handover, Wi-Fi drop, backgrounded/frozen tab) often never sends a proper
|
||||||
|
// WS close frame — the OS-level TCP timeout that would eventually notice can
|
||||||
|
// take minutes, during which the connector child process (and the TS3/TeaSpeak
|
||||||
|
// session it holds open) stays alive even though the frontend has already
|
||||||
|
// given up and shown "disconnected". Standard `ws` ping/pong liveness check
|
||||||
|
// closes those zombie sockets (and their connector) promptly instead.
|
||||||
|
const HEARTBEAT_INTERVAL_MS = 20_000;
|
||||||
|
|
||||||
|
interface HeartbeatState {
|
||||||
|
isAlive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const heartbeats = new WeakMap<WebSocket, HeartbeatState>();
|
||||||
|
|
||||||
|
const heartbeatTimer = setInterval(() => {
|
||||||
|
for (const socket of wss.clients) {
|
||||||
|
const state = heartbeats.get(socket);
|
||||||
|
if (!state) continue;
|
||||||
|
if (!state.isAlive) {
|
||||||
|
socket.terminate();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state.isAlive = false;
|
||||||
|
socket.ping();
|
||||||
|
}
|
||||||
|
}, HEARTBEAT_INTERVAL_MS);
|
||||||
|
|
||||||
|
wss.on("close", () => clearInterval(heartbeatTimer));
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`WebSpeak3 gateway listening on http://localhost:${PORT} (WebSocket at /ws)`);
|
console.log(`WebSpeak3 gateway listening on http://localhost:${PORT} (WebSocket at /ws)`);
|
||||||
if (SERVE_STATIC) {
|
if (SERVE_STATIC) {
|
||||||
@@ -101,6 +131,12 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
// multiple /ws connections in parallel (one per server tab).
|
// multiple /ws connections in parallel (one per server tab).
|
||||||
let connection: Ts3Connection | undefined;
|
let connection: Ts3Connection | undefined;
|
||||||
|
|
||||||
|
heartbeats.set(socket, { isAlive: true });
|
||||||
|
socket.on("pong", () => {
|
||||||
|
const state = heartbeats.get(socket);
|
||||||
|
if (state) state.isAlive = true;
|
||||||
|
});
|
||||||
|
|
||||||
socket.on("message", async (raw) => {
|
socket.on("message", async (raw) => {
|
||||||
const msg = JSON.parse(raw.toString());
|
const msg = JSON.parse(raw.toString());
|
||||||
|
|
||||||
@@ -138,6 +174,14 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "moveClient": {
|
||||||
|
const clientId = Number(msg.clientId);
|
||||||
|
const channelId = Number(msg.channelId);
|
||||||
|
if (Number.isFinite(clientId) && Number.isFinite(channelId)) {
|
||||||
|
await connection?.moveClient(clientId, channelId, msg.channelPassword);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "sendChatMessage": {
|
case "sendChatMessage": {
|
||||||
await connection?.sendChatMessage(msg.message);
|
await connection?.sendChatMessage(msg.message);
|
||||||
break;
|
break;
|
||||||
@@ -330,6 +374,7 @@ wss.on("connection", (socket: WebSocket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("close", () => {
|
socket.on("close", () => {
|
||||||
|
heartbeats.delete(socket);
|
||||||
connection?.disconnect();
|
connection?.disconnect();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -37,6 +37,8 @@ export interface ClientInfo {
|
|||||||
channelGroup: number;
|
channelGroup: number;
|
||||||
serverGroups: number[];
|
serverGroups: number[];
|
||||||
hasTalkPower: boolean;
|
hasTalkPower: boolean;
|
||||||
|
/** ServerQuery client; UI may hide these unless enabled per favorite. */
|
||||||
|
isQuery: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupEntry {
|
export interface GroupEntry {
|
||||||
@@ -252,6 +254,7 @@ export class Ts3Connection {
|
|||||||
channel_group: number;
|
channel_group: number;
|
||||||
server_groups: number[];
|
server_groups: number[];
|
||||||
has_talk_power: boolean;
|
has_talk_power: boolean;
|
||||||
|
is_query?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RawChannelInfo {
|
interface RawChannelInfo {
|
||||||
@@ -424,6 +427,7 @@ export class Ts3Connection {
|
|||||||
channelGroup: c.channel_group,
|
channelGroup: c.channel_group,
|
||||||
serverGroups: c.server_groups,
|
serverGroups: c.server_groups,
|
||||||
hasTalkPower: c.has_talk_power,
|
hasTalkPower: c.has_talk_power,
|
||||||
|
isQuery: Boolean(c.is_query),
|
||||||
})),
|
})),
|
||||||
ownClientId: event.own_client_id ?? 0,
|
ownClientId: event.own_client_id ?? 0,
|
||||||
serverMaxClients: event.server_max_clients ?? 0,
|
serverMaxClients: event.server_max_clients ?? 0,
|
||||||
@@ -550,6 +554,14 @@ export class Ts3Connection {
|
|||||||
this.child?.stdin.write(`switch ${id}${passwordArg}\n`);
|
this.child?.stdin.write(`switch ${id}${passwordArg}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async moveClient(clientId: number, channelId: number, channelPassword?: string): Promise<void> {
|
||||||
|
const clid = Number(clientId);
|
||||||
|
const cid = Number(channelId);
|
||||||
|
if (!Number.isFinite(clid) || !Number.isFinite(cid)) return;
|
||||||
|
const passwordArg = channelPassword ? ` ${Buffer.from(channelPassword, "utf8").toString("base64")}` : "";
|
||||||
|
this.child?.stdin.write(`moveclient ${clid} ${cid}${passwordArg}\n`);
|
||||||
|
}
|
||||||
|
|
||||||
async getClientConnectionInfo(clientId: number): Promise<void> {
|
async getClientConnectionInfo(clientId: number): Promise<void> {
|
||||||
this.child?.stdin.write(`clientconninfo ${clientId}\n`);
|
this.child?.stdin.write(`clientconninfo ${clientId}\n`);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule tsclientlib updated: 5fdf15cf5a...a879f17fec.
@@ -1787,6 +1787,13 @@
|
|||||||
background: var(--row-hover);
|
background: var(--row-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-channel-row.ts-drop-target,
|
||||||
|
.ts-channel-row.ts-spacer.ts-drop-target {
|
||||||
|
background: color-mix(in srgb, var(--accent) 22%, transparent);
|
||||||
|
outline: 1px dashed var(--accent);
|
||||||
|
outline-offset: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Channel spacers ([cspacer], [*spacer01], …) — GreenTeaSpeak / TS parity */
|
/* Channel spacers ([cspacer], [*spacer01], …) — GreenTeaSpeak / TS parity */
|
||||||
.ts-channel-row.ts-spacer {
|
.ts-channel-row.ts-spacer {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -1897,10 +1904,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ts-client-row {
|
.ts-client-row {
|
||||||
|
cursor: grab;
|
||||||
color: var(--client-text);
|
color: var(--client-text);
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-client-row:active {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
.ts-client-row.ts-self {
|
.ts-client-row.ts-self {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: var(--self-text);
|
color: var(--self-text);
|
||||||
|
|||||||
+512
-66
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
|
|
||||||
/** Only dismiss on a genuine backdrop click, not a text-selection drag that
|
/** Only dismiss on a genuine backdrop click, not a text-selection drag that
|
||||||
@@ -100,6 +100,21 @@ function loadServerType(): ServerType {
|
|||||||
const raw = localStorage.getItem(LAST_SERVER_TYPE_KEY);
|
const raw = localStorage.getItem(LAST_SERVER_TYPE_KEY);
|
||||||
return raw === "teamspeak" || raw === "teaspeak" || raw === "auto" ? raw : "auto";
|
return raw === "teamspeak" || raw === "teaspeak" || raw === "auto" ? raw : "auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Everything needed to (re)open a gateway connection for one session, kept
|
||||||
|
* around per session id so a dropped socket — active tab or a parked
|
||||||
|
* background one — can be silently reconnected. */
|
||||||
|
type ConnectParams = {
|
||||||
|
host: string;
|
||||||
|
nickname: string;
|
||||||
|
serverPassword: string;
|
||||||
|
channelPassword: string;
|
||||||
|
defaultChannel: string;
|
||||||
|
privilegeKey: string;
|
||||||
|
serverType: ServerType;
|
||||||
|
identityId: string | null;
|
||||||
|
favoriteId: string | null;
|
||||||
|
};
|
||||||
/** Identity persisted across sessions so the server sees the same client UID
|
/** Identity persisted across sessions so the server sees the same client UID
|
||||||
* each time, instead of a fresh one being generated per connection. */
|
* each time, instead of a fresh one being generated per connection. */
|
||||||
const IDENTITY_KEY = "webspeak3:identity";
|
const IDENTITY_KEY = "webspeak3:identity";
|
||||||
@@ -260,12 +275,33 @@ interface Favorite {
|
|||||||
serverPassword: string;
|
serverPassword: string;
|
||||||
defaultChannel: string;
|
defaultChannel: string;
|
||||||
defaultChannelPassword: string;
|
defaultChannelPassword: string;
|
||||||
|
/** When true, ServerQuery clients appear in the channel tree. Default: false. */
|
||||||
|
showServerQueryClients: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeFavorite(raw: Partial<Favorite> & Pick<Favorite, "id">): Favorite {
|
||||||
|
return {
|
||||||
|
id: raw.id,
|
||||||
|
bookmarkName: typeof raw.bookmarkName === "string" ? raw.bookmarkName : "",
|
||||||
|
nickname: typeof raw.nickname === "string" ? raw.nickname : "",
|
||||||
|
host: typeof raw.host === "string" ? raw.host : "",
|
||||||
|
serverPassword: typeof raw.serverPassword === "string" ? raw.serverPassword : "",
|
||||||
|
defaultChannel: typeof raw.defaultChannel === "string" ? raw.defaultChannel : "",
|
||||||
|
defaultChannelPassword:
|
||||||
|
typeof raw.defaultChannelPassword === "string" ? raw.defaultChannelPassword : "",
|
||||||
|
showServerQueryClients: raw.showServerQueryClients === true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFavorites(): Favorite[] {
|
function loadFavorites(): Favorite[] {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(FAVORITES_KEY);
|
const raw = localStorage.getItem(FAVORITES_KEY);
|
||||||
return raw ? (JSON.parse(raw) as Favorite[]) : [];
|
if (!raw) return [];
|
||||||
|
const parsed = JSON.parse(raw);
|
||||||
|
if (!Array.isArray(parsed)) return [];
|
||||||
|
return parsed
|
||||||
|
.filter((v): v is Partial<Favorite> & Pick<Favorite, "id"> => v && typeof v.id === "string")
|
||||||
|
.map(normalizeFavorite);
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -448,6 +484,8 @@ interface ClientInfo {
|
|||||||
channelGroup: number;
|
channelGroup: number;
|
||||||
serverGroups: number[];
|
serverGroups: number[];
|
||||||
hasTalkPower: boolean;
|
hasTalkPower: boolean;
|
||||||
|
/** ServerQuery client; filtered from the tree unless a favorite enables them. */
|
||||||
|
isQuery?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GroupEntry {
|
interface GroupEntry {
|
||||||
@@ -666,6 +704,27 @@ function ServerIcon() {
|
|||||||
const lastChannelClickBySession = new Map<string, { id: number; at: number }>();
|
const lastChannelClickBySession = new Map<string, { id: number; at: number }>();
|
||||||
let switchArmedUntil = 0;
|
let switchArmedUntil = 0;
|
||||||
|
|
||||||
|
const CLIENT_DRAG_MIME = "application/x-webspeak3-client";
|
||||||
|
|
||||||
|
type ClientDragPayload = { clientId: number; channelId: number };
|
||||||
|
|
||||||
|
function parseClientDragPayload(raw: string): ClientDragPayload | null {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(raw) as Partial<ClientDragPayload>;
|
||||||
|
if (
|
||||||
|
typeof data.clientId === "number" &&
|
||||||
|
Number.isFinite(data.clientId) &&
|
||||||
|
typeof data.channelId === "number" &&
|
||||||
|
Number.isFinite(data.channelId)
|
||||||
|
) {
|
||||||
|
return { clientId: data.clientId, channelId: data.channelId };
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function ChannelTree({
|
function ChannelTree({
|
||||||
channels,
|
channels,
|
||||||
clients,
|
clients,
|
||||||
@@ -680,6 +739,7 @@ function ChannelTree({
|
|||||||
onSwitchChannel,
|
onSwitchChannel,
|
||||||
onOpenPrivateChat,
|
onOpenPrivateChat,
|
||||||
onPokeClient,
|
onPokeClient,
|
||||||
|
onMoveClient,
|
||||||
onClientContextMenu,
|
onClientContextMenu,
|
||||||
onChannelContextMenu,
|
onChannelContextMenu,
|
||||||
}: {
|
}: {
|
||||||
@@ -698,11 +758,13 @@ function ChannelTree({
|
|||||||
onSwitchChannel: (channelId: number) => void;
|
onSwitchChannel: (channelId: number) => void;
|
||||||
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
||||||
onPokeClient: (clientId: number, clientName: string) => void;
|
onPokeClient: (clientId: number, clientName: string) => void;
|
||||||
|
onMoveClient: (clientId: number, channelId: number) => void;
|
||||||
onClientContextMenu: (e: React.MouseEvent, clientId: number, clientName: string, isSelf: boolean) => void;
|
onClientContextMenu: (e: React.MouseEvent, clientId: number, clientName: string, isSelf: boolean) => void;
|
||||||
onChannelContextMenu: (e: React.MouseEvent, channelId: number, channelName: string) => void;
|
onChannelContextMenu: (e: React.MouseEvent, channelId: number, channelName: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const [collapsed, setCollapsed] = useState<Set<number>>(() => new Set());
|
const [collapsed, setCollapsed] = useState<Set<number>>(() => new Set());
|
||||||
|
const [dragOverChannelId, setDragOverChannelId] = useState<number | null>(null);
|
||||||
// Module-level click tracking (see lastChannelClick) — refs alone are not
|
// Module-level click tracking (see lastChannelClick) — refs alone are not
|
||||||
// enough when Select re-renders remount nested ChannelTree instances.
|
// enough when Select re-renders remount nested ChannelTree instances.
|
||||||
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
||||||
@@ -744,7 +806,7 @@ function ChannelTree({
|
|||||||
<div
|
<div
|
||||||
className={`ts-row ts-channel-row${spacerClass}${
|
className={`ts-row ts-channel-row${spacerClass}${
|
||||||
selected?.type === "channel" && selected.id === channel.id ? " ts-row-selected" : ""
|
selected?.type === "channel" && selected.id === channel.id ? " ts-row-selected" : ""
|
||||||
}`}
|
}${dragOverChannelId === channel.id ? " ts-drop-target" : ""}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onSelectItem({ type: "channel", id: channel.id });
|
onSelectItem({ type: "channel", id: channel.id });
|
||||||
// Manual double-click: native dblclick is often lost when the first
|
// Manual double-click: native dblclick is often lost when the first
|
||||||
@@ -765,6 +827,24 @@ function ChannelTree({
|
|||||||
onSwitchChannel(channel.id);
|
onSwitchChannel(channel.id);
|
||||||
}}
|
}}
|
||||||
onContextMenu={(e) => onChannelContextMenu(e, channel.id, channel.name)}
|
onContextMenu={(e) => onChannelContextMenu(e, channel.id, channel.name)}
|
||||||
|
onDragOver={(e) => {
|
||||||
|
if (![...e.dataTransfer.types].includes(CLIENT_DRAG_MIME)) return;
|
||||||
|
e.preventDefault();
|
||||||
|
e.dataTransfer.dropEffect = "move";
|
||||||
|
if (dragOverChannelId !== channel.id) setDragOverChannelId(channel.id);
|
||||||
|
}}
|
||||||
|
onDragLeave={(e) => {
|
||||||
|
const related = e.relatedTarget as Node | null;
|
||||||
|
if (related && e.currentTarget.contains(related)) return;
|
||||||
|
setDragOverChannelId((prev) => (prev === channel.id ? null : prev));
|
||||||
|
}}
|
||||||
|
onDrop={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setDragOverChannelId(null);
|
||||||
|
const payload = parseClientDragPayload(e.dataTransfer.getData(CLIENT_DRAG_MIME));
|
||||||
|
if (!payload || payload.channelId === channel.id) return;
|
||||||
|
onMoveClient(payload.clientId, channel.id);
|
||||||
|
}}
|
||||||
title={t("tree.clickToJoin")}
|
title={t("tree.clickToJoin")}
|
||||||
>
|
>
|
||||||
{!spacer.isSpacer && (
|
{!spacer.isSpacer && (
|
||||||
@@ -816,6 +896,18 @@ function ChannelTree({
|
|||||||
? " ts-talking"
|
? " ts-talking"
|
||||||
: ""
|
: ""
|
||||||
}${selected?.type === "client" && selected.id === c.id ? " ts-row-selected" : ""}`}
|
}${selected?.type === "client" && selected.id === c.id ? " ts-row-selected" : ""}`}
|
||||||
|
draggable
|
||||||
|
onDragStart={(e) => {
|
||||||
|
const payload: ClientDragPayload = {
|
||||||
|
clientId: c.id,
|
||||||
|
channelId: c.channel,
|
||||||
|
};
|
||||||
|
const raw = JSON.stringify(payload);
|
||||||
|
e.dataTransfer.setData(CLIENT_DRAG_MIME, raw);
|
||||||
|
e.dataTransfer.setData("text/plain", raw);
|
||||||
|
e.dataTransfer.effectAllowed = "move";
|
||||||
|
}}
|
||||||
|
onDragEnd={() => setDragOverChannelId(null)}
|
||||||
onClick={() => onSelectItem({ type: "client", id: c.id })}
|
onClick={() => onSelectItem({ type: "client", id: c.id })}
|
||||||
onDoubleClick={
|
onDoubleClick={
|
||||||
c.id === ownClientId ? undefined : () => onOpenPrivateChat(c.id, c.name)
|
c.id === ownClientId ? undefined : () => onOpenPrivateChat(c.id, c.name)
|
||||||
@@ -904,6 +996,7 @@ function ChannelTree({
|
|||||||
onSwitchChannel={onSwitchChannel}
|
onSwitchChannel={onSwitchChannel}
|
||||||
onOpenPrivateChat={onOpenPrivateChat}
|
onOpenPrivateChat={onOpenPrivateChat}
|
||||||
onPokeClient={onPokeClient}
|
onPokeClient={onPokeClient}
|
||||||
|
onMoveClient={onMoveClient}
|
||||||
onClientContextMenu={onClientContextMenu}
|
onClientContextMenu={onClientContextMenu}
|
||||||
onChannelContextMenu={onChannelContextMenu}
|
onChannelContextMenu={onChannelContextMenu}
|
||||||
/>
|
/>
|
||||||
@@ -1470,6 +1563,7 @@ function FavoritesDialog({
|
|||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
bookmarkName: prefillNew.host || t("favorites.newFavoriteName"),
|
bookmarkName: prefillNew.host || t("favorites.newFavoriteName"),
|
||||||
...prefillNew,
|
...prefillNew,
|
||||||
|
showServerQueryClients: prefillNew.showServerQueryClients === true,
|
||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
);
|
);
|
||||||
@@ -1496,6 +1590,7 @@ function FavoritesDialog({
|
|||||||
serverPassword: "",
|
serverPassword: "",
|
||||||
defaultChannel: "",
|
defaultChannel: "",
|
||||||
defaultChannelPassword: "",
|
defaultChannelPassword: "",
|
||||||
|
showServerQueryClients: false,
|
||||||
};
|
};
|
||||||
setDraft((prev) => [...prev, nf]);
|
setDraft((prev) => [...prev, nf]);
|
||||||
setSelectedId(nf.id);
|
setSelectedId(nf.id);
|
||||||
@@ -1624,7 +1719,12 @@ function FavoritesDialog({
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-dialog-checkbox">
|
<label className="ts-dialog-checkbox">
|
||||||
<input type="checkbox" disabled defaultChecked title="Not supported yet" />
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
disabled={!selected}
|
||||||
|
checked={selected?.showServerQueryClients ?? false}
|
||||||
|
onChange={(e) => updateSelected({ showServerQueryClients: e.target.checked })}
|
||||||
|
/>
|
||||||
{t("favorites.showServerQueryClients")}
|
{t("favorites.showServerQueryClients")}
|
||||||
</label>
|
</label>
|
||||||
<label className="ts-dialog-checkbox">
|
<label className="ts-dialog-checkbox">
|
||||||
@@ -2269,6 +2369,80 @@ function GroupAssignDialog({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MoveClientDialog({
|
||||||
|
clientName,
|
||||||
|
currentChannelId,
|
||||||
|
channels,
|
||||||
|
onSelect,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
clientName: string;
|
||||||
|
currentChannelId: number;
|
||||||
|
channels: ChannelInfo[];
|
||||||
|
onSelect: (channelId: number) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}) {
|
||||||
|
const t = useT();
|
||||||
|
const backdrop = useBackdropDismiss(onClose);
|
||||||
|
const movable = [...channels].sort((a, b) => a.order - b.order);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||||
|
<div className="ts-dialog ts-group-assign-dialog" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className="ts-dialog-titlebar">
|
||||||
|
<span>
|
||||||
|
{t("moveClient.title")} - {clientName}
|
||||||
|
</span>
|
||||||
|
<button onClick={onClose} title={t("dialog.close")}>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="ts-dialog-body">
|
||||||
|
{movable.length === 0 ? (
|
||||||
|
<div className="ts-connection-info-loading">{t("moveClient.empty")}</div>
|
||||||
|
) : (
|
||||||
|
<ul className="ts-group-assign-list">
|
||||||
|
{movable.map((ch) => {
|
||||||
|
const current = ch.id === currentChannelId;
|
||||||
|
const spacer = spacerDisplayName(ch.name, ch.parent === 0);
|
||||||
|
const label = spacer.isSpacer
|
||||||
|
? spacer.label.trim() || ch.name
|
||||||
|
: ch.name;
|
||||||
|
return (
|
||||||
|
<li key={ch.id}>
|
||||||
|
<button
|
||||||
|
className={`ts-menu-item${current ? " ts-group-assign-current" : ""}`}
|
||||||
|
disabled={current || spacer.isSpacer}
|
||||||
|
onClick={() => onSelect(ch.id)}
|
||||||
|
>
|
||||||
|
<span className="ts-menu-item-icon">
|
||||||
|
{current ? "✔️" : spacer.isSpacer ? "➖" : "📁"}
|
||||||
|
</span>
|
||||||
|
<span className="ts-menu-item-label">{label}</span>
|
||||||
|
{current && (
|
||||||
|
<span className="ts-group-assign-hint">{t("moveClient.current")}</span>
|
||||||
|
)}
|
||||||
|
{!current && spacer.isSpacer && (
|
||||||
|
<span className="ts-group-assign-hint">{t("moveClient.spacer")}</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="ts-dialog-buttons">
|
||||||
|
<div />
|
||||||
|
<div className="ts-dialog-buttons-right">
|
||||||
|
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Builds the full channel-relative path TS3's ft* commands expect (e.g.
|
/** Builds the full channel-relative path TS3's ft* commands expect (e.g.
|
||||||
* "/foo/bar.txt") from a directory and a bare entry name. */
|
* "/foo/bar.txt") from a directory and a bare entry name. */
|
||||||
function ftJoinPath(dir: string, name: string): string {
|
function ftJoinPath(dir: string, name: string): string {
|
||||||
@@ -4950,6 +5124,11 @@ function AppInner() {
|
|||||||
clientId: number;
|
clientId: number;
|
||||||
clientName: string;
|
clientName: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
const [moveClientTarget, setMoveClientTarget] = useState<{
|
||||||
|
clientId: number;
|
||||||
|
clientName: string;
|
||||||
|
channelId: number;
|
||||||
|
} | null>(null);
|
||||||
const [permissionOverviewOpen, setPermissionOverviewOpen] = useState(false);
|
const [permissionOverviewOpen, setPermissionOverviewOpen] = useState(false);
|
||||||
const [permissionOverview, setPermissionOverview] = useState<PermissionOverviewEntry[] | null>(null);
|
const [permissionOverview, setPermissionOverview] = useState<PermissionOverviewEntry[] | null>(null);
|
||||||
const [permissionsEditorOpen, setPermissionsEditorOpen] = useState(false);
|
const [permissionsEditorOpen, setPermissionsEditorOpen] = useState(false);
|
||||||
@@ -5084,6 +5263,8 @@ function AppInner() {
|
|||||||
const [novaMenuOpen, setNovaMenuOpen] = useState(false);
|
const [novaMenuOpen, setNovaMenuOpen] = useState(false);
|
||||||
const novaMenuRef = useRef<HTMLDivElement | null>(null);
|
const novaMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [favorites, setFavorites] = useState<Favorite[]>(() => loadFavorites());
|
const [favorites, setFavorites] = useState<Favorite[]>(() => loadFavorites());
|
||||||
|
/** Favorite that opened the active session tab; drives ServerQuery visibility. */
|
||||||
|
const [activeFavoriteId, setActiveFavoriteId] = useState<string | null>(null);
|
||||||
const [favoritesMenuOpen, setFavoritesMenuOpen] = useState(false);
|
const [favoritesMenuOpen, setFavoritesMenuOpen] = useState(false);
|
||||||
const [favoritesDialogMode, setFavoritesDialogMode] = useState<
|
const [favoritesDialogMode, setFavoritesDialogMode] = useState<
|
||||||
{ kind: "add"; prefill: Omit<Favorite, "id" | "bookmarkName"> } | { kind: "manage" } | null
|
{ kind: "add"; prefill: Omit<Favorite, "id" | "bookmarkName"> } | { kind: "manage" } | null
|
||||||
@@ -5146,6 +5327,10 @@ function AppInner() {
|
|||||||
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
||||||
const sessionsRef = useRef<Map<string, SessionRecord>>(new Map());
|
const sessionsRef = useRef<Map<string, SessionRecord>>(new Map());
|
||||||
const activeSessionIdRef = useRef<string | null>(null);
|
const activeSessionIdRef = useRef<string | null>(null);
|
||||||
|
/** Last-used connect params per session, kept around so a dropped session
|
||||||
|
* (active OR parked/background) can reconnect itself without the user
|
||||||
|
* re-entering host/password — see reconnectSession(). */
|
||||||
|
const sessionParamsRef = useRef<Map<string, ConnectParams>>(new Map());
|
||||||
const connectionsMenuRef = useRef<HTMLDivElement | null>(null);
|
const connectionsMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
const favoritesMenuRef = useRef<HTMLDivElement | null>(null);
|
const favoritesMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
const awayMenuRef = useRef<HTMLDivElement | null>(null);
|
const awayMenuRef = useRef<HTMLDivElement | null>(null);
|
||||||
@@ -5392,6 +5577,7 @@ function AppInner() {
|
|||||||
hasConnected: hasConnectedRef.current,
|
hasConnected: hasConnectedRef.current,
|
||||||
previousClients: previousClientsRef.current,
|
previousClients: previousClientsRef.current,
|
||||||
micWasOn: micOn,
|
micWasOn: micOn,
|
||||||
|
favoriteId: activeFavoriteId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const applyParkedToUi = (parked: ParkedSessionState) => {
|
const applyParkedToUi = (parked: ParkedSessionState) => {
|
||||||
@@ -5417,6 +5603,7 @@ function AppInner() {
|
|||||||
setServerChat(parked.serverChat);
|
setServerChat(parked.serverChat);
|
||||||
setPmThreads(parked.pmThreads);
|
setPmThreads(parked.pmThreads);
|
||||||
setPokes(parked.pokes);
|
setPokes(parked.pokes);
|
||||||
|
setActiveFavoriteId(parked.favoriteId);
|
||||||
setActiveTab(parked.chatTab);
|
setActiveTab(parked.chatTab);
|
||||||
setTalkers(new Set(parked.talkers));
|
setTalkers(new Set(parked.talkers));
|
||||||
setWhisperChannelIds(new Set(parked.whisperChannelIds));
|
setWhisperChannelIds(new Set(parked.whisperChannelIds));
|
||||||
@@ -5468,6 +5655,7 @@ function AppInner() {
|
|||||||
hasConnectedRef.current = false;
|
hasConnectedRef.current = false;
|
||||||
previousClientsRef.current = null;
|
previousClientsRef.current = null;
|
||||||
cleanDisconnectRef.current = false;
|
cleanDisconnectRef.current = false;
|
||||||
|
setActiveFavoriteId(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// serverGroups/channelGroups/permissionCatalog/banList/fileBrowser* are
|
// serverGroups/channelGroups/permissionCatalog/banList/fileBrowser* are
|
||||||
@@ -5560,6 +5748,7 @@ function AppInner() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sessionsRef.current.delete(id);
|
sessionsRef.current.delete(id);
|
||||||
|
sessionParamsRef.current.delete(id);
|
||||||
lastChannelClickBySession.delete(id);
|
lastChannelClickBySession.delete(id);
|
||||||
setSessionTabs((prev) => prev.filter((t) => t.id !== id));
|
setSessionTabs((prev) => prev.filter((t) => t.id !== id));
|
||||||
|
|
||||||
@@ -5589,52 +5778,23 @@ function AppInner() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConnect = (overrides?: {
|
// Wires onopen/onmessage/onerror/onclose for one session's socket. Shared
|
||||||
host?: string;
|
// by handleConnect (brand-new session) and reconnectSession (an existing
|
||||||
nickname?: string;
|
// session — active or parked in the background — getting a fresh socket
|
||||||
serverPassword?: string;
|
// after an unexpected drop), so a reconnect behaves identically to the
|
||||||
channelPassword?: string;
|
// original connect from the gateway/UI's point of view.
|
||||||
defaultChannel?: string;
|
const wireSocket = (sessionId: string, socket: WebSocket | DemoSocket, params: ConnectParams) => {
|
||||||
privilegeKey?: string;
|
const connectHost = params.host;
|
||||||
serverType?: ServerType;
|
const connectNickname = params.nickname;
|
||||||
}) => {
|
const connectServerPassword = params.serverPassword;
|
||||||
const connectHost = overrides?.host ?? host;
|
const connectChannelPassword = params.channelPassword;
|
||||||
const connectNickname = overrides?.nickname ?? nickname;
|
const connectDefaultChannel = params.defaultChannel;
|
||||||
const connectServerPassword = overrides?.serverPassword ?? serverPassword;
|
const connectPrivilegeKey = params.privilegeKey;
|
||||||
const connectChannelPassword = overrides?.channelPassword ?? channelPassword;
|
const connectServerType = params.serverType;
|
||||||
const connectDefaultChannel = overrides?.defaultChannel ?? defaultChannel;
|
const connectIdentityId = params.identityId;
|
||||||
const connectPrivilegeKey = overrides?.privilegeKey ?? privilegeKey;
|
const connectFavoriteId = params.favoriteId;
|
||||||
const connectServerType = overrides?.serverType ?? serverType;
|
|
||||||
|
|
||||||
// Multi-join: keep existing sessions; park the active tab and open a new one.
|
|
||||||
if (activeSessionIdRef.current && sessionsRef.current.has(activeSessionIdRef.current)) {
|
|
||||||
parkActiveSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearActiveUi();
|
|
||||||
hasConnectedRef.current = false;
|
|
||||||
setConnecting(true);
|
|
||||||
setConnectError(null);
|
|
||||||
setConnectDialogOpen(false);
|
|
||||||
setHost(connectHost);
|
|
||||||
setNickname(connectNickname);
|
|
||||||
|
|
||||||
ensureAudioContext();
|
|
||||||
|
|
||||||
const sessionId = crypto.randomUUID();
|
|
||||||
const connectIdentityId = activeIdentityId;
|
|
||||||
const connectIdentityBlob = identities.find((i) => i.id === connectIdentityId)?.blob ?? undefined;
|
const connectIdentityBlob = identities.find((i) => i.id === connectIdentityId)?.blob ?? undefined;
|
||||||
|
|
||||||
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
|
||||||
sessionsRef.current.set(sessionId, { id: sessionId, socket, parked: null });
|
|
||||||
socketRef.current = socket;
|
|
||||||
activeSessionIdRef.current = sessionId;
|
|
||||||
setActiveSessionId(sessionId);
|
|
||||||
setSessionTabs((prev) => [
|
|
||||||
...prev,
|
|
||||||
{ id: sessionId, label: connectHost || "…", connected: false, connecting: true },
|
|
||||||
]);
|
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
logClient("info", "Connection", `Connecting to ${connectHost}…`);
|
logClient("info", "Connection", `Connecting to ${connectHost}…`);
|
||||||
socket.send(
|
socket.send(
|
||||||
@@ -5660,14 +5820,16 @@ function AppInner() {
|
|||||||
const rec = sessionsRef.current.get(sessionId);
|
const rec = sessionsRef.current.get(sessionId);
|
||||||
if (!rec) return;
|
if (!rec) return;
|
||||||
if (!rec.parked) {
|
if (!rec.parked) {
|
||||||
rec.parked = emptyParkedState({ host: connectHost, nickname: connectNickname });
|
rec.parked = emptyParkedState({
|
||||||
|
host: connectHost,
|
||||||
|
nickname: connectNickname,
|
||||||
|
favoriteId: connectFavoriteId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (data.type === "disconnected") {
|
if (data.type === "disconnected") {
|
||||||
sessionsRef.current.delete(sessionId);
|
sessionsRef.current.delete(sessionId);
|
||||||
|
sessionParamsRef.current.delete(sessionId);
|
||||||
setSessionTabs((prev) => prev.filter((t) => t.id !== sessionId));
|
setSessionTabs((prev) => prev.filter((t) => t.id !== sessionId));
|
||||||
if (hasConnectedRef.current === false) {
|
|
||||||
/* noop — background */
|
|
||||||
}
|
|
||||||
void playSound("disconnect");
|
void playSound("disconnect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5681,7 +5843,10 @@ function AppInner() {
|
|||||||
connected: rec.parked.connected,
|
connected: rec.parked.connected,
|
||||||
connecting: rec.parked.connecting,
|
connecting: rec.parked.connecting,
|
||||||
});
|
});
|
||||||
if (data.type === "connected") void playSound("connect");
|
if (data.type === "connected") {
|
||||||
|
reconnectAttemptsRef.current.delete(sessionId);
|
||||||
|
void playSound("connect");
|
||||||
|
}
|
||||||
else if (data.type === "poke") void playSound("poke");
|
else if (data.type === "poke") void playSound("poke");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5689,6 +5854,7 @@ function AppInner() {
|
|||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "connected":
|
case "connected":
|
||||||
logClient("info", "Connection", `Connected to ${data.serverName}`);
|
logClient("info", "Connection", `Connected to ${data.serverName}`);
|
||||||
|
reconnectAttemptsRef.current.delete(sessionId);
|
||||||
hasConnectedRef.current = true;
|
hasConnectedRef.current = true;
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
setConnectError(null);
|
setConnectError(null);
|
||||||
@@ -5731,8 +5897,13 @@ function AppInner() {
|
|||||||
if (prevClients) {
|
if (prevClients) {
|
||||||
const prevIds = new Set(prevClients.map((c) => c.id));
|
const prevIds = new Set(prevClients.map((c) => c.id));
|
||||||
const newIds = new Set(newClients.map((c) => c.id));
|
const newIds = new Set(newClients.map((c) => c.id));
|
||||||
const joined = newClients.some((c) => !prevIds.has(c.id) && c.name !== connectNickname);
|
// ServerQuery churn is noisy; never play join/leave for those clients.
|
||||||
const left = prevClients.some((c) => !newIds.has(c.id) && c.name !== connectNickname);
|
const joined = newClients.some(
|
||||||
|
(c) => !prevIds.has(c.id) && c.name !== connectNickname && !c.isQuery
|
||||||
|
);
|
||||||
|
const left = prevClients.some(
|
||||||
|
(c) => !newIds.has(c.id) && c.name !== connectNickname && !c.isQuery
|
||||||
|
);
|
||||||
if (joined) void playSound("clientJoin");
|
if (joined) void playSound("clientJoin");
|
||||||
if (left) void playSound("clientLeave");
|
if (left) void playSound("clientLeave");
|
||||||
}
|
}
|
||||||
@@ -5997,23 +6168,217 @@ function AppInner() {
|
|||||||
};
|
};
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
if (sessionId !== activeSessionIdRef.current) {
|
if (sessionId !== activeSessionIdRef.current) {
|
||||||
if (sessionsRef.current.has(sessionId)) {
|
const rec = sessionsRef.current.get(sessionId);
|
||||||
sessionsRef.current.delete(sessionId);
|
// Missing already means a deliberate disconnect (the "disconnected"
|
||||||
setSessionTabs((prev) => prev.filter((t) => t.id !== sessionId));
|
// message handler above already removed it) — nothing to do.
|
||||||
|
if (!rec) return;
|
||||||
|
if (rec.parked?.hasConnected) {
|
||||||
|
// Unexpected drop of a background tab (network blip, or the OS
|
||||||
|
// suspended the backgrounded/screen-off page) — keep the tab
|
||||||
|
// instead of dropping it, same as a real TS3 client keeps other
|
||||||
|
// server connections open while you're looking at a different
|
||||||
|
// one. It comes back on its own (immediately if we're still in
|
||||||
|
// the foreground, otherwise the visibilitychange handler retries
|
||||||
|
// it once the page is visible again), mic still off throughout.
|
||||||
|
rec.parked = { ...rec.parked, connecting: false, connected: false };
|
||||||
|
updateTabMeta(sessionId, { connecting: false, connected: false });
|
||||||
|
if (document.visibilityState === "visible") scheduleReconnectRef.current(sessionId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
sessionsRef.current.delete(sessionId);
|
||||||
|
sessionParamsRef.current.delete(sessionId);
|
||||||
|
setSessionTabs((prev) => prev.filter((t) => t.id !== sessionId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!hasConnectedRef.current && !cleanDisconnectRef.current) {
|
if (!hasConnectedRef.current && !cleanDisconnectRef.current) {
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
setConnectError((prev) => prev ?? "Connection closed before the server responded");
|
setConnectError((prev) => prev ?? "Connection closed before the server responded");
|
||||||
|
cleanDisconnectRef.current = false;
|
||||||
|
if (sessionsRef.current.has(sessionId)) {
|
||||||
|
removeSession(sessionId, { skipSocketClose: true });
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
const wasConnected = hasConnectedRef.current;
|
||||||
cleanDisconnectRef.current = false;
|
cleanDisconnectRef.current = false;
|
||||||
|
if (wasConnected && sessionsRef.current.has(sessionId)) {
|
||||||
|
// Same as above, for the active tab: an unexpected drop after a
|
||||||
|
// successful connect tries to come back rather than closing the tab.
|
||||||
|
// A deliberate disconnect goes through the "disconnected" message
|
||||||
|
// handler (or handleDisconnect()), both of which remove the session
|
||||||
|
// before this fires, so we only land here for a real hiccup.
|
||||||
|
setConnected(false);
|
||||||
|
updateTabMeta(sessionId, { connecting: false, connected: false });
|
||||||
|
if (document.visibilityState === "visible") scheduleReconnectRef.current(sessionId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (sessionsRef.current.has(sessionId)) {
|
if (sessionsRef.current.has(sessionId)) {
|
||||||
removeSession(sessionId, { skipSocketClose: true });
|
removeSession(sessionId, { skipSocketClose: true });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleConnect = (overrides?: {
|
||||||
|
host?: string;
|
||||||
|
nickname?: string;
|
||||||
|
serverPassword?: string;
|
||||||
|
channelPassword?: string;
|
||||||
|
defaultChannel?: string;
|
||||||
|
privilegeKey?: string;
|
||||||
|
serverType?: ServerType;
|
||||||
|
favoriteId?: string | null;
|
||||||
|
}) => {
|
||||||
|
const params: ConnectParams = {
|
||||||
|
host: overrides?.host ?? host,
|
||||||
|
nickname: overrides?.nickname ?? nickname,
|
||||||
|
serverPassword: overrides?.serverPassword ?? serverPassword,
|
||||||
|
channelPassword: overrides?.channelPassword ?? channelPassword,
|
||||||
|
defaultChannel: overrides?.defaultChannel ?? defaultChannel,
|
||||||
|
privilegeKey: overrides?.privilegeKey ?? privilegeKey,
|
||||||
|
serverType: overrides?.serverType ?? serverType,
|
||||||
|
identityId: activeIdentityId,
|
||||||
|
favoriteId: overrides?.favoriteId !== undefined ? overrides.favoriteId : null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Multi-join: keep existing sessions; park the active tab and open a new one.
|
||||||
|
if (activeSessionIdRef.current && sessionsRef.current.has(activeSessionIdRef.current)) {
|
||||||
|
parkActiveSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearActiveUi();
|
||||||
|
setActiveFavoriteId(params.favoriteId);
|
||||||
|
hasConnectedRef.current = false;
|
||||||
|
setConnecting(true);
|
||||||
|
setConnectError(null);
|
||||||
|
setConnectDialogOpen(false);
|
||||||
|
setHost(params.host);
|
||||||
|
setNickname(params.nickname);
|
||||||
|
|
||||||
|
ensureAudioContext();
|
||||||
|
|
||||||
|
const sessionId = crypto.randomUUID();
|
||||||
|
sessionParamsRef.current.set(sessionId, params);
|
||||||
|
|
||||||
|
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||||
|
sessionsRef.current.set(sessionId, { id: sessionId, socket, parked: null });
|
||||||
|
socketRef.current = socket;
|
||||||
|
activeSessionIdRef.current = sessionId;
|
||||||
|
setActiveSessionId(sessionId);
|
||||||
|
setSessionTabs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ id: sessionId, label: params.host || "…", connected: false, connecting: true },
|
||||||
|
]);
|
||||||
|
|
||||||
|
wireSocket(sessionId, socket, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Opens a fresh socket for a session that already exists (active or
|
||||||
|
// parked) and re-runs the same connect handshake, reusing the params
|
||||||
|
// stored at connect time. Used to recover from an unexpected drop —
|
||||||
|
// network blip, or the page coming back from being backgrounded/suspended
|
||||||
|
// — without disturbing which tab is active or losing chat/scroll history.
|
||||||
|
const reconnectSession = (sessionId: string) => {
|
||||||
|
const params = sessionParamsRef.current.get(sessionId);
|
||||||
|
const rec = sessionsRef.current.get(sessionId);
|
||||||
|
if (!params || !rec) return;
|
||||||
|
// Already open or mid-(re)connect — nothing to do.
|
||||||
|
if (rec.socket && rec.socket.readyState !== WebSocket.CLOSED && rec.socket.readyState !== WebSocket.CLOSING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logClient("info", "Connection", `Reconnecting to ${params.host}…`);
|
||||||
|
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||||
|
rec.socket = socket;
|
||||||
|
if (sessionId === activeSessionIdRef.current) {
|
||||||
|
socketRef.current = socket;
|
||||||
|
hasConnectedRef.current = false;
|
||||||
|
setConnecting(true);
|
||||||
|
setConnectError(null);
|
||||||
|
} else if (rec.parked) {
|
||||||
|
rec.parked = { ...rec.parked, connecting: true, connected: false, connectError: null };
|
||||||
|
}
|
||||||
|
updateTabMeta(sessionId, { connecting: true, connected: false });
|
||||||
|
wireSocket(sessionId, socket, params);
|
||||||
|
};
|
||||||
|
|
||||||
|
const reconnectSessionRef = useRef(reconnectSession);
|
||||||
|
reconnectSessionRef.current = reconnectSession;
|
||||||
|
|
||||||
|
// Per-session backoff so a persistently unreachable gateway doesn't get
|
||||||
|
// hammered with back-to-back reconnect attempts (each one fails near-
|
||||||
|
// instantly, which without a delay would tight-loop). Reset to 0 once a
|
||||||
|
// session actually reaches "connected" again (see the two spots below).
|
||||||
|
const reconnectAttemptsRef = useRef<Map<string, number>>(new Map());
|
||||||
|
const reconnectTimersRef = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||||
|
const scheduleReconnect = (sessionId: string) => {
|
||||||
|
if (reconnectTimersRef.current.has(sessionId)) return; // already scheduled
|
||||||
|
const attempt = reconnectAttemptsRef.current.get(sessionId) ?? 0;
|
||||||
|
const delay = Math.min(1000 * 2 ** attempt, 30_000);
|
||||||
|
reconnectAttemptsRef.current.set(sessionId, attempt + 1);
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
reconnectTimersRef.current.delete(sessionId);
|
||||||
|
// A manual disconnect meanwhile drops the session's stored params, so
|
||||||
|
// reconnectSession() below is a no-op in that case — no explicit
|
||||||
|
// cancellation needed.
|
||||||
|
reconnectSessionRef.current(sessionId);
|
||||||
|
}, delay);
|
||||||
|
reconnectTimersRef.current.set(sessionId, timer);
|
||||||
|
};
|
||||||
|
const scheduleReconnectRef = useRef(scheduleReconnect);
|
||||||
|
scheduleReconnectRef.current = scheduleReconnect;
|
||||||
|
|
||||||
|
// Android/mobile browsers aggressively suspend backgrounded or screen-off
|
||||||
|
// tabs — timers stall and the OS/browser can silently drop a WebSocket
|
||||||
|
// without ever firing onerror/onclose while hidden. There's no event for
|
||||||
|
// that; the only reliable signal is coming back to a socket that isn't
|
||||||
|
// OPEN anymore. Wake Lock keeps the screen (and the tab's throttling) at
|
||||||
|
// bay while any session is live — active tab AND parked background ones,
|
||||||
|
// same as a real TS3 client keeping every joined server connected, mic
|
||||||
|
// only ever live for the foreground tab. The visibilitychange re-check
|
||||||
|
// below catches whatever still slips through (screen-off ignores Wake
|
||||||
|
// Lock on some devices, the lock request can be refused, full app
|
||||||
|
// backgrounding on Android isn't preventable from a web page at all) by
|
||||||
|
// reconnecting every dropped session with the params used last time.
|
||||||
|
useEffect(() => {
|
||||||
|
if (sessionTabs.length === 0) return;
|
||||||
|
|
||||||
|
let wakeLock: { release: () => Promise<void> } | null = null;
|
||||||
|
const releaseWakeLock = () => {
|
||||||
|
wakeLock?.release().catch(() => {});
|
||||||
|
wakeLock = null;
|
||||||
|
};
|
||||||
|
const requestWakeLock = () => {
|
||||||
|
const wl = (navigator as { wakeLock?: { request: (type: "screen") => Promise<any> } }).wakeLock;
|
||||||
|
if (!wl || document.visibilityState !== "visible") return;
|
||||||
|
wl.request("screen")
|
||||||
|
.then((lock) => {
|
||||||
|
wakeLock = lock;
|
||||||
|
lock.addEventListener("release", () => {
|
||||||
|
if (wakeLock === lock) wakeLock = null;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
/* refused (battery saver, unsupported, …) — non-fatal */
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onVisibilityChange = () => {
|
||||||
|
if (document.visibilityState !== "visible") return;
|
||||||
|
requestWakeLock();
|
||||||
|
for (const id of sessionsRef.current.keys()) {
|
||||||
|
reconnectSessionRef.current(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||||
|
requestWakeLock();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||||
|
releaseWakeLock();
|
||||||
|
};
|
||||||
|
}, [sessionTabs.length]);
|
||||||
|
|
||||||
const handleDisconnect = () => {
|
const handleDisconnect = () => {
|
||||||
const id = activeSessionIdRef.current;
|
const id = activeSessionIdRef.current;
|
||||||
if (id) {
|
if (id) {
|
||||||
@@ -6071,12 +6436,14 @@ function AppInner() {
|
|||||||
serverPassword: f.serverPassword,
|
serverPassword: f.serverPassword,
|
||||||
channelPassword: f.defaultChannelPassword,
|
channelPassword: f.defaultChannelPassword,
|
||||||
defaultChannel: f.defaultChannel,
|
defaultChannel: f.defaultChannel,
|
||||||
|
favoriteId: f.id,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveFavorites = (next: Favorite[]) => {
|
const saveFavorites = (next: Favorite[]) => {
|
||||||
setFavorites(next);
|
const normalized = next.map((f) => normalizeFavorite(f));
|
||||||
localStorage.setItem(FAVORITES_KEY, JSON.stringify(next));
|
setFavorites(normalized);
|
||||||
|
localStorage.setItem(FAVORITES_KEY, JSON.stringify(normalized));
|
||||||
};
|
};
|
||||||
|
|
||||||
const openAddFavorite = () => {
|
const openAddFavorite = () => {
|
||||||
@@ -6088,6 +6455,7 @@ function AppInner() {
|
|||||||
serverPassword,
|
serverPassword,
|
||||||
defaultChannel,
|
defaultChannel,
|
||||||
defaultChannelPassword: channelPassword,
|
defaultChannelPassword: channelPassword,
|
||||||
|
showServerQueryClients: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setFavoritesMenuOpen(false);
|
setFavoritesMenuOpen(false);
|
||||||
@@ -6993,6 +7361,43 @@ function AppInner() {
|
|||||||
socketRef.current?.send(JSON.stringify({ type: "getChannelGroupList" }));
|
socketRef.current?.send(JSON.stringify({ type: "getChannelGroupList" }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleShowMoveClient = (clientId: number, clientName: string) => {
|
||||||
|
const target = clients.find((c) => c.id === clientId);
|
||||||
|
setMoveClientTarget({
|
||||||
|
clientId,
|
||||||
|
clientName,
|
||||||
|
channelId: target?.channel ?? 0,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMoveClient = (clientId: number, channelId: number) => {
|
||||||
|
const client = clients.find((c) => c.id === clientId);
|
||||||
|
if (client && client.channel === channelId) return;
|
||||||
|
// Moving yourself (e.g. dragging your own row) is a plain channel join,
|
||||||
|
// not an admin action - route it through the normal switch flow so it
|
||||||
|
// only needs join permission and still prompts for a channel password
|
||||||
|
// when required. The `moveClient` command below is for moving OTHER
|
||||||
|
// clients, which - like the native client - bypasses the target
|
||||||
|
// channel's password for whoever holds the move permission.
|
||||||
|
if (clientId === ownClientId) {
|
||||||
|
handleSwitchChannel(channelId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socketRef.current?.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "moveClient",
|
||||||
|
clientId,
|
||||||
|
channelId,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMoveClientToChannel = (channelId: number) => {
|
||||||
|
if (!moveClientTarget) return;
|
||||||
|
handleMoveClient(moveClientTarget.clientId, channelId);
|
||||||
|
setMoveClientTarget(null);
|
||||||
|
};
|
||||||
|
|
||||||
const handleShowServerGroupAssign = (clientId: number, clientName: string) => {
|
const handleShowServerGroupAssign = (clientId: number, clientName: string) => {
|
||||||
setGroupAssignTarget({ kind: "server", clientId, clientName });
|
setGroupAssignTarget({ kind: "server", clientId, clientName });
|
||||||
setServerGroups(null);
|
setServerGroups(null);
|
||||||
@@ -7267,6 +7672,26 @@ function AppInner() {
|
|||||||
selfActive && !inputMuted && ownClient?.hasTalkPower
|
selfActive && !inputMuted && ownClient?.hasTalkPower
|
||||||
? new Set(talkers).add(ownClient.id)
|
? new Set(talkers).add(ownClient.id)
|
||||||
: talkers;
|
: talkers;
|
||||||
|
const showServerQueryClients =
|
||||||
|
activeFavoriteId != null &&
|
||||||
|
favorites.some((f) => f.id === activeFavoriteId && f.showServerQueryClients);
|
||||||
|
// clients can be a large, frequently-unchanged list re-scanned on every
|
||||||
|
// render - including on every "talkers" voice-activity update, which has
|
||||||
|
// nothing to do with the client list itself - so memoize on the inputs
|
||||||
|
// that actually affect the result instead of re-filtering/re-reducing it
|
||||||
|
// every time.
|
||||||
|
const treeClients = useMemo(
|
||||||
|
() => (showServerQueryClients ? clients : clients.filter((c) => !c.isQuery)),
|
||||||
|
[clients, showServerQueryClients]
|
||||||
|
);
|
||||||
|
const queryClientCount = useMemo(
|
||||||
|
() => clients.reduce((n, c) => n + (c.isQuery ? 1 : 0), 0),
|
||||||
|
[clients]
|
||||||
|
);
|
||||||
|
const displayClientCount =
|
||||||
|
serverClientsOnline > 0
|
||||||
|
? serverClientsOnline + (showServerQueryClients ? queryClientCount : 0)
|
||||||
|
: treeClients.length;
|
||||||
const novaSplash = designTheme === "nova" && !connected;
|
const novaSplash = designTheme === "nova" && !connected;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -8163,6 +8588,16 @@ function AppInner() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{moveClientTarget && (
|
||||||
|
<MoveClientDialog
|
||||||
|
clientName={moveClientTarget.clientName}
|
||||||
|
currentChannelId={moveClientTarget.channelId}
|
||||||
|
channels={channels}
|
||||||
|
onSelect={handleMoveClientToChannel}
|
||||||
|
onClose={() => setMoveClientTarget(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{permissionOverviewOpen && (
|
{permissionOverviewOpen && (
|
||||||
<PermissionOverviewDialog
|
<PermissionOverviewDialog
|
||||||
entries={permissionOverview}
|
entries={permissionOverview}
|
||||||
@@ -8465,6 +8900,18 @@ function AppInner() {
|
|||||||
<span className="ts-menu-item-icon">👉</span>
|
<span className="ts-menu-item-icon">👉</span>
|
||||||
<span className="ts-menu-item-label">{t("clientContext.poke")}</span>
|
<span className="ts-menu-item-label">{t("clientContext.poke")}</span>
|
||||||
</button>
|
</button>
|
||||||
|
{!clientContextMenu.isSelf && (
|
||||||
|
<button
|
||||||
|
className="ts-menu-item"
|
||||||
|
onClick={() => {
|
||||||
|
handleShowMoveClient(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||||
|
setClientContextMenu(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="ts-menu-item-icon">🚚</span>
|
||||||
|
<span className="ts-menu-item-label">{t("clientContext.moveTo")}</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
className="ts-menu-item"
|
className="ts-menu-item"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -8726,7 +9173,7 @@ function AppInner() {
|
|||||||
</div>
|
</div>
|
||||||
<ChannelTree
|
<ChannelTree
|
||||||
channels={channels}
|
channels={channels}
|
||||||
clients={clients}
|
clients={treeClients}
|
||||||
parent={0}
|
parent={0}
|
||||||
ownClientId={ownClientId ?? ownClient?.id ?? null}
|
ownClientId={ownClientId ?? ownClient?.id ?? null}
|
||||||
talkers={displayTalkers}
|
talkers={displayTalkers}
|
||||||
@@ -8738,6 +9185,7 @@ function AppInner() {
|
|||||||
onSwitchChannel={handleSwitchChannel}
|
onSwitchChannel={handleSwitchChannel}
|
||||||
onOpenPrivateChat={handleOpenPrivateChat}
|
onOpenPrivateChat={handleOpenPrivateChat}
|
||||||
onPokeClient={handlePokeClient}
|
onPokeClient={handlePokeClient}
|
||||||
|
onMoveClient={handleMoveClient}
|
||||||
onClientContextMenu={handleClientContextMenu}
|
onClientContextMenu={handleClientContextMenu}
|
||||||
onChannelContextMenu={handleChannelContextMenu}
|
onChannelContextMenu={handleChannelContextMenu}
|
||||||
/>
|
/>
|
||||||
@@ -8764,14 +9212,12 @@ function AppInner() {
|
|||||||
serverVersion={serverVersion}
|
serverVersion={serverVersion}
|
||||||
serverLicense={serverLicense}
|
serverLicense={serverLicense}
|
||||||
serverLicenseId={serverLicenseId}
|
serverLicenseId={serverLicenseId}
|
||||||
totalClientCount={
|
totalClientCount={displayClientCount}
|
||||||
serverClientsOnline > 0 ? serverClientsOnline : clients.length
|
|
||||||
}
|
|
||||||
totalChannelCount={
|
totalChannelCount={
|
||||||
serverChannelsOnline > 0 ? serverChannelsOnline : channels.length
|
serverChannelsOnline > 0 ? serverChannelsOnline : channels.length
|
||||||
}
|
}
|
||||||
channels={channels}
|
channels={channels}
|
||||||
clients={clients}
|
clients={treeClients}
|
||||||
serverGroups={serverGroups}
|
serverGroups={serverGroups}
|
||||||
onShowServerConnectionInfo={handleShowServerConnectionInfo}
|
onShowServerConnectionInfo={handleShowServerConnectionInfo}
|
||||||
onEditServer={() => setServerEditOpen(true)}
|
onEditServer={() => setServerEditOpen(true)}
|
||||||
@@ -8784,7 +9230,7 @@ function AppInner() {
|
|||||||
|
|
||||||
<div className="ts-chat-panel">
|
<div className="ts-chat-panel">
|
||||||
{connected && designTheme === "pulse" && (
|
{connected && designTheme === "pulse" && (
|
||||||
<SpeakingNowBar clients={clients} talkers={displayTalkers} ownClientId={ownClient?.id ?? null} />
|
<SpeakingNowBar clients={treeClients} talkers={displayTalkers} ownClientId={ownClient?.id ?? null} />
|
||||||
)}
|
)}
|
||||||
<div className="ts-chat-messages">
|
<div className="ts-chat-messages">
|
||||||
{activeTab === "channel"
|
{activeTab === "channel"
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ export type ClientInfo = {
|
|||||||
channelGroup: number;
|
channelGroup: number;
|
||||||
serverGroups: number[];
|
serverGroups: number[];
|
||||||
hasTalkPower: boolean;
|
hasTalkPower: boolean;
|
||||||
|
/** ServerQuery client; hidden in the tree unless the favorite enables them. */
|
||||||
|
isQuery?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WhisperLogEntry = {
|
export type WhisperLogEntry = {
|
||||||
@@ -92,6 +94,8 @@ export type ParkedSessionState = {
|
|||||||
previousClients: ClientInfo[] | null;
|
previousClients: ClientInfo[] | null;
|
||||||
/** Whether the mic was on for this tab when it was parked, so switching back restores it. */
|
/** Whether the mic was on for this tab when it was parked, so switching back restores it. */
|
||||||
micWasOn: boolean;
|
micWasOn: boolean;
|
||||||
|
/** Favorite used to open this session (drives ServerQuery visibility). */
|
||||||
|
favoriteId: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SessionTabInfo = {
|
export type SessionTabInfo = {
|
||||||
@@ -143,6 +147,7 @@ export function emptyParkedState(partial?: Partial<ParkedSessionState>): ParkedS
|
|||||||
hasConnected: false,
|
hasConnected: false,
|
||||||
previousClients: null,
|
previousClients: null,
|
||||||
micWasOn: false,
|
micWasOn: false,
|
||||||
|
favoriteId: null,
|
||||||
...partial,
|
...partial,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,6 +277,20 @@ export class DemoSocket {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "moveClient": {
|
||||||
|
const clientId = Number(msg.clientId);
|
||||||
|
const channelId = Number(msg.channelId);
|
||||||
|
if (Number.isFinite(clientId) && Number.isFinite(channelId)) {
|
||||||
|
if (clientId === SELF_ID) {
|
||||||
|
this.selfChannel = channelId;
|
||||||
|
} else {
|
||||||
|
const npc = DEMO_NPCS.find((c) => c.id === clientId);
|
||||||
|
if (npc) npc.channel = channelId;
|
||||||
|
}
|
||||||
|
this.after(120, () => this.sendChannels(this.lastNickname));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "getClientConnectionInfo": {
|
case "getClientConnectionInfo": {
|
||||||
this.after(400, () =>
|
this.after(400, () =>
|
||||||
this.emit({
|
this.emit({
|
||||||
|
|||||||
@@ -521,6 +521,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
|
|
||||||
"clientContext.privateChat": "Privater Chat",
|
"clientContext.privateChat": "Privater Chat",
|
||||||
"clientContext.poke": "Anstupsen",
|
"clientContext.poke": "Anstupsen",
|
||||||
|
"clientContext.moveTo": "Verschieben in…",
|
||||||
"clientContext.copyName": "Namen kopieren",
|
"clientContext.copyName": "Namen kopieren",
|
||||||
"clientContext.connectionInfo": "Verbindungsinformationen anzeigen",
|
"clientContext.connectionInfo": "Verbindungsinformationen anzeigen",
|
||||||
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
||||||
@@ -532,6 +533,11 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"clientContext.ban": "Bannen",
|
"clientContext.ban": "Bannen",
|
||||||
"clientContext.notSupported": "Im Web-Client noch nicht unterstützt",
|
"clientContext.notSupported": "Im Web-Client noch nicht unterstützt",
|
||||||
|
|
||||||
|
"moveClient.title": "Verschieben",
|
||||||
|
"moveClient.empty": "Keine Channels verfügbar.",
|
||||||
|
"moveClient.current": "Aktueller Channel",
|
||||||
|
"moveClient.spacer": "Spacer",
|
||||||
|
|
||||||
"serverContext.connectionInfo": "Serververbindungsinformationen",
|
"serverContext.connectionInfo": "Serververbindungsinformationen",
|
||||||
"serverContext.copyAddress": "Serveradresse kopieren",
|
"serverContext.copyAddress": "Serveradresse kopieren",
|
||||||
"serverContext.addFavorite": "Zu Favoriten hinzufügen",
|
"serverContext.addFavorite": "Zu Favoriten hinzufügen",
|
||||||
@@ -1081,6 +1087,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
|
|
||||||
"clientContext.privateChat": "Private chat",
|
"clientContext.privateChat": "Private chat",
|
||||||
"clientContext.poke": "Poke",
|
"clientContext.poke": "Poke",
|
||||||
|
"clientContext.moveTo": "Move to…",
|
||||||
"clientContext.copyName": "Copy name",
|
"clientContext.copyName": "Copy name",
|
||||||
"clientContext.connectionInfo": "Show connection info",
|
"clientContext.connectionInfo": "Show connection info",
|
||||||
"clientContext.addWhisperTarget": "Add as whisper target",
|
"clientContext.addWhisperTarget": "Add as whisper target",
|
||||||
@@ -1092,6 +1099,11 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"clientContext.ban": "Ban",
|
"clientContext.ban": "Ban",
|
||||||
"clientContext.notSupported": "Not yet supported in the web client",
|
"clientContext.notSupported": "Not yet supported in the web client",
|
||||||
|
|
||||||
|
"moveClient.title": "Move",
|
||||||
|
"moveClient.empty": "No channels available.",
|
||||||
|
"moveClient.current": "Current channel",
|
||||||
|
"moveClient.spacer": "Spacer",
|
||||||
|
|
||||||
"serverContext.connectionInfo": "Server Connection Info",
|
"serverContext.connectionInfo": "Server Connection Info",
|
||||||
"serverContext.copyAddress": "Copy server address",
|
"serverContext.copyAddress": "Copy server address",
|
||||||
"serverContext.addFavorite": "Add to favorites",
|
"serverContext.addFavorite": "Add to favorites",
|
||||||
|
|||||||
@@ -486,6 +486,7 @@ export const zhCN: Record<string, string> = {
|
|||||||
|
|
||||||
"clientContext.privateChat": "私聊",
|
"clientContext.privateChat": "私聊",
|
||||||
"clientContext.poke": "戳一戳",
|
"clientContext.poke": "戳一戳",
|
||||||
|
"clientContext.moveTo": "移动到…",
|
||||||
"clientContext.copyName": "复制名称",
|
"clientContext.copyName": "复制名称",
|
||||||
"clientContext.connectionInfo": "查看连接信息",
|
"clientContext.connectionInfo": "查看连接信息",
|
||||||
"clientContext.addWhisperTarget": "添加为悄悄话目标",
|
"clientContext.addWhisperTarget": "添加为悄悄话目标",
|
||||||
@@ -497,6 +498,11 @@ export const zhCN: Record<string, string> = {
|
|||||||
"clientContext.ban": "封禁",
|
"clientContext.ban": "封禁",
|
||||||
"clientContext.notSupported": "网页客户端暂不支持此功能",
|
"clientContext.notSupported": "网页客户端暂不支持此功能",
|
||||||
|
|
||||||
|
"moveClient.title": "移动",
|
||||||
|
"moveClient.empty": "没有可用频道。",
|
||||||
|
"moveClient.current": "当前频道",
|
||||||
|
"moveClient.spacer": "间隔频道",
|
||||||
|
|
||||||
"serverContext.connectionInfo": "服务器连接信息",
|
"serverContext.connectionInfo": "服务器连接信息",
|
||||||
"serverContext.copyAddress": "复制服务器地址",
|
"serverContext.copyAddress": "复制服务器地址",
|
||||||
"serverContext.addFavorite": "添加到收藏夹",
|
"serverContext.addFavorite": "添加到收藏夹",
|
||||||
|
|||||||
@@ -652,6 +652,13 @@
|
|||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-app.ts-design-greenteaspeak .ts-channel-row.ts-drop-target,
|
||||||
|
.ts-app.ts-design-greenteaspeak .ts-channel-row.ts-spacer.ts-drop-target {
|
||||||
|
background: color-mix(in srgb, var(--accent, #4caf50) 28%, transparent);
|
||||||
|
outline: 1px dashed var(--accent, #4caf50);
|
||||||
|
outline-offset: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
.ts-app.ts-design-greenteaspeak .ts-channel-row.ts-spacer .ts-spacer-label {
|
.ts-app.ts-design-greenteaspeak .ts-channel-row.ts-spacer .ts-spacer-label {
|
||||||
left: 4px;
|
left: 4px;
|
||||||
right: 4px;
|
right: 4px;
|
||||||
|
|||||||
Reference in new issue
Block a user