mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 08:52:51 +08:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5858631e6d | ||
|
|
7217bc146a | ||
|
|
249687d98a | ||
|
|
3644ae7c41 | ||
|
|
0529ab72f1 | ||
|
|
af3a7c97cf | ||
|
|
69b256eb42 | ||
|
|
530415b50b | ||
|
|
fcbf3ea40d | ||
|
|
42f82d49aa | ||
|
|
0d8e9336f8 | ||
|
|
f6170f0576 | ||
|
|
65813b6367 | ||
|
|
fe1b5ff991 | ||
|
|
9b83e9d93f | ||
|
|
186a3f958b | ||
|
|
b6ccc6f627 |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: moepchi
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,85 @@
|
||||
name: Bug Report
|
||||
description: Something isn't working as expected
|
||||
labels: ["bug"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to report a bug! Please fill in as much detail as you can.
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: A clear description of the bug.
|
||||
placeholder: e.g. The Connect dialog closes unexpectedly when I select text inside it.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: How can we reproduce this?
|
||||
placeholder: |
|
||||
1. Open the Connect dialog
|
||||
2. Click and drag to select the server address text
|
||||
3. Release the mouse outside the dialog
|
||||
4. Dialog closes unexpectedly
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: What did you expect to happen instead?
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: dropdown
|
||||
id: browser
|
||||
attributes:
|
||||
label: Browser
|
||||
options:
|
||||
- Chrome / Chromium
|
||||
- Firefox
|
||||
- Safari
|
||||
- Edge
|
||||
- Other (mention in description)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: deployment
|
||||
attributes:
|
||||
label: Deployment method
|
||||
description: How are you running WebSpeak3?
|
||||
placeholder: e.g. Docker Hub image moepchi/webspeak3:latest, built from source, docker-compose
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version / commit
|
||||
description: Docker tag, commit hash, or release version if known
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant logs / console output
|
||||
description: Browser console errors, gateway logs, or connector output, if any.
|
||||
render: shell
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Screenshots, TeamSpeak server version, anything else relevant.
|
||||
validations:
|
||||
required: false
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Question / Discussion
|
||||
url: https://github.com/Moepchi/webspeak3/discussions
|
||||
about: Ask a question or discuss an idea before filing an issue.
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Feature Request
|
||||
description: Suggest an idea or improvement for WebSpeak3
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for the suggestion! Note that some native TeamSpeak 3 client features (myTeamSpeak integration,
|
||||
badges, plugins) are intentionally out of scope — see the README for details.
|
||||
|
||||
- type: textarea
|
||||
id: problem
|
||||
attributes:
|
||||
label: What problem does this solve?
|
||||
description: Is this related to something that's currently missing or annoying?
|
||||
placeholder: e.g. I can't send a targeted whisper to specific clients like in the native client.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Proposed solution
|
||||
description: What would you like to see happen?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Alternatives considered
|
||||
description: Any workarounds or alternative approaches you've thought of?
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Screenshots of the native client, links, or other context that helps explain the request.
|
||||
validations:
|
||||
required: false
|
||||
@@ -0,0 +1,57 @@
|
||||
name: Deploy demo to GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "web/**"
|
||||
- ".github/workflows/deploy-demo.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
cache-dependency-path: web/package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: web
|
||||
run: npm ci
|
||||
|
||||
- name: Build (demo mode)
|
||||
working-directory: web
|
||||
env:
|
||||
VITE_DEMO_MODE: "true"
|
||||
VITE_BASE_PATH: /webspeak3/
|
||||
run: npm run build
|
||||
|
||||
- uses: actions/configure-pages@v5
|
||||
|
||||
- uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: web/dist
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -17,11 +17,14 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://moepchi.github.io/webspeak3/">🕹️ Live Demo</a> ·
|
||||
<a href="#-installation">🚀 Quick Start</a> ·
|
||||
<a href="#-installation">📖 Installation</a> ·
|
||||
<a href="https://github.com/Moepchi/webspeak3/issues">🐛 Report Bug</a>
|
||||
</p>
|
||||
|
||||
> The [live demo](https://moepchi.github.io/webspeak3/) runs entirely in your browser with simulated data — no real TeamSpeak server involved. It's there to show the UI, not the real connection.
|
||||
|
||||
---
|
||||
|
||||
## 📸 Preview
|
||||
|
||||
+194
-11
@@ -11,11 +11,11 @@ use serde::Serialize;
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
|
||||
use tsclientlib::audio::AudioHandler;
|
||||
use tsclientlib::events::Event as BookEvent;
|
||||
use tsclientlib::events::{Event as BookEvent, PropertyId, PropertyValue};
|
||||
use tsclientlib::messages::c2s::{OutClientPokeRequestPart, OutSendTextMessagePart};
|
||||
use tsclientlib::prelude::*;
|
||||
use tsclientlib::{
|
||||
data, ChannelId, ClientId, Connection, DisconnectOptions, MaxClients, MessageHandle,
|
||||
data, ChannelId, ClientId, Connection, DisconnectOptions, Identity, MaxClients, MessageHandle,
|
||||
MessageTarget, Reason, StreamItem, TextMessageTargetMode,
|
||||
};
|
||||
use tsproto_packets::packets::{AudioData, CodecType, OutAudio};
|
||||
@@ -43,6 +43,12 @@ struct Args {
|
||||
/// instead of the server's actual default channel
|
||||
#[arg(long)]
|
||||
default_channel: Option<String>,
|
||||
/// Previously-issued identity (as emitted in the "connected" event's
|
||||
/// `identity` field) to reconnect with, so the server sees the same
|
||||
/// client UID across sessions. A fresh identity is generated - and
|
||||
/// reported back the same way - when omitted or unparseable.
|
||||
#[arg(long)]
|
||||
identity: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -68,6 +74,27 @@ struct ClientInfo {
|
||||
away: bool,
|
||||
away_message: String,
|
||||
is_channel_commander: bool,
|
||||
country: String,
|
||||
}
|
||||
|
||||
/// Human-facing entries for the Server tab's log-style notifications
|
||||
/// (client join/leave/switch, channel group assignment, channel/server
|
||||
/// changes, own permission errors) - mirrors what the native TS3 client
|
||||
/// shows inline in the server chat. `rename_all = "camelCase"` covers both
|
||||
/// the `kind` tag values and field names, so this needs no remapping on the
|
||||
/// gateway side (unlike the snake_case variants below).
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "kind", rename_all = "camelCase")]
|
||||
enum ServerLogEntry {
|
||||
ClientJoin { client: String, channel: String },
|
||||
ClientLeave { client: String },
|
||||
ClientChannelSwitch { client: String, from_channel: String, to_channel: String },
|
||||
ClientChannelGroupAssigned { client: String, group: String },
|
||||
ChannelCreated { channel: String },
|
||||
ChannelDeleted { channel: String },
|
||||
ChannelEdited { channel: String },
|
||||
ServerEdited,
|
||||
PermissionError { action: String },
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -81,6 +108,9 @@ enum Event {
|
||||
server_version: String,
|
||||
server_license: String,
|
||||
server_banner_url: String,
|
||||
/// Opaque JSON blob the frontend can store and pass back as `--identity`
|
||||
/// on a future connection to keep the same client UID.
|
||||
identity: String,
|
||||
},
|
||||
#[serde(rename = "channels")]
|
||||
Channels { channels: Vec<ChannelInfo>, clients: Vec<ClientInfo> },
|
||||
@@ -108,12 +138,118 @@ enum Event {
|
||||
Disconnected { reason: String },
|
||||
#[serde(rename = "error")]
|
||||
Error { message: String },
|
||||
/// Server-tab log notification (client join/leave/switch, channel group
|
||||
/// assignment, channel/server changes, own permission errors).
|
||||
#[serde(rename = "serverLog")]
|
||||
ServerLog {
|
||||
#[serde(flatten)]
|
||||
entry: ServerLogEntry,
|
||||
},
|
||||
}
|
||||
|
||||
fn emit(event: &Event) {
|
||||
println!("{}", serde_json::to_string(event).unwrap());
|
||||
}
|
||||
|
||||
fn emit_server_log(entry: ServerLogEntry) {
|
||||
emit(&Event::ServerLog { entry });
|
||||
}
|
||||
|
||||
/// Translates a single book-state diff into a Server-tab log entry, when it's
|
||||
/// one of the changes worth surfacing there (client join/leave/switch,
|
||||
/// channel group assignment, channel/server changes). Most diffs (e.g.
|
||||
/// per-field client updates like mute state) are intentionally not logged -
|
||||
/// only the categories the native client's server log shows for these.
|
||||
fn log_book_event(con: &data::Connection, event: &BookEvent) {
|
||||
match event {
|
||||
BookEvent::PropertyAdded { id: PropertyId::Client(client_id), .. } => {
|
||||
if let Some(client) = con.clients.get(client_id) {
|
||||
let channel = con.channels.get(&client.channel).map(|c| c.name.clone()).unwrap_or_default();
|
||||
emit_server_log(ServerLogEntry::ClientJoin { client: client.name.clone(), channel });
|
||||
}
|
||||
}
|
||||
BookEvent::PropertyRemoved { id: PropertyId::Client(_), old: PropertyValue::Client(client), .. } => {
|
||||
emit_server_log(ServerLogEntry::ClientLeave { client: client.name.clone() });
|
||||
}
|
||||
BookEvent::PropertyAdded { id: PropertyId::Channel(channel_id), .. } => {
|
||||
if let Some(channel) = con.channels.get(channel_id) {
|
||||
emit_server_log(ServerLogEntry::ChannelCreated { channel: channel.name.clone() });
|
||||
}
|
||||
}
|
||||
BookEvent::PropertyRemoved { id: PropertyId::Channel(_), old: PropertyValue::Channel(channel), .. } => {
|
||||
emit_server_log(ServerLogEntry::ChannelDeleted { channel: channel.name.clone() });
|
||||
}
|
||||
BookEvent::PropertyChanged { id: PropertyId::ClientChannel(client_id), old: PropertyValue::ChannelId(old_channel), .. } => {
|
||||
if let Some(client) = con.clients.get(client_id) {
|
||||
let from_channel = con.channels.get(old_channel).map(|c| c.name.clone()).unwrap_or_default();
|
||||
let to_channel = con.channels.get(&client.channel).map(|c| c.name.clone()).unwrap_or_default();
|
||||
emit_server_log(ServerLogEntry::ClientChannelSwitch {
|
||||
client: client.name.clone(),
|
||||
from_channel,
|
||||
to_channel,
|
||||
});
|
||||
}
|
||||
}
|
||||
BookEvent::PropertyChanged { id: PropertyId::ClientChannelGroup(client_id), .. } => {
|
||||
if let Some(client) = con.clients.get(client_id) {
|
||||
let group =
|
||||
con.channel_groups.get(&client.channel_group).map(|g| g.name.clone()).unwrap_or_default();
|
||||
emit_server_log(ServerLogEntry::ClientChannelGroupAssigned { client: client.name.clone(), group });
|
||||
}
|
||||
}
|
||||
BookEvent::PropertyChanged {
|
||||
id:
|
||||
PropertyId::ChannelName(channel_id)
|
||||
| PropertyId::ChannelTopic(channel_id)
|
||||
| PropertyId::ChannelMaxClients(channel_id)
|
||||
| PropertyId::ChannelMaxFamilyClients(channel_id)
|
||||
| PropertyId::ChannelHasPassword(channel_id)
|
||||
| PropertyId::ChannelNeededTalkPower(channel_id)
|
||||
| PropertyId::ChannelCodec(channel_id)
|
||||
| PropertyId::ChannelCodecQuality(channel_id)
|
||||
| PropertyId::ChannelIsDefault(channel_id)
|
||||
| PropertyId::ChannelDeleteDelay(channel_id)
|
||||
| PropertyId::ChannelPhoneticName(channel_id)
|
||||
| PropertyId::ChannelIsPrivate(channel_id)
|
||||
| PropertyId::ChannelForcedSilence(channel_id)
|
||||
| PropertyId::ChannelOrder(channel_id)
|
||||
| PropertyId::ChannelParent(channel_id),
|
||||
..
|
||||
} => {
|
||||
if let Some(channel) = con.channels.get(channel_id) {
|
||||
emit_server_log(ServerLogEntry::ChannelEdited { channel: channel.name.clone() });
|
||||
}
|
||||
}
|
||||
BookEvent::PropertyChanged {
|
||||
id:
|
||||
PropertyId::ServerName
|
||||
| PropertyId::ServerWelcomeMessage
|
||||
| PropertyId::ServerHostmessage
|
||||
| PropertyId::ServerHostmessageMode
|
||||
| PropertyId::ServerHostbannerUrl
|
||||
| PropertyId::ServerHostbannerGfxUrl
|
||||
| PropertyId::ServerHostbannerGfxInterval
|
||||
| PropertyId::ServerHostbannerMode
|
||||
| PropertyId::ServerHostbuttonTooltip
|
||||
| PropertyId::ServerHostbuttonUrl
|
||||
| PropertyId::ServerHostbuttonGfxUrl
|
||||
| PropertyId::ServerPhoneticName
|
||||
| PropertyId::ServerIcon
|
||||
| PropertyId::ServerMaxClients
|
||||
| PropertyId::ServerAskForPrivilegekey
|
||||
| PropertyId::ServerDefaultServerGroup
|
||||
| PropertyId::ServerDefaultChannelGroup
|
||||
| PropertyId::ServerCodecEncryptionMode
|
||||
| PropertyId::ServerTempChannelDefaultDeleteDelay
|
||||
| PropertyId::ServerPrioritySpeakerDimmModificator,
|
||||
..
|
||||
} => {
|
||||
emit_server_log(ServerLogEntry::ServerEdited);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// `Channel::order` is not a plain position, it's the id of the preceding
|
||||
/// sibling channel (0 = first child of its parent) - effectively a linked
|
||||
/// list per parent. This resolves that into a plain 0-based sequence index
|
||||
@@ -182,6 +318,7 @@ fn snapshot(con: &data::Connection) -> Event {
|
||||
away: c.away_message.is_some(),
|
||||
away_message: c.away_message.clone().unwrap_or_default(),
|
||||
is_channel_commander: c.is_channel_commander,
|
||||
country: c.country_code.clone(),
|
||||
})
|
||||
.collect();
|
||||
Event::Channels { channels, clients }
|
||||
@@ -220,7 +357,13 @@ async fn run(args: Args) -> Result<()> {
|
||||
tracing_subscriber::fmt().with_env_filter("warn").with_writer(std::io::stderr).init();
|
||||
|
||||
let address = args.address.clone();
|
||||
let mut con_config = Connection::build(args.address).name(args.nickname);
|
||||
let identity = args
|
||||
.identity
|
||||
.as_deref()
|
||||
.and_then(|s| serde_json::from_str::<Identity>(s).ok())
|
||||
.unwrap_or_else(Identity::create);
|
||||
let identity_str = serde_json::to_string(&identity).unwrap();
|
||||
let mut con_config = Connection::build(args.address).name(args.nickname).identity(identity);
|
||||
if let Some(pwd) = args.server_password {
|
||||
con_config = con_config.password(pwd);
|
||||
}
|
||||
@@ -268,6 +411,7 @@ async fn run(args: Args) -> Result<()> {
|
||||
server_version,
|
||||
server_license,
|
||||
server_banner_url,
|
||||
identity: identity_str,
|
||||
});
|
||||
|
||||
// Subscribe to all channels so we actually receive the full channel/client list.
|
||||
@@ -301,6 +445,11 @@ async fn run(args: Args) -> Result<()> {
|
||||
// `send_with_result()` for text messages gets us a `MessageResult` event we
|
||||
// can surface as a visible error instead of the message just vanishing.
|
||||
let mut pending_messages: HashMap<MessageHandle, String> = HashMap::new();
|
||||
// When non-empty, outgoing voice is whispered to just these channels/clients
|
||||
// instead of being sent to the current channel - set via the "whisper "
|
||||
// stdin command, cleared via "unwhisper".
|
||||
let mut whisper_channels: Vec<u64> = Vec::new();
|
||||
let mut whisper_clients: Vec<u16> = Vec::new();
|
||||
|
||||
enum LoopOutcome {
|
||||
StdinLine(std::io::Result<Option<String>>),
|
||||
@@ -340,8 +489,11 @@ async fn run(args: Args) -> Result<()> {
|
||||
let own = &state.clients[&state.own_client];
|
||||
own.client_move(ChannelId(id))
|
||||
};
|
||||
if let Err(e) = part.send(&mut con) {
|
||||
emit(&Event::Error { message: e.to_string() });
|
||||
match part.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_messages.insert(handle, "Channel switch".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
Err(_) => emit(&Event::Error { message: format!("Invalid channel id: {rest}") }),
|
||||
@@ -435,6 +587,17 @@ async fn run(args: Args) -> Result<()> {
|
||||
if let Err(e) = part.send(&mut con) {
|
||||
emit(&Event::Error { message: e.to_string() });
|
||||
}
|
||||
} else if let Some(rest) = l.strip_prefix("whisper ") {
|
||||
// Format: "whisper <channelId,channelId,...>;<clientId,clientId,...>"
|
||||
// (either side may be empty, e.g. "whisper 5;" or "whisper ;12,13").
|
||||
let mut parts = rest.splitn(2, ';');
|
||||
let channels_part = parts.next().unwrap_or("");
|
||||
let clients_part = parts.next().unwrap_or("");
|
||||
whisper_channels = channels_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
||||
whisper_clients = clients_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
||||
} else if l == "unwhisper" {
|
||||
whisper_channels.clear();
|
||||
whisper_clients.clear();
|
||||
} else if let Some(b64) = l.strip_prefix("audio ") {
|
||||
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
||||
Ok(bytes) => {
|
||||
@@ -446,11 +609,23 @@ async fn run(args: Args) -> Result<()> {
|
||||
let mut opus_output = [0u8; 1275];
|
||||
match opus_encoder.encode_float(&samples, &mut opus_output) {
|
||||
Ok(len) => {
|
||||
let packet = OutAudio::new(&AudioData::C2S {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
data: &opus_output[..len],
|
||||
});
|
||||
let has_whisper_targets =
|
||||
!whisper_channels.is_empty() || !whisper_clients.is_empty();
|
||||
let packet = if has_whisper_targets {
|
||||
OutAudio::new(&AudioData::C2SWhisper {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
channels: whisper_channels.clone(),
|
||||
clients: whisper_clients.clone(),
|
||||
data: &opus_output[..len],
|
||||
})
|
||||
} else {
|
||||
OutAudio::new(&AudioData::C2S {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
data: &opus_output[..len],
|
||||
})
|
||||
};
|
||||
if let Err(e) = con.send_audio(packet) {
|
||||
emit(&Event::Error { message: e.to_string() });
|
||||
}
|
||||
@@ -518,6 +693,8 @@ async fn run(args: Args) -> Result<()> {
|
||||
emit(&Event::Poke { from: invoker.name.clone(), message: message.clone() });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_book_event(con.get_state()?, event);
|
||||
}
|
||||
}
|
||||
emit(&snapshot(con.get_state()?));
|
||||
@@ -539,7 +716,13 @@ async fn run(args: Args) -> Result<()> {
|
||||
Some(Ok(StreamItem::MessageResult(handle, result))) => {
|
||||
if let Some(label) = pending_messages.remove(&handle) {
|
||||
if let Err(e) = result {
|
||||
emit(&Event::Error { message: format!("{label} failed: {e}") });
|
||||
if e.missing_permission.is_some() {
|
||||
emit(&Event::ServerLog {
|
||||
entry: ServerLogEntry::PermissionError { action: label },
|
||||
});
|
||||
} else {
|
||||
emit(&Event::Error { message: format!("{label} failed: {e}") });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
serverPassword: msg.serverPassword,
|
||||
channelPassword: msg.channelPassword,
|
||||
defaultChannel: msg.defaultChannel,
|
||||
identity: msg.identity,
|
||||
};
|
||||
connection = new Ts3Connection(options);
|
||||
connection.onEvent((event) => socket.send(JSON.stringify(event)));
|
||||
@@ -113,6 +114,10 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
await connection?.setOutputMuted(msg.muted);
|
||||
break;
|
||||
}
|
||||
case "setWhisperTargets": {
|
||||
await connection?.setWhisperTargets(msg.channelIds ?? [], msg.clientIds ?? []);
|
||||
break;
|
||||
}
|
||||
case "disconnect": {
|
||||
await connection?.disconnect(msg.message ?? "");
|
||||
break;
|
||||
|
||||
@@ -31,8 +31,20 @@ export interface ClientInfo {
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
export type ServerLogEntry =
|
||||
| { kind: "clientJoin"; client: string; channel: string }
|
||||
| { kind: "clientLeave"; client: string }
|
||||
| { kind: "clientChannelSwitch"; client: string; fromChannel: string; toChannel: string }
|
||||
| { kind: "clientChannelGroupAssigned"; client: string; group: string }
|
||||
| { kind: "channelCreated"; channel: string }
|
||||
| { kind: "channelDeleted"; channel: string }
|
||||
| { kind: "channelEdited"; channel: string }
|
||||
| { kind: "serverEdited" }
|
||||
| { kind: "permissionError"; action: string };
|
||||
|
||||
export type Ts3ConnectionEvent =
|
||||
| {
|
||||
type: "connected";
|
||||
@@ -42,6 +54,7 @@ export type Ts3ConnectionEvent =
|
||||
serverVersion: string;
|
||||
serverLicense: string;
|
||||
serverBannerUrl: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: ChannelInfo[]; clients: ClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
@@ -51,7 +64,8 @@ export type Ts3ConnectionEvent =
|
||||
| { type: "audioOut"; pcm: string }
|
||||
| { type: "talkers"; clients: number[] }
|
||||
| { type: "disconnected"; reason: string }
|
||||
| { type: "error"; message: string };
|
||||
| { type: "error"; message: string }
|
||||
| ({ type: "serverLog" } & ServerLogEntry);
|
||||
|
||||
export interface Ts3ConnectOptions {
|
||||
host: string;
|
||||
@@ -59,6 +73,9 @@ export interface Ts3ConnectOptions {
|
||||
serverPassword?: string;
|
||||
channelPassword?: string;
|
||||
defaultChannel?: string;
|
||||
/** Previously-issued identity (from a prior "connected" event) to keep
|
||||
* the same client UID across sessions. Omit to get a freshly generated one. */
|
||||
identity?: string;
|
||||
}
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
@@ -89,6 +106,7 @@ export class Ts3Connection {
|
||||
if (this.options.serverPassword) args.push("--server-password", this.options.serverPassword);
|
||||
if (this.options.channelPassword) args.push("--channel-password", this.options.channelPassword);
|
||||
if (this.options.defaultChannel) args.push("--default-channel", this.options.defaultChannel);
|
||||
if (this.options.identity) args.push("--identity", this.options.identity);
|
||||
this.child = spawn(CONNECTOR_BIN, args);
|
||||
|
||||
createInterface({ input: this.child.stdout }).on("line", (line) => {
|
||||
@@ -103,6 +121,7 @@ export class Ts3Connection {
|
||||
away: boolean;
|
||||
away_message: string;
|
||||
is_channel_commander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
interface RawChannelInfo {
|
||||
@@ -125,6 +144,7 @@ export class Ts3Connection {
|
||||
server_version: string;
|
||||
server_license: string;
|
||||
server_banner_url: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: RawChannelInfo[]; clients: RawClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
@@ -134,7 +154,8 @@ export class Ts3Connection {
|
||||
| { type: "audioOut"; pcm: string }
|
||||
| { type: "talkers"; clients: number[] }
|
||||
| { type: "disconnected"; reason: string }
|
||||
| { type: "error"; message: string };
|
||||
| { type: "error"; message: string }
|
||||
| ({ type: "serverLog" } & ServerLogEntry);
|
||||
|
||||
if (event.type === "connected") {
|
||||
this.emit({
|
||||
@@ -145,6 +166,7 @@ export class Ts3Connection {
|
||||
serverVersion: event.server_version,
|
||||
serverLicense: event.server_license,
|
||||
serverBannerUrl: event.server_banner_url,
|
||||
identity: event.identity,
|
||||
});
|
||||
} else if (event.type === "channels") {
|
||||
this.emit({
|
||||
@@ -169,6 +191,7 @@ export class Ts3Connection {
|
||||
away: c.away,
|
||||
awayMessage: c.away_message,
|
||||
isChannelCommander: c.is_channel_commander,
|
||||
country: c.country,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "privateMessage") {
|
||||
@@ -245,6 +268,16 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`);
|
||||
}
|
||||
|
||||
/** Empty channelIds/clientIds clears whisper mode, returning outgoing
|
||||
* voice to the normal current-channel broadcast. */
|
||||
async setWhisperTargets(channelIds: number[], clientIds: number[]): Promise<void> {
|
||||
if (channelIds.length === 0 && clientIds.length === 0) {
|
||||
this.child?.stdin.write("unwhisper\n");
|
||||
} else {
|
||||
this.child?.stdin.write(`whisper ${channelIds.join(",")};${clientIds.join(",")}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
async disconnect(message = ""): Promise<void> {
|
||||
if (this.child && !this.child.killed) {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
|
||||
@@ -9,6 +9,7 @@ lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-demo
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
|
||||
Generated
+9
-2
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "web",
|
||||
"name": "webspeak3-web",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "web",
|
||||
"name": "webspeak3-web",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"fflate": "^0.8.3",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7"
|
||||
},
|
||||
@@ -855,6 +856,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/fflate": {
|
||||
"version": "0.8.3",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",
|
||||
"integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"fflate": "^0.8.3",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7"
|
||||
},
|
||||
|
||||
+216
-1
@@ -26,6 +26,18 @@
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
color-scheme: light;
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
/* Demo-only: simulates a narrow viewport so the mobile layout (driven by
|
||||
the @container rules below) can be previewed without resizing the
|
||||
actual browser window. */
|
||||
.ts-app.ts-force-mobile {
|
||||
max-width: 390px;
|
||||
margin: 0 auto;
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(0, 0, 0, 0.4),
|
||||
0 0 40px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.ts-app.ts-theme-dark {
|
||||
@@ -52,6 +64,42 @@
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* Demo mode banner */
|
||||
|
||||
.ts-demo-banner {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
padding: 0.35rem 0.75rem;
|
||||
background: #7a4d00;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ts-demo-banner a {
|
||||
color: #fff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ts-demo-mobile-toggle {
|
||||
flex-shrink: 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.6);
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: #fff;
|
||||
padding: 0.15rem 0.6rem;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ts-demo-mobile-toggle:hover {
|
||||
background: rgba(255, 255, 255, 0.28);
|
||||
}
|
||||
|
||||
/* Toolbar */
|
||||
|
||||
.ts-menubar {
|
||||
@@ -142,6 +190,29 @@
|
||||
background: var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-context-menu {
|
||||
position: fixed;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 200px;
|
||||
padding: 0.25rem;
|
||||
background: var(--bg-toolbar-1);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.ts-context-menu-title {
|
||||
padding: 0.35rem 0.5rem;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.ts-toolbar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -584,6 +655,11 @@
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.ts-chat-line-log {
|
||||
color: var(--text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.ts-chat-input-row {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
@@ -592,14 +668,18 @@
|
||||
border-top: 1px solid var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-chat-input-row input {
|
||||
.ts-chat-input-row textarea {
|
||||
flex: 1;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 2px;
|
||||
padding: 0.3rem 0.5rem;
|
||||
font-size: 12px;
|
||||
font-family: inherit;
|
||||
background: var(--input-bg);
|
||||
color: var(--input-text);
|
||||
resize: none;
|
||||
max-height: 8.5em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.ts-chat-input-row button {
|
||||
@@ -1231,3 +1311,138 @@
|
||||
.ts-poke-notice button:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Mobile layout */
|
||||
|
||||
@container (max-width: 700px) {
|
||||
.ts-menubar {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 0.2rem;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
|
||||
.ts-toolbar {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ts-toolbar-icons {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 0.3rem;
|
||||
}
|
||||
|
||||
.ts-icon-slider input[type="range"] {
|
||||
width: 60px;
|
||||
}
|
||||
|
||||
.ts-icon-select select {
|
||||
max-width: 110px;
|
||||
}
|
||||
|
||||
.ts-app-logo {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.ts-toolbar-fields {
|
||||
flex-wrap: wrap;
|
||||
row-gap: 0.4rem;
|
||||
}
|
||||
|
||||
.ts-toolbar-fields input:not([type="range"]),
|
||||
.ts-toolbar-fields select {
|
||||
max-width: 40vw;
|
||||
}
|
||||
|
||||
.ts-body {
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.ts-upper {
|
||||
height: auto !important;
|
||||
flex-direction: column;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
|
||||
.ts-tree-panel {
|
||||
width: 100% !important;
|
||||
max-height: 35vh;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-resize-handle-vertical,
|
||||
.ts-resize-handle-horizontal {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ts-side-panel {
|
||||
max-height: 40vh;
|
||||
}
|
||||
|
||||
.ts-banner-panel {
|
||||
max-height: 25vh;
|
||||
}
|
||||
|
||||
.ts-chat-panel {
|
||||
min-height: 260px;
|
||||
}
|
||||
|
||||
.ts-chat-tabs {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/* Dialogs */
|
||||
|
||||
.ts-dialog {
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.ts-connect-dialog,
|
||||
.ts-favorites-dialog,
|
||||
.ts-away-dialog,
|
||||
.ts-options-dialog {
|
||||
width: 92vw !important;
|
||||
}
|
||||
|
||||
.ts-dialog-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ts-dialog-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.ts-favorites-body,
|
||||
.ts-options-body {
|
||||
flex-direction: column;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.ts-favorites-list-col,
|
||||
.ts-favorites-profile-col {
|
||||
width: 100%;
|
||||
border-right: none;
|
||||
border-left: none;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-options-sidebar {
|
||||
width: 100%;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
border-right: none;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
}
|
||||
|
||||
.ts-options-columns {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ts-poke-compose {
|
||||
flex-wrap: wrap;
|
||||
max-width: 92vw;
|
||||
}
|
||||
|
||||
.ts-poke-compose input {
|
||||
min-width: 160px;
|
||||
}
|
||||
}
|
||||
+415
-24
@@ -1,5 +1,19 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import "./App.css";
|
||||
|
||||
/** Only dismiss on a genuine backdrop click, not a text-selection drag that
|
||||
* starts inside the dialog and releases over the backdrop. */
|
||||
function useBackdropDismiss(onDismiss: () => void) {
|
||||
const mouseDownOnBackdrop = useRef(false);
|
||||
return {
|
||||
onMouseDown: (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
mouseDownOnBackdrop.current = e.target === e.currentTarget;
|
||||
},
|
||||
onClick: (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (mouseDownOnBackdrop.current && e.target === e.currentTarget) onDismiss();
|
||||
},
|
||||
};
|
||||
}
|
||||
import {
|
||||
AudioPlayer,
|
||||
MicCapture,
|
||||
@@ -10,6 +24,7 @@ import {
|
||||
pickAudioOutputDevice,
|
||||
} from "./voice";
|
||||
import { LanguageProvider, useLanguage, useT, type LangPref } from "./i18n";
|
||||
import { DEMO_HOST, DEMO_MODE, DemoSocket } from "./demoMode";
|
||||
import {
|
||||
SOUND_EVENTS,
|
||||
clearCustomSound,
|
||||
@@ -25,6 +40,7 @@ import {
|
||||
setSoundsOutputDevice,
|
||||
type SoundEventId,
|
||||
} from "./sounds";
|
||||
import { parseSoundpack } from "./soundpack";
|
||||
|
||||
// In dev, the gateway runs standalone on its own port. In production it's
|
||||
// served from the same origin/port as the web app (single container behind a
|
||||
@@ -49,6 +65,9 @@ const GATEWAY_URL = import.meta.env.DEV
|
||||
|
||||
const LAST_HOST_KEY = "webspeak3:last-host";
|
||||
const LAST_NICKNAME_KEY = "webspeak3:last-nickname";
|
||||
/** Identity persisted across sessions so the server sees the same client UID
|
||||
* each time, instead of a fresh one being generated per connection. */
|
||||
const IDENTITY_KEY = "webspeak3:identity";
|
||||
const FAVORITES_KEY = "webspeak3:favorites";
|
||||
const INPUT_DEVICE_KEY = "webspeak3:input-device";
|
||||
const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume";
|
||||
@@ -144,6 +163,16 @@ interface ClientInfo {
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
/** Converts an ISO 3166-1 alpha-2 country code (e.g. "DE") to its flag emoji
|
||||
* via Unicode regional indicator symbols. Returns null for codes the server
|
||||
* doesn't report (empty string - common when geo-IP isn't configured). */
|
||||
function countryFlag(code: string): string | null {
|
||||
if (!/^[A-Za-z]{2}$/.test(code)) return null;
|
||||
const codePoints = [...code.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65);
|
||||
return String.fromCodePoint(...codePoints);
|
||||
}
|
||||
|
||||
function ChannelIcon() {
|
||||
@@ -203,6 +232,7 @@ function ChannelTree({
|
||||
onSwitchChannel,
|
||||
onOpenPrivateChat,
|
||||
onPokeClient,
|
||||
onClientContextMenu,
|
||||
}: {
|
||||
channels: ChannelInfo[];
|
||||
clients: ClientInfo[];
|
||||
@@ -214,6 +244,7 @@ function ChannelTree({
|
||||
onSwitchChannel: (channelId: number) => void;
|
||||
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
||||
onPokeClient: (clientId: number, clientName: string) => void;
|
||||
onClientContextMenu: (e: React.MouseEvent, clientId: number, clientName: string, isSelf: boolean) => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const children = channels.filter((c) => c.parent === parent).sort((a, b) => a.order - b.order);
|
||||
@@ -245,9 +276,11 @@ function ChannelTree({
|
||||
talkers.has(c.id) ? " ts-talking" : ""
|
||||
}`}
|
||||
onClick={c.id === ownClientId ? undefined : () => onOpenPrivateChat(c.id, c.name)}
|
||||
onContextMenu={(e) => onClientContextMenu(e, c.id, c.name, c.id === ownClientId)}
|
||||
title={c.id === ownClientId ? undefined : `${t("tree.privateChatWith")} ${c.name}`}
|
||||
>
|
||||
<ClientIcon />
|
||||
{countryFlag(c.country) && <span title={c.country}>{countryFlag(c.country)}</span>}
|
||||
<span>{c.name}</span>
|
||||
{c.away && c.awayMessage && (
|
||||
<span className="ts-client-away-message">({c.awayMessage})</span>
|
||||
@@ -280,6 +313,7 @@ function ChannelTree({
|
||||
onSwitchChannel={onSwitchChannel}
|
||||
onOpenPrivateChat={onOpenPrivateChat}
|
||||
onPokeClient={onPokeClient}
|
||||
onClientContextMenu={onClientContextMenu}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
@@ -370,6 +404,9 @@ function InfoPanel({
|
||||
interface ChatEntry {
|
||||
from: string;
|
||||
message: string;
|
||||
/** Set for server-log notifications (join/leave/switch/etc.) so they render
|
||||
* without a "from:" prefix, like the native client's server tab. */
|
||||
isLog?: boolean;
|
||||
}
|
||||
|
||||
interface PmMessage {
|
||||
@@ -426,8 +463,9 @@ function ConnectDialog({
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onCancel);
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" onClick={onCancel}>
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-connect-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("connect.title")}</span>
|
||||
@@ -586,8 +624,9 @@ function FavoritesDialog({
|
||||
setSelectedId(null);
|
||||
};
|
||||
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" onClick={onClose}>
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-favorites-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("favorites.title")}</span>
|
||||
@@ -759,8 +798,9 @@ function AwayDialog({
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onCancel);
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" onClick={onCancel}>
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-away-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("away.dialog.title")}</span>
|
||||
@@ -1077,6 +1117,11 @@ function SoundsPanel() {
|
||||
);
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const uploadTargetRef = useRef<SoundEventId | null>(null);
|
||||
const soundpackInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [soundpackResult, setSoundpackResult] = useState<{
|
||||
matchedCount: number;
|
||||
unmatchedFiles: string[];
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
@@ -1134,6 +1179,27 @@ function SoundsPanel() {
|
||||
});
|
||||
};
|
||||
|
||||
const handleImportSoundpackClick = () => soundpackInputRef.current?.click();
|
||||
|
||||
const handleSoundpackSelected = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
e.target.value = "";
|
||||
if (!file) return;
|
||||
setSoundpackResult(null);
|
||||
const { matched, unmatchedFiles } = await parseSoundpack(file);
|
||||
for (const [event, sound] of Object.entries(matched) as [SoundEventId, { name: string; blob: Blob }][]) {
|
||||
await saveCustomSound(event, new File([sound.blob], sound.name, { type: sound.blob.type }));
|
||||
}
|
||||
setCustomNames((prev) => {
|
||||
const next = { ...prev };
|
||||
for (const [event, sound] of Object.entries(matched) as [SoundEventId, { name: string; blob: Blob }][]) {
|
||||
next[event] = sound.name;
|
||||
}
|
||||
return next;
|
||||
});
|
||||
setSoundpackResult({ matchedCount: Object.keys(matched).length, unmatchedFiles });
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3>{t("sounds.title")}</h3>
|
||||
@@ -1154,6 +1220,17 @@ function SoundsPanel() {
|
||||
/>
|
||||
<span>{Math.round(volume * 100)}%</span>
|
||||
</div>
|
||||
<div className="ts-options-field-row">
|
||||
<button onClick={handleImportSoundpackClick}>{t("sounds.importSoundpack")}</button>
|
||||
</div>
|
||||
{soundpackResult && (
|
||||
<p className="ts-options-subtitle">
|
||||
{t("sounds.importResult", {
|
||||
matched: String(soundpackResult.matchedCount),
|
||||
unmatched: String(soundpackResult.unmatchedFiles.length),
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
<table className="ts-options-sounds-table">
|
||||
<tbody>
|
||||
{SOUND_EVENTS.map((eventId) => (
|
||||
@@ -1190,6 +1267,13 @@ function SoundsPanel() {
|
||||
style={{ display: "none" }}
|
||||
onChange={(e) => void handleFileSelected(e)}
|
||||
/>
|
||||
<input
|
||||
ref={soundpackInputRef}
|
||||
type="file"
|
||||
accept=".ts3soundpack,.zip"
|
||||
style={{ display: "none" }}
|
||||
onChange={(e) => void handleSoundpackSelected(e)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1298,8 +1382,9 @@ function OptionsDialog({
|
||||
}) {
|
||||
const t = useT();
|
||||
const active = OPTIONS_SECTIONS.find((s) => s.id === section) ?? OPTIONS_SECTIONS[0];
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" onClick={onClose}>
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-options-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("options.title")}</span>
|
||||
@@ -1351,8 +1436,10 @@ function OptionsDialog({
|
||||
}
|
||||
|
||||
function AppInner() {
|
||||
const [host, setHost] = useState(() => localStorage.getItem(LAST_HOST_KEY) ?? "localhost");
|
||||
const [nickname, setNickname] = useState(() => localStorage.getItem(LAST_NICKNAME_KEY) ?? "");
|
||||
const [host, setHost] = useState(() => localStorage.getItem(LAST_HOST_KEY) ?? (DEMO_MODE ? DEMO_HOST : "localhost"));
|
||||
const [nickname, setNickname] = useState(
|
||||
() => localStorage.getItem(LAST_NICKNAME_KEY) ?? (DEMO_MODE ? "Guest" : "")
|
||||
);
|
||||
const [serverPassword, setServerPassword] = useState("");
|
||||
const [channelPassword, setChannelPassword] = useState("");
|
||||
const [defaultChannel, setDefaultChannel] = useState("");
|
||||
@@ -1375,10 +1462,25 @@ function AppInner() {
|
||||
const [chat, setChat] = useState<ChatEntry[]>([]);
|
||||
const [serverChat, setServerChat] = useState<ChatEntry[]>([]);
|
||||
const [chatInput, setChatInput] = useState("");
|
||||
const chatInputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const [pmThreads, setPmThreads] = useState<Record<number, PmThread>>({});
|
||||
const [pokes, setPokes] = useState<PokeNotice[]>([]);
|
||||
const [pokeTarget, setPokeTarget] = useState<{ id: number; name: string } | null>(null);
|
||||
const [pokeMessage, setPokeMessage] = useState("");
|
||||
const pokeBackdrop = useBackdropDismiss(() => setPokeTarget(null));
|
||||
const [demoForceMobile, setDemoForceMobile] = useState(false);
|
||||
const [clientContextMenu, setClientContextMenu] = useState<{
|
||||
x: number;
|
||||
y: number;
|
||||
clientId: number;
|
||||
clientName: string;
|
||||
isSelf: boolean;
|
||||
} | null>(null);
|
||||
const clientContextMenuRef = useRef<HTMLDivElement>(null);
|
||||
const [whisperChannelIds, setWhisperChannelIds] = useState<Set<number>>(new Set());
|
||||
const [whisperClientIds, setWhisperClientIds] = useState<Set<number>>(new Set());
|
||||
const [whisperMenuOpen, setWhisperMenuOpen] = useState(false);
|
||||
const whisperMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
const [activeTab, setActiveTab] = useState<ActiveTab>("channel");
|
||||
const [theme, setTheme] = useState<"light" | "dark">(() =>
|
||||
window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
||||
@@ -1390,7 +1492,6 @@ function AppInner() {
|
||||
const [vadHangover, setVadHangover] = useState(() => loadNumberPref(VAD_HANGOVER_KEY, 0.3));
|
||||
const [outputDevices, setOutputDevices] = useState<MediaDeviceInfo[]>([]);
|
||||
const [outputDeviceId, setOutputDeviceId] = useState("");
|
||||
const [outputDeviceLabel, setOutputDeviceLabel] = useState("System default");
|
||||
const [inputDevices, setInputDevices] = useState<MediaDeviceInfo[]>([]);
|
||||
const [inputDeviceId, setInputDeviceId] = useState(() => localStorage.getItem(INPUT_DEVICE_KEY) ?? "");
|
||||
const [playbackVolume, setPlaybackVolume] = useState(() => loadNumberPref(PLAYBACK_VOLUME_KEY, 1));
|
||||
@@ -1414,7 +1515,7 @@ function AppInner() {
|
||||
const [extrasMenuOpen, setExtrasMenuOpen] = useState(false);
|
||||
const [optionsDialogOpen, setOptionsDialogOpen] = useState(false);
|
||||
const [optionsSection, setOptionsSection] = useState<string>(OPTIONS_SECTIONS[0].id);
|
||||
const socketRef = useRef<WebSocket | null>(null);
|
||||
const socketRef = useRef<WebSocket | DemoSocket | null>(null);
|
||||
const connectionsMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
const favoritesMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
const awayMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
@@ -1425,6 +1526,10 @@ function AppInner() {
|
||||
const micCaptureRef = useRef<MicCapture | null>(null);
|
||||
const activeTabRef = useRef<ActiveTab>("channel");
|
||||
const hasConnectedRef = useRef(false);
|
||||
// Set when a "disconnected" event is received, so the socket's onclose
|
||||
// handler (which fires shortly after, on its own close handshake) can tell
|
||||
// a clean disconnect apart from the socket dying before ever connecting.
|
||||
const cleanDisconnectRef = useRef(false);
|
||||
const previousClientsRef = useRef<ClientInfo[] | null>(null);
|
||||
const pokeIdRef = useRef(0);
|
||||
const inputMutedRef = useRef(false);
|
||||
@@ -1469,7 +1574,7 @@ function AppInner() {
|
||||
|
||||
useEffect(() => {
|
||||
activeTabRef.current = activeTab;
|
||||
if (activeTab !== "channel") {
|
||||
if (typeof activeTab === "number") {
|
||||
setPmThreads((prev) => {
|
||||
const thread = prev[activeTab];
|
||||
if (!thread || !thread.unread) return prev;
|
||||
@@ -1609,7 +1714,7 @@ function AppInner() {
|
||||
|
||||
ensureAudioContext();
|
||||
|
||||
const socket = new WebSocket(GATEWAY_URL);
|
||||
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||
socketRef.current = socket;
|
||||
|
||||
socket.onopen = () => {
|
||||
@@ -1621,6 +1726,7 @@ function AppInner() {
|
||||
serverPassword: connectServerPassword || undefined,
|
||||
channelPassword: connectChannelPassword || undefined,
|
||||
defaultChannel: connectDefaultChannel || undefined,
|
||||
identity: localStorage.getItem(IDENTITY_KEY) || undefined,
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -1635,6 +1741,7 @@ function AppInner() {
|
||||
setConnected(true);
|
||||
localStorage.setItem(LAST_HOST_KEY, connectHost);
|
||||
localStorage.setItem(LAST_NICKNAME_KEY, connectNickname);
|
||||
if (data.identity) localStorage.setItem(IDENTITY_KEY, data.identity);
|
||||
setServerName(data.serverName);
|
||||
setServerMaxClients(data.serverMaxClients);
|
||||
setServerVersion(data.serverVersion);
|
||||
@@ -1703,9 +1810,48 @@ function AppInner() {
|
||||
void playSound("poke");
|
||||
break;
|
||||
}
|
||||
case "serverLog": {
|
||||
let message: string;
|
||||
switch (data.kind) {
|
||||
case "clientJoin":
|
||||
message = t("serverLog.clientJoin", { client: data.client, channel: data.channel });
|
||||
break;
|
||||
case "clientLeave":
|
||||
message = t("serverLog.clientLeave", { client: data.client });
|
||||
break;
|
||||
case "clientChannelSwitch":
|
||||
message = t("serverLog.clientChannelSwitch", {
|
||||
client: data.client,
|
||||
fromChannel: data.fromChannel,
|
||||
toChannel: data.toChannel,
|
||||
});
|
||||
break;
|
||||
case "clientChannelGroupAssigned":
|
||||
message = t("serverLog.clientChannelGroupAssigned", { client: data.client, group: data.group });
|
||||
break;
|
||||
case "channelCreated":
|
||||
message = t("serverLog.channelCreated", { channel: data.channel });
|
||||
break;
|
||||
case "channelDeleted":
|
||||
message = t("serverLog.channelDeleted", { channel: data.channel });
|
||||
break;
|
||||
case "channelEdited":
|
||||
message = t("serverLog.channelEdited", { channel: data.channel });
|
||||
break;
|
||||
case "serverEdited":
|
||||
message = t("serverLog.serverEdited");
|
||||
break;
|
||||
case "permissionError":
|
||||
message = t("serverLog.permissionError", { action: data.action });
|
||||
break;
|
||||
}
|
||||
setServerChat((prev) => [...prev, { from: "", message, isLog: true }]);
|
||||
break;
|
||||
}
|
||||
case "disconnected": {
|
||||
const wasConnected = hasConnectedRef.current;
|
||||
hasConnectedRef.current = false;
|
||||
cleanDisconnectRef.current = true;
|
||||
previousClientsRef.current = null;
|
||||
setConnecting(false);
|
||||
setConnected(false);
|
||||
@@ -1743,10 +1889,11 @@ function AppInner() {
|
||||
}
|
||||
};
|
||||
socket.onclose = () => {
|
||||
if (!hasConnectedRef.current) {
|
||||
if (!hasConnectedRef.current && !cleanDisconnectRef.current) {
|
||||
setConnecting(false);
|
||||
setConnectError((prev) => prev ?? "Connection closed before the server responded");
|
||||
}
|
||||
cleanDisconnectRef.current = false;
|
||||
setConnected(false);
|
||||
stopMic();
|
||||
audioPlayerRef.current?.dispose();
|
||||
@@ -1874,6 +2021,56 @@ function AppInner() {
|
||||
};
|
||||
}, [awayMenuOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!clientContextMenu) return;
|
||||
const onPointerDown = (e: MouseEvent) => {
|
||||
if (!clientContextMenuRef.current?.contains(e.target as Node)) setClientContextMenu(null);
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") setClientContextMenu(null);
|
||||
};
|
||||
window.addEventListener("mousedown", onPointerDown);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener("mousedown", onPointerDown);
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [clientContextMenu]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!connected) {
|
||||
setWhisperChannelIds(new Set());
|
||||
setWhisperClientIds(new Set());
|
||||
}
|
||||
}, [connected]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!connected) return;
|
||||
socketRef.current?.send(
|
||||
JSON.stringify({
|
||||
type: "setWhisperTargets",
|
||||
channelIds: [...whisperChannelIds],
|
||||
clientIds: [...whisperClientIds],
|
||||
})
|
||||
);
|
||||
}, [whisperChannelIds, whisperClientIds, connected]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!whisperMenuOpen) return;
|
||||
const onPointerDown = (e: MouseEvent) => {
|
||||
if (!whisperMenuRef.current?.contains(e.target as Node)) setWhisperMenuOpen(false);
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") setWhisperMenuOpen(false);
|
||||
};
|
||||
window.addEventListener("mousedown", onPointerDown);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener("mousedown", onPointerDown);
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [whisperMenuOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!extrasMenuOpen) return;
|
||||
const onPointerDown = (e: MouseEvent) => {
|
||||
@@ -1997,9 +2194,8 @@ function AppInner() {
|
||||
socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current }));
|
||||
};
|
||||
|
||||
const handleOutputDeviceChange = async (deviceId: string, label?: string) => {
|
||||
const handleOutputDeviceChange = async (deviceId: string) => {
|
||||
setOutputDeviceId(deviceId);
|
||||
setOutputDeviceLabel(label || (deviceId ? `Output ${deviceId.slice(0, 6)}` : "System default"));
|
||||
await audioPlayerRef.current?.setOutputDevice(deviceId);
|
||||
setSoundsOutputDevice(deviceId);
|
||||
};
|
||||
@@ -2007,7 +2203,7 @@ function AppInner() {
|
||||
const handlePickOutputDevice = async () => {
|
||||
try {
|
||||
const device = await pickAudioOutputDevice();
|
||||
if (device) await handleOutputDeviceChange(device.deviceId, device.label);
|
||||
if (device) await handleOutputDeviceChange(device.deviceId);
|
||||
} catch (error) {
|
||||
appendLog({ text: `Output device error: ${(error as Error).message}`, kind: "error" });
|
||||
}
|
||||
@@ -2024,6 +2220,13 @@ function AppInner() {
|
||||
|
||||
const handleSelectItem = (item: SelectedItem) => setSelected(item);
|
||||
|
||||
useEffect(() => {
|
||||
const el = chatInputRef.current;
|
||||
if (!el) return;
|
||||
el.style.height = "auto";
|
||||
el.style.height = `${el.scrollHeight}px`;
|
||||
}, [chatInput]);
|
||||
|
||||
const handleSendChat = () => {
|
||||
const message = chatInput.trim();
|
||||
if (!message) return;
|
||||
@@ -2050,6 +2253,41 @@ function AppInner() {
|
||||
setPokeMessage("");
|
||||
};
|
||||
|
||||
const toggleWhisperChannel = (channelId: number) => {
|
||||
setWhisperChannelIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(channelId)) next.delete(channelId);
|
||||
else next.add(channelId);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const toggleWhisperClient = (clientId: number) => {
|
||||
setWhisperClientIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(clientId)) next.delete(clientId);
|
||||
else next.add(clientId);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const clearWhisperTargets = () => {
|
||||
setWhisperChannelIds(new Set());
|
||||
setWhisperClientIds(new Set());
|
||||
};
|
||||
|
||||
const handleClientContextMenu = (
|
||||
e: React.MouseEvent,
|
||||
clientId: number,
|
||||
clientName: string,
|
||||
isSelf: boolean
|
||||
) => {
|
||||
e.preventDefault();
|
||||
const x = Math.min(e.clientX, window.innerWidth - 220);
|
||||
const y = Math.min(e.clientY, window.innerHeight - 300);
|
||||
setClientContextMenu({ x, y, clientId, clientName, isSelf });
|
||||
};
|
||||
|
||||
const handleSendPoke = () => {
|
||||
if (!pokeTarget) return;
|
||||
socketRef.current?.send(
|
||||
@@ -2077,7 +2315,18 @@ function AppInner() {
|
||||
const t = useT();
|
||||
|
||||
return (
|
||||
<div className={`ts-app ts-theme-${theme}`}>
|
||||
<div className={`ts-app ts-theme-${theme}${demoForceMobile ? " ts-force-mobile" : ""}`}>
|
||||
{DEMO_MODE && (
|
||||
<div className="ts-demo-banner">
|
||||
Demo mode — simulated data only, no real TeamSpeak server involved.{" "}
|
||||
<a href="https://github.com/Moepchi/webspeak3" target="_blank" rel="noreferrer">
|
||||
Get WebSpeak3
|
||||
</a>
|
||||
<button className="ts-demo-mobile-toggle" onClick={() => setDemoForceMobile((v) => !v)}>
|
||||
{demoForceMobile ? "🖥 Desktop view" : "📱 Mobile view"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="ts-menubar">
|
||||
<div className="ts-menubar-dropdown" ref={connectionsMenuRef}>
|
||||
<span
|
||||
@@ -2312,6 +2561,54 @@ function AppInner() {
|
||||
)}
|
||||
</div>
|
||||
<span className="ts-toolbar-sep" />
|
||||
<div className="ts-toolbar-away" ref={whisperMenuRef}>
|
||||
<button
|
||||
className={`ts-icon-button${whisperChannelIds.size > 0 || whisperClientIds.size > 0 ? " ts-away-on" : ""}`}
|
||||
onClick={() => setWhisperMenuOpen((v) => !v)}
|
||||
disabled={!connected}
|
||||
title={t("toolbar.whisper")}
|
||||
>
|
||||
🤫
|
||||
</button>
|
||||
{whisperMenuOpen && (
|
||||
<div className="ts-menu ts-menu-away">
|
||||
<div className="ts-context-menu-title">{t("whisper.channels")}</div>
|
||||
{channels.map((ch) => (
|
||||
<label key={ch.id} className="ts-menu-item">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={whisperChannelIds.has(ch.id)}
|
||||
onChange={() => toggleWhisperChannel(ch.id)}
|
||||
/>
|
||||
<span className="ts-menu-item-label">{ch.name}</span>
|
||||
</label>
|
||||
))}
|
||||
{whisperClientIds.size > 0 && (
|
||||
<>
|
||||
<div className="ts-menu-separator" />
|
||||
<div className="ts-context-menu-title">{t("whisper.clients")}</div>
|
||||
{[...whisperClientIds].map((id) => (
|
||||
<button key={id} className="ts-menu-item" onClick={() => toggleWhisperClient(id)}>
|
||||
<span className="ts-menu-item-icon">✕</span>
|
||||
<span className="ts-menu-item-label">
|
||||
{clients.find((c) => c.id === id)?.name ?? id}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
{(whisperChannelIds.size > 0 || whisperClientIds.size > 0) && (
|
||||
<>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" onClick={clearWhisperTargets}>
|
||||
<span className="ts-menu-item-label">{t("whisper.clearAll")}</span>
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<span className="ts-toolbar-sep" />
|
||||
<button
|
||||
className={`ts-icon-button${micOn && !inputMuted ? " ts-mic-on" : ""}${micOn && inputMuted ? " ts-muted-on" : ""}`}
|
||||
onClick={handleToggleMic}
|
||||
@@ -2374,7 +2671,7 @@ function AppInner() {
|
||||
>
|
||||
{theme === "dark" ? "☀️" : "🌙"}
|
||||
</button>
|
||||
<img src="/logo.png" alt="" className="ts-app-logo" />
|
||||
<img src={`${import.meta.env.BASE_URL}logo.png`} alt="" className="ts-app-logo" />
|
||||
<span className="ts-app-title">WebSpeak3</span>
|
||||
</div>
|
||||
|
||||
@@ -2463,7 +2760,7 @@ function AppInner() {
|
||||
)}
|
||||
|
||||
{pokeTarget && (
|
||||
<div className="ts-poke-compose-backdrop" onClick={() => setPokeTarget(null)}>
|
||||
<div className="ts-poke-compose-backdrop" {...pokeBackdrop}>
|
||||
<div className="ts-poke-compose" onClick={(e) => e.stopPropagation()}>
|
||||
<span>
|
||||
👉 {t("poke.title")} <strong>{pokeTarget.name}</strong>
|
||||
@@ -2495,6 +2792,86 @@ function AppInner() {
|
||||
</div>
|
||||
))}
|
||||
|
||||
{clientContextMenu && (
|
||||
<div
|
||||
ref={clientContextMenuRef}
|
||||
className="ts-context-menu"
|
||||
style={{ top: clientContextMenu.y, left: clientContextMenu.x }}
|
||||
>
|
||||
<div className="ts-context-menu-title">{clientContextMenu.clientName}</div>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
disabled={clientContextMenu.isSelf}
|
||||
onClick={() => {
|
||||
handleOpenPrivateChat(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">💬</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.privateChat")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
disabled={clientContextMenu.isSelf}
|
||||
onClick={() => {
|
||||
handlePokeClient(clientContextMenu.clientId, clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">👉</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.poke")}</span>
|
||||
</button>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
void navigator.clipboard?.writeText(clientContextMenu.clientName);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">📋</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.copyName")}</span>
|
||||
</button>
|
||||
{!clientContextMenu.isSelf && (
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
toggleWhisperClient(clientContextMenu.clientId);
|
||||
setClientContextMenu(null);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🤫</span>
|
||||
<span className="ts-menu-item-label">
|
||||
{whisperClientIds.has(clientContextMenu.clientId)
|
||||
? t("clientContext.removeWhisperTarget")
|
||||
: t("clientContext.addWhisperTarget")}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🏷️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignChannelGroup")}</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🎖️</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.assignServerGroup")}</span>
|
||||
</button>
|
||||
{!clientContextMenu.isSelf && (
|
||||
<>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">👢</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.kick")}</span>
|
||||
</button>
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<span className="ts-menu-item-icon">🚫</span>
|
||||
<span className="ts-menu-item-label">{t("clientContext.ban")}</span>
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="ts-body">
|
||||
<div className="ts-upper" style={{ height: upperHeight }}>
|
||||
<div className="ts-tree-panel" style={{ width: treeWidth }}>
|
||||
@@ -2518,6 +2895,7 @@ function AppInner() {
|
||||
onSwitchChannel={handleSwitchChannel}
|
||||
onOpenPrivateChat={handleOpenPrivateChat}
|
||||
onPokeClient={handlePokeClient}
|
||||
onClientContextMenu={handleClientContextMenu}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -2560,11 +2938,17 @@ function AppInner() {
|
||||
</div>
|
||||
))
|
||||
: activeTab === "server"
|
||||
? serverChat.map((entry, i) => (
|
||||
<div key={i} className="ts-chat-line">
|
||||
<span className="ts-chat-from">{entry.from}:</span> <span>{entry.message}</span>
|
||||
</div>
|
||||
))
|
||||
? serverChat.map((entry, i) =>
|
||||
entry.isLog ? (
|
||||
<div key={i} className="ts-chat-line ts-chat-line-log">
|
||||
<span>{entry.message}</span>
|
||||
</div>
|
||||
) : (
|
||||
<div key={i} className="ts-chat-line">
|
||||
<span className="ts-chat-from">{entry.from}:</span> <span>{entry.message}</span>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
: pmThreads[activeTab]?.messages.map((entry, i) => (
|
||||
<div key={i} className="ts-chat-line">
|
||||
<span className="ts-chat-from">
|
||||
@@ -2610,10 +2994,17 @@ function AppInner() {
|
||||
))}
|
||||
</div>
|
||||
<div className="ts-chat-input-row">
|
||||
<input
|
||||
<textarea
|
||||
ref={chatInputRef}
|
||||
rows={1}
|
||||
value={chatInput}
|
||||
onChange={(e) => setChatInput(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && handleSendChat()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSendChat();
|
||||
}
|
||||
}}
|
||||
disabled={!connected}
|
||||
placeholder={
|
||||
!connected
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
// Standalone frontend demo: no gateway, no real TeamSpeak server. Everything
|
||||
// below simulates the WebSocket protocol the real gateway speaks (see
|
||||
// gateway/src/index.ts) so App.tsx doesn't need to know it isn't talking to
|
||||
// a real backend. Only enabled in the GitHub Pages build (VITE_DEMO_MODE=true)
|
||||
// so the normal Docker image is completely unaffected.
|
||||
export const DEMO_MODE = import.meta.env.VITE_DEMO_MODE === "true";
|
||||
|
||||
export const DEMO_HOST = "demo.webspeak3.example";
|
||||
|
||||
interface DemoChannel {
|
||||
id: number;
|
||||
parent: number;
|
||||
order: number;
|
||||
name: string;
|
||||
topic: string;
|
||||
codec: string;
|
||||
maxClients: number | null;
|
||||
hasPassword: boolean;
|
||||
}
|
||||
|
||||
interface DemoClient {
|
||||
id: number;
|
||||
channel: number;
|
||||
name: string;
|
||||
inputMuted: boolean;
|
||||
outputMuted: boolean;
|
||||
inputHardwareEnabled: boolean;
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
}
|
||||
|
||||
const DEMO_CHANNELS: DemoChannel[] = [
|
||||
{ id: 1, parent: 0, order: 0, name: "Lobby", topic: "Welcome to the WebSpeak3 demo!", codec: "Opus Voice", maxClients: null, hasPassword: false },
|
||||
{ id: 2, parent: 0, order: 1, name: "Gaming", topic: "", codec: "Opus Voice", maxClients: 10, hasPassword: false },
|
||||
{ id: 3, parent: 0, order: 2, name: "AFK", topic: "", codec: "Opus Voice", maxClients: null, hasPassword: false },
|
||||
];
|
||||
|
||||
const DEMO_NPCS: DemoClient[] = [
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US" },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB" },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA" },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE" },
|
||||
];
|
||||
|
||||
const SELF_ID = 101;
|
||||
|
||||
/**
|
||||
* Drop-in stand-in for a real WebSocket. Implements the subset of the
|
||||
* WebSocket interface App.tsx actually uses (onopen/onmessage/onerror/
|
||||
* onclose/send/close/readyState), so it can be assigned to the same
|
||||
* socketRef without any changes to the event-handling code.
|
||||
*/
|
||||
export class DemoSocket {
|
||||
onopen: ((ev: Event) => void) | null = null;
|
||||
onmessage: ((ev: MessageEvent) => void) | null = null;
|
||||
onerror: ((ev: Event) => void) | null = null;
|
||||
onclose: ((ev: CloseEvent) => void) | null = null;
|
||||
readyState: number = WebSocket.CONNECTING;
|
||||
|
||||
private closed = false;
|
||||
private timers: number[] = [];
|
||||
private selfChannel = 1;
|
||||
|
||||
constructor() {
|
||||
this.after(400, () => {
|
||||
this.readyState = WebSocket.OPEN;
|
||||
this.onopen?.(new Event("open"));
|
||||
});
|
||||
}
|
||||
|
||||
send(raw: string) {
|
||||
if (this.closed) return;
|
||||
let msg: any;
|
||||
try {
|
||||
msg = JSON.parse(raw);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
this.handle(msg);
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.closed) return;
|
||||
// Mirrors the real gateway: a "disconnected" event arrives before the
|
||||
// socket itself finishes closing (see gateway's disconnected event vs.
|
||||
// the client-initiated WebSocket close in handleDisconnect).
|
||||
this.emit({ type: "disconnected", reason: "client requested" });
|
||||
this.closed = true;
|
||||
this.readyState = WebSocket.CLOSED;
|
||||
this.timers.forEach((id) => window.clearTimeout(id));
|
||||
this.timers = [];
|
||||
this.onclose?.({} as CloseEvent);
|
||||
}
|
||||
|
||||
private after(ms: number, fn: () => void) {
|
||||
const id = window.setTimeout(() => {
|
||||
if (this.closed) return;
|
||||
fn();
|
||||
}, ms);
|
||||
this.timers.push(id);
|
||||
}
|
||||
|
||||
private emit(data: unknown) {
|
||||
if (this.closed) return;
|
||||
this.onmessage?.({ data: JSON.stringify(data) } as MessageEvent);
|
||||
}
|
||||
|
||||
private handle(msg: any) {
|
||||
switch (msg.type) {
|
||||
case "connect": {
|
||||
const nickname = String(msg.nickname || "Guest").trim() || "Guest";
|
||||
this.after(900, () => {
|
||||
this.emit({
|
||||
type: "connected",
|
||||
serverName: "WebSpeak3 Demo Server",
|
||||
serverMaxClients: 32,
|
||||
serverVersion: "3.13.7 [Build: demo]",
|
||||
serverLicense: "Demo License",
|
||||
serverBannerUrl: null,
|
||||
welcomeMessage: "This is a simulated demo - no real TeamSpeak server is involved. Connect with any name/address you like.",
|
||||
});
|
||||
this.after(150, () => this.sendChannels(nickname));
|
||||
this.scriptServerLog(nickname);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "switchChannel": {
|
||||
const fromChannel = this.channelName(this.selfChannel);
|
||||
this.selfChannel = msg.channelId;
|
||||
const toChannel = this.channelName(this.selfChannel);
|
||||
this.emit({
|
||||
type: "serverLog",
|
||||
kind: "clientChannelSwitch",
|
||||
client: this.lastNickname,
|
||||
fromChannel,
|
||||
toChannel,
|
||||
});
|
||||
this.after(120, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "sendChatMessage":
|
||||
this.after(80, () => this.emit({ type: "chatMessage", from: this.lastNickname, message: msg.message }));
|
||||
break;
|
||||
case "sendServerMessage":
|
||||
this.after(80, () => this.emit({ type: "serverMessage", from: this.lastNickname, message: msg.message }));
|
||||
break;
|
||||
case "sendPrivateMessage": {
|
||||
const partner = DEMO_NPCS.find((c) => c.id === msg.clientId);
|
||||
this.after(80, () =>
|
||||
this.emit({
|
||||
type: "privateMessage",
|
||||
partnerId: msg.clientId,
|
||||
partnerName: partner?.name ?? "Unknown",
|
||||
message: msg.message,
|
||||
fromSelf: true,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "sendPoke": {
|
||||
const partner = DEMO_NPCS.find((c) => c.id === msg.clientId);
|
||||
this.after(400, () =>
|
||||
this.emit({ type: "poke", from: partner?.name ?? "Someone", message: "(demo poke - no reply expected)" })
|
||||
);
|
||||
break;
|
||||
}
|
||||
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||
// App.tsx always calls socket.close() right after sending it, and
|
||||
// close() already emits the "disconnected" event below.
|
||||
// setAway, setInputMuted, setOutputMuted, sendAudio: no observable effect
|
||||
// in a simulated single-user session, intentionally no-ops.
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private lastNickname = "Guest";
|
||||
|
||||
private channelName(id: number): string {
|
||||
return DEMO_CHANNELS.find((c) => c.id === id)?.name ?? "";
|
||||
}
|
||||
|
||||
/** A short, scripted burst of Server-tab log lines so the feature is visible
|
||||
* in the demo without needing a second real user to trigger them. */
|
||||
private scriptServerLog(nickname: string) {
|
||||
this.after(2500, () =>
|
||||
this.emit({ type: "serverLog", kind: "clientJoin", client: "Sam", channel: this.channelName(2) })
|
||||
);
|
||||
this.after(5000, () =>
|
||||
this.emit({
|
||||
type: "serverLog",
|
||||
kind: "clientChannelSwitch",
|
||||
client: "Jordan",
|
||||
fromChannel: this.channelName(2),
|
||||
toChannel: this.channelName(1),
|
||||
})
|
||||
);
|
||||
this.after(7500, () =>
|
||||
this.emit({
|
||||
type: "serverLog",
|
||||
kind: "clientChannelGroupAssigned",
|
||||
client: nickname,
|
||||
group: "Guest",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private sendChannels(nickname: string) {
|
||||
this.lastNickname = nickname;
|
||||
const self: DemoClient = {
|
||||
id: SELF_ID,
|
||||
channel: this.selfChannel,
|
||||
name: nickname,
|
||||
inputMuted: false,
|
||||
outputMuted: false,
|
||||
inputHardwareEnabled: true,
|
||||
away: false,
|
||||
awayMessage: "",
|
||||
isChannelCommander: false,
|
||||
country: "",
|
||||
};
|
||||
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
||||
}
|
||||
}
|
||||
+54
-2
@@ -38,12 +38,15 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"menu.extras.startRecording": "Aufnahme starten",
|
||||
"menu.extras.startMultitrackRecording": "Start Multitrack Recording",
|
||||
"menu.extras.stopRecording": "Aufnahme beenden",
|
||||
"menu.extras.installOverwolf": "Overwolf installieren",
|
||||
"menu.extras.options": "Optionen",
|
||||
|
||||
"toolbar.setAway": "Als abwesend markieren",
|
||||
"toolbar.backOnline": "Wieder online",
|
||||
"toolbar.awayOptions": "Abwesenheitsoptionen",
|
||||
"toolbar.whisper": "Whisper-Ziele",
|
||||
"whisper.channels": "Channels",
|
||||
"whisper.clients": "Clients",
|
||||
"whisper.clearAll": "Alle Whisper-Ziele entfernen",
|
||||
"toolbar.micEnable": "Mikrofon aktivieren",
|
||||
"toolbar.micMute": "Mikrofon stummschalten",
|
||||
"toolbar.micUnmute": "Mikrofon aktivieren (unmute)",
|
||||
@@ -189,6 +192,16 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"chat.send": "Senden",
|
||||
"chat.you": "Du",
|
||||
|
||||
"serverLog.clientJoin": "{client} loggte sich in Channel \"{channel}\" ein",
|
||||
"serverLog.clientLeave": "{client} hat die Verbindung getrennt (Verlassen)",
|
||||
"serverLog.clientChannelSwitch": "{client} ging von Channel \"{fromChannel}\" in \"{toChannel}\"",
|
||||
"serverLog.clientChannelGroupAssigned": "Die Channel-Gruppe \"{group}\" wurde {client} zugewiesen",
|
||||
"serverLog.channelCreated": "Channel \"{channel}\" wurde erstellt",
|
||||
"serverLog.channelDeleted": "Channel \"{channel}\" wurde gelöscht",
|
||||
"serverLog.channelEdited": "Channel \"{channel}\" wurde bearbeitet",
|
||||
"serverLog.serverEdited": "Die Servereinstellungen wurden geändert",
|
||||
"serverLog.permissionError": "Fehlende Berechtigung: {action}",
|
||||
|
||||
"poke.title": "Anstupsen",
|
||||
"poke.optionalMessage": "Optionale Nachricht...",
|
||||
"poke.send": "Anstupsen",
|
||||
@@ -196,6 +209,17 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"poke.pokedYou": "hat dich angestupst",
|
||||
"poke.dismiss": "Schließen",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
"clientContext.addWhisperTarget": "Als Whisper-Ziel hinzufügen",
|
||||
"clientContext.removeWhisperTarget": "Als Whisper-Ziel entfernen",
|
||||
"clientContext.assignChannelGroup": "Channel-Gruppe zuweisen",
|
||||
"clientContext.assignServerGroup": "Server-Gruppe zuweisen",
|
||||
"clientContext.kick": "Vom Server kicken",
|
||||
"clientContext.ban": "Bannen",
|
||||
"clientContext.notSupported": "Im Web-Client noch nicht unterstützt",
|
||||
|
||||
"connectError.dismiss": "Schließen",
|
||||
"dialog.close": "Schließen",
|
||||
|
||||
@@ -215,6 +239,8 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"sounds.test": "▶ Testen",
|
||||
"sounds.upload": "Hochladen",
|
||||
"sounds.reset": "Zurücksetzen",
|
||||
"sounds.importSoundpack": "Soundpack importieren (.ts3soundpack)",
|
||||
"sounds.importResult": "{matched} Sound(s) übernommen, {unmatched} Datei(en) nicht zugeordnet",
|
||||
|
||||
"nachrichten.title": "Nachrichten",
|
||||
"nachrichten.subtitle": "Nachrichten anpassen",
|
||||
@@ -256,12 +282,15 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"menu.extras.startRecording": "Start Recording",
|
||||
"menu.extras.startMultitrackRecording": "Start Multitrack Recording",
|
||||
"menu.extras.stopRecording": "Stop Recording",
|
||||
"menu.extras.installOverwolf": "Install Overwolf",
|
||||
"menu.extras.options": "Options",
|
||||
|
||||
"toolbar.setAway": "Set away",
|
||||
"toolbar.backOnline": "Back online",
|
||||
"toolbar.awayOptions": "Away options",
|
||||
"toolbar.whisper": "Whisper targets",
|
||||
"whisper.channels": "Channels",
|
||||
"whisper.clients": "Clients",
|
||||
"whisper.clearAll": "Clear all whisper targets",
|
||||
"toolbar.micEnable": "Enable microphone",
|
||||
"toolbar.micMute": "Mute microphone",
|
||||
"toolbar.micUnmute": "Unmute microphone",
|
||||
@@ -407,6 +436,16 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"chat.send": "Send",
|
||||
"chat.you": "You",
|
||||
|
||||
"serverLog.clientJoin": "{client} entered channel \"{channel}\"",
|
||||
"serverLog.clientLeave": "{client} disconnected (Left)",
|
||||
"serverLog.clientChannelSwitch": "{client} moved from channel \"{fromChannel}\" to \"{toChannel}\"",
|
||||
"serverLog.clientChannelGroupAssigned": "Channel group \"{group}\" was assigned to {client}",
|
||||
"serverLog.channelCreated": "Channel \"{channel}\" was created",
|
||||
"serverLog.channelDeleted": "Channel \"{channel}\" was deleted",
|
||||
"serverLog.channelEdited": "Channel \"{channel}\" was edited",
|
||||
"serverLog.serverEdited": "Server settings were changed",
|
||||
"serverLog.permissionError": "Missing permission: {action}",
|
||||
|
||||
"poke.title": "Poke",
|
||||
"poke.optionalMessage": "Optional message...",
|
||||
"poke.send": "Poke",
|
||||
@@ -414,6 +453,17 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"poke.pokedYou": "poked you",
|
||||
"poke.dismiss": "Dismiss",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
"clientContext.addWhisperTarget": "Add as whisper target",
|
||||
"clientContext.removeWhisperTarget": "Remove as whisper target",
|
||||
"clientContext.assignChannelGroup": "Assign channel group",
|
||||
"clientContext.assignServerGroup": "Assign server group",
|
||||
"clientContext.kick": "Kick from server",
|
||||
"clientContext.ban": "Ban",
|
||||
"clientContext.notSupported": "Not yet supported in the web client",
|
||||
|
||||
"connectError.dismiss": "Dismiss",
|
||||
"dialog.close": "Close",
|
||||
|
||||
@@ -433,6 +483,8 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"sounds.test": "▶ Test",
|
||||
"sounds.upload": "Upload",
|
||||
"sounds.reset": "Reset",
|
||||
"sounds.importSoundpack": "Import soundpack (.ts3soundpack)",
|
||||
"sounds.importResult": "{matched} sound(s) imported, {unmatched} file(s) not matched",
|
||||
|
||||
"nachrichten.title": "Messages",
|
||||
"nachrichten.subtitle": "Customize messages",
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { unzipSync } from "fflate";
|
||||
import type { SoundEventId } from "./sounds";
|
||||
|
||||
const AUDIO_EXTENSIONS = [".wav", ".mp3", ".ogg", ".m4a"];
|
||||
|
||||
const MIME_BY_EXTENSION: Record<string, string> = {
|
||||
".wav": "audio/wav",
|
||||
".mp3": "audio/mpeg",
|
||||
".ogg": "audio/ogg",
|
||||
".m4a": "audio/mp4",
|
||||
};
|
||||
|
||||
/** Real .ts3soundpack files use TeamSpeak's own internal event names, which
|
||||
* vary between client versions and aren't documented anywhere stable - so
|
||||
* this matches by keyword against the filename (soundpacks are zips of
|
||||
* individual audio files, not proprietary-encoded) rather than depending on
|
||||
* an exact manifest format. Falls back to a "not matched" list the caller
|
||||
* can surface, instead of silently dropping unrecognized files. */
|
||||
const EVENT_KEYWORDS: Record<SoundEventId, string[]> = {
|
||||
connect: ["connectionaccepted", "connectionestablished", "youhaveconnected", "connect"],
|
||||
disconnect: ["connectionlost", "connectiondisconnected", "youhavebeendisconnected", "disconnect"],
|
||||
clientJoin: ["userenteredchannel", "userenteredvisibility", "cliententerview", "userjoined", "enter"],
|
||||
clientLeave: ["userleftchannel", "userleftvisibility", "clientleftview", "userleave", "userleft", "leave"],
|
||||
message: ["textmessagereceived", "chatmessage", "newmessage", "message"],
|
||||
poke: ["gotpoked", "poke"],
|
||||
};
|
||||
|
||||
function normalize(filename: string): string {
|
||||
const base = filename.slice(filename.lastIndexOf("/") + 1);
|
||||
const dot = base.lastIndexOf(".");
|
||||
return (dot === -1 ? base : base.slice(0, dot)).toLowerCase().replace(/[^a-z0-9]/g, "");
|
||||
}
|
||||
|
||||
function extensionOf(filename: string): string | null {
|
||||
const lower = filename.toLowerCase();
|
||||
return AUDIO_EXTENSIONS.find((ext) => lower.endsWith(ext)) ?? null;
|
||||
}
|
||||
|
||||
export interface SoundpackImportResult {
|
||||
matched: Partial<Record<SoundEventId, { name: string; blob: Blob }>>;
|
||||
unmatchedFiles: string[];
|
||||
}
|
||||
|
||||
export async function parseSoundpack(file: File): Promise<SoundpackImportResult> {
|
||||
const buffer = new Uint8Array(await file.arrayBuffer());
|
||||
const entries = unzipSync(buffer, {
|
||||
filter: (entry) => extensionOf(entry.name) !== null,
|
||||
});
|
||||
|
||||
const matched: SoundpackImportResult["matched"] = {};
|
||||
const unmatchedFiles: string[] = [];
|
||||
|
||||
for (const [name, data] of Object.entries(entries)) {
|
||||
const ext = extensionOf(name);
|
||||
if (!ext) continue;
|
||||
const key = normalize(name);
|
||||
const eventId = (Object.keys(EVENT_KEYWORDS) as SoundEventId[]).find(
|
||||
(id) => !matched[id] && EVENT_KEYWORDS[id].some((keyword) => key.includes(keyword))
|
||||
);
|
||||
if (eventId) {
|
||||
matched[eventId] = {
|
||||
name: name.slice(name.lastIndexOf("/") + 1),
|
||||
blob: new Blob([data.slice()], { type: MIME_BY_EXTENSION[ext] }),
|
||||
};
|
||||
} else {
|
||||
unmatchedFiles.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
return { matched, unmatchedFiles };
|
||||
}
|
||||
+6
-5
@@ -61,13 +61,12 @@ export class MicCapture {
|
||||
private deviceId?: string;
|
||||
private echoCancellation: boolean;
|
||||
private noiseSuppression: boolean;
|
||||
private context: AudioContext;
|
||||
threshold: number;
|
||||
hangoverSeconds: number;
|
||||
|
||||
constructor(
|
||||
private context: AudioContext,
|
||||
options: MicCaptureOptions
|
||||
) {
|
||||
constructor(context: AudioContext, options: MicCaptureOptions) {
|
||||
this.context = context;
|
||||
this.onFrame = options.onFrame;
|
||||
this.onActivity = options.onActivity;
|
||||
this.onLevel = options.onLevel;
|
||||
@@ -222,8 +221,10 @@ export class AudioPlayer {
|
||||
private destination: MediaStreamAudioDestinationNode;
|
||||
private element: SinkableElement;
|
||||
private gain: GainNode;
|
||||
private context: AudioContext;
|
||||
|
||||
constructor(private context: AudioContext) {
|
||||
constructor(context: AudioContext) {
|
||||
this.context = context;
|
||||
this.destination = context.createMediaStreamDestination();
|
||||
this.gain = context.createGain();
|
||||
this.gain.connect(this.destination);
|
||||
|
||||
@@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react'
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
// Set by the GitHub Pages workflow to the repo subpath (e.g. /webspeak3/);
|
||||
// the normal Docker build serves from the domain root and leaves this unset.
|
||||
base: process.env.VITE_BASE_PATH || '/',
|
||||
})
|
||||
Reference in new issue
Block a user