add handler interface to receive agent worker updates (#2830)
* add handler interface to receive agent worker updates * cleanup
This commit is contained in:
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user