mirror of
https://github.com/Monibuca/plugin-jessica.git
synced 2025-10-20 06:44:44 +08:00
增加可共用网关端口
This commit is contained in:
@@ -17,4 +17,6 @@ ListenAddr = ":8080"
|
||||
CertFile = "../foo.cert"
|
||||
KeyFile = "../foo.key"
|
||||
ListenAddrTLS = ":8088"
|
||||
```
|
||||
```
|
||||
|
||||
- 如果不设置ListenAddr和ListenAddrTLS,将共用网关的端口监听
|
15
main.go
15
main.go
@@ -13,12 +13,12 @@ import (
|
||||
. "github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
var config = &struct {
|
||||
var config struct {
|
||||
ListenAddr string
|
||||
CertFile string
|
||||
KeyFile string
|
||||
ListenAddrTLS string
|
||||
}{}
|
||||
}
|
||||
|
||||
var publicPath string
|
||||
|
||||
@@ -26,16 +26,21 @@ func init() {
|
||||
plugin := &PluginConfig{
|
||||
Name: "Jessica",
|
||||
Type: PLUGIN_SUBSCRIBER,
|
||||
Config: config,
|
||||
Config: &config,
|
||||
Run: run,
|
||||
}
|
||||
InstallPlugin(plugin)
|
||||
publicPath = filepath.Join(plugin.Dir, "ui", "public")
|
||||
}
|
||||
func run() {
|
||||
Print(Green("server Jessica start at"), BrightBlue(config.ListenAddr))
|
||||
http.HandleFunc("/jessibuca/", jessibuca)
|
||||
utils.ListenAddrs(config.ListenAddr, config.ListenAddrTLS, config.CertFile, config.KeyFile, http.HandlerFunc(WsHandler))
|
||||
if config.ListenAddr != "" || config.ListenAddrTLS != "" {
|
||||
Print(Green("Jessica start at"), BrightBlue(config.ListenAddr), BrightBlue(config.ListenAddrTLS))
|
||||
utils.ListenAddrs(config.ListenAddr, config.ListenAddrTLS, config.CertFile, config.KeyFile, http.HandlerFunc(WsHandler))
|
||||
} else {
|
||||
Print(Green("Jessica start reuse gateway port"))
|
||||
http.HandleFunc("/jessica/", WsHandler)
|
||||
}
|
||||
}
|
||||
func jessibuca(w http.ResponseWriter, r *http.Request) {
|
||||
filePath := strings.TrimPrefix(r.URL.Path, "/jessibuca")
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user