Skip to content

Commit

Permalink
webrtc: move JavaScript reader and publisher into portable classes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 28, 2024
1 parent 51b21c8 commit 20ad88f
Show file tree
Hide file tree
Showing 5 changed files with 1,157 additions and 1,065 deletions.
22 changes: 22 additions & 0 deletions internal/servers/webrtc/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ import (
//go:embed publish_index.html
var publishIndex []byte

//go:embed publisher.js
var publisherJS []byte

//go:embed read_index.html
var readIndex []byte

//go:embed reader.js
var readerJS []byte

var (
reWHIPWHEPNoID = regexp.MustCompile("^/(.+?)/(whip|whep)$")
reWHIPWHEPWithID = regexp.MustCompile("^/(.+?)/(whip|whep)/(.+?)$")
Expand Down Expand Up @@ -323,6 +329,22 @@ func (s *httpServer) middlewareOrigin(ctx *gin.Context) {
}

func (s *httpServer) onRequest(ctx *gin.Context) {
if strings.HasSuffix(ctx.Request.URL.Path, "/publisher.js") {
ctx.Header("Cache-Control", "max-age=3600")
ctx.Header("Content-Type", "application/javascript")
ctx.Writer.WriteHeader(http.StatusOK)
ctx.Writer.Write(publisherJS)
return
}

if strings.HasSuffix(ctx.Request.URL.Path, "/reader.js") {
ctx.Header("Cache-Control", "max-age=3600")
ctx.Header("Content-Type", "application/javascript")
ctx.Writer.WriteHeader(http.StatusOK)
ctx.Writer.Write(readerJS)
return
}

// WHIP/WHEP, outside session
if m := reWHIPWHEPNoID.FindStringSubmatch(ctx.Request.URL.Path); m != nil {
switch ctx.Request.Method {
Expand Down
Loading

0 comments on commit 20ad88f

Please sign in to comment.