summaryrefslogtreecommitdiffstats
path: root/bridge/api
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-03-11 18:14:49 +0100
committerGitHub <noreply@github.com>2023-03-11 18:14:49 +0100
commit89e2dbac1504d6df205938df750fa9eb15996afd (patch)
tree51c94428af04fc882c5209e85afead9cf9a825f5 /bridge/api
parent356ada872c0e1564097e2f8165931fb8c9ee9d23 (diff)
downloadmatterbridge-msglm-89e2dbac1504d6df205938df750fa9eb15996afd.tar.gz
matterbridge-msglm-89e2dbac1504d6df205938df750fa9eb15996afd.tar.bz2
matterbridge-msglm-89e2dbac1504d6df205938df750fa9eb15996afd.zip
Check client disconnect to exit for loop (api). Fixes #1983 (#2012)
Also update to latest melody upstream
Diffstat (limited to 'bridge/api')
-rw-r--r--bridge/api/api.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go
index 515007f0..9e7679d3 100644
--- a/bridge/api/api.go
+++ b/bridge/api/api.go
@@ -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)
}
}