From e7f0294e3f950920e470f493379d7aa9559c6f89 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Sun, 8 Jun 2025 20:07:55 -0700 Subject: [PATCH] remove unused ws signal read loop (#3709) * remove unused ws signal read loop fixes #3708 * tidy --- pkg/service/wsprotocol.go | 100 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/pkg/service/wsprotocol.go b/pkg/service/wsprotocol.go index 9f4b50e2..3752753f 100644 --- a/pkg/service/wsprotocol.go +++ b/pkg/service/wsprotocol.go @@ -61,70 +61,66 @@ func (c *WSSignalConnection) SetReadDeadline(deadline time.Time) error { } func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, int, error) { - for { - // handle special messages and pass on the rest - messageType, payload, err := c.conn.ReadMessage() - if err != nil { - return nil, 0, err - } + // handle special messages and pass on the rest + messageType, payload, err := c.conn.ReadMessage() + if err != nil { + return nil, 0, err + } - msg := &livekit.SignalRequest{} - switch messageType { - case websocket.BinaryMessage: - if c.useJSON { - c.mu.Lock() - // switch to protobuf if client supports it - c.useJSON = false - c.mu.Unlock() - } - // protobuf encoded - err := proto.Unmarshal(payload, msg) - return msg, len(payload), err - case websocket.TextMessage: + msg := &livekit.SignalRequest{} + switch messageType { + case websocket.BinaryMessage: + if c.useJSON { c.mu.Lock() - // json encoded, also write back JSON - c.useJSON = true + // switch to protobuf if client supports it + c.useJSON = false c.mu.Unlock() - err := protojson.Unmarshal(payload, msg) - return msg, len(payload), err - default: - logger.Debugw("unsupported message", "message", messageType) - return nil, len(payload), nil } + // protobuf encoded + err := proto.Unmarshal(payload, msg) + return msg, len(payload), err + case websocket.TextMessage: + c.mu.Lock() + // json encoded, also write back JSON + c.useJSON = true + c.mu.Unlock() + err := protojson.Unmarshal(payload, msg) + return msg, len(payload), err + default: + logger.Debugw("unsupported message", "message", messageType) + return nil, len(payload), nil } } func (c *WSSignalConnection) ReadWorkerMessage() (*livekit.WorkerMessage, int, error) { - for { - // handle special messages and pass on the rest - messageType, payload, err := c.conn.ReadMessage() - if err != nil { - return nil, 0, err - } + // handle special messages and pass on the rest + messageType, payload, err := c.conn.ReadMessage() + if err != nil { + return nil, 0, err + } - msg := &livekit.WorkerMessage{} - switch messageType { - case websocket.BinaryMessage: - if c.useJSON { - c.mu.Lock() - // switch to protobuf if client supports it - c.useJSON = false - c.mu.Unlock() - } - // protobuf encoded - err := proto.Unmarshal(payload, msg) - return msg, len(payload), err - case websocket.TextMessage: + msg := &livekit.WorkerMessage{} + switch messageType { + case websocket.BinaryMessage: + if c.useJSON { c.mu.Lock() - // json encoded, also write back JSON - c.useJSON = true + // switch to protobuf if client supports it + c.useJSON = false c.mu.Unlock() - err := protojson.Unmarshal(payload, msg) - return msg, len(payload), err - default: - logger.Debugw("unsupported message", "message", messageType) - return nil, len(payload), nil } + // protobuf encoded + err := proto.Unmarshal(payload, msg) + return msg, len(payload), err + case websocket.TextMessage: + c.mu.Lock() + // json encoded, also write back JSON + c.useJSON = true + c.mu.Unlock() + err := protojson.Unmarshal(payload, msg) + return msg, len(payload), err + default: + logger.Debugw("unsupported message", "message", messageType) + return nil, len(payload), nil } }