MCPcopy
hub / github.com/livekit/livekit / ReadRequest

Method ReadRequest

pkg/service/wsprotocol.go:70–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68}
69
70func (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
102func (c *WSSignalConnection) ReadWorkerMessage() (*livekit.WorkerMessage, int, error) {
103 // handle special messages and pass on the rest

Callers 1

serveMethod · 0.95

Calls 2

ReadMessageMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected