4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 01:49:22 +00:00

Check client disconnect to exit for loop (api). Fixes #1983 (#2012)

Also update to latest melody upstream
This commit is contained in:
Wim
2023-03-11 18:14:49 +01:00
committed by GitHub
parent 356ada872c
commit 89e2dbac15
17 changed files with 278 additions and 254 deletions

View File

@ -6,7 +6,7 @@ import (
"sync"
"time"
"gopkg.in/olahol/melody.v1"
"github.com/olahol/melody"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
@ -166,15 +166,20 @@ func (b *API) handleStream(c echo.Context) error {
}
c.Response().Flush()
for {
select {
// TODO: this causes issues, messages should be broadcasted to all connected clients
msg := b.Messages.Dequeue()
if msg != nil {
if err := json.NewEncoder(c.Response()).Encode(msg); err != nil {
return err
default:
msg := b.Messages.Dequeue()
if msg != nil {
if err := json.NewEncoder(c.Response()).Encode(msg); err != nil {
return err
}
c.Response().Flush()
}
c.Response().Flush()
time.Sleep(100 * time.Millisecond)
case <-c.Request().Context().Done():
return nil
}
time.Sleep(200 * time.Millisecond)
}
}