Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ cmake-build-debug
/build
/cmake/build
/trunk/cmake/build

# proxy (Go)
srs-proxy
.go-formarted
.env
1 change: 1 addition & 0 deletions .kiro/skills
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}/proxy",
"program": "${workspaceFolder}/proxy"
"cwd": "${workspaceFolder}/cmd/proxy",
"program": "${workspaceFolder}/cmd/proxy"
},
{
"name": "Debug SRS (macOS, CodeLLDB) console.conf",
Expand Down
10 changes: 5 additions & 5 deletions proxy/Makefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ all: build

build: fmt ./srs-proxy

./srs-proxy: cmd/proxy-go/*.go internal/**/*.go
go build -o srs-proxy ./cmd/proxy-go
./srs-proxy: cmd/proxy/*.go internal/**/*.go
go build -o srs-proxy ./cmd/proxy

test:
go test ./...

fmt: ./.go-formarted

./.go-formarted: cmd/proxy-go/*.go internal/**/*.go
./.go-formarted: cmd/proxy/*.go internal/**/*.go
touch .go-formarted
go fmt ./...
go fmt ./cmd/... ./internal/...

clean:
rm -f srs-proxy .go-formarted

run: fmt
go run ./cmd/proxy-go
go run ./cmd/proxy
2 changes: 1 addition & 1 deletion proxy/cmd/proxy-go/main.go → cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"os"

"proxy/internal/bootstrap"
"srsx/internal/bootstrap"
)

func main() {
Expand Down
23 changes: 23 additions & 0 deletions docs/proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Proxy

Proxy is a common proxy server (`cmd/proxy`) for any media servers with RTMP/SRT/HLS/HTTP-FLV and WebRTC/WHIP/WHEP protocols support. More programs like `cmd/origin` will be added in the future.

## Usage

This project is managed by AI. We recommend OpenClaw by default, but you can use any AI agent that supports skills, such as Claude Code, OpenAI Codex, Kiro CLI, or similar tools that can read code and docs as context. Setup your AI code tool and ask questions like:

- How to use this project?
- How to run the proxy server?
- How to build an Origin Cluster for production?

You can not only use AI to show you the usage of this project, but also use AI to guide you to learn the details of this project, to understand the design and protocols, to learn each documents in docs directory.

## AI Guidelines

- AI assistants should ignore [ignore-worklog.md](ignore-worklog.md) as it's a personal work log that may contain misleading information, hallucinations, or falsehoods. Never rely on this file as a reference.
- For usage of proxy server and end to end test it, you should load [proxy-usage.md](proxy-usage.md). This is the first step for new users to learn how to use this project. It provides a general and overall view of the proxy server, including practical usage examples and end-to-end testing procedures.
- For proxy full usage to build an Origin Cluster for SRS media server, please load [proxy-origin-cluster.md](proxy-origin-cluster.md). This is an advanced topic about how to use the proxy server to build the SRS Origin Cluster. Users should read this document to learn more details and architectures about proxy and Origin Cluster.
- For proxy server: To understand proxy system design, you should load the [proxy-design.md](proxy-design.md). To understand the proxy protocol details, you should load the [proxy-protocol.md](proxy-protocol.md). To understand how load balance works, you should load [proxy-load-balancer.md](proxy-load-balancer.md). To understand the code structure and packages, you should load [proxy-files.md](proxy-files.md).

William Yang<br/>
June 23, 2025
7 changes: 7 additions & 0 deletions docs/proxy/ignore-worklog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Work Log

> Important notes for AI assistants: This file might includes misleading information, hallucinations, or even falsehoods, since it's just a personal work log. So AI should never rely on this file as a reference.
SRSX is not only the next generation of SRS (Simple Realtime Server), and it's also an approach to leverage AI to manage the project as a whole. So it's not just a useful open source project, but also a demostration of how AI can help develop, manage, and maintain a complex project.

Since AI is relatively a new tool for open source project development, I use this work log to record my thoughts, ideas, experiments, and even failures along the way, while integrating AI into this open source project.
2 changes: 1 addition & 1 deletion proxy/docs/proxy-design.md → docs/proxy/proxy-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

**proxy-go** is a stateless media streaming proxy with built-in load balancing that enables building scalable origin clusters. The proxy itself acts as the load balancer, routing streams from clients to backend origin servers.
**proxy** is a stateless media streaming proxy with built-in load balancing that enables building scalable origin clusters. The proxy itself acts as the load balancer, routing streams from clients to backend origin servers.

```
Client → Proxy (with Load Balancer) → Backend Origin Servers
Expand Down
2 changes: 1 addition & 1 deletion proxy/docs/proxy-files.md → docs/proxy/proxy-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document provides an overview of the Go codebase organization.

```
/
├── cmd/proxy-go/
├── cmd/proxy/
│ └── main.go # Application entry point
└── internal/
├── debug/ # Go profiling support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The proxy-go load balancer distributes client streams across multiple backend origin servers. It provides a pluggable interface with two implementations:
The proxy load balancer distributes client streams across multiple backend origin servers. It provides a pluggable interface with two implementations:

1. **Memory Load Balancer** - For single proxy deployments
2. **Redis Load Balancer** - For multi-proxy deployments with shared state
Expand Down Expand Up @@ -159,4 +159,3 @@ PROXY_REDIS_DB=0
| **Complexity** | Simple | Moderate |
| **Fault Tolerance** | Single point of failure | Multiple proxies |
| **Best For** | Moderate traffic | High traffic, high availability |

File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions proxy/go.mod → go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module proxy
module srsx

go 1.18
go 1.24

require github.com/go-redis/redis/v8 v8.11.5
require (
github.com/go-redis/redis/v8 v8.11.5
github.com/joho/godotenv v1.5.1
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/joho/godotenv v1.5.1 // indirect
)
9 changes: 9 additions & 0 deletions proxy/go.sum → go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"context"
"time"

"proxy/internal/debug"
"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/protocol"
"proxy/internal/signal"
"proxy/internal/version"
"srsx/internal/debug"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/protocol"
"srsx/internal/signal"
"srsx/internal/version"
)

