Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let oryx support external redis and srs service #228

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
support redis and srs host config.
  • Loading branch information
suzp1984 committed Oct 28, 2024
commit 50fee84f1c3b71b89039508a077f065e9b9a3f13
4 changes: 4 additions & 0 deletions platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"

// Use v8 because we use Go 1.16+, while v9 requires Go 1.18+
"github.com/go-redis/redis/v8"
"github.com/google/uuid"
Expand Down Expand Up @@ -113,6 +114,9 @@ func doMain(ctx context.Context) error {
setEnvDefault("REDIS_PORT", "6379")
setEnvDefault("MGMT_LISTEN", "2022")

// SRS HOST
setEnvDefault("SRS_HOST", "127.0.0.1")

// For HTTPS.
setEnvDefault("HTTPS_LISTEN", "2443")
setEnvDefault("AUTO_SELF_SIGNED_CERTIFICATE", "on")
Expand Down
14 changes: 8 additions & 6 deletions platform/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/joho/godotenv"
"io"
"io/ioutil"
"net/http"
Expand All @@ -19,9 +18,12 @@ import (
"sync"
"time"

"github.com/joho/godotenv"

"github.com/ossrs/go-oryx-lib/errors"
ohttp "github.com/ossrs/go-oryx-lib/http"
"github.com/ossrs/go-oryx-lib/logger"

// Use v8 because we use Go 1.16+, while v9 requires Go 1.18+
"github.com/go-redis/redis/v8"
)
Expand Down Expand Up @@ -288,22 +290,22 @@ func handleHTTPService(ctx context.Context, handler *http.ServeMux) error {
handleMgmtStreamsKickoff(ctx, handler)
handleMgmtUI(ctx, handler)

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

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

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

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

// Whether client exists in SRS server.
var code int
clientURL := fmt.Sprintf("http://127.0.0.1:1985/api/v1/clients/%v", 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/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ func srsGenerateConfig(ctx context.Context) error {

// Reload SRS to apply the new config.
if true {
api := "http://127.0.0.1:1985/api/v1/raw?rpc=reload"
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)
Expand Down