Add stats for data channel and signal (#1198)

* Add stats for data channel and signal

* Solve comment
This commit is contained in:
cnderrauber
2022-11-30 14:53:19 +08:00
committed by GitHub
parent caae389717
commit 3c907ed460
13 changed files with 217 additions and 46 deletions
+8 -8
View File
@@ -35,12 +35,12 @@ func NewWSSignalConnection(conn types.WebsocketClient) *WSSignalConnection {
return wsc
}
func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, 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, err
return nil, 0, err
}
msg := &livekit.SignalRequest{}
@@ -54,22 +54,22 @@ func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, error) {
}
// protobuf encoded
err := proto.Unmarshal(payload, msg)
return msg, err
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, err
return msg, len(payload), err
default:
logger.Debugw("unsupported message", "message", messageType)
return nil, nil
return nil, len(payload), nil
}
}
}
func (c *WSSignalConnection) WriteResponse(msg *livekit.SignalResponse) error {
func (c *WSSignalConnection) WriteResponse(msg *livekit.SignalResponse) (int, error) {
var msgType int
var payload []byte
var err error
@@ -85,10 +85,10 @@ func (c *WSSignalConnection) WriteResponse(msg *livekit.SignalResponse) error {
payload, err = proto.Marshal(msg)
}
if err != nil {
return err
return 0, err
}
return c.conn.WriteMessage(msgType, payload)
return len(payload), c.conn.WriteMessage(msgType, payload)
}
func (c *WSSignalConnection) pingWorker() {