// Bootstrap defines the interface for application bootstrap operations.
Expand Down
4 changes: 2 additions & 2 deletions proxy/internal/debug/pprof.go → internal/debug/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"context"
"net/http"

"proxy/internal/env"
"proxy/internal/logger"
"srsx/internal/env"
"srsx/internal/logger"
)

func HandleGoPprof(ctx context.Context, environment env.Environment) {
Expand Down
6 changes: 3 additions & 3 deletions proxy/internal/env/env.go → internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/joho/godotenv"

"proxy/internal/errors"
"proxy/internal/logger"
"srsx/internal/errors"
"srsx/internal/logger"
)

// Environment provides access to environment variables.
Expand Down Expand Up @@ -196,7 +196,7 @@ func buildDefaultEnvironmentVariables(ctx context.Context) {
// The API server of proxy itself.
setEnvDefault("PROXY_SYSTEM_API", "12025")
// The static directory for web server, optional.
setEnvDefault("PROXY_STATIC_FILES", "../trunk/research")
setEnvDefault("PROXY_STATIC_FILES", "./trunk/research")

// The load balancer, use redis or memory.
setEnvDefault("PROXY_LOAD_BALANCER_TYPE", "memory")
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions proxy/internal/lb/debug.go → internal/lb/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"os"
"time"

"proxy/internal/env"
"proxy/internal/logger"
"srsx/internal/env"
"srsx/internal/logger"
)

// NewDefaultSRSForDebugging initialize the default SRS media server, for debugging only.
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions proxy/internal/lb/mem.go → internal/lb/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"math/rand"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/logger"
"proxy/internal/sync"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/logger"
"srsx/internal/sync"
)

// MemoryLoadBalancer stores state in memory.
Expand Down
6 changes: 3 additions & 3 deletions proxy/internal/lb/redis.go → internal/lb/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
// Use v8 because we use Go 1.16+, while v9 requires Go 1.18+
"github.com/go-redis/redis/v8"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/logger"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/logger"
)

// RedisLoadBalancer stores state in Redis.
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions proxy/internal/protocol/api.go → internal/protocol/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"sync"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/utils"
"proxy/internal/version"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/utils"
"srsx/internal/version"
)

// srsHTTPAPIServer is the proxy for SRS HTTP API, to proxy the WebRTC HTTP API like WHIP and WHEP,
Expand Down
12 changes: 6 additions & 6 deletions proxy/internal/protocol/http.go → internal/protocol/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
stdSync "sync"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/utils"
"proxy/internal/version"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/utils"
"srsx/internal/version"
)

// srsHTTPStreamServer is the proxy server for SRS HTTP stream server, for HTTP-FLV, HTTP-TS,
Expand Down
12 changes: 6 additions & 6 deletions proxy/internal/protocol/rtc.go → internal/protocol/rtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
stdSync "sync"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/sync"
"proxy/internal/utils"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/sync"
"srsx/internal/utils"
)

// srsWebRTCServer is the proxy for SRS WebRTC server via WHIP or WHEP protocol. It will figure out
Expand Down
14 changes: 7 additions & 7 deletions proxy/internal/protocol/rtmp.go → internal/protocol/rtmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"strings"
"sync"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/rtmp"
"proxy/internal/utils"
"proxy/internal/version"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/rtmp"
"srsx/internal/utils"
"srsx/internal/version"
)

// srsRTMPServer is the proxy for SRS RTMP server, to proxy the RTMP stream to backend SRS
Expand Down
12 changes: 6 additions & 6 deletions proxy/internal/protocol/srt.go → internal/protocol/srt.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
stdSync "sync"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/lb"
"proxy/internal/logger"
"proxy/internal/sync"
"proxy/internal/utils"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/lb"
"srsx/internal/logger"
"srsx/internal/sync"
"srsx/internal/utils"
)

// srsSRTServer is the proxy for SRS server via SRT. It will figure out which backend server to
Expand Down
2 changes: 1 addition & 1 deletion proxy/internal/rtmp/amf0.go → internal/rtmp/amf0.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"math"
"sync"

"proxy/internal/errors"
"srsx/internal/errors"
)

// Please read @doc amf0_spec_121207.pdf, @page 4, @section 2.1 Types Overview
Expand Down
2 changes: 1 addition & 1 deletion proxy/internal/rtmp/rtmp.go → internal/rtmp/rtmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"io"
"sync"

"proxy/internal/errors"
"srsx/internal/errors"
)

// The handshake implements the RTMP handshake protocol.
Expand Down
6 changes: 3 additions & 3 deletions proxy/internal/signal/signal.go → internal/signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"syscall"
"time"

"proxy/internal/env"
"proxy/internal/errors"
"proxy/internal/logger"
"srsx/internal/env"
"srsx/internal/errors"
"srsx/internal/logger"
)

func InstallSignals(ctx context.Context, cancel context.CancelFunc) {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions proxy/internal/utils/utils.go → internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"strings"
"syscall"

"proxy/internal/errors"
"proxy/internal/logger"
"proxy/internal/version"
"srsx/internal/errors"
"srsx/internal/logger"
"srsx/internal/version"
)

func ApiResponse(ctx context.Context, w http.ResponseWriter, r *http.Request, data any) {
Expand Down
File renamed without changes.
Loading
Loading