remove unused ws signal read loop (#3709)
* remove unused ws signal read loop fixes #3708 * tidy
This commit is contained in:
+48
-52
@@ -61,70 +61,66 @@ func (c *WSSignalConnection) SetReadDeadline(deadline time.Time) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, int, error) {
|
func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, int, error) {
|
||||||
for {
|
// handle special messages and pass on the rest
|
||||||
// handle special messages and pass on the rest
|
messageType, payload, err := c.conn.ReadMessage()
|
||||||
messageType, payload, err := c.conn.ReadMessage()
|
if err != nil {
|
||||||
if err != nil {
|
return nil, 0, err
|
||||||
return nil, 0, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
msg := &livekit.SignalRequest{}
|
msg := &livekit.SignalRequest{}
|
||||||
switch messageType {
|
switch messageType {
|
||||||
case websocket.BinaryMessage:
|
case websocket.BinaryMessage:
|
||||||
if c.useJSON {
|
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:
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
// json encoded, also write back JSON
|
// switch to protobuf if client supports it
|
||||||
c.useJSON = true
|
c.useJSON = false
|
||||||
c.mu.Unlock()
|
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) {
|
func (c *WSSignalConnection) ReadWorkerMessage() (*livekit.WorkerMessage, int, error) {
|
||||||
for {
|
// handle special messages and pass on the rest
|
||||||
// handle special messages and pass on the rest
|
messageType, payload, err := c.conn.ReadMessage()
|
||||||
messageType, payload, err := c.conn.ReadMessage()
|
if err != nil {
|
||||||
if err != nil {
|
return nil, 0, err
|
||||||
return nil, 0, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
msg := &livekit.WorkerMessage{}
|
msg := &livekit.WorkerMessage{}
|
||||||
switch messageType {
|
switch messageType {
|
||||||
case websocket.BinaryMessage:
|
case websocket.BinaryMessage:
|
||||||
if c.useJSON {
|
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:
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
// json encoded, also write back JSON
|
// switch to protobuf if client supports it
|
||||||
c.useJSON = true
|
c.useJSON = false
|
||||||
c.mu.Unlock()
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user