clean up whep delivery

This commit is contained in:
legop3
2025-11-14 01:45:06 -05:00
parent 31e31bfe2d
commit c0dce561bd
9 changed files with 40 additions and 28 deletions
+33
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"net/url"
"os"
"strings"
"time"
@@ -59,6 +60,7 @@ type MediaConfig struct {
WhepPort int `yaml:"whepPort" json:"-"`
WhepPath string `yaml:"whepPath" json:"-"`
LegacyPublish string `yaml:"publishUrl,omitempty" json:"-"`
BridgeWhepURL string `yaml:"-" json:"bridgeWhepUrl,omitempty"`
Manage bool `yaml:"manage"`
Service string `yaml:"service"`
HealthURL string `yaml:"healthUrl"`
@@ -141,9 +143,40 @@ func LoadConfig(path string) (*Config, error) {
scheme := "http"
cfg.Media.WhepURL = fmt.Sprintf("%s://%s:%d%s", scheme, ip, effectivePort(cfg.Media.WhepPort), path)
}
if bridge, err := buildBridgeURL(cfg.Media.WhepURL); err == nil {
cfg.Media.BridgeWhepURL = bridge
}
return &cfg, nil
}
func buildBridgeURL(src string) (string, error) {
if src == "" {
return "", errors.New("empty whep url")
}
parsed, err := url.Parse(src)
if err != nil {
return "", err
}
if parsed.Host == "" {
return "", errors.New("missing host")
}
proto := "whep"
if parsed.Scheme == "https" {
proto = "wheps"
}
path := parsed.Path
if path == "" || path == "/" {
path = "/"
}
if !strings.HasSuffix(path, "/whep") {
if !strings.HasSuffix(path, "/") {
path += "/"
}
path += "whep"
}
return fmt.Sprintf("%s://%s%s", proto, parsed.Host, path), nil
}
func ensureLeadingSlash(path string) string {
if !strings.HasPrefix(path, "/") {
return "/" + path
-1
View File
@@ -15,7 +15,6 @@ battery:
urgent: 1650
maxWheelSpeed: 350
media:
whepUrl: http://roomba-alpha.local:8889/whep/rovercam
manage: false
service: mediamtx.service
healthUrl: http://127.0.0.1:9997/v3/paths/list
-1
View File
@@ -15,7 +15,6 @@ battery:
urgent: 1650
maxWheelSpeed: 350
media:
whepUrl: http://roomba-alpha.local:8889/whep/rovercam
manage: false
service: mediamtx.service
healthUrl: http://127.0.0.1:9997/v3/paths/list