mirror of
https://github.com/livekit/livekit.git
synced 2026-10-23 08:42:46 +00:00
use protobuf for clients with protocol > 1 (#52)
This commit is contained in:
1 parent
850fecf931
commit
53b52a67ca
3 files changed
+14
-4
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user