Skip to content

Commit

Permalink
added edge to cfg for the streams
Browse files Browse the repository at this point in the history
  • Loading branch information
DawinYurtseven committed Nov 25, 2024
1 parent e76637d commit 7ff1898
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
17 changes: 10 additions & 7 deletions api/runner_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"github.com/TUM-Dev/gocast/dao"
"github.com/TUM-Dev/gocast/model"
"github.com/TUM-Dev/gocast/tools"
"github.com/getsentry/sentry-go"
log "github.com/sirupsen/logrus"
"github.com/tum-dev/gocast/runner/protobuf"
Expand Down Expand Up @@ -327,8 +328,10 @@ func (g GrpcRunnerServer) NotifyStreamStarted(ctx context.Context, request *prot
logger.Error("Can't set StreamLiveNowTimestamp", "err", err)
}

hlsUrl := fmt.Sprintf("%v:%v/%v", tools.Cfg.Edge.Domain, tools.Cfg.Edge.Port, request.HLSUrl)

time.Sleep(time.Second * 5)
if !isHLSUrlOk(request.HLSUrl) {
if !isHLSUrlOk(hlsUrl) {
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetExtra("URL", request.HLSUrl)
scope.SetExtra("StreamID", request.StreamID)
Expand All @@ -337,18 +340,18 @@ func (g GrpcRunnerServer) NotifyStreamStarted(ctx context.Context, request *prot
scope.SetExtra("Version", request.SourceType)
sentry.CaptureException(errors.New("DVR URL 404s"))
})
request.HLSUrl = strings.ReplaceAll(request.HLSUrl, "?dvr", "")
hlsUrl = strings.ReplaceAll(hlsUrl, "?dvr", "")
}

logger.Info("hls url", "url", request.HLSUrl)
logger.Info("hls url", "url", hlsUrl)

switch request.Version {
case "CAM":
g.StreamsDao.SaveCAMURL(&stream, request.HLSUrl)
g.StreamsDao.SaveCAMURL(&stream, hlsUrl)
case "PRES":
g.StreamsDao.SavePRESURL(&stream, request.HLSUrl)
g.StreamsDao.SavePRESURL(&stream, hlsUrl)
default:
g.StreamsDao.SaveCOMBURL(&stream, request.HLSUrl)
g.StreamsDao.SaveCOMBURL(&stream, hlsUrl)
}

NotifyViewersLiveState(stream.Model.ID, true)
Expand Down Expand Up @@ -598,7 +601,7 @@ func AssignRunnerAction(dao dao.DaoWrapper, action *model.Action) error {
values := map[string]interface{}{}
err = json.Unmarshal([]byte(action.Values), &values)
for key, value := range values {
logger.Info("values", "value", value)
//logger.Info("values", "value", value)
ctx = context.WithValue(ctx, key, value)
}
ctx = context.WithValue(ctx, "actionID", fmt.Sprintf("%v", action.ID))
Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ db:
database: tumlive
password: example
user: root
edge:
domain: http://localhost
port: 8089
ingestbase: rtmp://ingest.tum.live/
jwtkey: # This is an example key, delete and restart to generate a proper one
|
Expand Down
18 changes: 3 additions & 15 deletions runner/actions/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/tum-dev/gocast/runner/protobuf"
"log/slog"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -35,10 +34,6 @@ func (a *ActionProvider) StreamAction() *Action {
if !ok {
return ctx, fmt.Errorf("%w: context doesn't contain hostname", ErrRequiredContextValNotFound)
}
edgeVM, ok := ctx.Value("Edge").(string)
if !ok {
return ctx, fmt.Errorf("%w: context doesn't contain edge", ErrRequiredContextValNotFound)
}
streamID, ok := ctx.Value("stream").(uint64)
if !ok {
return ctx, fmt.Errorf("%w: context doesn't contain stream", ErrRequiredContextValNotFound)
Expand Down Expand Up @@ -107,23 +102,16 @@ func (a *ActionProvider) StreamAction() *Action {
continue
}

localhls := fmt.Sprintf("%v/%d/%d/%s/%s/playlist.m3u8", hostname, courseID, streamID, version, end.Format("15-04-05"))
//this string is the local runner url that will be passed to TUMLive

edgeURL, err := url.Parse(fmt.Sprintf("http://%v:8089/%v",
edgeVM, localhls,
))
if err != nil {
return ctx, fmt.Errorf("%w: cannot create urlPath", err)
}
log.Info("streaming", "edgeURL", edgeURL.String())
localhls := fmt.Sprintf("%v/%d/%d/%s/%s/playlist.m3u8", hostname, courseID, streamID, version, end.Format("15-04-05"))

resp := a.Server.NotifyStreamStarted(ctx, &protobuf.StreamStarted{
Hostname: hostname,
StreamID: uint32(streamID),
CourseID: uint32(courseID),
Version: version,
HLSUrl: edgeURL.String(),
// fmt.Sprintf("http://%v:%v/%v:8187/%d/%d/%s/%s/playlist.m3u8", edgeVM, 8089, hostname, courseID, streamID, version, end.Format("15-04-05")), //edgeURL.String(),
HLSUrl: localhls,
})
if resp.Ok != true {
log.Warn("streamAction: NotifyStreamStarted failed")
Expand Down
1 change: 0 additions & 1 deletion runner/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (r *Runner) RequestStream(ctx context.Context, req *protobuf.StreamRequest)
ctx = context.WithValue(ctx, "URL", "")
ctx = context.WithValue(ctx, "Hostname", r.cfg.Hostname)
ctx = context.WithValue(ctx, "Port", r.cfg.Port)
ctx = context.WithValue(ctx, "Edge", r.cfg.EdgeServer)
ctx = context.WithValue(ctx, "actionID", req.ActionID)
r.log.Info("stream request", "jobID", req.ActionID)
a := []*actions.Action{
Expand Down
1 change: 0 additions & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type envConfig struct {
RecPath string `env:"REC_PATH" envDefault:"storage/rec"`
GocastServer string `env:"GOCAST_SERVER" envDefault:"localhost:50056"`
Hostname string `env:"REALHOST" envDefault:"localhost"`
EdgeServer string `env:"EDGE_SERVER" envDefault:"localhost"`
Version string `env:"VERSION" envDefault:"dev"`
}

Expand Down
11 changes: 10 additions & 1 deletion tools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ func initConfig() {
if err != nil {
panic(fmt.Errorf("fatal error config file: %v", err))
}

if Cfg.Edge.Domain == "" {
logger.Error("No domain for edge found, can't proxy streams")
}
if Cfg.Edge.Port == 0 {
logger.Error("No port for edge found, can't proxy streams")
}
// set defaults
if Cfg.WorkerToken == "" {
Cfg.WorkerToken = uuid.NewV4().String()
Expand Down Expand Up @@ -113,6 +118,10 @@ type Config struct {
Host string `yaml:"host"`
Port uint `yaml:"port"`
} `yaml:"db"`
Edge struct {
Domain string `yaml:"domain"`
Port int `yaml:"port"`
} `yaml:"edge"`
Campus struct {
Base string `yaml:"base"`
Tokens []string `yaml:"tokens"`
Expand Down

0 comments on commit 7ff1898

Please sign in to comment.