Skip to content

Commit bfbce12

Browse files
authored
Merge pull request #491 from IIamaseconds/merge-fork
Major update
2 parents b0425fe + c2b0ba7 commit bfbce12

134 files changed

Lines changed: 14644 additions & 5465 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ################
2+
# SERVER
3+
# ################
4+
5+
# HTTP_ADDRESS=:8080
6+
# HTTPS_REDIRECT_PORT=80
7+
# HTTP_ENABLE_REDIRECT=TRUE
8+
# NETWORK_TEST_ON_START=TRUE
9+
# INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP=TRUE
10+
11+
# ################
12+
# SSL
13+
# ################
14+
15+
# USE_SSL=TRUE
16+
# SSL_KEY=./certs/key.pem
17+
# SSL_CERT=./certs/cert.pem
18+
19+
# ################
20+
# AUTHORIZATION
21+
# ################
22+
23+
# LOCAL STREAM PROFILE
24+
# STREAM_PROFILE_ACTIVE=TRUE
25+
# STREAM_PROFILE_PATH=./profiles
26+
27+
# WEBHOOK AUTHORIZATION
28+
# WEBHOOK_URL=http://your-server
29+
30+
# ################
31+
# FRONTEND
32+
# ################
33+
34+
# DISABLE_FRONTEND=TRUE
35+
# FRONTEND_PATH="./web/build"
36+
37+
# ################
38+
# DEBUGGING
39+
# ################
40+
41+
# DEBUG_INCOMING_API_REQUEST=TRUE
42+
# DEBUG_PRINT_ANSWER=TRUE
43+
# DEBUG_PRINT_OFFER=TRUE

.env.development

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,64 @@
1-
HTTP_ADDRESS=":8080"
2-
ENABLE_HTTP_REDIRECT=
3-
VITE_API_PATH="http://localhost:8080/api"
1+
# ################
2+
# SERVER
3+
# ################
44

5-
# /etc/letsencrypt/live/<your-domain-name>/privkey.pem
6-
SSL_KEY=
5+
# HTTP_ADDRESS=:8080
6+
# HTTPS_REDIRECT_PORT=80
7+
# HTTP_ENABLE_REDIRECT=TRUE
8+
# NETWORK_TEST_ON_START=FALSE
9+
# INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP=TRUE
710

8-
# /etc/letsencrypt/live/<your-domain-name>/fullchain.pem
9-
SSL_CERT=
11+
# ################
12+
# SSL
13+
# ################
14+
15+
# USE_SSL=TRUE
16+
# SSL_KEY=./certs/key.pem
17+
# SSL_CERT=./certs/cert.pem
18+
19+
# ################
20+
# AUTHORIZATION
21+
# ################
22+
23+
# LOCAL STREAM PROFILE
24+
# STREAM_PROFILE_ACTIVE=TRUE
25+
# STREAM_PROFILE_PATH=./profiles
26+
27+
# WEBHOOK AUTHORIZATION
28+
# WEBHOOK_URL=http://your-server
29+
30+
# ################
31+
# FRONTEND
32+
# ################
33+
34+
# DISABLE_FRONTEND=TRUE
35+
# FRONTEND_PATH="./web/build"
36+
37+
# ################
38+
# TURN/STUN
39+
# ################
40+
41+
# STUN_SERVERS="192.168.1.101:3478|192.168.1.101:3478"
42+
# TURN_SERVERS="192.168.1.123:3478|192.168.1.321:3478"
43+
# TURN_SERVERS_INTERNAL="10.100.0.10:3478"
44+
# STUN_SERVERS_INTERNAL="10.100.0.10:3478"
45+
# TURN_SERVER_AUTH_SECRET="YouSecret"
46+
47+
# ################
48+
# DEBUGGING
49+
# ################
50+
51+
# DEBUG_INCOMING_API_REQUEST=TRUE
52+
# DEBUG_PRINT_ANSWER=TRUE
53+
# DEBUG_PRINT_OFFER=TRUE
54+
# DEBUG_PRINT_SSE_MESSAGES=TRUE
55+
56+
# ################
57+
# LOGGING
58+
# ################
59+
# LOGGING_ENABLED=TRUE
60+
# LOGGING_DIRECTORY=logs
61+
# LOGGING_SINGLEFILE=FALSE
62+
# LOGGING_NEW_FILE_ON_STARTUP=FALSE
63+
# LOGGING_API_ENABLED=TRUE
64+
# LOGGING_API_KEY=YourApiKey

.env.production

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1-
HTTP_ADDRESS=":8080"
2-
ENABLE_HTTP_REDIRECT=
3-
VITE_API_PATH="/api"
1+
# ################
2+
# SERVER
3+
# ################
44

