()
| 68 | } |
| 69 | |
| 70 | func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, int, error) { |
| 71 | // handle special messages and pass on the rest |
| 72 | messageType, payload, err := c.conn.ReadMessage() |
| 73 | if err != nil { |
| 74 | return nil, 0, err |
| 75 | } |
| 76 | |
| 77 | msg := &livekit.SignalRequest{} |
| 78 | switch messageType { |
| 79 | case websocket.BinaryMessage: |
| 80 | if c.useJSON { |
| 81 | c.mu.Lock() |
| 82 | // switch to protobuf if client supports it |
| 83 | c.useJSON = false |
| 84 | c.mu.Unlock() |
| 85 | } |
| 86 | // protobuf encoded |
| 87 | err := proto.Unmarshal(payload, msg) |
| 88 | return msg, len(payload), err |
| 89 | case websocket.TextMessage: |
| 90 | c.mu.Lock() |
| 91 | // json encoded, also write back JSON |
| 92 | c.useJSON = true |
| 93 | c.mu.Unlock() |
| 94 | err := protojson.Unmarshal(payload, msg) |
| 95 | return msg, len(payload), err |
| 96 | default: |
| 97 | logger.Debugw("unsupported message", "message", messageType) |
| 98 | return nil, len(payload), nil |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | func (c *WSSignalConnection) ReadWorkerMessage() (*livekit.WorkerMessage, int, error) { |
| 103 | // handle special messages and pass on the rest |
no test coverage detected