Add guest tally (on air / off air) and host connection warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
namandClaude Opus 5.5 committed 2026-11-06 11:35:10 -06:00
1 parent c2549bfab0
commit f5c5c593f9
7 files changed
+82 -4

No files matched your search

+17 -1
View File
@@ -89,6 +89,7 @@ type Hub struct {
call *Call
hosts map[*wsConn]bool
chat []chatMsg
onAir bool // tally shown on the guest page; set by the host, never automatic
udp *net.UDPConn
mux ice.UDPMux
}
@@ -129,6 +130,7 @@ func (h *Hub) stateLocked() map[string]any {
"link": h.link(),
"guestOnline": h.guest != nil,
"guestName": h.guestName,
"onAir": h.onAir,
"call": nil,
}
if h.call != nil {
@@ -322,13 +324,14 @@ func guestWS(w http.ResponseWriter, r *http.Request) {
old := hub.guest
hub.guest = me
hist := append([]chatMsg(nil), hub.chat...)
onAir := hub.onAir
hub.mu.Unlock()
if old != nil {
old.send(map[string]any{"t": "ended", "reason": "This link was opened in another window."})
old.c.Close()
}
log.Printf("guest connected from %s", r.Header.Get("X-Real-IP"))
me.send(map[string]any{"t": "welcome", "hostLabel": *hostLabel, "history": hist})
me.send(map[string]any{"t": "welcome", "hostLabel": *hostLabel, "history": hist, "onAir": onAir})
hub.pushState()
chatRL := &rateLimiter{n: 8, per: 10 * time.Second}
@@ -447,6 +450,7 @@ func hostWS(w http.ResponseWriter, r *http.Request) {
var m struct {
T string `json:"t"`
Text string `json:"text"`
On bool `json:"on"`
}
if err := c.ReadJSON(&m); err != nil {
return
@@ -462,6 +466,7 @@ func hostWS(w http.ResponseWriter, r *http.Request) {
hub.token = randToken()
hub.chat = nil
hub.guestName = ""
hub.onAir = false
hub.saveToken()
hub.mu.Unlock()
log.Printf("new invite link created")
@@ -471,6 +476,7 @@ func hostWS(w http.ResponseWriter, r *http.Request) {
hub.kickGuest("The host closed this session.")
hub.mu.Lock()
hub.token = ""
hub.onAir = false
hub.saveToken()
hub.mu.Unlock()
log.Printf("invite link revoked")
@@ -485,6 +491,16 @@ func hostWS(w http.ResponseWriter, r *http.Request) {
if g != nil {
g.send(map[string]any{"t": "callended"})
}
case "onair":
hub.mu.Lock()
hub.onAir = m.On
g := hub.guest
hub.mu.Unlock()
log.Printf("tally: on air %v", m.On)
if g != nil {
g.send(map[string]any{"t": "onair", "on": m.On})
}
hub.pushState()
case "clearchat":
hub.mu.Lock()
hub.chat = nil