add handler interface to receive agent worker updates (#2830)

* add handler interface to receive agent worker updates

* cleanup
This commit is contained in:
Paul Wells
2024-07-02 13:11:08 -07:00
committed by GitHub
parent 7dff092285
commit e511464d3d
6 changed files with 343 additions and 285 deletions
+21
View File
@@ -15,6 +15,9 @@
package service
import (
"errors"
"io"
"strings"
"sync"
"time"
@@ -49,6 +52,10 @@ func NewWSSignalConnection(conn types.WebsocketClient) *WSSignalConnection {
return wsc
}
func (c *WSSignalConnection) Close() error {
return c.conn.Close()
}
func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, int, error) {
for {
// handle special messages and pass on the rest
@@ -172,3 +179,17 @@ func (c *WSSignalConnection) pingWorker() {
}
}
}
// IsWebSocketCloseError checks that error is normal/expected closure
func IsWebSocketCloseError(err error) bool {
return errors.Is(err, io.EOF) ||
strings.HasSuffix(err.Error(), "use of closed network connection") ||
strings.HasSuffix(err.Error(), "connection reset by peer") ||
websocket.IsCloseError(
err,
websocket.CloseAbnormalClosure,
websocket.CloseGoingAway,
websocket.CloseNormalClosure,
websocket.CloseNoStatusReceived,
)
}