b15e637f14
DataSource (C++): - New optional config: MulticastGroup (e.g. "239.0.0.1") and DataPort (default Port+1); when set, enables multicast mode; absent = unicast - Control plane: BasicTCPSocket listener on Port; CONNECT received over TCP triggers HandleTCPConnect() which sends CONFIG via the same TCP connection - Data plane: BasicUDPSocket aimed at MulticastGroup:DataPort; all DATA fragments sent via dataSocket.Write() so any joined client receives them - useMulticast is the single branch point; every unicast code path is unchanged when MulticastGroup is absent - New methods: HandleTCPConnect(), IsMulticast() - 5 new unit tests (ports 44710-44729); all 38 tests passing WebUI hub (Go): - SourceConfig gains MulticastGroup and DataPort fields (JSON, optional) - UDPClient gains multicastGroup/dataPort; Run() routes to new runMulticastSession() when multicastGroup is non-empty - runMulticastSession(): TCP dial for CONNECT/CONFIG, net.ListenMulticastUDP for DATA, background goroutine watches TCP for DISCONNECT/close - All existing sm.Add() call sites updated (unicast callers pass "", 0) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"io/fs"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// version is set at build time via -ldflags "-X main.version=..."
|
|
var version = "dev"
|
|
|
|
//go:embed static
|
|
var staticFiles embed.FS
|
|
|
|
// multiFlag allows a flag to be repeated: --source a --source b
|
|
type multiFlag []string
|
|
|
|
func (f *multiFlag) String() string { return fmt.Sprintf("%v", []string(*f)) }
|
|
func (f *multiFlag) Set(v string) error { *f = append(*f, v); return nil }
|
|
|
|
func main() {
|
|
var sourceArgs multiFlag
|
|
flag.Var(&sourceArgs, "source", `Data source in the form [label@]host:port (repeatable)`)
|
|
sourcesFile := flag.String("sources-file", "", "JSON file for persistent source list (load on start, save target)")
|
|
listenAddr := flag.String("listen", ":8080", "HTTP listen address")
|
|
flag.Parse()
|
|
|
|
hub := NewHub()
|
|
sm := NewSourceManager(hub, *sourcesFile)
|
|
hub.sm = sm
|
|
|
|
go hub.Run()
|
|
|
|
// Load sources from file first (if specified), then add any CLI --source flags.
|
|
if *sourcesFile != "" {
|
|
if err := sm.Load(*sourcesFile); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
log.Printf("sources-file load: %v", err)
|
|
}
|
|
}
|
|
for _, arg := range sourceArgs {
|
|
label, addr := ParseSourceArg(arg)
|
|
sm.Add(label, addr, "", 0)
|
|
}
|
|
|
|
sub, err := fs.Sub(staticFiles, "static")
|
|
if err != nil {
|
|
log.Fatalf("static sub-fs: %v", err)
|
|
}
|
|
http.Handle("/", http.FileServer(http.FS(sub)))
|
|
http.HandleFunc("/ws", hub.HandleWebSocket)
|
|
http.HandleFunc("/api/zoom", hub.HandleZoom)
|
|
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprint(w, version)
|
|
})
|
|
|
|
log.Printf("WebUI listening on %s (version=%s)", *listenAddr, version)
|
|
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
|
|
log.Fatalf("http: %v", err)
|
|
}
|
|
}
|