|
@@ -8,22 +8,42 @@ import (
|
|
"os/signal"
|
|
"os/signal"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
- "git.lattuga.net/boyska/direttoforo.git/liquidsoap"
|
|
|
|
- "git.lattuga.net/boyska/direttoforo.git/uiserver"
|
|
|
|
|
|
+ "git.lattuga.net/boyska/direttoforo/liquidsoap"
|
|
|
|
+ "git.lattuga.net/boyska/direttoforo/uiserver"
|
|
)
|
|
)
|
|
|
|
|
|
-func outUI(output <-chan liquidsoap.Output) {
|
|
|
|
- for msg := range output {
|
|
|
|
- if msg.Level <= 2 {
|
|
|
|
- fmt.Println(msg)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+type State struct {
|
|
|
|
+ Streams map[string]liquidsoap.Stream
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func NewState() State {
|
|
|
|
+ s := State{}
|
|
|
|
+ s.Streams = make(map[string]liquidsoap.Stream)
|
|
|
|
+ return s
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
liqfile := flag.String("liq", "foo.liq", "Path to liquidsoap script to run")
|
|
liqfile := flag.String("liq", "foo.liq", "Path to liquidsoap script to run")
|
|
|
|
+ bindpath := flag.String("bindpath", "/var/lib/direttoforo/ui.sock", "UNIX domain socket path for UIs")
|
|
flag.Parse()
|
|
flag.Parse()
|
|
|
|
|
|
|
|
+ state := NewState()
|
|
|
|
+
|
|
|
|
+ netUIsock, err := net.Listen("unix", *bindpath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "error binding UI socket!")
|
|
|
|
+ fmt.Fprintln(os.Stderr, err)
|
|
|
|
+ os.Exit(1)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ netUI := uiserver.NewNetUI(&state)
|
|
|
|
+ go func() {
|
|
|
|
+ err := netUI.Run(netUIsock)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "NetUI error", err)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
killLs := make(chan struct{}) // when it is closed, liquidsoap will die
|
|
killLs := make(chan struct{}) // when it is closed, liquidsoap will die
|
|
killed := make(chan os.Signal, 1)
|
|
killed := make(chan os.Signal, 1)
|
|
signal.Notify(killed, os.Interrupt) // ctrl-c
|
|
signal.Notify(killed, os.Interrupt) // ctrl-c
|
|
@@ -33,7 +53,15 @@ func main() {
|
|
os.Exit(1)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
|
|
- go outUI(output)
|
|
|
|
|
|
+ go func(log <-chan liquidsoap.Output) {
|
|
|
|
+ for {
|
|
|
|
+ msg := <-log
|
|
|
|
+ if msg.Msg != "" && msg.Level < 3 {
|
|
|
|
+ fmt.Println("msg", msg)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }(output)
|
|
|
|
+
|
|
go func() {
|
|
go func() {
|
|
tick := time.Tick(3 * time.Second)
|
|
tick := time.Tick(3 * time.Second)
|
|
for {
|
|
for {
|
|
@@ -44,13 +72,29 @@ func main() {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
t.Conn.SetDeadline(time.Now().Add(3 * time.Second))
|
|
t.Conn.SetDeadline(time.Now().Add(3 * time.Second))
|
|
- out, err := t.Outputs()
|
|
|
|
|
|
+ outs, err := t.Outputs()
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("telnet cmd errored", err)
|
|
fmt.Println("telnet cmd errored", err)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ changed := false
|
|
|
|
+ for name, enabled := range outs {
|
|
|
|
+ if stream, exists := state.Streams[name]; exists {
|
|
|
|
+ if stream.State != enabled {
|
|
|
|
+ stream.State = enabled
|
|
|
|
+ changed = true
|
|
|
|
+ }
|
|
|
|
+ state.Streams[name] = stream
|
|
|
|
+ } else {
|
|
|
|
+ state.Streams[name] = liquidsoap.Stream{State: enabled}
|
|
|
|
+ changed = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
t.Close()
|
|
t.Close()
|
|
- fmt.Println("list=", out)
|
|
|
|
|
|
+ fmt.Println(changed, "state=", state)
|
|
|
|
+ if changed {
|
|
|
|
+ netUI.Update()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -59,13 +103,16 @@ func main() {
|
|
case how := <-exit: // liquidsoap exits
|
|
case how := <-exit: // liquidsoap exits
|
|
if !how.Success() {
|
|
if !how.Success() {
|
|
fmt.Fprintln(os.Stderr, "liquidsoap terminated,", how.Err)
|
|
fmt.Fprintln(os.Stderr, "liquidsoap terminated,", how.Err)
|
|
|
|
+ netUI.Close()
|
|
os.Exit(1)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
os.Exit(0)
|
|
os.Exit(0)
|
|
case <-killed: // we receive a SIGINT: ask liquidsoap to die is enough
|
|
case <-killed: // we receive a SIGINT: ask liquidsoap to die is enough
|
|
|
|
+ netUI.Close()
|
|
close(killLs)
|
|
close(killLs)
|
|
fmt.Println("Closed by user interaction, waiting for liquidsoap to exit")
|
|
fmt.Println("Closed by user interaction, waiting for liquidsoap to exit")
|
|
- // TODO: schedule a more aggressive SIGKILL if liquidsoap doesn't exit soon
|
|
|
|
|
|
+ // TODO: schedule a more aggressive SIGKILL if liquidsoap doesn't
|
|
|
|
+ // exit soon
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|