Low-Latency Streaming Kit

Self-hosted real-time video: one Go binary (signaling + SFU) plus a browser publisher, a viewer with automatic recovery, and a live diagnostics panel.

Documentation version 1.0 — corresponds to kit version 0.1.1.

Contents
  1. What this kit is
  2. Requirements
  3. Quick start (5 minutes, local)
  4. A tour of the pages
  5. Configuration reference
  6. Deploying to a real server
  7. Adding a TURN relay
  8. Integrating it into your own product
  9. Customising the look
  10. Troubleshooting
  11. Known limits
  12. Credits and third-party assets
  13. Support

1. What this kit is

WebRTC lets two browsers send video to each other directly, but a real product needs a server: something has to exchange the connection details, and when one sender has many viewers, something has to forward the media. This kit is that server plus a working browser client, written so you can read it.

It contains four pieces:

The room model is deliberately simple: one publisher, many viewers. That covers "show me what you see" support, one-to-many broadcast, and remote assistance. It is not a multi-party conferencing product.

2. Requirements

3. Quick start (5 minutes, local)

cd server
go run ./cmd/kitserver

The server prints the address it is listening on. By default that is http://localhost:18080/. It finds the web directory on its own if you run it from inside server/.

Now open http://localhost:18080/test/v2/. You should see a canvas on the left and the same picture on the right, with the badge reading PASS within a couple of seconds. That page needs no camera and no second tab — if it passes, the server and the browser are talking to each other correctly.

Why start here. Most WebRTC problems are connectivity problems, not code problems. The self-test removes the camera and the second browser from the equation, so you find out immediately whether the failure is in your setup or in your network.

4. A tour of the pages

PageWhat it does
/test/v2/ Canvas → server → playback. No camera needed. This is the end-to-end proof.
/publisher/ Publishes a camera, a screen share, or the built-in demo source.
/viewer/ Plays the room and shows the diagnostics panel. Reconnects on its own.
/test/turn/ Checks whether a TURN relay can actually be allocated from your network.
/test/ The first-generation self-test. Superseded by /test/v2/; kept because it is a simpler read.

To see the interesting part, open /publisher/ and /viewer/ in two tabs with the same room name, start the stream, and then disconnect your network for a few seconds. The viewer performs an ICE restart first; if that has not recovered within about five seconds it does a full rejoin. The diagnostics panel reports which of the two happened, so "it reconnected" is a fact you can point at rather than a guess.

5. Configuration reference

Everything is a command-line flag. There is no configuration file to hunt for.

FlagDefaultWhat it does
-addr:18080Listen address.
-webautoStatic site directory. Auto-detects ./web or ../web.
-stunemptySTUN server, for example stun:stun.l.google.com:19302. Needed once clients are not on the same machine.
-turn, -turn-user, -turn-pass emptyRelay URL and long-term credentials, for example -turn turn:turn.example.com:3478. The server advertises the relay to every browser automatically; no frontend change is needed.
-udp-port-min, -udp-port-max0 (ephemeral) Pins the media UDP port range, so a firewall or cloud security group only has to allow one block.
-public-ipemptyThe public IP to advertise when the machine only has a private address. Essential on most cloud VMs — see section 6.
-leadsleads.jsonlWhere the optional POST /api/waitlist endpoint appends signups, one JSON object per line. Remove or ignore it if you do not want that endpoint.

Example with a fixed media port range and a public IP:

go run ./cmd/kitserver \
  -stun stun:stun.l.google.com:19302 \
  -udp-port-min 50000 -udp-port-max 51000 \
  -public-ip 203.0.113.10

6. Deploying to a real server

The detailed walkthrough is in deploy/README.md inside the package. The short version, and the two things that catch almost everyone:

Ports

Only the pages and the signaling WebSocket travel over TCP 443. The video does not go over HTTPS. It is direct UDP from the browser to your server. If your firewall or cloud security group does not allow that UDP range, the pages load, the logs look fine, and no picture ever arrives.

PortProtocolPurpose
80TCPCertificate issuance and renewal.
443TCPPages and signaling.
50000–51000UDPMedia. Must match -udp-port-min/-udp-port-max.

The private-IP trap

On Aliyun, AWS, Tencent Cloud and similar, the machine's network interface only carries a private address; the public IP is one-to-one NAT done upstream. The server then advertises private addresses as its connection candidates and no browser can reach it — signaling works, the logs are clean, there is simply no video. Fix it with -public-ip <your public IP>.

The recommended route is a plain binary plus a systemd unit; deploy/kitserver.service is ready to copy. A Docker Compose route behind Caddy is provided as well. Cross-compile from Windows with:

cd server
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o kitserver ./cmd/kitserver

