Add SSE endpoint for real-time status updates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-25 18:49:39 -08:00
parent a96eb7db8c
commit a94f816f3d
5 changed files with 218 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ import (
"net"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
@@ -37,6 +38,10 @@ type Tendrils struct {
errors *ErrorTracker
config *Config
sseSubsMu sync.RWMutex
sseSubsNext int
sseSubs map[int]chan struct{}
Interface string
ConfigFile string
DisableARP bool
@@ -68,12 +73,46 @@ func New() *Tendrils {
activeInterfaces: map[string]context.CancelFunc{},
artnet: NewArtNetNodes(),
danteFlows: NewDanteFlows(),
errors: NewErrorTracker(),
sseSubs: map[int]chan struct{}{},
}
t.nodes = NewNodes(t)
t.errors = NewErrorTracker(t)
return t
}
func (t *Tendrils) NotifyUpdate() {
t.sseSubsMu.RLock()
defer t.sseSubsMu.RUnlock()
for _, ch := range t.sseSubs {
select {
case ch <- struct{}{}:
default:
}
}
}
func (t *Tendrils) subscribeSSE() (int, chan struct{}) {
t.sseSubsMu.Lock()
defer t.sseSubsMu.Unlock()
t.sseSubsNext++
id := t.sseSubsNext
ch := make(chan struct{}, 1)
t.sseSubs[id] = ch
return id, ch
}
func (t *Tendrils) unsubscribeSSE(id int) {
t.sseSubsMu.Lock()
defer t.sseSubsMu.Unlock()
if ch, ok := t.sseSubs[id]; ok {
close(ch)
delete(t.sseSubs, id)
}
}
func (t *Tendrils) Run() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()