26 KiB
TeamsPeach core bridge — protocol v1
Contract between the Electron main process and the native protocol core
(teamspeach-core, Rust, built on ReSpeak tsclientlib). The renderer never talks
to the core directly: main forwards only the commands listed here, after checking
cmd against this allowlist and argument shapes.
1. Process model
teamspeach-core --data-dir <ABSOLUTE_DIR>
--data-diris resolved and passed only by main (e.g.<userData>/core). The core creates it if missing. One core process per data dir: the core takes an exclusive lock (<data-dir>/core.lock); a second instance fails at startup with exit code 3 and a stderr message.- stdin: UTF-8, one JSON object per line (
\n,\r\ntolerated). Max line 256 KiB; a longer line is discarded up to its newline and answered with anerroreventbad_request(noidcan be recovered). - stdout: UTF-8, one JSON object per line. Nothing else is ever written to stdout.
- stderr: human-readable logs only (never parse). Verbosity: env
TEAMSPEACH_LOG(error|warn|info|debug|trace, tracing filter syntax), defaultinfo. - stdin EOF or
shutdowncommand → graceful disconnect (if connected), then exit 0. - Exit codes:
0clean,2bad CLI arguments,3data dir locked/unusable,1fatal internal error. - Windows dev binary:
core/target/release/teamspeach-core.exe(debug:core/target/debug/teamspeach-core.exe). Packaged:resources/core/teamspeach-core[.exe].
The first stdout line is always:
{"event":"ready","protocol":1,"core_version":"0.1.0"}
2. Framing
Request (stdin):
{"id":"r1","cmd":"connect","args":{"address":"10.10.10.160:9987"}}
id: string, 1–64 chars, chosen by main; echoed in the response. Required for every command exceptaudio_frameandaudio_end(high-rate, never answered; anidthere is ignored).cmd: one of the commands in §4. Unknowncmd→unknown_command.args: object; may be omitted when a command takes no arguments. Unknown argument keys are rejected (bad_request).
Response (stdout), exactly one per request with id:
{"id":"r1","ok":true,"result":{}}
{"id":"r1","ok":false,"error":{"code":"not_connected","message":"..."}}
Event (stdout), no id, discriminated by event:
{"event":"state","state":"connected", ...}
A line is a response iff it has an id key; otherwise it is an event.
Events may be emitted before the response of the command that caused them
(e.g. state: connecting precedes the connect response).
3. Error object
{"code": string, "message": string, "ts_error"?: {"id": number, "name": string, "missing_permission"?: number}, "detail"?: object}
ts_error is present when the TeamSpeak server rejected a command: numeric TeamSpeak
error id and tsclientlib's name for it (live example: send_text to a channel without
permission → {"id":2568,"name":"PermissionsClientInsufficient","missing_permission":224}).
detail carries structured extra state where stated (e.g. rename).
Repository-authored message text and stderr diagnostics are English technical details, not UI
translation keys. The renderer selects a localized explanation by stable code and may append the
technical detail. Do not translate protocol tokens, server-supplied text or user content, and do not
branch on human-readable message wording.
| code | meaning |
|---|---|
bad_request |
malformed JSON, missing/unknown/invalid argument, bad id |
unknown_command |
cmd not in allowlist |
profile_missing |
no identity yet → call profile_create |
profile_exists |
profile_create when an identity already exists (never overwritten) |
identity_corrupt |
identity file unreadable/invalid/UID mismatch. Core never regenerates; user/main must resolve (restore backup / import) |
profile_corrupt |
profile (nickname) file unreadable/invalid |
invalid_nickname |
nickname rule violated (§4.3) |
nickname_required |
identity exists but no nickname saved (connect refused) |
not_connected |
command needs an active connection |
already_connected |
connect while connecting/connected |
connect_failed |
could not connect (resolve, timeout, server refused …; ts_error when the server sent one) |
server_error |
server answered a command with an error (ts_error set) |
audio_format |
audio_frame.pcm not 1920 bytes after base64 decode |
audio_overflow |
outgoing PCM queue full, oldest frames dropped (event, throttled ≤1/s) |
audio_muted |
audio_frame while input or output muted; frames discarded (event, once per burst) |
audio_codec |
Opus encode/decode failure (event) |
audio_codec_unsupported |
current channel codec is not Opus (legacy Speex/CELT): we cannot transmit there (event, once per burst); received non-Opus voice is reported once per speaker |
rename_not_persisted |
server accepted the new nickname but saving it failed; see §4.3 |
not_found |
requested icon/avatar/banner does not exist (detail.builtin:true for built-in icon ids) |
media_too_large |
file exceeds the size limit of its kind (§4.17) |
media_unsupported |
file is not a recognized image, or a banner reference the core cannot fetch |
external_media |
banner or avatar lives at an https:// URL (detail.url for banners, detail.urls for avatars); main may fetch it itself |
io |
data dir I/O failure |
internal |
bug; message has details |
Asynchronous failures (not tied to a request) are emitted as
{"event":"error","error":{...}}.
4. Commands
4.1 profile_get — no args
Result = profile object:
{"exists":true,"uid":"Zx1...base64...=","nickname":"Alice","security_level":8}
{"exists":false,"uid":null,"nickname":null,"security_level":null}
uid is the permanent public TeamSpeak unique identifier (base64 SHA-1 of the
public key). The private key is never sent over the bridge.
If the identity exists but no nickname is saved: exists:true, nickname:null
(UI should prompt and call rename). Corrupt files → error identity_corrupt /
profile_corrupt.
4.2 profile_create — {nickname: string}
Generates a new P-256 identity (security level ≥ 8), persists it privately, saves
the nickname. Fails with profile_exists if any identity exists. Result = profile object.
Also emits {"event":"profile", ...profile object}.
4.3 rename — {nickname: string}
Persists the nickname. UID never changes.
- Disconnected: validate → atomically save
profile.json→ result. - Connected: send
clientupdate client_nicknameand wait for the server's answer. Server rejects (e.g. nickname in use) →server_error, nothing saved, nothing changed. Server accepts → save atomically. If saving fails, the core immediately sendsclientupdateback to the saved nickname and answersrename_not_persistedwithdetail: {"saved_nickname": "<still on disk>", "server_nickname": "<what the server shows now>", "reverted": bool}(reverted:false= revert also failed; the server keeps the new name for this session only).
Result = profile object; emits profile event.
Nickname rules: after trimming, 3–30 Unicode scalar values, no control characters.
4.4 connect — {address, server_password?, channel?, channel_password?}
address:host,host:port,[v6]:port(default port 9987). Not a path.server_password: optional string.channel: optional initial channel, either numeric channel id string"cid:12"or a path"Parent/Child".- Uses the persisted identity and nickname (
profile_missing/nickname_requiredotherwise). If the nickname is taken on the server, the server appends digits (e.g.Name1); the snapshot shows the server-side name, the profile keeps the saved one. - After connecting the core subscribes to all channels (
channelsubscribeall), so the snapshot lists clients in every channel.
Emits state: connecting, then on success snapshot, audio_state, state: connected,
then the response {"ok":true,"result":{"own_client_id":7}}. On failure the response is
connect_failed and state: disconnected with reason.
4.5 disconnect — {message?: string}
Sends a clean clientdisconnect and waits (≤ 3 s) for the server. Result
{"clean": true} when the server confirmed, {"clean": false} on timeout or when a
pending connect attempt was abandoned. not_connected if idle. Emits
state: disconnecting → state: disconnected.
4.6 join_channel — {channel_id: number, password?: string}
Moves self (clientmove). Result {} after the server confirms; snapshot follows.
4.7 send_text — {target: "channel"|"server"|"client", client_id?: number, message: string}
client_id required iff target = "client". Message 1–8192 bytes UTF-8;
TeamSpeak escaping is done by the core. Result {} after server confirmation.
The server echoes our own messages as text events (verified live for private messages:
the sender receives exactly one text with to_client_id = recipient); the core adds no
synthetic echo.
4.8 set_audio — {input_muted?: bool, output_muted?: bool}
input_muted = mute microphone, output_muted = deafen. Updates the server-visible
flags (client_input_muted / client_output_muted) when connected, and the core-side
gates: while input_muted || output_muted outgoing frames are discarded; while
output_muted no audio events are emitted. Allowed when disconnected (applied at
next connect). Result = audio state object; emits audio_state.
Initial state at process start: both false.
4.9 audio_frame — {pcm: string} (no id, no response)
One 20 ms microphone frame: base64 (standard alphabet, padded) of 960 signed
16-bit little-endian mono samples at 48 kHz = 1920 bytes (2560 base64 chars).
In transmit mode direct (see 4.11) the renderer decides: it sends frames only while
push-to-talk is held or the open microphone is on, and audio_end when it stops; the core
sends every frame. In mode vad the renderer sends frames continuously while connected and
not muted, and the core's voice detector decides which are sent. The core Opus-encodes 20 ms
frames with the current channel's codec: Opus Voice (mono) or Opus Music (stereo — the
mono frame is duplicated to both channels). Legacy Speex/CELT channels →
audio_codec_unsupported event and nothing is sent. Outgoing queue bound: 10 frames
(200 ms); on overflow the oldest frames are dropped (audio_overflow event).
If no frame arrives for 200 ms during a burst the core ends the burst itself.
Not connected → frames dropped with one not_connected error event per burst. Muted,
deafened, or not allowed to talk by the server → frames dropped with one audio_muted event
per burst; in mode vad the detector state and preroll are discarded as well.
4.10 audio_end — no args (no id, no response)
Ends the current transmission burst (core sends the TeamSpeak end-of-voice packet). In mode
vad it also discards the detector state and preroll (capture stopped or the renderer stopped
forwarding).
4.11 set_transmit — {mode: "direct"|"vad", sensitivity?: "high"|"normal"|"low"}
Selects who decides when voice is sent. direct (initial state at process start): every
forwarded frame is sent. vad: voice activation in the core (core/src/vad.rs): frames are
decimated to 16 kHz and scored by the earshot voice detector (embedded model, 16 ms windows,
probability 0–1). The gate opens after 3 consecutive windows at or above the threshold
(high 0.45, normal 0.6 — default, low 0.75) and sends the 5 frames (100 ms) held before
the onset, then the current frame. While open, a window counts as voiced down to 0.15 below the
threshold; the gate closes 20 frames (400 ms) after the last voiced frame. It cannot open
during the first 10 frames after a reset; until the first spurt after a reset all frames since it are held
(at most 15 = 300 ms) and sent before the current one, later spurts send 5. Detector, filter history and preroll are reset on
every set_transmit, audio_end, mute/deafen, disconnect, channel or codec change and when
the server does not allow talking. sensitivity is accepted only with vad.
Before answering, the core discards frames still queued from the previous mode and ends any
open burst; the renderer forwards nothing until it has this answer.
Result {"mode":"direct"} or {"mode":"vad","sensitivity":"normal"}. audio_state.transmitting
is true only while voice packets are actually being sent.
4.12 stream_list — {client_id?: number}
TS6 screenshare discovery. Sends requeststreaminfo clid=<id> for client_id, or for
every other client in our current channel when omitted. Result:
{"results":[{"client_id":5,"ok":true},{"client_id":9,"ok":false,"ts_error":{"id":...}}]}
Live behaviour (TS6 6.0.0-beta13.1): every requeststreaminfo is answered ok, plus one
stream event notifystreaminfo per request. For a streaming client the item carries
id (stream UUID), clid, name, type, mode, accessibility, audio, bitrate,
viewer, viewer_limit; for a non-streaming client the item has only return_code.
So: "is streaming" ⇔ the notifystreaminfo item has id.
4.13 stream_join — {stream_id: string, client_id: number, message?: string}
Sends joinstreamrequest id=<stream_id> clid=<client_id> msg=<message|our nickname> is_remove=0.
Result {} (or server_error). The SDP offer arrives as stream event
notifyrespondjoinstreamrequest (decision=1, offer=<sdp>).
4.14 stream_signal — {stream_id: string, client_id: number, json: object}
Sends streamsignaling id=<stream_id> clid=<client_id> json=<compact JSON of json>.
Examples of json: {"cmd":"answer","args":{"answer":"<sdp>"}},
{"cmd":"iceCandidate","args":{"mLine":0,"mid":"0","sdp":"candidate:..."}}.
Max serialized json size 60 KiB (the whole stdin line is capped at 256 KiB). Result {} or server_error.
4.15 stream_leave — {stream_id: string, client_id: number}
Sends joinstreamrequest id=… clid=… msg= is_remove=1. Result {}.
4.16 shutdown — no args
Disconnects cleanly if needed, responds {}, exits 0.
4.17 Media: fetch_icon, fetch_avatar, fetch_banner, fetch_server_banner
Read-only downloads over TeamSpeak file transfer from the connected server. No paths cross the bridge: the core derives the server file from ids it already knows.
| command | args | server file | limit |
|---|---|---|---|
fetch_icon |
{icon_id: number} (u32, non-zero) |
/icon_<id> in the server root |
256 KiB |
fetch_avatar |
{client_id: number} |
/avatar_<uid> of that visible client (needs avatar_hash); myTeamSpeak-only avatar → external_media with detail.urls:[{variant,url}] |
1 MiB |
fetch_banner |
{channel_id: number} |
file referenced by the channel's banner_url |
4 MiB |
fetch_server_banner |
— | file referenced by server.hostbanner_gfx_url |
4 MiB |
Result: {"mime":"image/png","bytes":108726,"data":"<base64>"}. mime is sniffed from the
bytes (image/png|jpeg|gif|webp|x-icon|svg+xml); anything else → media_unsupported.
Render only via <img>/canvas (SVG included). Cache by icon_id / avatar_hash / URL.
- Icon ids 100, 200, 300, 500, 600 are TeamSpeak's default group icons that clients ship;
servers have no file for them (verified live for each: error 2054
FileInvalidPath), so the core answersnot_foundwithdetail.builtin:truewithout asking. Draw built-in glyphs. Every other id is requested from the server. - Banners:
ts3image://<host>?port=<p>&channel=<cid>&path=<dir>&filename=<name>references are fetched from that channel's file area on the connected server (port must match;../backslashes/control characters rejected).http(s)://→external_mediawithdetail.urlfor main to fetch (untrusted URL). - At most 3 transfers run at once (the rest queue); each has a 20 s deadline (
ioerror). Server refusals surface asserver_errorwithts_error.
5. Events
ready
See §1.
profile
{"event":"profile","exists":true,"uid":"...","nickname":"...","security_level":8} — after
profile_create / rename.
state
{"event":"state","state":"connecting|connected|disconnecting|disconnected",
"address":"10.10.10.160:9987","reason":{"code":"...","message":"...","ts_error":{...}}}
reason only on disconnected when not user-initiated (kicked, banned, timeout,
server shutdown, connect failure) and on an automatic-reconnect connecting. For a
server-closed connection reason.detail.reason is one of kicked, banned,
server_shutdown, timeout, connection_closed. tsclientlib reconnects automatically
after a timeout: connecting may then follow connected without a connect command.
snapshot
Full replacement of the server view, emitted after connect and after every change (coalesced, ≤ 1 per 50 ms). The UI must replace its model wholesale.
{"event":"snapshot","rev":12,
"server":{"name":"...","welcome_message":"...","platform":"...","version":"...",
"icon_id":null,"hostbanner_url":null,"hostbanner_gfx_url":"ts3image://…",
"hostbanner_gfx_interval_s":0,"hostbanner_mode":"adjust_keep_aspect",
"hostbutton_url":null,"hostbutton_gfx_url":null,"hostbutton_tooltip":null,
"default_server_group":8,"default_channel_group":8},
"own_client_id":7,"own_channel_id":1,
"server_groups":[{"id":10,"name":"…","icon_id":3558086607,"sort_id":0,
"name_mode":"after","type":"regular"}],
"channel_groups":[{"id":5,"name":"Channel Admin","icon_id":100,"sort_id":0,
"name_mode":"none","type":"regular"}],
"channels":[{"id":1,"parent_id":0,"order":0,"name":"Lobby","topic":"",
"has_password":false,"is_default":true,"max_clients":null,
"needed_talk_power":0,"codec":"opus_voice","codec_quality":6,
"icon_id":1775712350,"banner_url":"ts3image://…","banner_mode":2,"depth":0}],
"clients":[{"id":7,"uid":"...","nickname":"Alice","channel_id":1,"is_self":true,
"client_type":"normal","input_muted":false,"output_muted":false,
"input_hardware":true,"output_hardware":true,"away":false,
"away_message":null,"talk_power":0,"is_talker":false,
"is_channel_commander":false,"is_priority_speaker":false,"is_recording":false,
"is_streaming":false,"description":null,"country":"RU","server_groups":[7,10],
"channel_group_id":8,"channel_group_inherited_from":20,"avatar_hash":null,
"has_myts":true,"myts_avatars":[{"variant":2,"url":"https://storage.googleapis.com/ts-sys-myts-avatars/…"}],
"myts_avatar_unparsed":null,"icon_id":null,"badges":null}]}
channelsis in display order (pre-order tree walk following TeamSpeakorder);depth= nesting level.max_clients: null= unlimited.codec:"opus_voice","opus_music","speex_narrowband","speex_wideband","speex_ultrawideband","celt_mono"ornullif unknown. Only Opus channels can transmit; the UI should show the reason for others.client_type:"normal"or"query".uidmay benullif not visible.icon_id: TeamSpeak icon id ornull(0 = none). Fetch withfetch_icon(§4.17).- Groups:
server_groups/channel_groupsare the server's group catalogs (sent to every client on connect; sorted bysort_id, thenid). A client'sserver_groupsandchannel_group_idreference them.name_mode(none|before|after) is TeamSpeak's "show group name in tree" setting: live, the label shown next to a nickname by the official client is the name of a server group withname_mode:"after"(verified: a client with groups[7,10], group 10name_mode:"after"→ that group's name is the label). Group icons are drawn fromicon_id.type:template|regular|query. country: ISO code ornull(flag).description: client description ornull.badges: raw myTeamSpeak badges string (not groups) ornull.- Avatars, in the official client's precedence:
avatar_hashnon-null → server-stored avatar (fetch_avatar); otherwisemyts_avatars(TeamSpeak 6 / myTeamSpeak,client_myteamspeak_avatar=<variant>,<https url>; live: variant 2 onstorage.googleapis.com/ts-sys-myts-avatars/…, publicly readable without an account, served asContent-Type: text/plainbut PNG bytes → main must sniff, not trust the header). Multiple pairs are accepted separated by;/|(only one pair observed). A value the core cannot parse is passed asmyts_avatar_unparsed.has_myts= the client has a myTeamSpeak id (nullif not sent). Neither set → default avatar. - Deliberately not exposed:
client_user_tag(live it carries a signedmyts_tokenand the account handle) andclient_myteamspeak_id(account id; onlyhas_myts). - Nickname colour: no colour field was observed in
notifycliententerviewon this server (checkedclient_user_tag,client_integrations,client_badges,client_signed_badges,client_meta_data); the snapshot has none. is_streaming: TeamSpeak 6client_is_streamingflag (nullif the server did not send it). Confirm/obtain the stream id withstream_list.- Channel
banner_url/banner_mode(int) are the TS5/6 channel banner properties,nullwhen unset; fetch withfetch_banner. Serverhostbanner_*likewise viafetch_server_banner. All strings here are server-controlled, untrusted input.
audio_state
{"event":"audio_state","input_muted":false,"output_muted":false,"transmitting":false}
talking
{"event":"talking","client_id":5,"talking":true} — start/stop of a remote speaker's
voice stream (also for self: transmitting in audio_state).
audio
{"event":"audio","pcm":"<base64 1920 bytes>","speakers":[5,9]} — mixed playback,
960 i16le mono samples at 48 kHz, emitted on a 20 ms clock only while someone is
audible and output is not muted. Per-speaker jitter buffering and Opus decoding
(incl. packet-loss concealment) happen in the core. The renderer should keep a small
playback ring (target 40–60 ms, drop oldest beyond ~200 ms, play silence on underrun).
text
{"event":"text","target":"channel|server|client|poke","from_client_id":5,
"from_uid":"...","from_nickname":"Bob","message":"hi","to_client_id":7}
to_client_id only for target:"client" (recipient: our id for incoming, the peer for
our own echoed message). poke = a TeamSpeak poke addressed to us.
stream
Raw TS6 screenshare notifications, lifted from the protocol layer before tsclientlib would discard them:
{"event":"stream","name":"notifystreamsignaling",
"items":[{"id":"…","clid":"5","json":"{\"cmd\":\"offer\",…}"}]}
name∈ everynotifystream*notification (notifystreaminfo,notifystreamstarted,notifystreamstopped,notifystreamupdated,notifystreamsignaling,notifystreamclientjoined,notifystreamclientleft,notifystreamattendees, …),notifyjoinstreamrequest,notifyrespondjoinstreamrequest, andnotifysfuaccessinfo. TeamsPeach supports only the P2P path: onnotifysfuaccessinfo(SFU/mediasoup stream) the UI must report "SFU streams are not supported" instead of "no stream". The core never logs stream payloads (SDP/ICE/tokens).items: one map per|-separated entry; keys and values are unescaped strings (JSON/SDP stay raw strings — parse them in the renderer). Flags without value →"".
error
{"event":"error","error":{...}} — asynchronous error (see §3).
6. Identity storage (main-only concern)
Files in --data-dir (never sent over the bridge):
identity.json— private key + key offset + UID; written at creation (atomic temp+rename), never rewritten byrename. Only when a server demands a higher security level does the core rewrite it with the larger key offset (same key, same UID; checked before writing). Permissions: owner-only (Unix0600; Windows protected DACL granting only the current user).profile.json— nickname; rewritten atomically byrename.core.lock— instance lock.
On load the UID is recomputed from the key and must match the stored UID; any
mismatch or parse failure → identity_corrupt (no regeneration).
Backup/migration is not a bridge command (no paths cross stdin). Main runs the binary separately with the core process stopped:
teamspeach-core identity export --data-dir <DIR> --out <FILE>
teamspeach-core identity import --data-dir <DIR> --in <FILE> [--replace]
<FILE> comes from main's native dialog. Exit 0 on success with one JSON line on
stdout ({"ok":true,"uid":"..."}), else non-zero and {"ok":false,"error":{...}}.
import refuses to overwrite an existing identity unless --replace. Export file
format: TeamSpeak-compatible ini ([Identity], id, identity="<offset>V<key>",
nickname) — contains the private key; the core creates it owner-only (same permissions as
identity.json, atomic write next to <FILE>).
7. Build prerequisites
All platforms: Rust stable ≥ 1.89 (rustup), CMake (any version; .cargo/config.toml (repository root; cargo reads config from the working directory, so run cargo from the repo root or below)
sets CMAKE_POLICY_VERSION_MINIMUM=3.5 for CMake ≥ 4 and forces the bundled libopus to be
built and linked statically: LIBOPUS_STATIC=1, LIBOPUS_NO_PKG=1), a C compiler, and
network access to crates.io and github.com (tsclientlib git dependencies at the pinned
revision, including its tsdeclarations submodule, fetched by cargo).
- Windows: target
x86_64-pc-windows-msvc, Visual Studio Build Tools (MSVC) + Windows SDK. The VS-bundled CMake must know the installed VS generator (with VS 18/2026 installed use the VS 18 CMake 4.x; VS 2022's CMake 3.31 fails with "Could not create named generator"). - Linux/macOS:
cc/c++toolchain and CMake; no system libopus needed. - Build:
cargo build --release --locked --manifest-path core/Cargo.toml→core/target/release/teamspeach-core[.exe]. On memory-constrained machines add-j 2(full parallelism exhausted the Windows commit limit here: link.exe0xc000012d). - Tests:
cargo test --locked --manifest-path core/Cargo.toml(unit tests + offline stdio smoke of the built binary; no network). - tsclientlib is vendored with a small patch (
core/vendor/README.md); third-party notices:core/THIRD_PARTY_NOTICES.md(regenerate withpython core/tools/third_party_notices.py).