test relay server
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 2m1s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 2m1s
This commit is contained in:
57
cmd/main.go
Normal file
57
cmd/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/okdaichi/gomoqt/moqt"
|
||||
|
||||
"qgo/internal/relay"
|
||||
)
|
||||
|
||||
func main() {
|
||||
domain := "qgo-server.quizer.space"
|
||||
email := "serverussnap@outlook.com"
|
||||
|
||||
certmagic.DefaultACME.Email = email
|
||||
certmagic.DefaultACME.Agreed = true
|
||||
certmagic.Default.Storage = &certmagic.FileStorage{
|
||||
Path: "/root/.local/share/certmagic",
|
||||
}
|
||||
|
||||
tlsConf, err := certmagic.TLS([]string{domain})
|
||||
if err != nil {
|
||||
slog.Error("TLS failed", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
tlsConf.NextProtos = []string{"h3"}
|
||||
tlsConf.MinVersion = tls.VersionTLS13
|
||||
|
||||
relayServer := relay.New()
|
||||
|
||||
moqt.HandleFunc("/relay/", func(w moqt.SetupResponseWriter, r *moqt.SetupRequest) {
|
||||
|
||||
room := strings.TrimPrefix(r.Path, "/relay/")
|
||||
mux := relayServer.GetMux(room)
|
||||
|
||||
_, err := moqt.Accept(w, r, mux)
|
||||
if err != nil {
|
||||
slog.Error("accept failed", "err", err)
|
||||
w.Reject(moqt.InternalSessionErrorCode)
|
||||
return
|
||||
}
|
||||
|
||||
slog.Info("session connected", "room", room)
|
||||
})
|
||||
|
||||
slog.Info("Mini-SFU running",
|
||||
"url", "https://"+domain+"/relay/{room}",
|
||||
)
|
||||
|
||||
if err := moqt.ListenAndServe(":443", tlsConf); err != nil {
|
||||
slog.Error("server failed", "err", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user