use protobuf for clients with protocol > 1 (#52)

This commit is contained in:
David Zhao authored and GitHub committed 2021-07-13 22:28:34 -07:00
1 parent 850fecf931
commit 53b52a67ca
3 files changed
+14 -4

No files matched your search

+4
View File
@@ -8,6 +8,10 @@ func (v ProtocolVersion) SupportsPackedStreamId() bool {
return v > 0
}
func (v ProtocolVersion) SupportsProtobuf() bool {
return v > 0
}
func (v ProtocolVersion) HandlesDataPackets() bool {
return v > 1
}
+4
View File
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/gorilla/websocket"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
@@ -126,6 +127,9 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
sigConn := NewWSSignalConnection(conn)
if types.ProtocolVersion(pi.ProtocolVersion).SupportsProtobuf() {
sigConn.useJSON = false
}
logger.Infow("new client WS connected",
"connectionId", connId,
+6 -4
View File
@@ -45,10 +45,12 @@ func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, error) {
msg := &livekit.SignalRequest{}
switch messageType {
case websocket.BinaryMessage:
c.mu.Lock()
// switch to protobuf if client supports it
c.useJSON = false
c.mu.Unlock()
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, err