Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e917e8e906 | ||
|
|
5e2b2860ae | ||
|
|
80e36539f3 | ||
|
|
b70b4d1fc9 | ||
|
|
fd24ae740e | ||
|
|
c10572feda | ||
|
|
c305fc4e1e | ||
|
|
ec3a693292 | ||
|
|
6bc3dca567 | ||
|
|
0a1163d4f9 | ||
|
|
fee0169463 | ||
|
|
b7ef6f78e7 | ||
|
|
6e343c4d4c | ||
|
|
4847972c80 | ||
|
|
44450ab35f | ||
|
|
9d6dcebfa9 | ||
|
|
e26b02c449 | ||
|
|
f629666bc2 | ||
|
|
684e597529 | ||
|
|
79df26c3bc | ||
|
|
b4ec2a26b6 | ||
|
|
ecc07308f6 | ||
|
|
53ccb22189 | ||
|
|
17899ae137 | ||
|
|
ea7b97b161 | ||
|
|
6d6803d9b3 | ||
|
|
7901aafbb1 | ||
|
|
41ac845fbc | ||
|
|
0f8576ac6c | ||
|
|
db8b5ea958 | ||
|
|
203e8fba51 | ||
|
|
b9d4bd533d | ||
|
|
dbe9a3c2df | ||
|
|
bd0122812d | ||
|
|
4318ce359f | ||
|
|
181b0fc43b | ||
|
|
330ecccadb | ||
|
|
74f688aba8 | ||
|
|
a300daedeb | ||
|
|
46ae5b120e | ||
|
|
284645f18d | ||
|
|
67c4bc1072 | ||
|
|
7bcced06fd | ||
|
|
f5cb4dd160 | ||
|
|
a0ede4a12a | ||
|
|
6c1fec8dcc | ||
|
|
6c4ace585d | ||
|
|
5858631e6d | ||
|
|
7217bc146a | ||
|
|
249687d98a | ||
|
|
3644ae7c41 | ||
|
|
0529ab72f1 | ||
|
|
af3a7c97cf | ||
|
|
69b256eb42 | ||
|
|
530415b50b | ||
|
|
fcbf3ea40d | ||
|
|
42f82d49aa | ||
|
|
0d8e9336f8 | ||
|
|
f6170f0576 | ||
|
|
65813b6367 | ||
|
|
fe1b5ff991 | ||
|
|
9b83e9d93f | ||
|
|
186a3f958b | ||
|
|
b6ccc6f627 | ||
|
|
8fb6d72957 | ||
|
|
234feb4d55 | ||
|
|
7a69d8602c | ||
|
|
3881742338 | ||
|
|
a5551dad54 | ||
|
|
9f41f4bcbe | ||
|
|
302c025018 | ||
|
|
6a0ba6f732 | ||
|
|
6158779184 | ||
|
|
507f9e8e3c | ||
|
|
85b48fe214 | ||
|
|
4f24d98e9f | ||
|
|
ddf4f149f7 | ||
|
|
a77172b55a | ||
|
|
0b7d2b7346 | ||
|
|
f523005972 | ||
|
|
26eff72528 | ||
|
|
8af60bd0c2 | ||
|
|
deb3f7b131 | ||
|
|
0f24c4b092 | ||
|
|
e5c5cc3f80 | ||
|
|
a2863520a5 | ||
|
|
0d65c3b123 | ||
|
|
41559c7712 | ||
|
|
234213d33e | ||
|
|
c48534dbc4 | ||
|
|
3715a52de6 | ||
|
|
53e2887e14 |
No files matched your search
@@ -0,0 +1,8 @@
|
||||
**/node_modules
|
||||
**/dist
|
||||
**/target
|
||||
tsclientlib/.git
|
||||
.git
|
||||
*.log
|
||||
.env
|
||||
.env.local
|
||||
@@ -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
|
||||
@@ -6,3 +6,6 @@ dist-ssr/
|
||||
.env
|
||||
.env.local
|
||||
.DS_Store
|
||||
docker-compose.override.yml
|
||||
.claude/
|
||||
CLAUDE.md
|
||||
@@ -1,3 +1,3 @@
|
||||
[submodule "tsclientlib"]
|
||||
path = tsclientlib
|
||||
url = https://github.com/ReSpeak/tsclientlib.git
|
||||
url = https://github.com/Moepchi/tsclientlib.git
|
||||
@@ -0,0 +1,2 @@
|
||||
/cache
|
||||
/project.local.yml
|
||||
@@ -0,0 +1,170 @@
|
||||
# the name by which the project can be referenced within Serena/when chatting with the LLM.
|
||||
project_name: "ts-web-client"
|
||||
|
||||
# list of language servers to start when using the LSP backend; choose from:
|
||||
# ada al angular ansible bash
|
||||
# bsl clojure cpp cpp_ccls crystal
|
||||
# csharp csharp_omnisharp cue dart deno
|
||||
# elixir elm erlang fortran fsharp
|
||||
# gdscript gleam go groovy haskell
|
||||
# haxe hlsl html java json
|
||||
# julia kotlin latex lean4 lua
|
||||
# luau markdown matlab msl nextflow
|
||||
# nix ocaml pascal perl php
|
||||
# php_phpactor php_phpantom powershell python python_basedpyright
|
||||
# python_jedi python_pyrefly python_ty qml r
|
||||
# rego ruby ruby_solargraph rust scala
|
||||
# scss solidity svelte swift systemverilog
|
||||
# terraform toml typescript typescript_vts vue
|
||||
# wolfram yaml zig
|
||||
# (This list may be outdated; generated with scripts/print_language_list.py;
|
||||
# For the current list, see values of the LanguageServerId enum here:
|
||||
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py)
|
||||
# For some languages, there are several alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
|
||||
# Note:
|
||||
# - For C, use cpp
|
||||
# - For JavaScript, use typescript
|
||||
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
|
||||
# - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
|
||||
# - For Deno projects, use deno (serves the same .ts/.js files as typescript; requires the deno CLI on PATH)
|
||||
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
|
||||
# - For Free Pascal/Lazarus, use pascal
|
||||
# Special requirements:
|
||||
# Some language servers require additional setup/installations.
|
||||
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
|
||||
# When using multiple language servers, the first language server that supports a given file will be used for that file.
|
||||
# The first language server is the default language and the respective language server will be used as a fallback.
|
||||
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
||||
language_servers:
|
||||
- rust
|
||||
- typescript
|
||||
|
||||
# the encoding used by text files in the project
|
||||
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
||||
encoding: "utf-8"
|
||||
|
||||
# optional shell command to run before the language backend (LSP or JetBrains) is initialised.
|
||||
# the command runs in the project root directory and is only executed if the project is trusted
|
||||
# (see trusted_project_path_patterns in the global configuration).
|
||||
# serena waits for the command to exit: a non-zero exit code is logged as an error but does not
|
||||
# abort activation. a per-project timeout (activation_command_timeout, default 180s) is the safety
|
||||
# backstop for non-terminating commands; on expiry the process is killed and activation continues.
|
||||
# example: activation_command: "npx nx run-many -t build"
|
||||
activation_command:
|
||||
|
||||
# maximum time in seconds to wait for activation_command to complete before killing it (default 180s).
|
||||
# must be a positive number.
|
||||
activation_command_timeout: 180.0
|
||||
|
||||
# line ending convention to use when writing source files.
|
||||
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
|
||||
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
|
||||
line_ending:
|
||||
|
||||
# The language backend to use for this project.
|
||||
# If not set, the global setting from serena_config.yml is used.
|
||||
# Valid values: LSP, JetBrains
|
||||
# Note: the backend is fixed at startup. If a project with a different backend
|
||||
# is activated post-init, an error will be returned.
|
||||
language_backend:
|
||||
|
||||
# whether to use project's .gitignore files to ignore files
|
||||
ignore_all_files_in_gitignore: true
|
||||
|
||||
# advanced configuration option allowing to configure language server-specific options.
|
||||
# Maps the language key to the options.
|
||||
# The settings are considered only if the project is trusted (see global configuration to define trusted projects).
|
||||
# See https://oraios.github.io/serena/02-usage/050_configuration.html#language-server-specific-settings
|
||||
ls_specific_settings: {}
|
||||
|
||||
# list of workspace folder paths (LSP backend only).
|
||||
# These folders will be used to build up Serena's symbol index.
|
||||
# Paths must be within the project root and should thus be relative to the project root.
|
||||
# Furthermore, the paths should not be filtered by ignore settings.
|
||||
# Default setting: The entire project root folder (".") is considered.
|
||||
# In (large) monorepos, this can be used to index only subfolders of the project root, e.g.
|
||||
# ls_workspace_folders:
|
||||
# - "./subproject1"
|
||||
# - "./subproject2"
|
||||
ls_workspace_folders:
|
||||
- "."
|
||||
|
||||
# list of additional workspace folder paths for cross-package reference support.
|
||||
# Paths can be absolute or relative to the project root.
|
||||
# Each folder is registered as an LSP workspace folder, enabling language servers to discover
|
||||
# symbols and references across package boundaries, but these folders are not indexed by Serena,
|
||||
# i.e. the respective symbols will not be found using Serena's symbol search tools.
|
||||
# Example:
|
||||
# additional_workspace_folders:
|
||||
# - ../sibling-package
|
||||
# - ../shared-lib
|
||||
ls_additional_workspace_folders: []
|
||||
|
||||
# list of additional paths to ignore in this project.
|
||||
# Same syntax as gitignore, so you can use * and **.
|
||||
# Important: quote patterns that start with `*`, otherwise YAML treats them as aliases.
|
||||
# Example:
|
||||
# ignored_paths:
|
||||
# - "examples/**"
|
||||
# - ".worktrees/**"
|
||||
# - "**/bin/**"
|
||||
# - "**/obj/**"
|
||||
# Note: global ignored_paths from serena_config.yml are also applied additively.
|
||||
ignored_paths: []
|
||||
|
||||
# whether the project is in read-only mode
|
||||
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
||||
# Added on 2025-04-18
|
||||
read_only: false
|
||||
|
||||
# list of tool names to exclude.
|
||||
# This extends the existing exclusions (e.g. from the global configuration)
|
||||
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
||||
excluded_tools: []
|
||||
|
||||
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
|
||||
# This extends the existing inclusions (e.g. from the global configuration).
|
||||
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
||||
included_optional_tools: []
|
||||
|
||||
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
|
||||
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
|
||||
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
|
||||
fixed_tools: []
|
||||
|
||||
# list of mode names that are to be activated by default, overriding the setting in the global configuration.
|
||||
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
|
||||
# If the setting is undefined/empty, the default_modes from the global configuration (serena_config.yml) apply.
|
||||
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
|
||||
# Therefore, you can set this to [] if you do not want the default modes defined in the global config to apply
|
||||
# for this project.
|
||||
# This setting can, in turn, be overridden by CLI parameters (--mode).
|
||||
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
|
||||
default_modes:
|
||||
|
||||
# list of mode names to be activated additionally for this project, e.g. ["query-projects"]
|
||||
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
|
||||
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
|
||||
added_modes:
|
||||
|
||||
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
||||
# (contrary to the memories, which are loaded on demand).
|
||||
initial_prompt: ""
|
||||
|
||||
# time budget (seconds) per tool call for the retrieval of additional symbol information
|
||||
# such as docstrings or parameter information.
|
||||
# This overrides the corresponding setting in the global configuration; see the documentation there.
|
||||
# If null or missing, use the setting from the global configuration.
|
||||
symbol_info_budget:
|
||||
|
||||
# list of regex patterns which, when matched, mark a memory entry as read‑only.
|
||||
# Extends the list from the global configuration, merging the two lists.
|
||||
read_only_memory_patterns: []
|
||||
|
||||
# list of regex patterns for memories to completely ignore.
|
||||
# Matching memories will not appear in list_memories or activate_project output
|
||||
# and cannot be accessed via read_memory or write_memory.
|
||||
# To access ignored memory files, use the read_file tool on the raw file path.
|
||||
# Extends the list from the global configuration, merging the two lists.
|
||||
# Example: ["_archive/.*", "_episodes/.*"]
|
||||
ignored_memory_patterns: []
|
||||
@@ -0,0 +1,45 @@
|
||||
# --- Rust connector -----------------------------------------------------
|
||||
FROM rust:1-bookworm AS connector-builder
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends cmake && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /src
|
||||
COPY tsclientlib/ tsclientlib/
|
||||
COPY connector/ connector/
|
||||
WORKDIR /src/connector
|
||||
ENV CMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||
RUN cargo build --release
|
||||
|
||||
# --- Web frontend ---------------------------------------------------------
|
||||
FROM node:22-bookworm-slim AS web-builder
|
||||
WORKDIR /src/web
|
||||
COPY web/package*.json ./
|
||||
RUN npm ci
|
||||
COPY web/ ./
|
||||
# tsc -b currently fails on pre-existing type errors unrelated to this build;
|
||||
# vite build alone is enough to produce the production bundle.
|
||||
RUN npx vite build
|
||||
|
||||
# --- Gateway ----------------------------------------------------------------
|
||||
FROM node:22-bookworm-slim AS gateway-builder
|
||||
WORKDIR /src/gateway
|
||||
COPY gateway/package*.json ./
|
||||
RUN npm ci
|
||||
COPY gateway/ ./
|
||||
RUN npm run build
|
||||
|
||||
# --- Runtime ----------------------------------------------------------------
|
||||
FROM node:22-bookworm-slim AS runtime
|
||||
LABEL org.opencontainers.image.title="WebSpeak3"
|
||||
LABEL org.opencontainers.image.description="Self-hosted web client for TeamSpeak 3 servers"
|
||||
WORKDIR /app
|
||||
COPY gateway/package*.json ./
|
||||
RUN npm ci --omit=dev
|
||||
COPY --from=gateway-builder /src/gateway/dist ./dist
|
||||
COPY --from=connector-builder /src/connector/target/release/ts-connector /app/connector-bin/ts-connector
|
||||
COPY --from=web-builder /src/web/dist /app/web/dist
|
||||
|
||||
ENV PORT=8080
|
||||
ENV WEB_DIST=/app/web/dist
|
||||
ENV CONNECTOR_BIN=/app/connector-bin/ts-connector
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["node", "dist/index.js"]
|
||||
@@ -1,87 +0,0 @@
|
||||
# Installation
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **Node.js** 20+ and npm
|
||||
- **Rust** (stable toolchain) — [rustup.rs](https://rustup.rs)
|
||||
- **CMake** and a C/C++ toolchain — needed to build the Opus codec library
|
||||
(`audiopus_sys`) used for voice. On Windows, the Visual Studio "Desktop
|
||||
development with C++" workload covers this; on Linux, install `cmake` and
|
||||
`build-essential` (or equivalent); on macOS, `cmake` via Homebrew plus Xcode
|
||||
command line tools.
|
||||
- **git**
|
||||
|
||||
## 1. Clone the repository
|
||||
|
||||
The Rust connector depends on the `tsclientlib` crate, vendored as a git
|
||||
submodule — make sure to pull it in too:
|
||||
|
||||
```bash
|
||||
git clone --recurse-submodules <your-repo-url>
|
||||
cd ts-web-client
|
||||
```
|
||||
|
||||
If you already cloned without `--recurse-submodules`:
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## 2. Build the Rust connector
|
||||
|
||||
```bash
|
||||
cd connector
|
||||
cargo build
|
||||
```
|
||||
|
||||
> **Note:** if the build fails with a CMake error like `Compatibility with
|
||||
> CMake < 3.5 has been removed`, it's because the vendored Opus source uses an
|
||||
> old `cmake_minimum_required`. Work around it with:
|
||||
>
|
||||
> ```bash
|
||||
> CMAKE_POLICY_VERSION_MINIMUM=3.5 cargo build
|
||||
> ```
|
||||
> (On Windows PowerShell: `$env:CMAKE_POLICY_VERSION_MINIMUM = "3.5"; cargo build`)
|
||||
|
||||
This produces `connector/target/debug/ts-connector` (or `ts-connector.exe` on
|
||||
Windows), which the gateway spawns automatically — no manual step needed
|
||||
after this.
|
||||
|
||||
## 3. Install and start the gateway
|
||||
|
||||
```bash
|
||||
cd gateway
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
This starts the WebSocket gateway on `ws://localhost:8080`.
|
||||
|
||||
## 4. Install and start the web frontend
|
||||
|
||||
In a separate terminal:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Vite will print a local dev URL (typically `http://localhost:5173`) — open
|
||||
it in a browser.
|
||||
|
||||
## 5. Connect
|
||||
|
||||
In the web UI, enter the address of a TeamSpeak server and a nickname, then
|
||||
click **Connect**. Voice requires microphone permission when you enable the
|
||||
mic button; the output-device picker (if your browser supports it) requires
|
||||
no extra permission.
|
||||
|
||||
## Rebuilding after changes
|
||||
|
||||
- Frontend and gateway changes hot-reload automatically (`npm run dev` in
|
||||
both cases).
|
||||
- Connector changes require a rebuild (`cargo build` in `connector/`) and a
|
||||
reconnect from the browser — if the old `ts-connector` binary is still
|
||||
running (an active browser connection), disconnect first or the build will
|
||||
fail to overwrite the binary.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Moepchi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,29 +1,83 @@
|
||||
# TS Web Client
|
||||
<p align="center">
|
||||
<img src="web/public/logo.png" width="140" alt="WebSpeak3 logo">
|
||||
</p>
|
||||
|
||||
Browser-based client for TeamSpeak servers — same idea as the native
|
||||
installable client, but running in a web browser. The TeamSpeak server side
|
||||
stays exactly as-is (a regular TS server); only the client is being
|
||||
reimagined.
|
||||
<h1 align="center">WebSpeak3</h1>
|
||||
|
||||
**Status: private prototype, not for production use.**
|
||||
<p align="center">
|
||||
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
||||
<a href="Dockerfile"><img src="https://img.shields.io/badge/docker-build%20passing-2496ED?logo=docker&logoColor=white" alt="Docker Build"></a>
|
||||
<a href="gateway/package.json"><img src="https://img.shields.io/badge/node-%3E%3D18-339933?logo=node.js&logoColor=white" alt="Node Version"></a>
|
||||
<a href="connector/Cargo.toml"><img src="https://img.shields.io/badge/rust-2021-000000?logo=rust&logoColor=white" alt="Rust Version"></a>
|
||||
<img src="https://img.shields.io/badge/status-beta%20%2F%20prototype-yellow" alt="Project Status">
|
||||
</p>
|
||||
|
||||
## Features
|
||||
<p align="center">
|
||||
<b>A modern, self-hosted browser client for TeamSpeak 3 servers — no install, just open a tab.</b>
|
||||
</p>
|
||||
|
||||
- Connect to a real TeamSpeak (3/6) server, with optional server and
|
||||
default-channel passwords
|
||||
- Remembers the last server/nickname you connected with
|
||||
- Channel/client tree with correct ordering, click to switch channels
|
||||
- Per-client status icons (channel commander, away, mic muted, deafened)
|
||||
- Text chat: channel, server-wide, and private (1:1) — each in its own tab
|
||||
- Voice with voice activation ("Sprachaktivierung", not push-to-talk),
|
||||
adjustable sensitivity, and per-client speaking indicators
|
||||
- Audio output device picker (routes playback to a chosen device) — works in
|
||||
Chrome/Edge and Firefox 130+; playback is routed through a hidden `<audio>`
|
||||
element so device switching works even in browsers without
|
||||
`AudioContext.setSinkId`
|
||||
- Light/dark theme
|
||||
<p align="center">
|
||||
<a href="https://webspeak3.de">🌐 Website</a> ·
|
||||
<a href="https://client.webspeak3.de">💬 Open Client</a> ·
|
||||
<a href="https://demo.webspeak3.de">🕹️ 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>
|
||||
|
||||
## Architecture
|
||||
> The [live demo](https://demo.webspeak3.de) 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
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Dark Mode</th>
|
||||
<th>Light Mode</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="docs/screenshots/webspeak_dark.png" width="100%" alt="Dark mode screenshot"></td>
|
||||
<td><img src="docs/screenshots/webspeak_light.png" width="100%" alt="Light mode screenshot"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## ✨ Features
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 🔌 **Real TeamSpeak protocol** | Connects to actual TS3/TS6 servers over a WebSocket gateway — the server stays exactly as-is |
|
||||
| 🎙️ **Low-latency voice** | Opus-encoded voice with voice activation ("Sprachaktivierung") and adjustable sensitivity |
|
||||
| 🤫 **Whisper** | Target your voice at specific channels or clients instead of your whole current channel |
|
||||
| 🔊 **Custom audio output picker** | Route playback to any output device — works even in browsers without `AudioContext.setSinkId` |
|
||||
| 💬 **Full text chat** | Channel, server-wide, and private (1:1) chat, each in its own tab — Shift+Enter for a newline |
|
||||
| 🌳 **Live channel/client tree** | Correct ordering, status icons (channel commander, away, muted, deafened), country flags, click to switch channels |
|
||||
| 🖱️ **Right-click context menu** | Private chat, poke, copy name, and whisper-target toggle straight from a client's row |
|
||||
| 📜 **Server log** | Join/leave/switch, channel-group, and channel/server-change events shown inline, like the native client |
|
||||
| 🔔 **Custom sound notifications** | Per-event sounds (connect, poke, messages, ...) with volume control and `.ts3soundpack` import |
|
||||
| 🪪 **Persistent identity** | Keeps the same client UID across sessions instead of generating a new one every connect |
|
||||
| 👉 **Poke & away status** | Poke clients with an optional message; set yourself away with presets or a custom status |
|
||||
| ⭐ **Favorites & reconnect** | Remembers your last server/nickname; switch servers without leaving your tab |
|
||||
| 📱 **Mobile-friendly layout** | Responsive single-column layout for narrow screens, not just a shrunk desktop UI |
|
||||
| 🌍 **Localized UI** | Interface available in German and English, detected automatically or switchable in Options |
|
||||
| 🌗 **Dark / light theme** | Clean, modern UI that adapts to your preference |
|
||||
| 🔁 **Seamless reconnect** | Switch connections mid-session — old state tears down cleanly, no leaks or duplicates |
|
||||
|
||||
## 🧱 Tech Stack
|
||||
|
||||
<p>
|
||||
<img src="https://img.shields.io/badge/React-61DAFB?logo=react&logoColor=black" alt="React">
|
||||
<img src="https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white" alt="Vite">
|
||||
<img src="https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white" alt="TypeScript">
|
||||
<img src="https://img.shields.io/badge/Node.js-339933?logo=node.js&logoColor=white" alt="Node.js">
|
||||
<img src="https://img.shields.io/badge/Rust-000000?logo=rust&logoColor=white" alt="Rust">
|
||||
<img src="https://img.shields.io/badge/Docker-2496ED?logo=docker&logoColor=white" alt="Docker">
|
||||
</p>
|
||||
|
||||
<details>
|
||||
<summary><b>🏗️ Architecture details</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
Browsers can't send raw UDP, which is what TeamSpeak's native protocol runs
|
||||
over, so a pure client-side implementation isn't possible — a server-side
|
||||
@@ -44,10 +98,138 @@ Browser (web/) <--WebSocket--> Gateway (gateway/) <--stdin/stdout JSON--> Ru
|
||||
protocol implementation. Handles connecting, channel/client state, chat,
|
||||
and Opus-encoded voice.
|
||||
|
||||
## Installation
|
||||
</details>
|
||||
|
||||
See [INSTALL.md](INSTALL.md).
|
||||
## 🚀 Installation
|
||||
|
||||
### 🐳 Docker (recommended)
|
||||
|
||||
Clone the repo (the Rust connector depends on a git submodule, so pull it in too):
|
||||
|
||||
```bash
|
||||
git clone --recurse-submodules https://github.com/Moepchi/webspeak3.git
|
||||
cd webspeak3
|
||||
```
|
||||
|
||||
This is what ships in [`docker-compose.yml`](docker-compose.yml):
|
||||
|
||||
```yaml
|
||||
services:
|
||||
webspeak3:
|
||||
build: .
|
||||
image: moepchi/webspeak3:latest
|
||||
container_name: webspeak3
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- PORT=8080
|
||||
```
|
||||
|
||||
Port publishing is left out on purpose — set it in a local, gitignored `docker-compose.override.yml` so it doesn't clash with whatever else is already using a port on your host:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
webspeak3:
|
||||
ports:
|
||||
- "8080:8080"
|
||||
```
|
||||
|
||||
Then `docker compose up -d` and open `http://localhost:8080` (or whatever host port you chose).
|
||||
|
||||
Prefer to skip the build entirely? A prebuilt image is published on [Docker Hub](https://hub.docker.com/r/moepchi/webspeak3):
|
||||
|
||||
```bash
|
||||
docker run -d -p 8080:8080 --name webspeak3 moepchi/webspeak3:latest
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><b>🛠️ Manual installation (without Docker)</b></summary>
|
||||
|
||||
<br>
|
||||
|
||||
**Prerequisites**
|
||||
|
||||
- **Node.js** 20+ and npm
|
||||
- **Rust** (stable toolchain) — [rustup.rs](https://rustup.rs)
|
||||
- **CMake** and a C/C++ toolchain — needed to build the Opus codec library (`audiopus_sys`) used for voice. On Windows, the Visual Studio "Desktop development with C++" workload covers this; on Linux, install `cmake` and `build-essential` (or equivalent); on macOS, `cmake` via Homebrew plus Xcode command line tools.
|
||||
- **git**
|
||||
|
||||
**1. Clone the repository**
|
||||
|
||||
The Rust connector depends on the `tsclientlib` crate, vendored as a git submodule — make sure to pull it in too:
|
||||
|
||||
```bash
|
||||
git clone --recurse-submodules https://github.com/Moepchi/webspeak3.git
|
||||
cd webspeak3
|
||||
```
|
||||
|
||||
If you already cloned without `--recurse-submodules`:
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
**2. Build the Rust connector**
|
||||
|
||||
```bash
|
||||
cd connector
|
||||
cargo build
|
||||
```
|
||||
|
||||
> **Note:** if the build fails with a CMake error like `Compatibility with CMake < 3.5 has been removed`, it's because the vendored Opus source uses an old `cmake_minimum_required`. Work around it with:
|
||||
>
|
||||
> ```bash
|
||||
> CMAKE_POLICY_VERSION_MINIMUM=3.5 cargo build
|
||||
> ```
|
||||
> (On Windows PowerShell: `$env:CMAKE_POLICY_VERSION_MINIMUM = "3.5"; cargo build`)
|
||||
|
||||
This produces `connector/target/debug/ts-connector` (or `ts-connector.exe` on Windows), which the gateway spawns automatically — no manual step needed after this.
|
||||
|
||||
**3. Install and start the gateway**
|
||||
|
||||
```bash
|
||||
cd gateway
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
This starts the WebSocket gateway on `ws://localhost:8080`.
|
||||
|
||||
**4. Install and start the web frontend**
|
||||
|
||||
In a separate terminal:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Vite will print a local dev URL (typically `http://localhost:5173`) — open it in a browser.
|
||||
|
||||
**5. Connect**
|
||||
|
||||
In the web UI, enter the address of a TeamSpeak server and a nickname, then click **Connect**. Voice requires microphone permission when you enable the mic button; the output-device picker (if your browser supports it) requires no extra permission.
|
||||
|
||||
**Rebuilding after changes**
|
||||
|
||||
- Frontend and gateway changes hot-reload automatically (`npm run dev` in both cases).
|
||||
- Connector changes require a rebuild (`cargo build` in `connector/`) and a reconnect from the browser — if the old `ts-connector` binary is still running (an active browser connection), disconnect first or the build will fail to overwrite the binary.
|
||||
|
||||
</details>
|
||||
|
||||
## Credits
|
||||
|
||||
The vast majority of this project's code was written by [Claude Code](https://claude.com/claude-code) (Anthropic's Claude), working iteratively with the repo owner one feature at a time.
|
||||
|
||||
---
|
||||
|
||||
### Legal / Disclaimer
|
||||
|
||||
**WebSpeak3** is an independent, open-source, self-hosted project and is
|
||||
**not** affiliated with, associated with, authorized by, endorsed by, or in
|
||||
any way officially connected with TeamSpeak Systems GmbH.
|
||||
|
||||
"TeamSpeak", "TS3", and related logos or names are registered trademarks of
|
||||
TeamSpeak Systems GmbH. All product and company names are trademarks™ or
|
||||
registered® trademarks of their respective holders. Use of them does not
|
||||
imply any affiliation with or endorsement by them.
|
||||
@@ -2641,6 +2641,7 @@ dependencies = [
|
||||
"futures",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"time",
|
||||
"tokio",
|
||||
"tracing-subscriber",
|
||||
"tsclientlib",
|
||||
|
||||
@@ -15,3 +15,4 @@ clap = { version = "4", features = ["derive"] }
|
||||
anyhow = "1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
base64 = "0.22"
|
||||
time = "0.3"
|
||||
@@ -0,0 +1,30 @@
|
||||
services:
|
||||
webspeak3:
|
||||
build: .
|
||||
image: moepchi/webspeak3:latest
|
||||
container_name: webspeak3
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- PORT=8080
|
||||
# Port publishing is deployment-specific and left out of this file on
|
||||
# purpose - Compose concatenates `ports:` lists across an override file
|
||||
# instead of replacing them, so adding one here would double-publish
|
||||
# instead of letting an override change it. Set it in a local, gitignored
|
||||
# docker-compose.override.yml:
|
||||
#
|
||||
# services:
|
||||
# webspeak3:
|
||||
# ports:
|
||||
# - "8080:8080"
|
||||
|
||||
cloudflared:
|
||||
image: cloudflare/cloudflared:latest
|
||||
container_name: webspeak3-cloudflared
|
||||
restart: unless-stopped
|
||||
command: tunnel --no-autoupdate run --token ${CLOUDFLARE_TUNNEL_TOKEN}
|
||||
# Token comes from a gitignored .env file next to this compose file:
|
||||
# CLOUDFLARE_TUNNEL_TOKEN=eyJ...
|
||||
# No depends_on/network wiring needed - the tunnel's Public Hostname
|
||||
# config (set in the Cloudflare dashboard) points at the webspeak3
|
||||
# service by its Compose service name (http://webspeak3:8080), and
|
||||
# Compose puts both services on the same default network automatically.
|
||||
|
After Width: | Height: | Size: 820 KiB |
|
After Width: | Height: | Size: 811 KiB |
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "ts-web-gateway",
|
||||
"name": "webspeak3-gateway",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Gateway server: bridges browser (WebSocket) clients to a native TeamSpeak server",
|
||||
"description": "WebSpeak3 gateway server: bridges browser (WebSocket) clients to a native TeamSpeak server",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/index.ts",
|
||||
|
||||
@@ -1,11 +1,61 @@
|
||||
import { createServer } from "node:http";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { WebSocketServer, type WebSocket } from "ws";
|
||||
import { Ts3Connection, type Ts3ConnectOptions } from "./ts3/connection.js";
|
||||
|
||||
const PORT = Number(process.env.PORT ?? 8080);
|
||||
|
||||
const wss = new WebSocketServer({ port: PORT });
|
||||
// In production (Docker), the built web app lives alongside the gateway and
|
||||
// is served from the same port as the WebSocket endpoint, so a single
|
||||
// reverse-proxied origin (e.g. a Zoraxy subdomain) is enough for everything.
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const WEB_DIST = process.env.WEB_DIST ?? path.resolve(__dirname, "../../web/dist");
|
||||
|
||||
console.log(`Gateway listening on ws://localhost:${PORT}`);
|
||||
const MIME_TYPES: Record<string, string> = {
|
||||
".html": "text/html",
|
||||
".js": "text/javascript",
|
||||
".css": "text/css",
|
||||
".svg": "image/svg+xml",
|
||||
".png": "image/png",
|
||||
".ico": "image/x-icon",
|
||||
".json": "application/json",
|
||||
".woff2": "font/woff2",
|
||||
};
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
void (async () => {
|
||||
try {
|
||||
const url = new URL(req.url ?? "/", "http://localhost");
|
||||
let filePath = path.join(WEB_DIST, decodeURIComponent(url.pathname));
|
||||
if (!filePath.startsWith(WEB_DIST)) {
|
||||
res.writeHead(403);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
let body: Buffer;
|
||||
try {
|
||||
body = await readFile(filePath);
|
||||
} catch {
|
||||
// SPA fallback: unknown paths (client-side routes, or "/") serve index.html.
|
||||
filePath = path.join(WEB_DIST, "index.html");
|
||||
body = await readFile(filePath);
|
||||
}
|
||||
res.writeHead(200, { "Content-Type": MIME_TYPES[path.extname(filePath)] ?? "application/octet-stream" });
|
||||
res.end(body);
|
||||
} catch {
|
||||
res.writeHead(404);
|
||||
res.end("Not found");
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
const wss = new WebSocketServer({ server, path: "/ws" });
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`WebSpeak3 gateway listening on http://localhost:${PORT} (WebSocket at /ws)`);
|
||||
});
|
||||
|
||||
wss.on("connection", (socket: WebSocket) => {
|
||||
let connection: Ts3Connection | undefined;
|
||||
@@ -20,6 +70,8 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
nickname: msg.nickname,
|
||||
serverPassword: msg.serverPassword,
|
||||
channelPassword: msg.channelPassword,
|
||||
defaultChannel: msg.defaultChannel,
|
||||
identity: msg.identity,
|
||||
};
|
||||
connection = new Ts3Connection(options);
|
||||
connection.onEvent((event) => socket.send(JSON.stringify(event)));
|
||||
@@ -50,6 +102,170 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
await connection?.sendAudio(msg.pcm);
|
||||
break;
|
||||
}
|
||||
case "setAway": {
|
||||
await connection?.setAway(msg.away, msg.message ?? "");
|
||||
break;
|
||||
}
|
||||
case "setInputMuted": {
|
||||
await connection?.setInputMuted(msg.muted);
|
||||
break;
|
||||
}
|
||||
case "setOutputMuted": {
|
||||
await connection?.setOutputMuted(msg.muted);
|
||||
break;
|
||||
}
|
||||
case "setNickname": {
|
||||
await connection?.setNickname(msg.nickname);
|
||||
break;
|
||||
}
|
||||
case "setWhisperTargets": {
|
||||
await connection?.setWhisperTargets(msg.channelIds ?? [], msg.clientIds ?? []);
|
||||
break;
|
||||
}
|
||||
case "getClientConnectionInfo": {
|
||||
await connection?.getClientConnectionInfo(msg.clientId);
|
||||
break;
|
||||
}
|
||||
case "getServerConnectionInfo": {
|
||||
await connection?.getServerConnectionInfo();
|
||||
break;
|
||||
}
|
||||
case "kickFromChannel": {
|
||||
await connection?.kickFromChannel(msg.clientId, msg.reason ?? "");
|
||||
break;
|
||||
}
|
||||
case "kickFromServer": {
|
||||
await connection?.kickFromServer(msg.clientId, msg.reason ?? "");
|
||||
break;
|
||||
}
|
||||
case "banClient": {
|
||||
await connection?.banClient(msg.clientId, msg.seconds ?? 0, msg.reason ?? "");
|
||||
break;
|
||||
}
|
||||
case "editServer": {
|
||||
await connection?.editServer(msg.payload ?? {});
|
||||
break;
|
||||
}
|
||||
case "getServerLog": {
|
||||
await connection?.getServerLog();
|
||||
break;
|
||||
}
|
||||
case "getBanList": {
|
||||
await connection?.getBanList();
|
||||
break;
|
||||
}
|
||||
case "deleteBan": {
|
||||
await connection?.deleteBan(msg.banId);
|
||||
break;
|
||||
}
|
||||
case "deleteAllBans": {
|
||||
await connection?.deleteAllBans();
|
||||
break;
|
||||
}
|
||||
case "getComplainList": {
|
||||
await connection?.getComplainList();
|
||||
break;
|
||||
}
|
||||
case "deleteComplaint": {
|
||||
await connection?.deleteComplaint(msg.targetClientDbId, msg.fromClientDbId);
|
||||
break;
|
||||
}
|
||||
case "deleteAllComplaintsFor": {
|
||||
await connection?.deleteAllComplaintsFor(msg.targetClientDbId);
|
||||
break;
|
||||
}
|
||||
case "getOfflineMessageList": {
|
||||
await connection?.getOfflineMessageList();
|
||||
break;
|
||||
}
|
||||
case "getOfflineMessage": {
|
||||
await connection?.getOfflineMessage(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "sendOfflineMessage": {
|
||||
await connection?.sendOfflineMessage(msg.clientUid, msg.subject, msg.message);
|
||||
break;
|
||||
}
|
||||
case "deleteOfflineMessage": {
|
||||
await connection?.deleteOfflineMessage(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "markOfflineMessageRead": {
|
||||
await connection?.markOfflineMessageRead(msg.messageId);
|
||||
break;
|
||||
}
|
||||
case "getChannelGroupList": {
|
||||
await connection?.getChannelGroupList();
|
||||
break;
|
||||
}
|
||||
case "getServerGroupList": {
|
||||
await connection?.getServerGroupList();
|
||||
break;
|
||||
}
|
||||
case "setChannelGroup": {
|
||||
await connection?.setChannelGroup(msg.channelGroupId, msg.channelId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "addServerGroup": {
|
||||
await connection?.addServerGroup(msg.serverGroupId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "removeServerGroup": {
|
||||
await connection?.removeServerGroup(msg.serverGroupId, msg.clientDbId);
|
||||
break;
|
||||
}
|
||||
case "serverQueryLogin": {
|
||||
await connection?.serverQueryLogin(msg.username, msg.password);
|
||||
break;
|
||||
}
|
||||
case "getPermissionOverview": {
|
||||
await connection?.getPermissionOverview();
|
||||
break;
|
||||
}
|
||||
case "getFileList": {
|
||||
await connection?.getFileList(msg.channelId, msg.path);
|
||||
break;
|
||||
}
|
||||
case "createDirectory": {
|
||||
await connection?.createDirectory(msg.channelId, msg.dirname);
|
||||
break;
|
||||
}
|
||||
case "deleteFile": {
|
||||
await connection?.deleteFile(msg.channelId, msg.name);
|
||||
break;
|
||||
}
|
||||
case "renameFile": {
|
||||
await connection?.renameFile(msg.channelId, msg.oldName, msg.newName);
|
||||
break;
|
||||
}
|
||||
case "downloadFile": {
|
||||
await connection?.downloadFile(msg.channelId, msg.path);
|
||||
break;
|
||||
}
|
||||
case "uploadFile": {
|
||||
await connection?.uploadFile(msg.channelId, msg.path, msg.dataBase64);
|
||||
break;
|
||||
}
|
||||
case "getPermissionCatalog": {
|
||||
await connection?.getPermissionCatalog();
|
||||
break;
|
||||
}
|
||||
case "getPermList": {
|
||||
await connection?.getPermList(msg.scope, msg.id1, msg.id2);
|
||||
break;
|
||||
}
|
||||
case "addPermission": {
|
||||
await connection?.addPermission(msg.scope, msg.ids, msg.permId, msg.value, msg.negated, msg.skip);
|
||||
break;
|
||||
}
|
||||
case "removePermission": {
|
||||
await connection?.removePermission(msg.scope, msg.ids, msg.permId);
|
||||
break;
|
||||
}
|
||||
case "disconnect": {
|
||||
await connection?.disconnect(msg.message ?? "");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
socket.send(
|
||||
JSON.stringify({ type: "error", message: `Unknown message type: ${msg.type}` })
|
||||
|
||||
@@ -29,11 +29,98 @@ export interface ClientInfo {
|
||||
outputMuted: boolean;
|
||||
inputHardwareEnabled: boolean;
|
||||
away: boolean;
|
||||
awayMessage: string;
|
||||
isChannelCommander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
databaseId: number;
|
||||
channelGroup: number;
|
||||
serverGroups: number[];
|
||||
hasTalkPower: boolean;
|
||||
}
|
||||
|
||||
export interface GroupEntry {
|
||||
id: number;
|
||||
name: string;
|
||||
iconId: number;
|
||||
}
|
||||
|
||||
export interface PermissionOverviewEntry {
|
||||
name: string;
|
||||
description: string;
|
||||
value: number;
|
||||
negated: boolean;
|
||||
skip: boolean;
|
||||
}
|
||||
|
||||
export interface PermissionCatalogEntry {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export type PermScope = "server" | "channelgroup" | "channel" | "client" | "channelclient";
|
||||
|
||||
export interface BanListEntry {
|
||||
banId: number;
|
||||
ip: string;
|
||||
name: string;
|
||||
uid: string;
|
||||
lastNickname: string;
|
||||
created: string;
|
||||
durationSecs: number;
|
||||
invokerName: string;
|
||||
reason: string;
|
||||
enforcements: number;
|
||||
}
|
||||
|
||||
export interface ComplainListEntry {
|
||||
targetClientDbId: number;
|
||||
targetName: string;
|
||||
fromClientDbId: number;
|
||||
fromName: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface OfflineMessageListEntry {
|
||||
messageId: number;
|
||||
clientUid: string;
|
||||
subject: string;
|
||||
timestamp: string;
|
||||
isRead: boolean;
|
||||
}
|
||||
|
||||
export interface FileListEntry {
|
||||
path: string;
|
||||
name: string;
|
||||
size: number;
|
||||
isFile: boolean;
|
||||
timestamp: 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"; welcomeMessage: string; serverName: string; serverMaxClients: number }
|
||||
| {
|
||||
type: "connected";
|
||||
welcomeMessage: string;
|
||||
serverName: string;
|
||||
serverMaxClients: number;
|
||||
serverVersion: string;
|
||||
serverLicense: string;
|
||||
serverBannerUrl: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: ChannelInfo[]; clients: ClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
| { type: "serverMessage"; from: string; message: string }
|
||||
@@ -42,21 +129,72 @@ 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)
|
||||
| {
|
||||
type: "clientConnectionInfo";
|
||||
clientId: number;
|
||||
pingMs: number | null;
|
||||
connectedSecs: number | null;
|
||||
ip: string | null;
|
||||
packetsSent: number;
|
||||
bytesSent: number;
|
||||
packetsReceived: number;
|
||||
bytesReceived: number;
|
||||
packetLossPercent: number;
|
||||
}
|
||||
| {
|
||||
type: "serverConnectionInfo";
|
||||
pingMs: number;
|
||||
connectedSecs: number;
|
||||
packetLossPercent: number;
|
||||
packetsSentTotal: number;
|
||||
bytesSentTotal: number;
|
||||
packetsReceivedTotal: number;
|
||||
bytesReceivedTotal: number;
|
||||
bandwidthSentLastSecond: number;
|
||||
bandwidthReceivedLastSecond: number;
|
||||
}
|
||||
| { type: "serverProtocolLog"; lines: string[] }
|
||||
| { type: "banList"; entries: BanListEntry[] }
|
||||
| { type: "complainList"; entries: ComplainListEntry[] }
|
||||
| { type: "offlineMessageList"; entries: OfflineMessageListEntry[] }
|
||||
| {
|
||||
type: "offlineMessage";
|
||||
messageId: number;
|
||||
clientUid: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}
|
||||
| { type: "channelGroupList"; entries: GroupEntry[] }
|
||||
| { type: "serverGroupList"; entries: GroupEntry[] }
|
||||
| { type: "permissionOverview"; entries: PermissionOverviewEntry[] }
|
||||
| { type: "fileList"; cid: number; path: string; entries: FileListEntry[] }
|
||||
| { type: "fileDownloadData"; cid: number; path: string; data: string }
|
||||
| { type: "fileUploadDone"; cid: number; path: string }
|
||||
| { type: "permList"; scope: PermScope; id1: number; id2: number | null; entries: PermissionOverviewEntry[] }
|
||||
| { type: "permissionCatalog"; entries: PermissionCatalogEntry[] };
|
||||
|
||||
export interface Ts3ConnectOptions {
|
||||
host: string;
|
||||
nickname: string;
|
||||
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));
|
||||
const CONNECTOR_BIN = path.resolve(
|
||||
__dirname,
|
||||
"../../../connector/target/debug",
|
||||
process.platform === "win32" ? "ts-connector.exe" : "ts-connector"
|
||||
);
|
||||
const CONNECTOR_BIN =
|
||||
process.env.CONNECTOR_BIN ??
|
||||
path.resolve(
|
||||
__dirname,
|
||||
"../../../connector/target/debug",
|
||||
process.platform === "win32" ? "ts-connector.exe" : "ts-connector"
|
||||
);
|
||||
|
||||
export class Ts3Connection {
|
||||
private listeners = new Set<(event: Ts3ConnectionEvent) => void>();
|
||||
@@ -76,6 +214,8 @@ export class Ts3Connection {
|
||||
const args = ["--address", this.options.host, "--nickname", this.options.nickname];
|
||||
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) => {
|
||||
@@ -88,7 +228,14 @@ export class Ts3Connection {
|
||||
output_muted: boolean;
|
||||
input_hardware_enabled: boolean;
|
||||
away: boolean;
|
||||
away_message: string;
|
||||
is_channel_commander: boolean;
|
||||
country: string;
|
||||
uid: string;
|
||||
database_id: number;
|
||||
channel_group: number;
|
||||
server_groups: number[];
|
||||
has_talk_power: boolean;
|
||||
}
|
||||
|
||||
interface RawChannelInfo {
|
||||
@@ -103,7 +250,16 @@ export class Ts3Connection {
|
||||
}
|
||||
|
||||
const event = JSON.parse(line) as
|
||||
| { type: "connected"; welcome_message: string; server_name: string; server_max_clients: number }
|
||||
| {
|
||||
type: "connected";
|
||||
welcome_message: string;
|
||||
server_name: string;
|
||||
server_max_clients: number;
|
||||
server_version: string;
|
||||
server_license: string;
|
||||
server_banner_url: string;
|
||||
identity: string;
|
||||
}
|
||||
| { type: "channels"; channels: RawChannelInfo[]; clients: RawClientInfo[] }
|
||||
| { type: "chatMessage"; from: string; message: string }
|
||||
| { type: "serverMessage"; from: string; message: string }
|
||||
@@ -112,7 +268,88 @@ 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)
|
||||
| {
|
||||
type: "clientConnectionInfo";
|
||||
client_id: number;
|
||||
ping_ms: number | null;
|
||||
connected_secs: number | null;
|
||||
ip: string | null;
|
||||
packets_sent: number;
|
||||
bytes_sent: number;
|
||||
packets_received: number;
|
||||
bytes_received: number;
|
||||
packet_loss_percent: number;
|
||||
}
|
||||
| {
|
||||
type: "serverConnectionInfo";
|
||||
ping_ms: number;
|
||||
connected_secs: number;
|
||||
packet_loss_percent: number;
|
||||
packets_sent_total: number;
|
||||
bytes_sent_total: number;
|
||||
packets_received_total: number;
|
||||
bytes_received_total: number;
|
||||
bandwidth_sent_last_second: number;
|
||||
bandwidth_received_last_second: number;
|
||||
}
|
||||
| { type: "serverProtocolLog"; lines: string[] }
|
||||
| {
|
||||
type: "banList";
|
||||
entries: {
|
||||
ban_id: number;
|
||||
ip: string;
|
||||
name: string;
|
||||
uid: string;
|
||||
last_nickname: string;
|
||||
created: string;
|
||||
duration_secs: number;
|
||||
invoker_name: string;
|
||||
reason: string;
|
||||
enforcements: number;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
type: "complainList";
|
||||
entries: {
|
||||
target_client_db_id: number;
|
||||
target_name: string;
|
||||
from_client_db_id: number;
|
||||
from_name: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
type: "offlineMessageList";
|
||||
entries: {
|
||||
message_id: number;
|
||||
client_uid: string;
|
||||
subject: string;
|
||||
timestamp: string;
|
||||
is_read: boolean;
|
||||
}[];
|
||||
}
|
||||
| {
|
||||
type: "offlineMessage";
|
||||
message_id: number;
|
||||
client_uid: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
timestamp: string;
|
||||
}
|
||||
| { type: "channelGroupList"; entries: GroupEntry[] }
|
||||
| { type: "serverGroupList"; entries: GroupEntry[] }
|
||||
| {
|
||||
type: "permissionOverview";
|
||||
entries: { name: string; description: string; value: number; negated: boolean; skip: boolean }[];
|
||||
}
|
||||
| { type: "fileList"; cid: number; path: string; entries: FileListEntry[] }
|
||||
| { type: "fileDownloadData"; cid: number; path: string; data: string }
|
||||
| { type: "fileUploadDone"; cid: number; path: string }
|
||||
| { type: "permList"; scope: PermScope; id1: number; id2: number | null; entries: PermissionOverviewEntry[] }
|
||||
| { type: "permissionCatalog"; entries: PermissionCatalogEntry[] };
|
||||
|
||||
if (event.type === "connected") {
|
||||
this.emit({
|
||||
@@ -120,6 +357,10 @@ export class Ts3Connection {
|
||||
welcomeMessage: event.welcome_message,
|
||||
serverName: event.server_name,
|
||||
serverMaxClients: event.server_max_clients,
|
||||
serverVersion: event.server_version,
|
||||
serverLicense: event.server_license,
|
||||
serverBannerUrl: event.server_banner_url,
|
||||
identity: event.identity,
|
||||
});
|
||||
} else if (event.type === "channels") {
|
||||
this.emit({
|
||||
@@ -142,7 +383,14 @@ export class Ts3Connection {
|
||||
outputMuted: c.output_muted,
|
||||
inputHardwareEnabled: c.input_hardware_enabled,
|
||||
away: c.away,
|
||||
awayMessage: c.away_message,
|
||||
isChannelCommander: c.is_channel_commander,
|
||||
country: c.country,
|
||||
uid: c.uid,
|
||||
databaseId: c.database_id,
|
||||
channelGroup: c.channel_group,
|
||||
serverGroups: c.server_groups,
|
||||
hasTalkPower: c.has_talk_power,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "privateMessage") {
|
||||
@@ -153,6 +401,80 @@ export class Ts3Connection {
|
||||
fromSelf: event.from_self,
|
||||
message: event.message,
|
||||
});
|
||||
} else if (event.type === "clientConnectionInfo") {
|
||||
this.emit({
|
||||
type: "clientConnectionInfo",
|
||||
clientId: event.client_id,
|
||||
pingMs: event.ping_ms,
|
||||
connectedSecs: event.connected_secs,
|
||||
ip: event.ip,
|
||||
packetsSent: event.packets_sent,
|
||||
bytesSent: event.bytes_sent,
|
||||
packetsReceived: event.packets_received,
|
||||
bytesReceived: event.bytes_received,
|
||||
packetLossPercent: event.packet_loss_percent,
|
||||
});
|
||||
} else if (event.type === "serverConnectionInfo") {
|
||||
this.emit({
|
||||
type: "serverConnectionInfo",
|
||||
pingMs: event.ping_ms,
|
||||
connectedSecs: event.connected_secs,
|
||||
packetLossPercent: event.packet_loss_percent,
|
||||
packetsSentTotal: event.packets_sent_total,
|
||||
bytesSentTotal: event.bytes_sent_total,
|
||||
packetsReceivedTotal: event.packets_received_total,
|
||||
bytesReceivedTotal: event.bytes_received_total,
|
||||
bandwidthSentLastSecond: event.bandwidth_sent_last_second,
|
||||
bandwidthReceivedLastSecond: event.bandwidth_received_last_second,
|
||||
});
|
||||
} else if (event.type === "banList") {
|
||||
this.emit({
|
||||
type: "banList",
|
||||
entries: event.entries.map((e) => ({
|
||||
banId: e.ban_id,
|
||||
ip: e.ip,
|
||||
name: e.name,
|
||||
uid: e.uid,
|
||||
lastNickname: e.last_nickname,
|
||||
created: e.created,
|
||||
durationSecs: e.duration_secs,
|
||||
invokerName: e.invoker_name,
|
||||
reason: e.reason,
|
||||
enforcements: e.enforcements,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "complainList") {
|
||||
this.emit({
|
||||
type: "complainList",
|
||||
entries: event.entries.map((e) => ({
|
||||
targetClientDbId: e.target_client_db_id,
|
||||
targetName: e.target_name,
|
||||
fromClientDbId: e.from_client_db_id,
|
||||
fromName: e.from_name,
|
||||
message: e.message,
|
||||
timestamp: e.timestamp,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "offlineMessageList") {
|
||||
this.emit({
|
||||
type: "offlineMessageList",
|
||||
entries: event.entries.map((e) => ({
|
||||
messageId: e.message_id,
|
||||
clientUid: e.client_uid,
|
||||
subject: e.subject,
|
||||
timestamp: e.timestamp,
|
||||
isRead: e.is_read,
|
||||
})),
|
||||
});
|
||||
} else if (event.type === "offlineMessage") {
|
||||
this.emit({
|
||||
type: "offlineMessage",
|
||||
messageId: event.message_id,
|
||||
clientUid: event.client_uid,
|
||||
subject: event.subject,
|
||||
message: event.message,
|
||||
timestamp: event.timestamp,
|
||||
});
|
||||
} else {
|
||||
this.emit(event);
|
||||
}
|
||||
@@ -178,6 +500,194 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`switch ${channelId}\n`);
|
||||
}
|
||||
|
||||
async getClientConnectionInfo(clientId: number): Promise<void> {
|
||||
this.child?.stdin.write(`clientconninfo ${clientId}\n`);
|
||||
}
|
||||
|
||||
async getServerConnectionInfo(): Promise<void> {
|
||||
this.child?.stdin.write(`serverconninfo\n`);
|
||||
}
|
||||
|
||||
async kickFromChannel(clientId: number, reason: string): Promise<void> {
|
||||
const sanitized = reason.replace(/[\r\n]+/g, " ").trim();
|
||||
this.child?.stdin.write(`kickchannel ${clientId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
async kickFromServer(clientId: number, reason: string): Promise<void> {
|
||||
const sanitized = reason.replace(/[\r\n]+/g, " ").trim();
|
||||
this.child?.stdin.write(`kickserver ${clientId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
async banClient(clientId: number, seconds: number, reason: string): Promise<void> {
|
||||
const sanitized = reason.replace(/[\r\n]+/g, " ").trim();
|
||||
this.child?.stdin.write(`banclient ${clientId} ${Math.max(0, Math.floor(seconds))} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
/** Every field is optional - only send what actually changed. JSON.stringify
|
||||
* already escapes embedded newlines, so this is safe as a single stdin line
|
||||
* without extra sanitization. */
|
||||
async editServer(payload: {
|
||||
name?: string;
|
||||
welcomeMessage?: string;
|
||||
password?: string;
|
||||
maxClients?: number;
|
||||
hostmessage?: string;
|
||||
hostmessageMode?: string;
|
||||
hostbannerUrl?: string;
|
||||
hostbannerGfxUrl?: string;
|
||||
hostbannerGfxIntervalSecs?: number;
|
||||
hostbannerMode?: string;
|
||||
hostbuttonTooltip?: string;
|
||||
hostbuttonUrl?: string;
|
||||
hostbuttonGfxUrl?: string;
|
||||
nickname?: string;
|
||||
phoneticName?: string;
|
||||
codecEncryptionMode?: string;
|
||||
}): Promise<void> {
|
||||
this.child?.stdin.write(`serveredit ${JSON.stringify(payload)}\n`);
|
||||
}
|
||||
|
||||
async getServerLog(): Promise<void> {
|
||||
this.child?.stdin.write(`serverlog\n`);
|
||||
}
|
||||
|
||||
async getBanList(): Promise<void> {
|
||||
this.child?.stdin.write(`banlist\n`);
|
||||
}
|
||||
|
||||
async deleteBan(banId: number): Promise<void> {
|
||||
this.child?.stdin.write(`bandel ${banId}\n`);
|
||||
}
|
||||
|
||||
async deleteAllBans(): Promise<void> {
|
||||
this.child?.stdin.write(`bandelall\n`);
|
||||
}
|
||||
|
||||
async getComplainList(): Promise<void> {
|
||||
this.child?.stdin.write(`complainlist\n`);
|
||||
}
|
||||
|
||||
async deleteComplaint(targetClientDbId: number, fromClientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`complaindel ${targetClientDbId} ${fromClientDbId}\n`);
|
||||
}
|
||||
|
||||
async deleteAllComplaintsFor(targetClientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`complaindelall ${targetClientDbId}\n`);
|
||||
}
|
||||
|
||||
async getOfflineMessageList(): Promise<void> {
|
||||
this.child?.stdin.write(`messagelist\n`);
|
||||
}
|
||||
|
||||
async getOfflineMessage(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messageget ${messageId}\n`);
|
||||
}
|
||||
|
||||
async sendOfflineMessage(clientUid: string, subject: string, message: string): Promise<void> {
|
||||
const sanitize = (s: string) => s.replace(/[\r\n\t]+/g, " ").trim();
|
||||
this.child?.stdin.write(`messageadd ${sanitize(clientUid)}\t${sanitize(subject)}\t${sanitize(message)}\n`);
|
||||
}
|
||||
|
||||
async deleteOfflineMessage(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messagedel ${messageId}\n`);
|
||||
}
|
||||
|
||||
async markOfflineMessageRead(messageId: number): Promise<void> {
|
||||
this.child?.stdin.write(`messageupdateflag ${messageId} 1\n`);
|
||||
}
|
||||
|
||||
async getChannelGroupList(): Promise<void> {
|
||||
this.child?.stdin.write(`channelgrouplist\n`);
|
||||
}
|
||||
|
||||
async getServerGroupList(): Promise<void> {
|
||||
this.child?.stdin.write(`servergrouplist\n`);
|
||||
}
|
||||
|
||||
async setChannelGroup(channelGroupId: number, channelId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`setchannelgroup ${channelGroupId} ${channelId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async addServerGroup(serverGroupId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`addservergroup ${serverGroupId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async removeServerGroup(serverGroupId: number, clientDbId: number): Promise<void> {
|
||||
this.child?.stdin.write(`delservergroup ${serverGroupId} ${clientDbId}\n`);
|
||||
}
|
||||
|
||||
async serverQueryLogin(username: string, password: string): Promise<void> {
|
||||
const u = Buffer.from(username, "utf8").toString("base64");
|
||||
const p = Buffer.from(password, "utf8").toString("base64");
|
||||
this.child?.stdin.write(`serverquerylogin ${u} ${p}\n`);
|
||||
}
|
||||
|
||||
async getPermissionOverview(): Promise<void> {
|
||||
this.child?.stdin.write(`permoverview\n`);
|
||||
}
|
||||
|
||||
async getPermissionCatalog(): Promise<void> {
|
||||
this.child?.stdin.write(`permissionlist\n`);
|
||||
}
|
||||
|
||||
async getPermList(scope: PermScope, id1: number, id2?: number): Promise<void> {
|
||||
const args = id2 !== undefined ? `${scope} ${id1} ${id2}` : `${scope} ${id1}`;
|
||||
this.child?.stdin.write(`permlist ${args}\n`);
|
||||
}
|
||||
|
||||
/** `negated`/`skip` only apply to the "server" and "client" scopes - the
|
||||
* connector ignores extra trailing args for scopes that don't use them, so
|
||||
* it's safe to always pass through what the caller gave. */
|
||||
async addPermission(
|
||||
scope: PermScope,
|
||||
ids: number[],
|
||||
permId: number,
|
||||
value: number,
|
||||
negated = false,
|
||||
skip = false
|
||||
): Promise<void> {
|
||||
let args = `${scope} ${ids.join(" ")} ${permId} ${value}`;
|
||||
if (scope === "server") args += ` ${negated ? 1 : 0} ${skip ? 1 : 0}`;
|
||||
else if (scope === "client") args += ` ${skip ? 1 : 0}`;
|
||||
this.child?.stdin.write(`permadd ${args}\n`);
|
||||
}
|
||||
|
||||
async removePermission(scope: PermScope, ids: number[], permId: number): Promise<void> {
|
||||
this.child?.stdin.write(`permdel ${scope} ${ids.join(" ")} ${permId}\n`);
|
||||
}
|
||||
|
||||
async getFileList(channelId: number, path: string): Promise<void> {
|
||||
const sanitized = (path || "/").replace(/[\r\n]+/g, " ").trim() || "/";
|
||||
this.child?.stdin.write(`ftlist ${channelId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
async createDirectory(channelId: number, dirname: string): Promise<void> {
|
||||
const sanitized = dirname.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`ftmkdir ${channelId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
async deleteFile(channelId: number, name: string): Promise<void> {
|
||||
const sanitized = name.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`ftdelete ${channelId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
async renameFile(channelId: number, oldName: string, newName: string): Promise<void> {
|
||||
const sanitize = (s: string) => s.replace(/[\r\n\t]+/g, " ").trim();
|
||||
this.child?.stdin.write(`ftrename ${channelId}\t${sanitize(oldName)}\t${sanitize(newName)}\n`);
|
||||
}
|
||||
|
||||
async downloadFile(channelId: number, path: string): Promise<void> {
|
||||
const sanitized = path.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`ftdownload ${channelId} ${sanitized}\n`);
|
||||
}
|
||||
|
||||
/** `dataBase64` is the raw file content, base64-encoded - the browser reads
|
||||
* the picked File as a data URL/ArrayBuffer and sends it up already encoded. */
|
||||
async uploadFile(channelId: number, path: string, dataBase64: string): Promise<void> {
|
||||
const sanitizedPath = path.replace(/[\r\n\t]+/g, " ").trim();
|
||||
this.child?.stdin.write(`ftupload ${channelId}\t${sanitizedPath}\t${dataBase64}\n`);
|
||||
}
|
||||
|
||||
async sendChatMessage(message: string): Promise<void> {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||
@@ -202,9 +712,42 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`audio ${pcmBase64}\n`);
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
async setAway(away: boolean, message: string): Promise<void> {
|
||||
if (away) {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
this.child?.stdin.write(`away ${sanitized}\n`);
|
||||
} else {
|
||||
this.child?.stdin.write("unaway\n");
|
||||
}
|
||||
}
|
||||
|
||||
async setInputMuted(muted: boolean): Promise<void> {
|
||||
this.child?.stdin.write(`muteinput ${muted ? "1" : "0"}\n`);
|
||||
}
|
||||
|
||||
async setOutputMuted(muted: boolean): Promise<void> {
|
||||
this.child?.stdin.write(`muteoutput ${muted ? "1" : "0"}\n`);
|
||||
}
|
||||
|
||||
async setNickname(nickname: string): Promise<void> {
|
||||
const sanitized = nickname.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`nickname ${sanitized}\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) {
|
||||
this.child.stdin.write("disconnect\n");
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
this.child.stdin.write(`disconnect ${sanitized}\n`);
|
||||
this.child.stdin.end();
|
||||
}
|
||||
this.listeners.clear();
|
||||
|
||||
@@ -9,6 +9,7 @@ lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-demo
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
|
||||
@@ -2,9 +2,24 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png" />
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/favicon-192.png" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>web</title>
|
||||
<title>WebSpeak3</title>
|
||||
<meta name="description" content="WebSpeak3 — an independent, self-hosted web client for TeamSpeak 3 servers." />
|
||||
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:title" content="WebSpeak3" />
|
||||
<meta property="og:description" content="An independent, self-hosted web client for TeamSpeak 3 servers." />
|
||||
<meta property="og:url" content="https://ts.moepchi.de/" />
|
||||
<meta property="og:image" content="https://ts.moepchi.de/og-image.png" />
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content="WebSpeak3" />
|
||||
<meta name="twitter:description" content="An independent, self-hosted web client for TeamSpeak 3 servers." />
|
||||
<meta name="twitter:image" content="https://ts.moepchi.de/og-image.png" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "web",
|
||||
"name": "webspeak3-web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
@@ -10,6 +10,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"fflate": "^0.8.3",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7"
|
||||
},
|
||||
|
||||
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="46" fill="none" viewBox="0 0 48 46"><path fill="#863bff" d="M25.946 44.938c-.664.845-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.287c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.497 0-3.578-1.842-3.578H1.237c-.92 0-1.456-1.04-.92-1.788L10.013.474c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.579 1.842 3.579h11.377c.943 0 1.473 1.088.89 1.83L25.947 44.94z" style="fill:#863bff;fill:color(display-p3 .5252 .23 1);fill-opacity:1"/><mask id="a" width="48" height="46" x="0" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M25.842 44.938c-.664.844-2.021.375-2.021-.698V33.937a2.26 2.26 0 0 0-2.262-2.262H10.183c-.92 0-1.456-1.04-.92-1.788l7.48-10.471c1.07-1.498 0-3.579-1.842-3.579H1.133c-.92 0-1.456-1.04-.92-1.787L9.91.473c.214-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.471c-1.07 1.498 0 3.578 1.842 3.578h11.377c.943 0 1.473 1.088.89 1.832L25.843 44.94z" style="fill:#000;fill-opacity:1"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#ede6ff" rx="5.508" ry="14.704" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -4.47 31.516)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#ede6ff" rx="10.399" ry="29.851" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -39.328 7.883)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#7e14ff" rx="5.508" ry="30.487" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -25.913 -14.639)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.814 -32.644 -3.334)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#7e14ff" rx="5.508" ry="30.599" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="matrix(.00324 1 1 -.00324 -34.34 30.47)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#ede6ff" rx="14.072" ry="22.078" style="fill:#ede6ff;fill:color(display-p3 .9275 .9033 1);fill-opacity:1" transform="rotate(93.35 24.506 48.493)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#7e14ff" rx="3.47" ry="21.501" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(89.009 28.708 47.59)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx=".387" cy="8.972" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(39.51 .387 8.972)"/></g><g filter="url(#k)"><ellipse cx="47.523" cy="-6.092" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 47.523 -6.092)"/></g><g filter="url(#l)"><ellipse cx="41.412" cy="6.333" fill="#47bfff" rx="5.971" ry="9.665" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 41.412 6.333)"/></g><g filter="url(#m)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#n)"><ellipse cx="-1.879" cy="38.332" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 -1.88 38.332)"/></g><g filter="url(#o)"><ellipse cx="35.651" cy="29.907" fill="#7e14ff" rx="4.407" ry="29.108" style="fill:#7e14ff;fill:color(display-p3 .4922 .0767 1);fill-opacity:1" transform="rotate(37.892 35.651 29.907)"/></g><g filter="url(#p)"><ellipse cx="38.418" cy="32.4" fill="#47bfff" rx="5.971" ry="15.297" style="fill:#47bfff;fill:color(display-p3 .2799 .748 1);fill-opacity:1" transform="rotate(37.892 38.418 32.4)"/></g></g><defs><filter id="b" width="60.045" height="41.654" x="-19.77" y="16.149" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-54.613" y="-7.533" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17158" stdDeviation="7.659"/></filtLine truncated
|
||||
|
Before Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 911 KiB |
|
After Width: | Height: | Size: 145 KiB |
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generates every derived favicon/OG-image size from the single source logo
|
||||
# at web/public/logo.png. Requires ImageMagick (`magick` on the PATH).
|
||||
#
|
||||
# Usage: run from web/ after dropping the source logo at public/logo.png:
|
||||
# bash scripts/generate-icons.sh
|
||||
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
SRC=public/logo.png
|
||||
if [ ! -f "$SRC" ]; then
|
||||
echo "Missing $SRC - drop the source logo there first (square PNG, >=512x512, transparent background)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
magick "$SRC" -resize 32x32 public/favicon-32.png
|
||||
magick "$SRC" -resize 192x192 public/favicon-192.png
|
||||
magick "$SRC" -resize 180x180 -background white -alpha remove -alpha off public/apple-touch-icon.png
|
||||
magick "$SRC" -define icon:auto-resize=16,32,48 public/favicon.ico
|
||||
magick "$SRC" -resize 400x400 -background "#1e1e1e" -gravity center -extent 1200x630 public/og-image.png
|
||||
|
||||
echo "Generated favicon-32.png, favicon-192.png, apple-touch-icon.png, favicon.ico, og-image.png in public/"
|
||||
@@ -0,0 +1,625 @@
|
||||
// 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;
|
||||
uid: string;
|
||||
databaseId: number;
|
||||
channelGroup: number;
|
||||
serverGroups: number[];
|
||||
hasTalkPower: boolean;
|
||||
}
|
||||
|
||||
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_CHANNEL_GROUPS = [
|
||||
{ id: 1, name: "Channel Admin", iconId: 0 },
|
||||
{ id: 2, name: "Operator", iconId: 0 },
|
||||
{ id: 3, name: "Voice", iconId: 0 },
|
||||
{ id: 4, name: "Guest", iconId: 0 },
|
||||
];
|
||||
|
||||
const DEMO_SERVER_GROUPS = [
|
||||
{ id: 1, name: "Server Admin", iconId: 0 },
|
||||
{ id: 2, name: "Moderator", iconId: 0 },
|
||||
{ id: 3, name: "Trusted", iconId: 0 },
|
||||
{ id: 4, name: "Guest", iconId: 0 },
|
||||
];
|
||||
|
||||
const DEMO_NPCS: DemoClient[] = [
|
||||
{ id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex", databaseId: 2, channelGroup: 2, serverGroups: [2], hasTalkPower: true },
|
||||
{ id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam", databaseId: 3, channelGroup: 4, serverGroups: [4], hasTalkPower: true },
|
||||
{ id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan", databaseId: 4, channelGroup: 4, serverGroups: [4], hasTalkPower: true },
|
||||
{ id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley", databaseId: 5, channelGroup: 4, serverGroups: [3, 4], hasTalkPower: true },
|
||||
];
|
||||
|
||||
interface DemoFileEntry {
|
||||
path: string;
|
||||
name: string;
|
||||
size: number;
|
||||
isFile: boolean;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
/** Keyed by "<channelId>:<path>" - a tiny in-memory filesystem so the
|
||||
* channel file browser has something real to navigate/mutate in the demo. */
|
||||
const DEMO_FILES: Record<string, DemoFileEntry[]> = {
|
||||
"1:/": [
|
||||
{ path: "/", name: "readme.txt", size: 182, isFile: true, timestamp: "2024-01-01 12:00:00" },
|
||||
{ path: "/", name: "Musik", size: 0, isFile: false, timestamp: "2024-01-01 12:00:00" },
|
||||
],
|
||||
"1:/Musik": [
|
||||
{ path: "/Musik", name: "lobby-theme.mp3", size: 4 * 1024 * 1024, isFile: true, timestamp: "2024-01-02 09:30:00" },
|
||||
],
|
||||
"2:/": [],
|
||||
"3:/": [],
|
||||
// Channel 0 is TS3's special server-wide icon repository, not a real channel.
|
||||
"0:/": [
|
||||
{ path: "/", name: "icon_100", size: 68, isFile: true, timestamp: "2024-01-01 12:00:00" },
|
||||
{ path: "/", name: "icon_200", size: 68, isFile: true, timestamp: "2024-01-01 12:00:00" },
|
||||
],
|
||||
};
|
||||
|
||||
// A tiny 1x1 transparent PNG, reused as the fake image data for every demo icon.
|
||||
const DEMO_ICON_PNG_BASE64 =
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
|
||||
|
||||
function demoFileKey(channelId: number, path: string): string {
|
||||
return `${channelId}:${path}`;
|
||||
}
|
||||
|
||||
function demoNowTimestamp(): string {
|
||||
return new Date().toISOString().slice(0, 19).replace("T", " ");
|
||||
}
|
||||
|
||||
interface DemoPermEntry {
|
||||
name: string;
|
||||
description: string;
|
||||
value: number;
|
||||
negated: boolean;
|
||||
skip: boolean;
|
||||
}
|
||||
|
||||
// A small fake permission catalog (real TS3 servers expose ~500 of these) -
|
||||
// enough for the permissions editor's "add permission" picker to be usable.
|
||||
const DEMO_PERMISSION_CATALOG: { id: number; name: string; description: string }[] = [
|
||||
{ id: 1, name: "b_client_info_view", description: "View own client info" },
|
||||
{ id: 2, name: "b_client_permissionoverview_view", description: "View permission overview" },
|
||||
{ id: 3, name: "i_channel_join_power", description: "Power to join channels" },
|
||||
{ id: 4, name: "i_client_talk_power", description: "Talk power" },
|
||||
{ id: 5, name: "b_client_use_priority_speaker", description: "Use priority speaker" },
|
||||
{ id: 6, name: "i_client_max_channel_subscriptions", description: "Max channel subscriptions" },
|
||||
{ id: 7, name: "b_channel_join_permanent", description: "Join permanent channels" },
|
||||
{ id: 8, name: "b_client_kick_from_channel", description: "Kick client from channel" },
|
||||
{ id: 9, name: "b_client_kick_from_server", description: "Kick client from server" },
|
||||
{ id: 10, name: "b_client_ban_client", description: "Ban client" },
|
||||
{ id: 11, name: "i_channel_create_modify_power", description: "Power to create/modify channels" },
|
||||
{ id: 12, name: "b_virtualserver_modify_name", description: "Modify server name" },
|
||||
{ id: 13, name: "b_ft_file_upload", description: "Upload files" },
|
||||
{ id: 14, name: "b_ft_file_download", description: "Download files" },
|
||||
];
|
||||
|
||||
// Keyed by "<scope>:<id1>:<id2 ?? ->" - the fake permission set currently
|
||||
// assigned to one server group / channel group / channel / client /
|
||||
// channel+client combination.
|
||||
const DEMO_PERM_LISTS: Record<string, DemoPermEntry[]> = {
|
||||
"server:1:-": [
|
||||
{ name: "b_client_kick_from_server", description: "Kick client from server", value: 1, negated: false, skip: false },
|
||||
{ name: "b_client_ban_client", description: "Ban client", value: 1, negated: false, skip: false },
|
||||
],
|
||||
"server:4:-": [
|
||||
{ name: "i_channel_join_power", description: "Power to join channels", value: 25, negated: false, skip: false },
|
||||
],
|
||||
"channelgroup:1:-": [
|
||||
{ name: "i_channel_create_modify_power", description: "Power to create/modify channels", value: 75, negated: false, skip: false },
|
||||
],
|
||||
"client:1:-": [
|
||||
{ name: "b_client_info_view", description: "View own client info", value: 1, negated: false, skip: false },
|
||||
],
|
||||
};
|
||||
|
||||
function demoPermKey(scope: string, id1: number, id2?: number): string {
|
||||
return `${scope}:${id1}:${id2 ?? "-"}`;
|
||||
}
|
||||
|
||||
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;
|
||||
private selfChannelGroup = 4;
|
||||
private selfServerGroups = new Set<number>([4]);
|
||||
|
||||
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;
|
||||
}
|
||||
case "getClientConnectionInfo": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "clientConnectionInfo",
|
||||
clientId: msg.clientId,
|
||||
pingMs: 12.4,
|
||||
connectedSecs: 217,
|
||||
ip: msg.clientId === SELF_ID ? "127.0.0.1" : null,
|
||||
packetsSent: 4213,
|
||||
bytesSent: 512_340,
|
||||
packetsReceived: 3987,
|
||||
bytesReceived: 498_120,
|
||||
packetLossPercent: 0,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getServerConnectionInfo": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "serverConnectionInfo",
|
||||
pingMs: 8.1,
|
||||
connectedSecs: 217,
|
||||
packetLossPercent: 0,
|
||||
packetsSentTotal: 21_004,
|
||||
bytesSentTotal: 2_411_000,
|
||||
packetsReceivedTotal: 19_872,
|
||||
bytesReceivedTotal: 2_198_500,
|
||||
bandwidthSentLastSecond: 4200,
|
||||
bandwidthReceivedLastSecond: 3900,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getServerLog": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "serverProtocolLog",
|
||||
lines: [
|
||||
"2026-08-05 10:12:03.421128|INFO |VirtualServerBase|1 |connect to server successful, connection accepted",
|
||||
"2026-08-05 10:12:04.001912|INFO |VirtualServerBase|1 |client 'Guest'(id:101) connected",
|
||||
"2026-08-05 10:14:19.552031|INFO |VirtualServerBase|1 |client 'Sam'(id:103) connected",
|
||||
"2026-08-05 10:15:02.884120|INFO |VirtualServerBase|1 |client 'Jordan'(id:104) switched channel",
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getBanList": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "banList",
|
||||
entries: [
|
||||
{
|
||||
banId: 1,
|
||||
ip: "203.0.113.42",
|
||||
name: "TrollUser",
|
||||
uid: "demo-uid-troll",
|
||||
lastNickname: "TrollUser",
|
||||
created: "2026-07-28 14:02:11",
|
||||
durationSecs: 0,
|
||||
invokerName: "Alex",
|
||||
reason: "Spamming the server chat",
|
||||
enforcements: 0,
|
||||
},
|
||||
{
|
||||
banId: 2,
|
||||
ip: "198.51.100.7",
|
||||
name: "",
|
||||
uid: "demo-uid-annoying",
|
||||
lastNickname: "AnnoyingGuest",
|
||||
created: "2026-08-01 09:44:53",
|
||||
durationSecs: 3600,
|
||||
invokerName: "Sam",
|
||||
reason: "Repeated channel spam",
|
||||
enforcements: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "deleteBan":
|
||||
case "deleteAllBans":
|
||||
// No observable effect - the frontend already optimistically removes
|
||||
// the deleted row(s) from its own state.
|
||||
break;
|
||||
case "getComplainList": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "complainList",
|
||||
entries: [
|
||||
{
|
||||
targetClientDbId: 104,
|
||||
targetName: "Jordan",
|
||||
fromClientDbId: 103,
|
||||
fromName: "Sam",
|
||||
message: "Kept talking over everyone in voice chat.",
|
||||
timestamp: "2026-08-02 18:21:07",
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "deleteComplaint":
|
||||
case "deleteAllComplaintsFor":
|
||||
break;
|
||||
case "getOfflineMessageList": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "offlineMessageList",
|
||||
entries: [
|
||||
{
|
||||
messageId: 1,
|
||||
clientUid: "demo-uid-sam",
|
||||
subject: "Missed you online",
|
||||
timestamp: "2026-08-03 20:11:44",
|
||||
isRead: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getOfflineMessage": {
|
||||
this.after(300, () =>
|
||||
this.emit({
|
||||
type: "offlineMessage",
|
||||
messageId: msg.messageId,
|
||||
clientUid: "demo-uid-sam",
|
||||
subject: "Missed you online",
|
||||
message: "Hey, we were on last night in the Gaming channel - join us next time!",
|
||||
timestamp: "2026-08-03 20:11:44",
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "sendOfflineMessage":
|
||||
case "deleteOfflineMessage":
|
||||
case "markOfflineMessageRead":
|
||||
// No observable effect - the frontend already optimistically updates
|
||||
// its own state for delete/read, and there's no NPC to reply to a send.
|
||||
break;
|
||||
case "getChannelGroupList":
|
||||
this.after(300, () => this.emit({ type: "channelGroupList", entries: DEMO_CHANNEL_GROUPS }));
|
||||
break;
|
||||
case "getServerGroupList":
|
||||
this.after(300, () => this.emit({ type: "serverGroupList", entries: DEMO_SERVER_GROUPS }));
|
||||
break;
|
||||
case "setChannelGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) npc.channelGroup = msg.channelGroupId;
|
||||
else if (msg.clientDbId === 1) this.selfChannelGroup = msg.channelGroupId;
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "addServerGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) {
|
||||
if (!npc.serverGroups.includes(msg.serverGroupId)) npc.serverGroups.push(msg.serverGroupId);
|
||||
} else if (msg.clientDbId === 1) {
|
||||
this.selfServerGroups.add(msg.serverGroupId);
|
||||
}
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "removeServerGroup": {
|
||||
const npc = DEMO_NPCS.find((c) => c.databaseId === msg.clientDbId);
|
||||
if (npc) {
|
||||
npc.serverGroups = npc.serverGroups.filter((g) => g !== msg.serverGroupId);
|
||||
} else if (msg.clientDbId === 1) {
|
||||
this.selfServerGroups.delete(msg.serverGroupId);
|
||||
}
|
||||
this.after(200, () => this.sendChannels(this.lastNickname));
|
||||
break;
|
||||
}
|
||||
case "serverQueryLogin":
|
||||
// No observable effect - the demo has no real ServerQuery backend to
|
||||
// authenticate against.
|
||||
break;
|
||||
case "getPermissionOverview": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "permissionOverview",
|
||||
entries: [
|
||||
{ name: "b_client_info_view", description: "View own client info", value: 1, negated: false, skip: false },
|
||||
{ name: "b_client_permissionoverview_view", description: "View permission overview", value: 1, negated: false, skip: false },
|
||||
{ name: "i_channel_join_power", description: "Power to join channels", value: 25, negated: false, skip: false },
|
||||
{ name: "i_client_talk_power", description: "Talk power", value: 25, negated: false, skip: false },
|
||||
{ name: "b_client_use_priority_speaker", description: "Use priority speaker", value: 0, negated: true, skip: false },
|
||||
{ name: "i_client_max_channel_subscriptions", description: "Max channel subscriptions", value: -1, negated: false, skip: false },
|
||||
{ name: "b_channel_join_permanent", description: "Join permanent channels", value: 1, negated: false, skip: false },
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getPermissionCatalog": {
|
||||
this.after(300, () => this.emit({ type: "permissionCatalog", entries: DEMO_PERMISSION_CATALOG }));
|
||||
break;
|
||||
}
|
||||
case "getPermList": {
|
||||
const key = demoPermKey(msg.scope, msg.id1, msg.id2);
|
||||
this.after(300, () =>
|
||||
this.emit({ type: "permList", scope: msg.scope, id1: msg.id1, id2: msg.id2 ?? null, entries: DEMO_PERM_LISTS[key] ?? [] })
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "addPermission": {
|
||||
const [id1, id2] = msg.ids as number[];
|
||||
const key = demoPermKey(msg.scope, id1, id2);
|
||||
const catalogEntry = DEMO_PERMISSION_CATALOG.find((p) => p.id === msg.permId);
|
||||
const name = catalogEntry?.name ?? `#${msg.permId}`;
|
||||
const description = catalogEntry?.description ?? "";
|
||||
const list = (DEMO_PERM_LISTS[key] ?? []).filter((e) => e.name !== name);
|
||||
list.push({ name, description, value: msg.value, negated: !!msg.negated, skip: !!msg.skip });
|
||||
DEMO_PERM_LISTS[key] = list;
|
||||
break;
|
||||
}
|
||||
case "removePermission": {
|
||||
const [id1, id2] = msg.ids as number[];
|
||||
const key = demoPermKey(msg.scope, id1, id2);
|
||||
const catalogEntry = DEMO_PERMISSION_CATALOG.find((p) => p.id === msg.permId);
|
||||
const name = catalogEntry?.name ?? `#${msg.permId}`;
|
||||
if (DEMO_PERM_LISTS[key]) DEMO_PERM_LISTS[key] = DEMO_PERM_LISTS[key].filter((e) => e.name !== name);
|
||||
break;
|
||||
}
|
||||
case "getFileList": {
|
||||
const key = demoFileKey(msg.channelId, msg.path);
|
||||
this.after(300, () =>
|
||||
this.emit({ type: "fileList", cid: msg.channelId, path: msg.path, entries: DEMO_FILES[key] ?? [] })
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "createDirectory": {
|
||||
const dir = msg.dirname as string;
|
||||
const parent = dir.slice(0, dir.lastIndexOf("/")) || "/";
|
||||
const name = dir.slice(dir.lastIndexOf("/") + 1);
|
||||
const parentKey = demoFileKey(msg.channelId, parent);
|
||||
DEMO_FILES[parentKey] = (DEMO_FILES[parentKey] ?? []).filter((e) => e.name !== name);
|
||||
DEMO_FILES[parentKey].push({ path: parent, name, size: 0, isFile: false, timestamp: demoNowTimestamp() });
|
||||
DEMO_FILES[demoFileKey(msg.channelId, dir)] = [];
|
||||
break;
|
||||
}
|
||||
case "deleteFile": {
|
||||
const full = msg.name as string;
|
||||
const parent = full.slice(0, full.lastIndexOf("/")) || "/";
|
||||
const name = full.slice(full.lastIndexOf("/") + 1);
|
||||
const parentKey = demoFileKey(msg.channelId, parent);
|
||||
if (DEMO_FILES[parentKey]) DEMO_FILES[parentKey] = DEMO_FILES[parentKey].filter((e) => e.name !== name);
|
||||
break;
|
||||
}
|
||||
case "renameFile": {
|
||||
const oldFull = msg.oldName as string;
|
||||
const newFull = msg.newName as string;
|
||||
const parent = oldFull.slice(0, oldFull.lastIndexOf("/")) || "/";
|
||||
const oldName = oldFull.slice(oldFull.lastIndexOf("/") + 1);
|
||||
const newName = newFull.slice(newFull.lastIndexOf("/") + 1);
|
||||
const entry = DEMO_FILES[demoFileKey(msg.channelId, parent)]?.find((e) => e.name === oldName);
|
||||
if (entry) entry.name = newName;
|
||||
break;
|
||||
}
|
||||
case "downloadFile": {
|
||||
const full = msg.path as string;
|
||||
const name = full.slice(full.lastIndexOf("/") + 1);
|
||||
const data =
|
||||
msg.channelId === 0
|
||||
? DEMO_ICON_PNG_BASE64
|
||||
: btoa(`This is a demo file. There is no real content behind "${name}" in WebSpeak3's demo mode.`);
|
||||
this.after(400, () => this.emit({ type: "fileDownloadData", cid: msg.channelId, path: full, data }));
|
||||
break;
|
||||
}
|
||||
case "uploadFile": {
|
||||
const full = msg.path as string;
|
||||
const parent = full.slice(0, full.lastIndexOf("/")) || "/";
|
||||
const name = full.slice(full.lastIndexOf("/") + 1);
|
||||
const parentKey = demoFileKey(msg.channelId, parent);
|
||||
const sizeBytes = Math.floor(((msg.dataBase64 as string).length * 3) / 4);
|
||||
DEMO_FILES[parentKey] = (DEMO_FILES[parentKey] ?? []).filter((e) => e.name !== name);
|
||||
DEMO_FILES[parentKey].push({ path: parent, name, size: sizeBytes, isFile: true, timestamp: demoNowTimestamp() });
|
||||
this.after(400, () => this.emit({ type: "fileUploadDone", cid: msg.channelId, path: full }));
|
||||
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: "",
|
||||
uid: "demo-uid-self",
|
||||
databaseId: 1,
|
||||
channelGroup: this.selfChannelGroup,
|
||||
serverGroups: [...this.selfServerGroups],
|
||||
hasTalkPower: true,
|
||||
};
|
||||
this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] });
|
||||
}
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
export type SoundEventId = "connect" | "disconnect" | "clientJoin" | "clientLeave" | "message" | "poke";
|
||||
|
||||
export const SOUND_EVENTS: SoundEventId[] = ["connect", "disconnect", "clientJoin", "clientLeave", "message", "poke"];
|
||||
|
||||
const ENABLED_KEY = "webspeak3:sounds-enabled";
|
||||
const VOLUME_KEY = "webspeak3:sounds-volume";
|
||||
const EVENT_ENABLED_KEY_PREFIX = "webspeak3:sounds-enabled:";
|
||||
const DB_NAME = "webspeak3-sounds";
|
||||
const STORE_NAME = "custom";
|
||||
|
||||
interface StoredSound {
|
||||
blob: Blob;
|
||||
name: string;
|
||||
}
|
||||
|
||||
function openDb(): Promise<IDBDatabase> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = indexedDB.open(DB_NAME, 1);
|
||||
req.onupgradeneeded = () => {
|
||||
req.result.createObjectStore(STORE_NAME);
|
||||
};
|
||||
req.onsuccess = () => resolve(req.result);
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveCustomSound(event: SoundEventId, file: File): Promise<void> {
|
||||
const db = await openDb();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, "readwrite");
|
||||
tx.objectStore(STORE_NAME).put({ blob: file, name: file.name } satisfies StoredSound, event);
|
||||
tx.oncomplete = () => resolve();
|
||||
tx.onerror = () => reject(tx.error);
|
||||
});
|
||||
db.close();
|
||||
}
|
||||
|
||||
export async function loadCustomSound(event: SoundEventId): Promise<StoredSound | undefined> {
|
||||
const db = await openDb();
|
||||
const result = await new Promise<StoredSound | undefined>((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, "readonly");
|
||||
const req = tx.objectStore(STORE_NAME).get(event);
|
||||
req.onsuccess = () => resolve(req.result as StoredSound | undefined);
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
db.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function clearCustomSound(event: SoundEventId): Promise<void> {
|
||||
const db = await openDb();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, "readwrite");
|
||||
tx.objectStore(STORE_NAME).delete(event);
|
||||
tx.oncomplete = () => resolve();
|
||||
tx.onerror = () => reject(tx.error);
|
||||
});
|
||||
db.close();
|
||||
}
|
||||
|
||||
export function loadSoundsEnabled(): boolean {
|
||||
const raw = localStorage.getItem(ENABLED_KEY);
|
||||
return raw === null ? true : raw === "true";
|
||||
}
|
||||
|
||||
export function saveSoundsEnabled(enabled: boolean): void {
|
||||
localStorage.setItem(ENABLED_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export function loadEventSoundEnabled(event: SoundEventId): boolean {
|
||||
const raw = localStorage.getItem(EVENT_ENABLED_KEY_PREFIX + event);
|
||||
return raw === null ? true : raw === "true";
|
||||
}
|
||||
|
||||
export function saveEventSoundEnabled(event: SoundEventId, enabled: boolean): void {
|
||||
localStorage.setItem(EVENT_ENABLED_KEY_PREFIX + event, String(enabled));
|
||||
}
|
||||
|
||||
export function loadSoundsVolume(): number {
|
||||
const raw = localStorage.getItem(VOLUME_KEY);
|
||||
const n = raw ? Number(raw) : 0.5;
|
||||
return Number.isFinite(n) ? Math.min(1, Math.max(0, n)) : 0.5;
|
||||
}
|
||||
|
||||
export function saveSoundsVolume(volume: number): void {
|
||||
localStorage.setItem(VOLUME_KEY, String(volume));
|
||||
}
|
||||
|
||||
type SinkableElement = HTMLAudioElement & { setSinkId?: (id: string) => Promise<void> };
|
||||
|
||||
/**
|
||||
* Notification sounds get their own AudioContext, independent from the
|
||||
* voice AudioContext in voice.ts - that one is created on connect and torn
|
||||
* down on disconnect, but sounds must keep working (and be testable from
|
||||
* Options) regardless of connection state.
|
||||
*/
|
||||
class NotificationSoundPlayer {
|
||||
private context: AudioContext | null = null;
|
||||
private destination: MediaStreamAudioDestinationNode | null = null;
|
||||
private element: SinkableElement | null = null;
|
||||
private outputDeviceId = "";
|
||||
|
||||
private ensure(): { context: AudioContext; destination: MediaStreamAudioDestinationNode } {
|
||||
if (!this.context) {
|
||||
const context = new AudioContext();
|
||||
const destination = context.createMediaStreamDestination();
|
||||
const element: SinkableElement = new Audio();
|
||||
element.srcObject = destination.stream;
|
||||
element.autoplay = true;
|
||||
this.context = context;
|
||||
this.destination = destination;
|
||||
this.element = element;
|
||||
if (this.outputDeviceId && typeof element.setSinkId === "function") {
|
||||
element.setSinkId(this.outputDeviceId).catch(() => {});
|
||||
}
|
||||
}
|
||||
return { context: this.context, destination: this.destination! };
|
||||
}
|
||||
|
||||
async setOutputDevice(deviceId: string): Promise<void> {
|
||||
this.outputDeviceId = deviceId;
|
||||
if (this.element && typeof this.element.setSinkId === "function") {
|
||||
await this.element.setSinkId(deviceId).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
async playBlob(blob: Blob, volume: number): Promise<void> {
|
||||
const { context, destination } = this.ensure();
|
||||
if (context.state === "suspended") await context.resume().catch(() => {});
|
||||
const arrayBuffer = await blob.arrayBuffer();
|
||||
const audioBuffer = await context.decodeAudioData(arrayBuffer);
|
||||
const source = context.createBufferSource();
|
||||
source.buffer = audioBuffer;
|
||||
const gain = context.createGain();
|
||||
gain.gain.value = volume;
|
||||
source.connect(gain).connect(destination);
|
||||
source.start();
|
||||
}
|
||||
|
||||
playSynth(event: SoundEventId, volume: number): void {
|
||||
const { context, destination } = this.ensure();
|
||||
if (context.state === "suspended") context.resume().catch(() => {});
|
||||
const now = context.currentTime;
|
||||
for (const note of synthNotes(event)) {
|
||||
this.playNote(context, destination, now + note.delay, note.freq, note.duration, volume * note.gain);
|
||||
}
|
||||
}
|
||||
|
||||
private playNote(
|
||||
context: AudioContext,
|
||||
destination: AudioNode,
|
||||
startTime: number,
|
||||
freq: number,
|
||||
duration: number,
|
||||
peakGain: number
|
||||
): void {
|
||||
const osc = context.createOscillator();
|
||||
osc.type = "sine";
|
||||
osc.frequency.value = freq;
|
||||
const gain = context.createGain();
|
||||
gain.gain.setValueAtTime(0, startTime);
|
||||
gain.gain.linearRampToValueAtTime(peakGain, startTime + 0.02);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, startTime + duration);
|
||||
osc.connect(gain).connect(destination);
|
||||
osc.start(startTime);
|
||||
osc.stop(startTime + duration + 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
/** Soft, modern two/three-note chimes - a sine-wave, quick-attack/exponential-decay
|
||||
* shape reads as gentle rather than the harsh square/saw beeps of classic UI sounds. */
|
||||
function synthNotes(event: SoundEventId): { delay: number; freq: number; duration: number; gain: number }[] {
|
||||
switch (event) {
|
||||
case "connect":
|
||||
return [
|
||||
{ delay: 0, freq: 523.25, duration: 0.16, gain: 0.5 },
|
||||
{ delay: 0.09, freq: 783.99, duration: 0.22, gain: 0.5 },
|
||||
];
|
||||
case "disconnect":
|
||||
return [
|
||||
{ delay: 0, freq: 659.25, duration: 0.16, gain: 0.45 },
|
||||
{ delay: 0.09, freq: 440.0, duration: 0.24, gain: 0.45 },
|
||||
];
|
||||
case "clientJoin":
|
||||
return [{ delay: 0, freq: 880.0, duration: 0.14, gain: 0.4 }];
|
||||
case "clientLeave":
|
||||
return [{ delay: 0, freq: 587.33, duration: 0.16, gain: 0.4 }];
|
||||
case "message":
|
||||
return [
|
||||
{ delay: 0, freq: 987.77, duration: 0.09, gain: 0.35 },
|
||||
{ delay: 0.06, freq: 1318.51, duration: 0.12, gain: 0.3 },
|
||||
];
|
||||
case "poke":
|
||||
return [
|
||||
{ delay: 0, freq: 987.77, duration: 0.1, gain: 0.5 },
|
||||
{ delay: 0.12, freq: 987.77, duration: 0.1, gain: 0.5 },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
const player = new NotificationSoundPlayer();
|
||||
|
||||
export function setSoundsOutputDevice(deviceId: string): void {
|
||||
void player.setOutputDevice(deviceId);
|
||||
}
|
||||
|
||||
export async function playSound(event: SoundEventId): Promise<void> {
|
||||
if (!loadSoundsEnabled()) return;
|
||||
if (!loadEventSoundEnabled(event)) return;
|
||||
const volume = loadSoundsVolume();
|
||||
const custom = await loadCustomSound(event).catch(() => undefined);
|
||||
if (custom) {
|
||||
try {
|
||||
await player.playBlob(custom.blob, volume);
|
||||
return;
|
||||
} catch {
|
||||
// Stored file failed to decode (corrupted/unsupported) - fall back to the default chime.
|
||||
}
|
||||
}
|
||||
player.playSynth(event, volume);
|
||||
}
|
||||
@@ -24,8 +24,19 @@ function base64ToInt16(b64: string): Int16Array {
|
||||
return new Int16Array(bytes.buffer);
|
||||
}
|
||||
|
||||
/** How long transmission continues after the level drops back below the threshold, so words aren't clipped. */
|
||||
const VAD_HANGOVER_SECONDS = 0.4;
|
||||
export interface MicCaptureOptions {
|
||||
onFrame: (base64Pcm: string) => void;
|
||||
onActivity?: (active: boolean) => void;
|
||||
/** Reports the raw input RMS (roughly 0-1) on every processing tick, for live level meters. */
|
||||
onLevel?: (rms: number) => void;
|
||||
threshold?: number;
|
||||
/** How long transmission continues after the level drops back below the threshold, so words aren't clipped. */
|
||||
hangoverSeconds?: number;
|
||||
/** `MediaDeviceInfo.deviceId` of the input device to use - omit for the system default. */
|
||||
deviceId?: string;
|
||||
echoCancellation?: boolean;
|
||||
noiseSuppression?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the microphone and emits base64-encoded mono 16-bit PCM frames.
|
||||
@@ -40,24 +51,48 @@ export class MicCapture {
|
||||
private source: MediaStreamAudioSourceNode | null = null;
|
||||
private processor: ScriptProcessorNode | null = null;
|
||||
private silence: GainNode | null = null;
|
||||
private monitorTarget: AudioNode | null = null;
|
||||
private pending: number[] = [];
|
||||
private active = false;
|
||||
private activeUntil = 0;
|
||||
private onFrame: (base64Pcm: string) => void;
|
||||
private onActivity?: (active: boolean) => void;
|
||||
private onLevel?: (rms: number) => void;
|
||||
private deviceId?: string;
|
||||
private echoCancellation: boolean;
|
||||
private noiseSuppression: boolean;
|
||||
private context: AudioContext;
|
||||
threshold: number;
|
||||
hangoverSeconds: number;
|
||||
|
||||
constructor(
|
||||
private context: AudioContext,
|
||||
private onFrame: (base64Pcm: string) => void,
|
||||
private onActivity?: (active: boolean) => void,
|
||||
threshold = 0.02
|
||||
) {
|
||||
this.threshold = threshold;
|
||||
constructor(context: AudioContext, options: MicCaptureOptions) {
|
||||
this.context = context;
|
||||
this.onFrame = options.onFrame;
|
||||
this.onActivity = options.onActivity;
|
||||
this.onLevel = options.onLevel;
|
||||
this.threshold = options.threshold ?? 0.02;
|
||||
this.hangoverSeconds = options.hangoverSeconds ?? 0.3;
|
||||
this.deviceId = options.deviceId;
|
||||
this.echoCancellation = options.echoCancellation ?? true;
|
||||
this.noiseSuppression = options.noiseSuppression ?? true;
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
if (!navigator.mediaDevices) {
|
||||
throw new Error("Microphone access requires HTTPS (or localhost) - the site is not a secure context.");
|
||||
}
|
||||
this.stream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true },
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
echoCancellation: this.echoCancellation,
|
||||
noiseSuppression: this.noiseSuppression,
|
||||
...(this.deviceId ? { deviceId: { exact: this.deviceId } } : {}),
|
||||
},
|
||||
});
|
||||
// Granting the permission prompt counts as a user gesture, so this can
|
||||
// succeed even when start() was triggered automatically on page load,
|
||||
// before the AudioContext would otherwise be allowed to leave "suspended".
|
||||
if (this.context.state === "suspended") await this.context.resume();
|
||||
this.source = this.context.createMediaStreamSource(this.stream);
|
||||
this.processor = this.context.createScriptProcessor(2048, 1, 1);
|
||||
this.processor.onaudioprocess = (event) => {
|
||||
@@ -66,9 +101,10 @@ export class MicCapture {
|
||||
let sumSquares = 0;
|
||||
for (let i = 0; i < input.length; i++) sumSquares += input[i] * input[i];
|
||||
const rms = Math.sqrt(sumSquares / input.length);
|
||||
this.onLevel?.(rms);
|
||||
|
||||
const now = this.context.currentTime;
|
||||
if (rms >= this.threshold) this.activeUntil = now + VAD_HANGOVER_SECONDS;
|
||||
if (rms >= this.threshold) this.activeUntil = now + this.hangoverSeconds;
|
||||
const shouldBeActive = now < this.activeUntil;
|
||||
if (shouldBeActive !== this.active) {
|
||||
this.active = shouldBeActive;
|
||||
@@ -98,7 +134,27 @@ export class MicCapture {
|
||||
this.silence.connect(this.context.destination);
|
||||
}
|
||||
|
||||
/** The raw mic input node, e.g. to additionally route it into a recorder. */
|
||||
getSourceNode(): AudioNode | null {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/** Routes the raw mic signal to `destination` too, so you can hear yourself (a mic test), until disabled again. */
|
||||
setMonitoring(enabled: boolean, destination: AudioNode): void {
|
||||
if (!this.source) return;
|
||||
if (enabled && this.monitorTarget !== destination) {
|
||||
if (this.monitorTarget) this.source.disconnect(this.monitorTarget);
|
||||
this.source.connect(destination);
|
||||
this.monitorTarget = destination;
|
||||
} else if (!enabled && this.monitorTarget) {
|
||||
this.source.disconnect(this.monitorTarget);
|
||||
this.monitorTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
if (this.source && this.monitorTarget) this.source.disconnect(this.monitorTarget);
|
||||
this.monitorTarget = null;
|
||||
this.processor?.disconnect();
|
||||
this.silence?.disconnect();
|
||||
this.source?.disconnect();
|
||||
@@ -115,16 +171,64 @@ export class MicCapture {
|
||||
}
|
||||
}
|
||||
|
||||
function writeAsciiString(view: DataView, offset: number, text: string): void {
|
||||
for (let i = 0; i < text.length; i++) view.setUint8(offset + i, text.charCodeAt(i));
|
||||
}
|
||||
|
||||
/** Encodes raw stereo float samples (range -1..1) as an uncompressed 16-bit PCM WAV file. */
|
||||
export function encodeWavStereo(left: Float32Array, right: Float32Array, sampleRate: number): Blob {
|
||||
const numChannels = 2;
|
||||
const bytesPerSample = 2;
|
||||
const blockAlign = numChannels * bytesPerSample;
|
||||
const dataSize = left.length * blockAlign;
|
||||
const buffer = new ArrayBuffer(44 + dataSize);
|
||||
const view = new DataView(buffer);
|
||||
|
||||
writeAsciiString(view, 0, "RIFF");
|
||||
view.setUint32(4, 36 + dataSize, true);
|
||||
writeAsciiString(view, 8, "WAVE");
|
||||
writeAsciiString(view, 12, "fmt ");
|
||||
view.setUint32(16, 16, true);
|
||||
view.setUint16(20, 1, true); // PCM
|
||||
view.setUint16(22, numChannels, true);
|
||||
view.setUint32(24, sampleRate, true);
|
||||
view.setUint32(28, sampleRate * blockAlign, true);
|
||||
view.setUint16(32, blockAlign, true);
|
||||
view.setUint16(34, 16, true);
|
||||
writeAsciiString(view, 36, "data");
|
||||
view.setUint32(40, dataSize, true);
|
||||
|
||||
let offset = 44;
|
||||
for (let i = 0; i < left.length; i++) {
|
||||
const l = Math.max(-1, Math.min(1, left[i]));
|
||||
const r = Math.max(-1, Math.min(1, right[i]));
|
||||
view.setInt16(offset, l < 0 ? l * 0x8000 : l * 0x7fff, true);
|
||||
view.setInt16(offset + 2, r < 0 ? r * 0x8000 : r * 0x7fff, true);
|
||||
offset += blockAlign;
|
||||
}
|
||||
|
||||
return new Blob([buffer], { type: "audio/wav" });
|
||||
}
|
||||
|
||||
/** Output ("audiooutput") devices available for playback, e.g. for a device picker. */
|
||||
export async function listAudioOutputDevices(): Promise<MediaDeviceInfo[]> {
|
||||
if (!navigator.mediaDevices) return [];
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
return devices.filter((d) => d.kind === "audiooutput");
|
||||
}
|
||||
|
||||
/** Input ("audioinput") devices available for the mic, e.g. for a device picker. */
|
||||
export async function listAudioInputDevices(): Promise<MediaDeviceInfo[]> {
|
||||
if (!navigator.mediaDevices) return [];
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
return devices.filter((d) => d.kind === "audioinput");
|
||||
}
|
||||
|
||||
type MediaDevicesWithPicker = MediaDevices & { selectAudioOutput?: () => Promise<MediaDeviceInfo> };
|
||||
|
||||
/** Whether the browser supports the native OS output-device picker (Chrome/Edge 105+). */
|
||||
export function hasNativeOutputPicker(): boolean {
|
||||
if (!navigator.mediaDevices) return false;
|
||||
return typeof (navigator.mediaDevices as MediaDevicesWithPicker).selectAudioOutput === "function";
|
||||
}
|
||||
|
||||
@@ -135,6 +239,7 @@ export function hasNativeOutputPicker(): boolean {
|
||||
* the user to pick one, each call - no persistent listing to keep in sync.
|
||||
*/
|
||||
export async function pickAudioOutputDevice(): Promise<MediaDeviceInfo | null> {
|
||||
if (!navigator.mediaDevices) return null;
|
||||
const md = navigator.mediaDevices as MediaDevicesWithPicker;
|
||||
if (typeof md.selectAudioOutput !== "function") return null;
|
||||
return md.selectAudioOutput();
|
||||
@@ -159,9 +264,14 @@ export class AudioPlayer {
|
||||
private nextTime = 0;
|
||||
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);
|
||||
this.element = document.createElement("audio") as SinkableElement;
|
||||
this.element.autoplay = true;
|
||||
this.element.srcObject = this.destination.stream;
|
||||
@@ -184,7 +294,7 @@ export class AudioPlayer {
|
||||
|
||||
const source = this.context.createBufferSource();
|
||||
source.buffer = buffer;
|
||||
source.connect(this.destination);
|
||||
source.connect(this.gain);
|
||||
|
||||
const now = this.context.currentTime;
|
||||
if (this.nextTime < now + 0.02) {
|
||||
@@ -200,6 +310,34 @@ export class AudioPlayer {
|
||||
this.nextTime = 0;
|
||||
}
|
||||
|
||||
/** Playback volume as linear gain (1 = unity/0dB). */
|
||||
setVolume(gain: number): void {
|
||||
this.gain.gain.value = gain;
|
||||
}
|
||||
|
||||
/** The node all voice/test audio ultimately reaches - use as a mic-monitoring target so it also respects volume/output device. */
|
||||
getInputNode(): AudioNode {
|
||||
return this.gain;
|
||||
}
|
||||
|
||||
/** Plays a short sine-wave test tone through the same volume/output-device routing as voice playback. */
|
||||
playTestTone(): void {
|
||||
const osc = this.context.createOscillator();
|
||||
osc.type = "sine";
|
||||
osc.frequency.value = 440;
|
||||
const toneGain = this.context.createGain();
|
||||
toneGain.gain.value = 0.3;
|
||||
osc.connect(toneGain);
|
||||
toneGain.connect(this.gain);
|
||||
const now = this.context.currentTime;
|
||||
osc.start(now);
|
||||
osc.stop(now + 0.6);
|
||||
osc.onended = () => {
|
||||
osc.disconnect();
|
||||
toneGain.disconnect();
|
||||
};
|
||||
}
|
||||
|
||||
/** Routes playback to a specific device (empty string = system default). */
|
||||
async setOutputDevice(deviceId: string): Promise<void> {
|
||||
if (typeof this.element.setSinkId === "function") {
|
||||
|
||||
@@ -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 || '/',
|
||||
})
|
||||