use protobuf for clients with protocol > 1 (#52)
This commit is contained in:
@@ -8,6 +8,10 @@ func (v ProtocolVersion) SupportsPackedStreamId() bool {
|
|||||||
return v > 0
|
return v > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v ProtocolVersion) SupportsProtobuf() bool {
|
||||||
|
return v > 0
|
||||||
|
}
|
||||||
|
|
||||||
func (v ProtocolVersion) HandlesDataPackets() bool {
|
func (v ProtocolVersion) HandlesDataPackets() bool {
|
||||||
return v > 1
|
return v > 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"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/config"
|
||||||
"github.com/livekit/livekit-server/pkg/logger"
|
"github.com/livekit/livekit-server/pkg/logger"
|
||||||
@@ -126,6 +127,9 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
sigConn := NewWSSignalConnection(conn)
|
sigConn := NewWSSignalConnection(conn)
|
||||||
|
if types.ProtocolVersion(pi.ProtocolVersion).SupportsProtobuf() {
|
||||||
|
sigConn.useJSON = false
|
||||||
|
}
|
||||||
|
|
||||||
logger.Infow("new client WS connected",
|
logger.Infow("new client WS connected",
|
||||||
"connectionId", connId,
|
"connectionId", connId,
|
||||||
|
|||||||
@@ -45,10 +45,12 @@ func (c *WSSignalConnection) ReadRequest() (*livekit.SignalRequest, error) {
|
|||||||
msg := &livekit.SignalRequest{}
|
msg := &livekit.SignalRequest{}
|
||||||
switch messageType {
|
switch messageType {
|
||||||
case websocket.BinaryMessage:
|
case websocket.BinaryMessage:
|
||||||
c.mu.Lock()
|
if c.useJSON {
|
||||||
// switch to protobuf if client supports it
|
c.mu.Lock()
|
||||||
c.useJSON = false
|
// switch to protobuf if client supports it
|
||||||
c.mu.Unlock()
|
c.useJSON = false
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
// protobuf encoded
|
// protobuf encoded
|
||||||
err := proto.Unmarshal(payload, msg)
|
err := proto.Unmarshal(payload, msg)
|
||||||
return msg, err
|
return msg, err
|
||||||
|
|||||||
Reference in New Issue
Block a user