🎉 live server seems to be working now

This commit is contained in:
2026-05-14 14:29:57 +02:00
commit d72e439fd9
181 changed files with 47406 additions and 0 deletions

88
cmd/server/main.go Normal file
View File

@@ -0,0 +1,88 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/Sendspin/sendspin-go/pkg/sendspin"
"rpi-sendspin/internal/pipewire"
)
func main() {
port := flag.Int("port", 8927, "listen port")
name := flag.String("name", "Sendspin Server", "server name")
source := flag.String("source", "", "PipeWire source node name")
listSources := flag.Bool("list-sources", false, "list available PipeWire sources and exit")
rate := flag.Int("rate", 48000, "capture sample rate")
channels := flag.Int("channels", 2, "capture channels")
flag.Parse()
if *listSources {
printSources()
return
}
if *source == "" {
sources, err := pipewire.ListSources()
if err != nil {
log.Fatalf("list sources: %v", err)
}
if len(sources) == 0 {
log.Fatal("no PipeWire sources found; is PipeWire running?")
}
fmt.Println("Available PipeWire sources:")
for i, s := range sources {
fmt.Printf(" %d. %s\n", i+1, s)
}
fmt.Printf("\nSpecify a source with --source <node-name>\n")
fmt.Printf("Example: --source %s\n", sources[0].Name)
os.Exit(1)
}
src := pipewire.NewSource(*source, *rate, *channels)
log.Printf("capturing from %q at %d Hz %d ch", *source, *rate, *channels)
server, err := sendspin.NewServer(sendspin.ServerConfig{
Port: *port,
Name: *name,
Source: src,
})
if err != nil {
log.Fatalf("create server: %v", err)
}
if err := server.Start(); err != nil {
log.Fatalf("start server: %v", err)
}
log.Printf("server %q listening on :%d", *name, *port)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
<-sig
log.Println("stopping")
server.Stop()
src.Close()
}
func printSources() {
sources, err := pipewire.ListSources()
if err != nil {
log.Fatalf("list sources: %v", err)
}
if len(sources) == 0 {
fmt.Println("no PipeWire sources found")
return
}
fmt.Println("Available PipeWire sources:")
for _, s := range sources {
fmt.Printf(" %s\n", s)
}
}