From d1ffc2ac313fe7a386f61abe10ab398b53818fb4 Mon Sep 17 00:00:00 2001 From: Jacob Su Date: Tue, 22 Oct 2024 00:08:15 +0800 Subject: [PATCH] support srs http api config by env. --- platform/main.go | 3 +-- platform/service.go | 11 ++++++----- platform/srs-hooks.go | 2 +- platform/utils.go | 6 ++++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/platform/main.go b/platform/main.go index 0b527953..9a03f862 100644 --- a/platform/main.go +++ b/platform/main.go @@ -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") diff --git a/platform/service.go b/platform/service.go index 38f72efe..30c044f4 100644 --- a/platform/service.go +++ b/platform/service.go @@ -11,6 +11,7 @@ import ( "io" "io/ioutil" "net/http" + "os" "path" "runtime" "strconv" @@ -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 } @@ -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 { diff --git a/platform/srs-hooks.go b/platform/srs-hooks.go index 526197c0..7001b648 100644 --- a/platform/srs-hooks.go +++ b/platform/srs-hooks.go @@ -740,7 +740,7 @@ func handleOnHls(ctx context.Context, handler *http.ServeMux) error { if tsFile, err := os.Create(msg.File); err != nil { 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 { diff --git a/platform/utils.go b/platform/utils.go index cc065f1f..bda9c354 100644 --- a/platform/utils.go +++ b/platform/utils.go @@ -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() @@ -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") }