7. Adding a TURN relay

STUN helps two peers discover each other when a direct path exists. It cannot create a path that does not exist. When both sides are behind a symmetric NAT — a phone on cellular is the classic case — the viewer connects, then sits there with no picture. TURN solves that by relaying the media through a server both sides can reach.

This kit does not bundle a TURN server. You run coturn as a separate service and pass the kit its address and credentials. deploy/turnserver.conf is a starting configuration with the two settings people get wrong called out in comments.

sudo apt-get install -y coturn
sudo cp deploy/turnserver.conf /etc/turnserver.conf   # then edit the CHANGE_ME values
sudo systemctl enable --now coturn
sudo ss -lunp | grep 3478                             # confirm it is bound

Then start the kit server with the relay details:

./kitserver -turn turn:turn.example.com:3478 -turn-user kituser -turn-pass 'your-password'

Open /test/turn/ on your deployment. It runs two separate probes and tells them apart: a STUN binding to the same host and port (is that UDP port reachable at all?), and a relay-only allocation with your credentials (does the relay hand out a candidate?). "Port unreachable" and "relay refused" are different problems with different fixes, and that page is what separates them.

Remember to open 3478/UDP for the handshake and the relay range (coturn's min-port..max-port, 49152–49215 in the supplied template) for the media, in both the cloud security group and the host firewall.

8. Integrating it into your own product

The client is plain ES modules with no build step, so integration is a matter of reusing two files and calling them.

FileWhat it gives you
web/shared/net.jsThe signaling client: connect, join a room, automatic reconnect with backoff.
web/shared/stats.js getStats() sampling and rendering. describePath(s) is exported, and render(el, s, extra) accepts extra rows, so you can append your own numbers or a preserved record underneath the live ones.

A minimal publisher flow, at the level of the API you will actually call:

  1. Open the WebSocket to /ws and join a room as publisher.
  2. Get a stream: getUserMedia for a camera, or getDisplayMedia for a screen.
  3. Add the tracks to the peer connection the signaling client hands you.
  4. Offer; the server answers and starts forwarding to whoever joins as a viewer.

On the server side, server/internal/sfu/ holds the hub, the room and the client. The room is the unit of state; a room has one publisher and any number of viewers. If you need to authenticate joins, that is the natural place to add a check.

The server also serves the web directory as a static site. In production you will usually put your own reverse proxy in front of it and keep only /ws and the media ports pointed at the kit.

9. Customising the look

All styling lives in one file, web/style.css, and the palette is defined in CSS custom properties at the top:

:root{
  --bg:#0f1115; --panel:#171b22; --line:#2a3140; --fg:#e6e9ef; --muted:#9aa4b2;
  --acc:#5b8cff; --ok:#3ecf8e; --warn:#f5a524; --err:#f04a5e;
}

Changing --acc re-colours buttons and links throughout; changing --bg and --panel gives you a light theme. The pages share the same wrapper class (.wrap), so you can drop the whole client into an existing layout by replacing that one rule.

Static assets are served with Cache-Control: no-cache, so edits show up on reload without clearing anything.

10. Troubleshooting

docs/pitfalls.md in the package documents nine real problems hit while building this, each written as symptom → cause → fix. The ones that account for most support questions:

SymptomMost likely cause
Pages load, signaling connects, no picture at all The media UDP ports are closed, or the server is advertising a private IP. Check section 6.
Works on the same machine, fails between two machines No -stun, or the port range was never opened.
Works on Wi-Fi, fails on a phone on cellular Symmetric NAT. You need TURN. See section 7.
Connects, then goes black after a minute or so A reverse proxy is reaping an idle WebSocket. The kit sends a 25-second application-level heartbeat for exactly this reason; make sure your proxy allows at least that.
Camera does not start The page is not a secure context. Use HTTPS, or test on localhost.
A frozen picture that never recovers The viewer waits for a keyframe. Confirm RTCP is reaching the publisher — the kit forwards viewer PLI/NACK back to it for precisely this case.

11. Known limits

These are deliberate scope decisions, listed so there is nothing to discover later:

12. Credits and third-party assets

This item depends on open-source Go modules, fetched by go mod download:

The browser client contains no third-party JavaScript and uses system font stacks only, so there are no font licenses to carry.

The TURN configuration template targets coturn (BSD-3-Clause), which is not bundled with this item.

13. Support

Please use the support tab on the item's CodeCanyon page, and include: the kit version, your Go version, the browser and its version, whether /test/v2/ reads PASS, and what the diagnostics panel shows. That is usually enough to tell a configuration problem from a network one in a single reply.

Support covers installation, configuration and defects in the code as shipped. It does not include custom development, deployment onto your infrastructure, or changes to the room model.