|
|
|
@ -6,6 +6,8 @@ import (
@@ -6,6 +6,8 @@ import (
|
|
|
|
|
"io" |
|
|
|
|
"net" |
|
|
|
|
"net/http" |
|
|
|
|
"net/url" |
|
|
|
|
"regexp" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -25,13 +27,29 @@ var webrtcPublishIndex []byte
@@ -25,13 +27,29 @@ var webrtcPublishIndex []byte
|
|
|
|
|
//go:embed webrtc_read_index.html
|
|
|
|
|
var webrtcReadIndex []byte |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
reWHIPWHEPNoID = regexp.MustCompile("^/(.+?)/(whip|whep)$") |
|
|
|
|
reWHIPWHEPWithID = regexp.MustCompile("^/(.+?)/(whip|whep)/(.+?)$") |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func relativeLocation(u *url.URL) string { |
|
|
|
|
p := u.Path |
|
|
|
|
if u.RawQuery != "" { |
|
|
|
|
p += "?" + u.RawQuery |
|
|
|
|
} |
|
|
|
|
return p |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type webRTCHTTPServerParent interface { |
|
|
|
|
logger.Writer |
|
|
|
|
generateICEServers() ([]webrtc.ICEServer, error) |
|
|
|
|
newSession(req webRTCNewSessionReq) webRTCNewSessionRes |
|
|
|
|
addSessionCandidates(req webRTCAddSessionCandidatesReq) webRTCAddSessionCandidatesRes |
|
|
|
|
deleteSession(req webRTCDeleteSessionReq) error |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This implements https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
|
|
|
|
|
// This implements https://datatracker.ietf.org/doc/draft-murillo-whep/
|
|
|
|
|
type webRTCHTTPServer struct { |
|
|
|
|
allowOrigin string |
|
|
|
|
pathManager *pathManager |
|
|
|
@ -97,214 +115,244 @@ func (s *webRTCHTTPServer) close() {
@@ -97,214 +115,244 @@ func (s *webRTCHTTPServer) close() {
|
|
|
|
|
s.inner.Close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) { |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Origin", s.allowOrigin) |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true") |
|
|
|
|
|
|
|
|
|
// remove leading prefix
|
|
|
|
|
pa := ctx.Request.URL.Path[1:] |
|
|
|
|
func (s *webRTCHTTPServer) checkAuthOutsideSession(ctx *gin.Context, path string, publish bool) bool { |
|
|
|
|
ip := ctx.ClientIP() |
|
|
|
|
_, port, _ := net.SplitHostPort(ctx.Request.RemoteAddr) |
|
|
|
|
remoteAddr := net.JoinHostPort(ip, port) |
|
|
|
|
user, pass, hasCredentials := ctx.Request.BasicAuth() |
|
|
|
|
|
|
|
|
|
isWHIPorWHEP := strings.HasSuffix(pa, "/whip") || strings.HasSuffix(pa, "/whep") |
|
|
|
|
isPreflight := ctx.Request.Method == http.MethodOptions && |
|
|
|
|
ctx.Request.Header.Get("Access-Control-Request-Method") != "" |
|
|
|
|
res := s.pathManager.getConfForPath(pathGetConfForPathReq{ |
|
|
|
|
accessRequest: pathAccessRequest{ |
|
|
|
|
name: path, |
|
|
|
|
query: ctx.Request.URL.RawQuery, |
|
|
|
|
publish: publish, |
|
|
|
|
ip: net.ParseIP(ip), |
|
|
|
|
user: user, |
|
|
|
|
pass: pass, |
|
|
|
|
proto: authProtocolWebRTC, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
if terr, ok := res.err.(*errAuthentication); ok { |
|
|
|
|
if !hasCredentials { |
|
|
|
|
ctx.Header("WWW-Authenticate", `Basic realm="mediamtx"`) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusUnauthorized) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !isWHIPorWHEP || isPreflight { |
|
|
|
|
switch ctx.Request.Method { |
|
|
|
|
case http.MethodOptions: |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, If-Match") |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
return |
|
|
|
|
s.Log(logger.Info, "connection %v failed to authenticate: %v", remoteAddr, terr.message) |
|
|
|
|
|
|
|
|
|
case http.MethodGet: |
|
|
|
|
// wait some seconds to stop brute force attacks
|
|
|
|
|
<-time.After(webrtcPauseAfterAuthError) |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
return |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusUnauthorized) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNotFound) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var dir string |
|
|
|
|
var fname string |
|
|
|
|
var publish bool |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
case pa == "", pa == "favicon.ico": |
|
|
|
|
func (s *webRTCHTTPServer) onWHIPOptions(ctx *gin.Context, path string, publish bool) { |
|
|
|
|
if !s.checkAuthOutsideSession(ctx, path, publish) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case strings.HasSuffix(pa, "/publish"): |
|
|
|
|
dir, fname = pa[:len(pa)-len("/publish")], "publish" |
|
|
|
|
publish = true |
|
|
|
|
|
|
|
|
|
case strings.HasSuffix(pa, "/whip"): |
|
|
|
|
dir, fname = pa[:len(pa)-len("/whip")], "whip" |
|
|
|
|
publish = true |
|
|
|
|
|
|
|
|
|
case strings.HasSuffix(pa, "/whep"): |
|
|
|
|
dir, fname = pa[:len(pa)-len("/whep")], "whep" |
|
|
|
|
publish = false |
|
|
|
|
servers, err := s.parent.generateICEServers() |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
dir, fname = pa, "" |
|
|
|
|
publish = false |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH, DELETE") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, If-Match") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Expose-Headers", "Link") |
|
|
|
|
ctx.Writer.Header()["Link"] = whip.LinkHeaderMarshal(servers) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !strings.HasSuffix(dir, "/") { |
|
|
|
|
l := "/" + dir + "/" |
|
|
|
|
if ctx.Request.URL.RawQuery != "" { |
|
|
|
|
l += "?" + ctx.Request.URL.RawQuery |
|
|
|
|
} |
|
|
|
|
ctx.Writer.Header().Set("Location", l) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusMovedPermanently) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
func (s *webRTCHTTPServer) onWHIPPost(ctx *gin.Context, path string, publish bool) { |
|
|
|
|
if ctx.Request.Header.Get("Content-Type") != "application/sdp" { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dir = strings.TrimSuffix(dir, "/") |
|
|
|
|
if dir == "" { |
|
|
|
|
offer, err := io.ReadAll(ctx.Request.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ip := ctx.ClientIP() |
|
|
|
|
_, port, _ := net.SplitHostPort(ctx.Request.RemoteAddr) |
|
|
|
|
remoteAddr := net.JoinHostPort(ip, port) |
|
|
|
|
user, pass, hasCredentials := ctx.Request.BasicAuth() |
|
|
|
|
user, pass, _ := ctx.Request.BasicAuth() |
|
|
|
|
|
|
|
|
|
res := s.parent.newSession(webRTCNewSessionReq{ |
|
|
|
|
pathName: path, |
|
|
|
|
remoteAddr: remoteAddr, |
|
|
|
|
query: ctx.Request.URL.RawQuery, |
|
|
|
|
user: user, |
|
|
|
|
pass: pass, |
|
|
|
|
offer: offer, |
|
|
|
|
publish: publish, |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(res.errStatusCode) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if request doesn't belong to a session, check authentication here
|
|
|
|
|
if !isWHIPorWHEP || ctx.Request.Method == http.MethodOptions { |
|
|
|
|
res := s.pathManager.getConfForPath(pathGetConfForPathReq{ |
|
|
|
|
accessRequest: pathAccessRequest{ |
|
|
|
|
name: dir, |
|
|
|
|
query: ctx.Request.URL.RawQuery, |
|
|
|
|
publish: publish, |
|
|
|
|
ip: net.ParseIP(ip), |
|
|
|
|
user: user, |
|
|
|
|
pass: pass, |
|
|
|
|
proto: authProtocolWebRTC, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
if terr, ok := res.err.(*errAuthentication); ok { |
|
|
|
|
if !hasCredentials { |
|
|
|
|
ctx.Header("WWW-Authenticate", `Basic realm="mediamtx"`) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusUnauthorized) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
s.Log(logger.Info, "connection %v failed to authenticate: %v", remoteAddr, terr.message) |
|
|
|
|
|
|
|
|
|
// wait some seconds to stop brute force attacks
|
|
|
|
|
<-time.After(webrtcPauseAfterAuthError) |
|
|
|
|
servers, err := s.parent.generateICEServers() |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.WriteHeader(http.StatusUnauthorized) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ctx.Writer.Header().Set("Content-Type", "application/sdp") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Expose-Headers", "ETag, Accept-Patch, Link, Location") |
|
|
|
|
ctx.Writer.Header().Set("ETag", "*") |
|
|
|
|
ctx.Writer.Header().Set("ID", res.sx.uuid.String()) |
|
|
|
|
ctx.Writer.Header().Set("Accept-Patch", "application/trickle-ice-sdpfrag") |
|
|
|
|
ctx.Writer.Header()["Link"] = whip.LinkHeaderMarshal(servers) |
|
|
|
|
ctx.Request.URL.Path += "/" + res.sx.secret.String() |
|
|
|
|
ctx.Writer.Header().Set("Location", relativeLocation(ctx.Request.URL)) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusCreated) |
|
|
|
|
ctx.Writer.Write(res.answer) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNotFound) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
func (s *webRTCHTTPServer) onWHIPPatch(ctx *gin.Context, rawSecret string) { |
|
|
|
|
secret, err := uuid.Parse(rawSecret) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch fname { |
|
|
|
|
case "": |
|
|
|
|
ctx.Writer.Header().Set("Cache-Control", "max-age=3600") |
|
|
|
|
ctx.Writer.Header().Set("Content-Type", "text/html") |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusOK) |
|
|
|
|
ctx.Writer.Write(webrtcReadIndex) |
|
|
|
|
if ctx.Request.Header.Get("Content-Type") != "application/trickle-ice-sdpfrag" { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case "publish": |
|
|
|
|
ctx.Writer.Header().Set("Cache-Control", "max-age=3600") |
|
|
|
|
ctx.Writer.Header().Set("Content-Type", "text/html") |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusOK) |
|
|
|
|
ctx.Writer.Write(webrtcPublishIndex) |
|
|
|
|
byts, err := io.ReadAll(ctx.Request.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case "whip", "whep": |
|
|
|
|
switch ctx.Request.Method { |
|
|
|
|
case http.MethodOptions: |
|
|
|
|
servers, err := s.parent.generateICEServers() |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
candidates, err := whip.ICEFragmentUnmarshal(byts) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, If-Match") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Expose-Headers", "Link") |
|
|
|
|
ctx.Writer.Header()["Link"] = whip.LinkHeaderMarshal(servers) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
res := s.parent.addSessionCandidates(webRTCAddSessionCandidatesReq{ |
|
|
|
|
secret: secret, |
|
|
|
|
candidates: candidates, |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case http.MethodPost: |
|
|
|
|
if ctx.Request.Header.Get("Content-Type") != "application/sdp" { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
offer, err := io.ReadAll(ctx.Request.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
func (s *webRTCHTTPServer) onWHIPDelete(ctx *gin.Context, rawSecret string) { |
|
|
|
|
secret, err := uuid.Parse(rawSecret) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res := s.parent.newSession(webRTCNewSessionReq{ |
|
|
|
|
pathName: dir, |
|
|
|
|
remoteAddr: remoteAddr, |
|
|
|
|
query: ctx.Request.URL.RawQuery, |
|
|
|
|
user: user, |
|
|
|
|
pass: pass, |
|
|
|
|
offer: offer, |
|
|
|
|
publish: (fname == "whip"), |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(res.errStatusCode) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
err = s.parent.deleteSession(webRTCDeleteSessionReq{ |
|
|
|
|
secret: secret, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
servers, err := s.parent.generateICEServers() |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusOK) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.Header().Set("Content-Type", "application/sdp") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Expose-Headers", "ETag, Accept-Patch, Link, Location") |
|
|
|
|
ctx.Writer.Header().Set("ETag", res.sx.secret.String()) |
|
|
|
|
ctx.Writer.Header().Set("ID", res.sx.uuid.String()) |
|
|
|
|
ctx.Writer.Header().Set("Accept-Patch", "application/trickle-ice-sdpfrag") |
|
|
|
|
ctx.Writer.Header()["Link"] = whip.LinkHeaderMarshal(servers) |
|
|
|
|
ctx.Writer.Header().Set("Location", ctx.Request.URL.String()) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusCreated) |
|
|
|
|
ctx.Writer.Write(res.answer) |
|
|
|
|
func (s *webRTCHTTPServer) onPage(ctx *gin.Context, path string, publish bool) { |
|
|
|
|
if !s.checkAuthOutsideSession(ctx, path, publish) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx.Writer.Header().Set("Cache-Control", "max-age=3600") |
|
|
|
|
ctx.Writer.Header().Set("Content-Type", "text/html") |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusOK) |
|
|
|
|
|
|
|
|
|
if publish { |
|
|
|
|
ctx.Writer.Write(webrtcPublishIndex) |
|
|
|
|
} else { |
|
|
|
|
ctx.Writer.Write(webrtcReadIndex) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) { |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Origin", s.allowOrigin) |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true") |
|
|
|
|
|
|
|
|
|
// preflight requests
|
|
|
|
|
if ctx.Request.Method == http.MethodOptions && |
|
|
|
|
ctx.Request.Header.Get("Access-Control-Request-Method") != "" { |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH, DELETE") |
|
|
|
|
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, If-Match") |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WHIP, outside session
|
|
|
|
|
if m := reWHIPWHEPNoID.FindStringSubmatch(ctx.Request.URL.Path); m != nil { |
|
|
|
|
switch ctx.Request.Method { |
|
|
|
|
case http.MethodOptions: |
|
|
|
|
s.onWHIPOptions(ctx, m[1], m[2] == "whip") |
|
|
|
|
|
|
|
|
|
case http.MethodPost: |
|
|
|
|
s.onWHIPPost(ctx, m[1], m[2] == "whip") |
|
|
|
|
|
|
|
|
|
case http.MethodGet, http.MethodHead, http.MethodPut: |
|
|
|
|
// RFC draft-ietf-whip-09
|
|
|
|
|
// The WHIP endpoints MUST return an "405 Method Not Allowed" response
|
|
|
|
|
// for any HTTP GET, HEAD or PUT requests
|
|
|
|
|
ctx.Writer.WriteHeader(http.StatusMethodNotAllowed) |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WHIP, inside session
|
|
|
|
|
if m := reWHIPWHEPWithID.FindStringSubmatch(ctx.Request.URL.Path); m != nil { |
|
|
|
|
switch ctx.Request.Method { |
|
|
|
|
case http.MethodPatch: |
|
|
|
|
secret, err := uuid.Parse(ctx.Request.Header.Get("If-Match")) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
s.onWHIPPatch(ctx, m[3]) |
|
|
|
|
|
|
|
|
|
if ctx.Request.Header.Get("Content-Type") != "application/trickle-ice-sdpfrag" { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
case http.MethodDelete: |
|
|
|
|
s.onWHIPDelete(ctx, m[3]) |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
byts, err := io.ReadAll(ctx.Request.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// static resources
|
|
|
|
|
if ctx.Request.Method == http.MethodGet { |
|
|
|
|
switch { |
|
|
|
|
case ctx.Request.URL.Path == "/favicon.ico": |
|
|
|
|
|
|
|
|
|
candidates, err := whip.ICEFragmentUnmarshal(byts) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
case len(ctx.Request.URL.Path) >= 3: |
|
|
|
|
switch { |
|
|
|
|
case strings.HasSuffix(ctx.Request.URL.Path, "/publish"): |
|
|
|
|
s.onPage(ctx, ctx.Request.URL.Path[1:len(ctx.Request.URL.Path)-len("/publish")], true) |
|
|
|
|
|
|
|
|
|
res := s.parent.addSessionCandidates(webRTCAddSessionCandidatesReq{ |
|
|
|
|
secret: secret, |
|
|
|
|
candidates: candidates, |
|
|
|
|
}) |
|
|
|
|
if res.err != nil { |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusBadRequest) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
case ctx.Request.URL.Path[len(ctx.Request.URL.Path)-1] != '/': |
|
|
|
|
ctx.Request.URL.Path += "/" |
|
|
|
|
ctx.Writer.Header().Set("Location", relativeLocation(ctx.Request.URL)) |
|
|
|
|
ctx.Writer.WriteHeader(http.StatusMovedPermanently) |
|
|
|
|
|
|
|
|
|
ctx.Writer.WriteHeader(http.StatusNoContent) |
|
|
|
|
default: |
|
|
|
|
s.onPage(ctx, ctx.Request.URL.Path[1:len(ctx.Request.URL.Path)-1], false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|