master
bel 2023-03-26 08:44:30 -06:00
parent fbded57807
commit a3650642ca
2 changed files with 28 additions and 19 deletions

View File

@ -13,6 +13,10 @@ func (v01 *V01) listen() {
if v01.cfg.Feedback.Addr == "" { if v01.cfg.Feedback.Addr == "" {
return return
} }
return v01._listen()
}
func (v01 *V01) _listen() {
mutex := &sync.RWMutex{} mutex := &sync.RWMutex{}
s := &http.Server{ s := &http.Server{
Addr: v01.cfg.Feedback.Addr, Addr: v01.cfg.Feedback.Addr,
@ -24,25 +28,7 @@ func (v01 *V01) listen() {
mutex.Lock() mutex.Lock()
defer mutex.Unlock() defer mutex.Unlock()
} }
if r.Method == http.MethodGet { v01.ServeHTTP(w, r)
r = r.WithContext(v01.ctx)
user, ok := v01.cfg.Users[r.URL.Query().Get("user")]
if !ok {
user = v01.cfg.Users["broadcast"]
}
w.Write([]byte(user.Message))
} else if r.URL.Path == "/broadcast" {
b, _ := io.ReadAll(r.Body)
v := v01.cfg.Users["broadcast"]
v.Message = string(b)
v01.cfg.Users["broadcast"] = v
}
if _, ok := r.URL.Query()["refresh"]; ok {
select {
case wrap.ChSigUsr1 <- syscall.SIGUSR1:
default:
}
}
}), }),
} }
go func() { go func() {
@ -56,3 +42,25 @@ func (v01 *V01) listen() {
panic(err) panic(err)
} }
} }
func (v01 *V01) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
r = r.WithContext(v01.ctx)
user, ok := v01.cfg.Users[r.URL.Query().Get("user")]
if !ok {
user = v01.cfg.Users["broadcast"]
}
w.Write([]byte(user.Message))
} else if r.URL.Path == "/broadcast" {
b, _ := io.ReadAll(r.Body)
v := v01.cfg.Users["broadcast"]
v.Message = string(b)
v01.cfg.Users["broadcast"] = v
}
if _, ok := r.URL.Query()["refresh"]; ok {
select {
case wrap.ChSigUsr1 <- syscall.SIGUSR1:
default:
}
}
}

View File

@ -1,4 +1,5 @@
todo: todo:
- https via home.blapointe and rproxy
- tts for when someone said the word via larynx docker + http.get + https://pkg.go.dev/github.com/faiface/beep@v1.1.0/wav - tts for when someone said the word via larynx docker + http.get + https://pkg.go.dev/github.com/faiface/beep@v1.1.0/wav
- endpoint for v01 to start read-only mode so when hotword spoken, players are dcd - endpoint for v01 to start read-only mode so when hotword spoken, players are dcd
without losing players; press a hotkey that is bound to dolphin emulator pause without losing players; press a hotkey that is bound to dolphin emulator pause