Skip to content

Commit

Permalink
Merge branch 'enh/runner' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
SebiWrn committed Nov 29, 2024
2 parents cdb2b00 + fe262c2 commit 8ea33d0
Show file tree
Hide file tree
Showing 48 changed files with 250 additions and 208 deletions.
3 changes: 2 additions & 1 deletion api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ func (r coursesRoutes) getCourseBySlug(c *gin.Context) {

if (course.IsLoggedIn() && tumLiveContext.User == nil) || (course.IsEnrolled() && !tumLiveContext.User.IsEligibleToWatchCourse(course)) {
c.AbortWithStatus(http.StatusUnauthorized)
return
}

user := tumLiveContext.User
Expand Down Expand Up @@ -1059,7 +1060,7 @@ func (r coursesRoutes) fetchLectures(c *gin.Context) {
tlctx := c.MustGet("TUMLiveContext").(tools.TUMLiveContext)

lectureHalls := r.LectureHallsDao.GetAllLectureHalls()
streams := tlctx.Course.AdminJson(lectureHalls)
streams := tools.AdminCourseJson(tlctx.Course, lectureHalls, tlctx.User)

c.JSON(http.StatusOK, gin.H{
"streams": streams,
Expand Down
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
26 changes: 15 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
####################################################
# Not production ready, only for local development #
####################################################
version: "3.8"

services:
Expand All @@ -20,7 +23,7 @@ services:
container_name: tum-live-worker
depends_on:
- tum-live
- vod-service
#- vod-service # Omitted for local development due to size. Comment out to use voice-service
build: worker
platform: linux/amd64
environment:
Expand Down Expand Up @@ -68,16 +71,17 @@ services:
- ./init.sql:/data/application/init.sql
- mariadb-data:/var/lib/mysql
restart: always
voice-service:
container_name: tum-live-voice-service
image: ghcr.io/tum-dev/tum-live-voice-service:latest
environment:
- TRANSCRIBER=whisper
- WHISPER_MODEL=tiny
- MAX_WORKERS=10
- DEBUG=1
volumes:
- mass:/mass
# Omitted for local development due to size. Comment out to use voice-service
# voice-service:
# container_name: tum-live-voice-service
# image: ghcr.io/tum-dev/tum-live-voice-service:latest
# environment:
# - TRANSCRIBER=whisper
# - WHISPER_MODEL=tiny
# - MAX_WORKERS=10
# - DEBUG=1
# volumes:
# - mass:/mass

volumes:
recordings:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/go-gormigrate/gormigrate/v2 v2.1.1
github.com/go-ldap/ldap/v3 v3.4.6
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang/glog v1.2.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/jinzhu/now v1.1.5
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGF
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
Expand Down
10 changes: 0 additions & 10 deletions model/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"time"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -332,12 +331,3 @@ func (c Course) IsLoggedIn() bool {
func (c Course) IsEnrolled() bool {
return c.Visibility == "enrolled"
}

// AdminJson is the JSON representation of a courses streams for the admin panel
func (c Course) AdminJson(lhs []LectureHall) []gin.H {
var res []gin.H
for _, s := range c.Streams {
res = append(res, s.getJson(lhs, c))
}
return res
}
3 changes: 1 addition & 2 deletions model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const (
// Notification is a message (e.g. a feature alert) that is displayed to users
type Notification struct {
Model

Title *string `json:"title,omitempty"`
Body string `json:"-" gorm:"not null"`
Target NotificationTarget `json:"-" gorm:"not null; default:1"`
Target NotificationTarget `json:"target" gorm:"not null; default:1"`

// SanitizedBody is the body of the notification, converted from markdown to HTML
SanitizedBody string `json:"body" gorm:"-"`
Expand Down
2 changes: 1 addition & 1 deletion model/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (s Stream) Color() string {
}
}

func (s Stream) getJson(lhs []LectureHall, course Course) gin.H {
func (s Stream) GetJson(lhs []LectureHall, course Course) gin.H {
var files []gin.H
for _, file := range s.Files {
files = append(files, gin.H{
Expand Down
3 changes: 0 additions & 3 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func (s PlaybackSpeedSettings) GetEnabled() (res []float32) {
}

func (u *User) GetEnabledPlaybackSpeeds() (res []float32) {
if u == nil {
return []float32{1}
}
// Possibly, this could be collapsed into a single line, but readibility suffers.
res = append(res, u.GetPlaybackSpeeds().GetEnabled()...)
res = append(res, u.GetCustomSpeeds()...)
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
20 changes: 20 additions & 0 deletions tools/json-generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tools

import (
"github.com/TUM-Dev/gocast/model"
"github.com/gin-gonic/gin"
)

// AdminCourseJson is the JSON representation of a courses streams for the admin panel
func AdminCourseJson(c *model.Course, lhs []model.LectureHall, u *model.User) []gin.H {
var res []gin.H
streams := c.Streams
for _, s := range streams {
err := SetSignedPlaylists(&s, u, true)
if err != nil {
logger.Error("Could not sign playlist for admin", "err", err)
}
res = append(res, s.GetJson(lhs, *c))
}
return res
}
5 changes: 5 additions & 0 deletions web/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,13 @@ func (r mainRoutes) EditCoursePage(c *gin.Context) {
if err != nil {
logger.Error("Error getting invited users for course", "err", err)
}
y, t := tum.GetCurrentSemester()

indexData := NewIndexData()
indexData.TUMLiveContext = tumLiveContext
indexData.CurrentYear = y
indexData.CurrentTerm = t

courses, err := r.CoursesDao.GetAdministeredCoursesByUserId(context.Background(), tumLiveContext.User.ID, "", 0)
if err != nil {
logger.Error("couldn't query courses for user.", "err", err)
Expand Down
5 changes: 5 additions & 0 deletions web/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
@apply text-gray-700 dark:text-gray-300;
}

/*low contrast text*/
.important-text-4 {
@apply text-gray-700 dark:text-gray-300 !important;
}

/*full contrast text*/
.text-5 {
@apply text-gray-600 dark:text-gray-400;
Expand Down
31 changes: 30 additions & 1 deletion web/template/admin/admin_tabs/edit-course.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{{- /*gotype: github.com/TUM-Dev/gocast/web.AdminPageData*/ -}}
{{$course := .IndexData.TUMLiveContext.Course}}
{{$lecture := .IndexData.TUMLiveContext.Stream}}
{{$currentYear := .IndexData.CurrentYear}}
{{$currentTerm := .IndexData.CurrentTerm}}

<div class="text-1 mt-4" x-data="{userId: {{.IndexData.TUMLiveContext.User.Model.ID}} }">
<div class="min-w-screen items-center justify-center">

Expand All @@ -20,6 +23,32 @@
role="alert">
Course was created successfully.
</div>
{{if (eq $course.TeachingTerm "Test")}}
<div class="p-3 text-md border border-blue-500 text-blue-500 bg-blue-100 dark:bg-blue-200 dark:border-blue-700 dark:text-blue-700 rounded-lg flex items-center" role="alert">
<div class="flex-shrink-0">
<i class="fa-solid fa-info-circle text-4 text-blue-500 dark:text-blue-700"></i>
</div>
<div class="ml-3" x-init="console.log('currentYear: {{$currentYear}}', 'currentTerm: {{$currentTerm}}', 'courseYear: {{$course.Year}}', 'courseTerm: {{$course.TeachingTerm}}')">
<div class="font-bold">Info: Test Course</div>
<div class="text-sm">
This course is your personal test course. It will not be shown in the course overview to students and is only visible to you as an admin. <br>
</div>
</div>
</div>
{{else if or (ne $course.TeachingTerm $currentTerm) (ne $course.Year $currentYear)}}
<div class="p-3 text-md border bg-yellow-100 border-yellow-600 text-yellow-600 dark:bg-yellow-200 dark:border-yellow-700 dark:text-yellow-700 rounded-lg flex items-center" role="alert">
<div class="flex-shrink-0">
<i class="fa-solid fa-warning text-4 text-yellow-500 dark:text-yellow-700"></i>
</div>
<div class="ml-3" x-init="console.log('currentYear: {{$currentYear}}', 'currentTerm: {{$currentTerm}}', 'courseYear: {{$course.Year}}', 'courseTerm: {{$course.TeachingTerm}}')">
<div class="font-bold">Warning: Outdated Semester</div>
<div class="text-sm">
This course is not from the current semester and might not be shown in the course overview to students. <br>
If this is a recurring course, please select the course from the current semester and year.
</div>
</div>
</div>
{{end}}
</div>

<label class="hidden" for="courseID">CourseID<input id="courseID" type="text" class="hidden"
Expand Down Expand Up @@ -114,4 +143,4 @@
</div>
</div>
</div>
{{end}}
{{end}}
Loading

0 comments on commit 8ea33d0

Please sign in to comment.