5-
# /etc/letsencrypt/live/<your-domain-name>/privkey.pem
6-
SSL_KEY=
5+
# HTTP_ADDRESS=:8080
6+
# HTTPS_REDIRECT_PORT=80
7+
# HTTP_ENABLE_REDIRECT=TRUE
8+
# NETWORK_TEST_ON_START=TRUE
9+
# INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP=TRUE
710

8-
# /etc/letsencrypt/live/<your-domain-name>/fullchain.pem
9-
SSL_CERT=
11+
# ################
12+
# SSL
13+
# ################
14+
15+
# USE_SSL=TRUE
16+
# SSL_KEY=./certs/key.pem
17+
# SSL_CERT=./certs/cert.pem
18+
19+
# ################
20+
# AUTHORIZATION
21+
# ################
22+
23+
# LOCAL STREAM PROFILE
24+
# STREAM_PROFILE_ACTIVE=TRUE
25+
# STREAM_PROFILE_PATH=./profiles
26+
27+
# WEBHOOK AUTHORIZATION
28+
# WEBHOOK_URL=http://your-server
29+
30+
# ################
31+
# FRONTEND
32+
# ################
33+
34+
# DISABLE_FRONTEND=TRUE
35+
# FRONTEND_PATH="./web/build"
36+
37+
# ################
38+
# DEBUGGING
39+
# ################
40+
41+
# DEBUG_INCOMING_API_REQUEST=TRUE
42+
# DEBUG_PRINT_ANSWER=TRUE
43+
# DEBUG_PRINT_OFFER=TRUE

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ yarn-error.log*
2828
# media files
2929
*.ogg
3030
*.h264
31+
32+
# build files
33+
BroadcastBox.exe
34+
35+
# log files
36+
/logs
37+
38+
# profile files
39+
/profiles
40+
41+
# Go vendors
42+
/vendor

.golangci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- unused
5+
exclusions:
6+
generated: lax
7+
presets:
8+
- comments
9+
- common-false-positives
10+
- legacy
11+
- std-error-handling
12+
paths:
13+
- third_party$
14+
- builtin$
15+
- examples$
16+
formatters:
17+
exclusions:
18+
generated: lax
19+
paths:
20+
- third_party$
21+
- builtin$
22+
- examples$

GoRun.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go build -o BroadcastBox.exe
2+
if ($LASTEXITCODE -eq 0) {
3+
.\BroadcastBox.exe $args
4+
}

README.md

