- Refactor the Go proxy for dependency injection: every proxy server, the bootstrap, the signal handler, the load balancers, and AMF0 now accept functional-option seams (factories/closures) so tests can inject fakes without binding real sockets, talking to real Redis, or racing on package globals. - Drop the package-global `lb.SrsLoadBalancer`. The bootstrap creates the LB locally and threads it through every proxy server constructor. Two old global indirections in `internal/signal` and `internal/rtmp/amf0` are likewise replaced by per-instance fields. - Rename `internal/server` → `internal/proxy` and rename the `lb` public surface for clarity: `SRSLoadBalancer` is split into `OriginService` / `HLSService` / `RTCService` and recomposed as `OriginLoadBalancer`; `SRSServer` → `OriginServer`; all proxy server types gain a `Proxy` qualifier (e.g. `RTMPServer` → `RTMPProxyServer`). - Extract the Redis client behind a new `internal/redisclient` package with a minimal `RedisClient` interface and a counterfeiter fake. - Add counterfeiter fakes (`proxyfakes`, `lbfakes`, `redisclientfakes`) and ~7.5k lines of unit tests covering bootstrap, memory + Redis LBs, all five proxy servers, the signal handler, and AMF0. - Add two new E2E flows — `proxy-e2e-srt-test.sh` (SRT publish through proxy, verify SRT/RTMP/HTTP-FLV/HLS playback) and `proxy-e2e-whip-test.sh` (WHIP publish, verify RTMP/HTTP-FLV/HLS via origin `rtc_to_rtmp`) — plus `setup-ffmpeg-with-whip.sh`, a macOS builder for an ffmpeg with openssl-DTLS WHIP and SRT support that the two scripts auto-invoke when needed. - Workspace reorg: move `memory/` and `skills/` to the repo root so all agent tools (Claude / Codex / Kiro / OpenClaw) share one source of truth via symlinks. Sync `docs/proxy/proxy-load-balancer.md` and `memory/srs-codebase-map.md` with the new names. No protocol, log, HTTP API, or wire-format changes. Refactor only — all externally observable proxy behavior is unchanged. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
193 lines
5.7 KiB
Go
193 lines
5.7 KiB
Go
// Code generated by counterfeiter. DO NOT EDIT.
|
|
package lbfakes
|
|
|
|
import (
|
|
"context"
|
|
"srsx/internal/lb"
|
|
"sync"
|
|
)
|
|
|
|
type FakeRTCService struct {
|
|
LoadWebRTCByUfragStub func(context.Context, string) (lb.RTCConnection, error)
|
|
loadWebRTCByUfragMutex sync.RWMutex
|
|
loadWebRTCByUfragArgsForCall []struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
}
|
|
loadWebRTCByUfragReturns struct {
|
|
result1 lb.RTCConnection
|
|
result2 error
|
|
}
|
|
loadWebRTCByUfragReturnsOnCall map[int]struct {
|
|
result1 lb.RTCConnection
|
|
result2 error
|
|
}
|
|
StoreWebRTCStub func(context.Context, string, lb.RTCConnection) error
|
|
storeWebRTCMutex sync.RWMutex
|
|
storeWebRTCArgsForCall []struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
arg3 lb.RTCConnection
|
|
}
|
|
storeWebRTCReturns struct {
|
|
result1 error
|
|
}
|
|
storeWebRTCReturnsOnCall map[int]struct {
|
|
result1 error
|
|
}
|
|
invocations map[string][][]interface{}
|
|
invocationsMutex sync.RWMutex
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfrag(arg1 context.Context, arg2 string) (lb.RTCConnection, error) {
|
|
fake.loadWebRTCByUfragMutex.Lock()
|
|
ret, specificReturn := fake.loadWebRTCByUfragReturnsOnCall[len(fake.loadWebRTCByUfragArgsForCall)]
|
|
fake.loadWebRTCByUfragArgsForCall = append(fake.loadWebRTCByUfragArgsForCall, struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
}{arg1, arg2})
|
|
stub := fake.LoadWebRTCByUfragStub
|
|
fakeReturns := fake.loadWebRTCByUfragReturns
|
|
fake.recordInvocation("LoadWebRTCByUfrag", []interface{}{arg1, arg2})
|
|
fake.loadWebRTCByUfragMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1, arg2)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1, ret.result2
|
|
}
|
|
return fakeReturns.result1, fakeReturns.result2
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfragCallCount() int {
|
|
fake.loadWebRTCByUfragMutex.RLock()
|
|
defer fake.loadWebRTCByUfragMutex.RUnlock()
|
|
return len(fake.loadWebRTCByUfragArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfragCalls(stub func(context.Context, string) (lb.RTCConnection, error)) {
|
|
fake.loadWebRTCByUfragMutex.Lock()
|
|
defer fake.loadWebRTCByUfragMutex.Unlock()
|
|
fake.LoadWebRTCByUfragStub = stub
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfragArgsForCall(i int) (context.Context, string) {
|
|
fake.loadWebRTCByUfragMutex.RLock()
|
|
defer fake.loadWebRTCByUfragMutex.RUnlock()
|
|
argsForCall := fake.loadWebRTCByUfragArgsForCall[i]
|
|
return argsForCall.arg1, argsForCall.arg2
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfragReturns(result1 lb.RTCConnection, result2 error) {
|
|
fake.loadWebRTCByUfragMutex.Lock()
|
|
defer fake.loadWebRTCByUfragMutex.Unlock()
|
|
fake.LoadWebRTCByUfragStub = nil
|
|
fake.loadWebRTCByUfragReturns = struct {
|
|
result1 lb.RTCConnection
|
|
result2 error
|
|
}{result1, result2}
|
|
}
|
|
|
|
func (fake *FakeRTCService) LoadWebRTCByUfragReturnsOnCall(i int, result1 lb.RTCConnection, result2 error) {
|
|
fake.loadWebRTCByUfragMutex.Lock()
|
|
defer fake.loadWebRTCByUfragMutex.Unlock()
|
|
fake.LoadWebRTCByUfragStub = nil
|
|
if fake.loadWebRTCByUfragReturnsOnCall == nil {
|
|
fake.loadWebRTCByUfragReturnsOnCall = make(map[int]struct {
|
|
result1 lb.RTCConnection
|
|
result2 error
|
|
})
|
|
}
|
|
fake.loadWebRTCByUfragReturnsOnCall[i] = struct {
|
|
result1 lb.RTCConnection
|
|
result2 error
|
|
}{result1, result2}
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTC(arg1 context.Context, arg2 string, arg3 lb.RTCConnection) error {
|
|
fake.storeWebRTCMutex.Lock()
|
|
ret, specificReturn := fake.storeWebRTCReturnsOnCall[len(fake.storeWebRTCArgsForCall)]
|
|
fake.storeWebRTCArgsForCall = append(fake.storeWebRTCArgsForCall, struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
arg3 lb.RTCConnection
|
|
}{arg1, arg2, arg3})
|
|
stub := fake.StoreWebRTCStub
|
|
fakeReturns := fake.storeWebRTCReturns
|
|
fake.recordInvocation("StoreWebRTC", []interface{}{arg1, arg2, arg3})
|
|
fake.storeWebRTCMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1, arg2, arg3)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTCCallCount() int {
|
|
fake.storeWebRTCMutex.RLock()
|
|
defer fake.storeWebRTCMutex.RUnlock()
|
|
return len(fake.storeWebRTCArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTCCalls(stub func(context.Context, string, lb.RTCConnection) error) {
|
|
fake.storeWebRTCMutex.Lock()
|
|
defer fake.storeWebRTCMutex.Unlock()
|
|
fake.StoreWebRTCStub = stub
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTCArgsForCall(i int) (context.Context, string, lb.RTCConnection) {
|
|
fake.storeWebRTCMutex.RLock()
|
|
defer fake.storeWebRTCMutex.RUnlock()
|
|
argsForCall := fake.storeWebRTCArgsForCall[i]
|
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTCReturns(result1 error) {
|
|
fake.storeWebRTCMutex.Lock()
|
|
defer fake.storeWebRTCMutex.Unlock()
|
|
fake.StoreWebRTCStub = nil
|
|
fake.storeWebRTCReturns = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRTCService) StoreWebRTCReturnsOnCall(i int, result1 error) {
|
|
fake.storeWebRTCMutex.Lock()
|
|
defer fake.storeWebRTCMutex.Unlock()
|
|
fake.StoreWebRTCStub = nil
|
|
if fake.storeWebRTCReturnsOnCall == nil {
|
|
fake.storeWebRTCReturnsOnCall = make(map[int]struct {
|
|
result1 error
|
|
})
|
|
}
|
|
fake.storeWebRTCReturnsOnCall[i] = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRTCService) Invocations() map[string][][]interface{} {
|
|
fake.invocationsMutex.RLock()
|
|
defer fake.invocationsMutex.RUnlock()
|
|
copiedInvocations := map[string][][]interface{}{}
|
|
for key, value := range fake.invocations {
|
|
copiedInvocations[key] = value
|
|
}
|
|
return copiedInvocations
|
|
}
|
|
|
|
func (fake *FakeRTCService) recordInvocation(key string, args []interface{}) {
|
|
fake.invocationsMutex.Lock()
|
|
defer fake.invocationsMutex.Unlock()
|
|
if fake.invocations == nil {
|
|
fake.invocations = map[string][][]interface{}{}
|
|
}
|
|
if fake.invocations[key] == nil {
|
|
fake.invocations[key] = [][]interface{}{}
|
|
}
|
|
fake.invocations[key] = append(fake.invocations[key], args)
|
|
}
|
|
|
|
var _ lb.RTCService = new(FakeRTCService)
|