增加可共用网关端口

This commit is contained in:
langhuihui
2021-01-09 18:26:21 +08:00
parent 84b230a050
commit ad29c0ada4
3 changed files with 21 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ package jessica
import (
"encoding/binary"
"net/http"
"strings"
"regexp"
. "github.com/Monibuca/engine/v2"
"github.com/Monibuca/engine/v2/avformat"
@@ -11,6 +11,8 @@ import (
"github.com/gobwas/ws"
)
var streamPathReg = regexp.MustCompile("/(jessica/)?((.+)(\\.flv)|(.+))")
func WsHandler(w http.ResponseWriter, r *http.Request) {
sign := r.URL.Query().Get("sign")
isFlv := false
@@ -18,9 +20,11 @@ func WsHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(403)
return
}
streamPath := strings.TrimLeft(r.RequestURI, "/")
if strings.HasSuffix(streamPath, ".flv") {
streamPath = strings.TrimRight(streamPath, ".flv")
parts := streamPathReg.FindStringSubmatch(r.RequestURI)
stringPath := parts[3]
if stringPath == "" {
stringPath = parts[5]
} else {
isFlv = true
}
conn, _, _, err := ws.UpgradeHTTP(r, w)