Lines changed: 106 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
- [Docker](#docker)
1717
- [Docker Compose](#docker-compose)
1818
- [Environment variables](#environment-variables)
19-
- [Authentication and Logging](#authentication-and-logging)
19+
- [Webhook - Authentication and Logging](#webhook---authentication-and-logging)
2020
- [Network Test on Start](#network-test-on-start)
2121
- [Design](#design)
2222

23-
## What is Broadcast Box
23+
## What is Broadcast Box
2424

2525
Broadcast Box lets you broadcast to others in sub-second time. It was designed
2626
to be simple to use and easily modifiable. We wrote Broadcast Box to show off some
@@ -197,6 +197,7 @@ will be automatically updated every night. If you are running on a VPS/Cloud ser
197197
export URL=my-server.com
198198
docker-compose up -d
199199
```
200+
200201
## URL Parameters
201202

202203
The frontend can be configured by passing these URL Parameters.
@@ -205,43 +206,105 @@ The frontend can be configured by passing these URL Parameters.
205206

206207
## Environment Variables
207208

208-
The backend can be configured with the following environment variables.
209-
210-
- `WEBHOOK_URL` - URL for Webhook Backend. Provides authentication and logging
211-
- `DISABLE_STATUS` - Disable the status API
212-
- `DISABLE_FRONTEND` - Disable the serving of frontend. Only REST APIs + WebRTC is enabled.
213-
- `HTTP_ADDRESS` - HTTP Server Address
214-
- `NETWORK_TEST_ON_START` - When "true" on startup Broadcast Box will check network connectivity
215-
216-
- `ENABLE_HTTP_REDIRECT` - HTTP traffic will be redirect to HTTPS
217-
- `SSL_CERT` - Path to SSL certificate if using Broadcast Box's HTTP Server
218-
- `SSL_KEY` - Path to SSL key if using Broadcast Box's HTTP Server
219-
220-
- `NAT_1_TO_1_IP` - Announce IPs that don't belong to local machine (like Public IP). delineated by '|'
221-
- `INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP` - Like `NAT_1_TO_1_IP` but autoconfigured
222-
- `INTERFACE_FILTER` - Only use a certain interface for UDP traffic
223-
- `NAT_ICE_CANDIDATE_TYPE` - By default setting a NAT_1_TO_1_IP overrides. Set this to `srflx` to instead append IPs
224-
- `STUN_SERVERS` - List of STUN servers delineated by '|'. Useful if Broadcast Box is running behind a NAT
225-
- `NETWORK_TYPES` - List of network types to use, delineated by '|'. Default is `udp4|udp6`.
226-
- `INCLUDE_LOOPBACK_CANDIDATE` - Also listen for WebRTC traffic on loopback, disabled by default
227-
228-
- `UDP_MUX_PORT_WHEP` - Like `UDP_MUX_PORT` but only for WHEP traffic
229-
- `UDP_MUX_PORT_WHIP` - Like `UDP_MUX_PORT` but only for WHIP traffic
230-
- `UDP_MUX_PORT` - Serve all UDP traffic via one port. By default Broadcast Box listens on a random port
231-
232-
- `TCP_MUX_ADDRESS` - If you wish to make WebRTC traffic available via TCP.
233-
- `TCP_MUX_FORCE` - If you wish to make WebRTC traffic only available via TCP.
234-
235-
- `APPEND_CANDIDATE` - Append candidates to Offer that ICE Agent did not generate. Worse version of `NAT_1_TO_1_IP`
236-
237-
- `DEBUG_PRINT_OFFER` - Print WebRTC Offers from client to Broadcast Box. Debug things like accepted codecs.
238-
- `DEBUG_PRINT_ANSWER` - Print WebRTC Answers from Broadcast Box to Browser. Debug things like IP/Ports returned to client.
239-
240-
## Authentication and Logging
209+
### Server Configuration
210+
211+
| Variable | Description |
212+
| ----------------------- | -------------------------------------------------------- |
213+
| `HTTP_ADDRESS` | Address for the HTTP server to bind to. |
214+
| `ENABLE_HTTP_REDIRECT` | Enables automatic redirection from HTTP to HTTPS. |
215+
| `HTTPS_REDIRECT_PORT` | Port to redirect HTTP traffic to HTTPS when using HTTPS. |
216+
| `NETWORK_TEST_ON_START` | If "true", checks network connectivity on startup. |
217+
| `DISABLE_STATUS` | Disables the status API endpoint. |
218+
| `ENABLE_PROFILING` | Enables PPROF profiling on localhost:6060 |
219+
220+
### SSL Configuration
221+
222+
| Variable | Description |
223+
| ---------- | --------------------------------- |
224+
| `USE_SSL` | Setup the server to run with SSL. |
225+
| `SSL_CERT` | Path to the SSL certificate file. |
226+
| `SSL_KEY` | Path to the SSL key file. |
227+
228+
### Authorization & Profiles
229+
230+
| Variable | Description |
231+
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
232+
| `STREAM_PROFILE_PATH` | Path to store stream profile configurations. |
233+
| `STREAM_PROFILE_POLICY` | Policy configuration for stream profiles. Default is 'Anyone' See [Stream Profile Policy](#stream-profile-policy). |
234+
| `WEBHOOK_URL` | URL for webhook backend used for authentication and logging. see [Webhook - Authentication and Logging](#webhook---authentication-and-logging). |
235+
236+
### Frontend Configuration
237+
238+
| Variable | Description |
239+
| ---------------------- | -------------------------------- |
240+
| `DISABLE_FRONTEND` | Disables frontend serving. |
241+
| `FRONTEND_PATH` | Path to frontend assets. |
242+
| `FRONTEND_ADMIN_TOKEN` | Admin token for frontend access. |
243+
244+
### WebRTC & Networking
245+
246+
| Variable | Description |
247+
| ------------------------------------ | ------------------------------------------------------------------------ |
248+
| `INCLUDE_PUBLIC_IP_IN_NAT_1_TO_1_IP` | Automatically includes public IPs in NAT configuration. |
249+
| `NAT_1_TO_1_IP` | Manually specify IPs (like Public IP) to announce, delineated by `\|` |
250+
| `INTERFACE_FILTER` | Restrict UDP traffic to a specific network interface. |
251+
| `NAT_ICE_CANDIDATE_TYPE` | Set to `srflx` to append IPs instead of overriding with `NAT_1_TO_1_IP`. |
252+
| `NETWORK_TYPES` | List of network types to use delineated by `\|` (e.g.,`udp4 \|udp6`). |
253+
| `INCLUDE_LOOPBACK_CANDIDATE` | Enables WebRTC traffic on loopback interface. |
254+
| `UDP_MUX_PORT` | Port to multiplex all UDP traffic. Uses random port by default. |
255+
| `UDP_MUX_PORT_WHEP` | Port to multiplex WHEP traffic only. |
256+
| `UDP_MUX_PORT_WHIP` | Port to multiplex WHIP traffic only. |
257+
| `TCP_MUX_ADDRESS` | Address to serve WebRTC traffic over TCP. |
258+
| `TCP_MUX_FORCE` | Forces WebRTC traffic to use TCP only. |
259+
| `APPEND_CANDIDATE` | Appends ICE candidates not generated by the agent. |
260+
| `WHEP_SESSION_AUDIOCHANNEL_SIZE` | Tunes the AudioChannel size for WHEP sessions. |
261+
| `WHEP_SESSION_VIDEOCHANNEL_SIZE` | Tunes the VideoChannel size for WHEP sessions. |
262+
263+
### STUN/TURN Servers
264+
265+
| Variable | Description |
266+
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
267+
| `STUN_SERVERS` | List of public STUN servers separated by `\|`. |
268+
| `STUN_SERVERS_INTERNAL` | List of internal STUN servers used by the backend in case it has trouble connecting to the public STUN server. Separated by `\|`. |
269+
| `TURN_SERVERS` | List of public TURN servers separated by `\|`. |
270+
| `TURN_SERVERS_INTERNAL` | List of internal TURN servers used by the backend in case it has trouble connecting to the public TURN server. Separated by `\|`. |
271+
| `TURN_SERVER_AUTH_SECRET` | Shared secret for TURN server authentication. |
272+
273+
### Debugging
274+
275+
| Variable | Description |
276+
| ---------------------------- | ------------------------------------------- |
277+
| `DEBUG_PRINT_OFFER` | Prints WebRTC offers received from clients. |
278+
| `DEBUG_PRINT_ANSWER` | Prints WebRTC answers sent to clients. |
279+
| `DEBUG_INCOMING_API_REQUEST` | Logs incoming API request paths. |
280+
| `DEBUG_PRINT_SSE_MESSAGES` | Logs Server-Sent Events messages. |
281+
282+
### Logging
283+
284+
| Variable | Description |
285+
| ----------------------------- | -------------------------------------------------------------------------------------------------------- |
286+
| `LOGGING_ENABLED` | Enables logging system. |
287+
| `LOGGING_DIRECTORY` | Directory to store log files. |
288+
| `LOGGING_SINGLEFILE` | Logs everything into a single file called 'log'. Default is log files are stamped with current date. |
289+
| `LOGGING_NEW_FILE_ON_STARTUP` | Creates a new log file on each startup. Either a new 'log' file, or replaces the current dates log file. |
290+
| `LOGGING_API_ENABLED` | Enables logging API to show current log entries on the backend. `/api/log` |
291+
| `LOGGING_API_KEY` | When set, the logging API requires a bearer token that uses this key. |
292+
293+
## Stream Profile Policy
294+
295+
The `STREAM_PROFILE_POLICY` environment variable controls who is allowed to initiate streaming sessions based on profile reservation status.
296+
297+
| Value | Description |
298+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
299+
| `ANYONE_WITH_RESERVED` | If Stream keys are reserved in advance, only a valid token can be used with them. If not reserved, anyone can used the streamkey |
300+
| `RESERVED` | Only users with a valid token **and** a reserved stream key are allowed to stream. This is the most restrictive mode. |
301+
302+
## Webhook - Authentication and Logging
241303

242304
To prevent random users from streaming to your server, you can set the `WEBHOOK_URL` and validate/process requests in your code. This enables you to separate the authorization between broadcasting (whip) and watching (whep). So you can safely share a watch link without exposing the key used for broadcasting.
243305

244-
If the request succeeds (meaning the stream key is accepted), broadcast-box redirects the stream to an url given by the external server, otherwise the streaming request is dropped.
306+
If the request succeeds (meaning the stream key is accepted), broadcast-box redirects the stream to an url given
307+
by the external server, otherwise the streaming request is dropped.
245308

246309
See [here](examples/webhook-server.go). For an example Webhook Server that only allows the stream `broadcastBoxRulez`
247310

@@ -285,11 +348,14 @@ If you wish to disable the test set the environment variable `NETWORK_TEST_ON_ST
285348

286349
## Design
287350

288-
The backend exposes three endpoints (the status page is optional, if hosting locally).
351+
The backend exposes the following endpoints to support WebRTC streaming and server-side monitoring:
289352

290-
- `/api/whip` - Start a WHIP Session. WHIP broadcasts video via WebRTC.
291-
- `/api/whep` - Start a WHEP Session. WHEP is video playback via WebRTC.
292-
- `/api/status` - Status of the all active WHIP streams
353+
| Endpoint | Description |
354+
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
355+
| `/api/whip` | Initiates a WHIP session for broadcasting video via WebRTC. Requires the Authorization header with a bearer token |
356+
| `/api/whep` | Initiates a WHEP session for video playback via WebRTC. |
357+
| `/api/status` | Returns the status of all active WHIP streams. If a Stream Profile is not public, it will not be included. |
358+
| `/api/log` | Retrieves current server logs. Useful for debugging and monitoring runtime activity. |
293359

294360
[license-image]: https://img.shields.io/badge/License-MIT-yellow.svg
295361
[license-url]: https://opensource.org/licenses/MIT

0 commit comments

Comments
 (0)