package srs import ( "context" "fmt" "sync-live/gen" ) // Provider 暴露 SRS 后端能力(本地 docker 默认可达)。 type Provider struct { baseURL string httpBaseURL string app string secret string candidate string } func NewProvider(baseURL, app, secret, candidate string) *Provider { return &Provider{baseURL: baseURL, app: app, secret: secret, candidate: candidate} } func NewProviderWithHTTP(baseURL, httpBaseURL, app, secret, candidate string) *Provider { return &Provider{baseURL: baseURL, httpBaseURL: httpBaseURL, app: app, secret: secret, candidate: candidate} } func (p *Provider) Name() string { return "srs" } func (p *Provider) Primary() bool { return false } func (p *Provider) Configured() bool { return true } func (p *Provider) Kind() string { return "srs-hls" } func (p *Provider) Forward(ctx context.Context, room, stream string) (*ForwardResult, error) { if stream == "" { return nil, fmt.Errorf("stream required") } url := fmt.Sprintf("/live/%s.m3u8", stream) return &ForwardResult{Kind: "srs-hls", URL: url, Status: "ready"}, nil } type ForwardResult struct { Kind string URL string Status string } func (p *Provider) BaseURL() string { return p.baseURL } func (p *Provider) App() string { return p.app } func (p *Provider) Secret() string { return p.secret } func (p *Provider) Candidate() string { return p.candidate } func (p *Provider) ApplyConfig(baseURL, httpURL, app, secret, candidate string) { if baseURL != "" { p.baseURL = baseURL } if httpURL != "" { p.httpBaseURL = httpURL } if app != "" { p.app = app } p.secret = secret if candidate != "" { p.candidate = candidate } } func (p *Provider) ApplyConfigHTTP(httpURL string) { if httpURL != "" { p.httpBaseURL = httpURL } } func (p *Provider) HTTPBaseURL() string { return p.httpBaseURL } func (p *Provider) BackendInfo() *gen.BackendInfo { return &gen.BackendInfo{ Kind: gen.BackendKind_BACKEND_KIND_SRS, Name: "SRS", Configured: true, Primary: false, } }