Skip to content

Commit

Permalink
support srs http api config by env.
Browse files Browse the repository at this point in the history
  • Loading branch information
suzp1984 committed Oct 28, 2024
1 parent 1963d25 commit d1ffc2a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func doMain(ctx context.Context) error {

// SRS HOST
setEnvDefault("SRS_HOST", "127.0.0.1")
setEnvDefault("SRS_PROXY_HOST", "127.0.0.1")
setEnvDefault("SRS_PROXY_HTTP_PORT", "8080")
setEnvDefault("SRS_HTTP_STREAM_PORT", "8080")

// For HTTPS.
setEnvDefault("HTTPS_LISTEN", "2443")
Expand Down
11 changes: 6 additions & 5 deletions platform/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"net/http"
"os"
"path"
"runtime"
"strconv"
Expand Down Expand Up @@ -290,22 +291,22 @@ func handleHTTPService(ctx context.Context, handler *http.ServeMux) error {
handleMgmtStreamsKickoff(ctx, handler)
handleMgmtUI(ctx, handler)

proxy2023, err := httpCreateProxy("http://" + os.Getenv("SRS_PROXY_HOST") + ":2023")
proxy2023, err := httpCreateProxy("http://" + os.Getenv("SRS_HOST") + ":2023")
if err != nil {
return err
}

proxy1985, err := httpCreateProxy("http://" + os.Getenv("SRS_PROXY_HOST") + ":1985")
proxy1985, err := httpCreateProxy("http://" + os.Getenv("SRS_HOST") + ":1985")
if err != nil {
return err
}

proxyWhxp, err := httpCreateProxy("http://" + os.Getenv("SRS_PROXY_HOST") + ":1985")
proxyWhxp, err := httpCreateProxy("http://" + os.Getenv("SRS_HOST") + ":1985")
if err != nil {
return err
}

proxy8080, err := httpCreateProxy("http://" + os.Getenv("SRS_PROXY_HOST") + ":8080")
proxy8080, err := httpCreateProxy("http://" + os.Getenv("SRS_HOST") + ":8080")
if err != nil {
return err
}
Expand Down Expand Up @@ -1692,7 +1693,7 @@ func handleMgmtStreamsKickoff(ctx context.Context, handler *http.ServeMux) {

// Whether client exists in SRS server.
var code int
clientURL := fmt.Sprintf("http://%v:1985/api/v1/clients/%v", os.Getenv("SRS_PROXY_HOST"), streamObject.Client)
clientURL := fmt.Sprintf("http://%v:1985/api/v1/clients/%v", os.Getenv("SRS_HOST"), streamObject.Client)
if r0, body, err := requestClient(ctx, clientURL, http.MethodGet); err != nil {
return errors.Wrapf(err, "http query client %v", clientURL)
} else if r0 != 0 && r0 != ErrorRtmpClientNotFound {
Expand Down
2 changes: 1 addition & 1 deletion platform/srs-hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func handleOnHls(ctx context.Context, handler *http.ServeMux) error {
if tsFile, err := os.Create(msg.File); err != nil {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return errors.Wrapf(err, "failed to create ts file %v", msg.File)
} else {
tsUrl := "http://" + os.Getenv("SRS_PROXY_HOST") + ":" + os.Getenv("SRS_PROXY_HTTP_PORT") + "/" + msg.URL
tsUrl := "http://" + os.Getenv("SRS_HOST") + ":" + os.Getenv("SRS_HTTP_STREAM_PORT") + "/" + msg.URL
logger.Tf(ctx, "download ts from %v", tsUrl)
client := http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
6 changes: 4 additions & 2 deletions platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ func srsGenerateConfig(ctx context.Context) error {
api := "http://" + os.Getenv("SRS_HOST") + ":1985/api/v1/raw?rpc=reload"
res, err := http.DefaultClient.Get(api)
if err != nil {
return errors.Wrapf(err, "reload srs %v", api)
logger.Tf(ctx, "srs api reload error %v", err)
return nil
}
defer res.Body.Close()

Expand All @@ -771,7 +772,8 @@ func srsGenerateConfig(ctx context.Context) error {
}

if res.StatusCode != http.StatusOK {
return errors.Errorf("reload srs %v, code=%v, body=%v", api, res.StatusCode, string(b))
logger.Tf(ctx, "reload srs %v, code=%v, body=%v", api, res.StatusCode, string(b))
return nil
}
logger.Tf(ctx, "reload submit srs ok")
}
Expand Down

0 comments on commit d1ffc2a

Please sign in to comment.