Skip to content

Commit 34c7a0e

Browse files
More v2 stuff (#1141)
* More v2 stuff - Adding `Trickle` to client -> server message. There should not be any tricklw from server -> client in v2. So, not adding it. Will add if needed later. - Some utils to parse envelopes as we are moving in the direction of having an envelope of messages in the initial connect request to keep it modular. May change again later, but today's state is this. - change relay signal to pass wire message back and forth. * generated protobuf * add utils --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ecfb508 commit 34c7a0e

File tree

5 files changed

+163
-60
lines changed

5 files changed

+163
-60
lines changed

livekit/livekit_rtc_v2.pb.go

Lines changed: 53 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobufs/livekit_rtc_v2.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ message Signalv2ClientMessage {
5252
ConnectRequest connect_request = 2;
5353
SessionDescription publisher_sdp = 3; // SDP offer for publisher peer connection
5454
SessionDescription subscriber_sdp = 4; // SDP answer for subscriber peer connection
55+
TrickleRequest trickle = 5;
5556
}
5657
}
5758

protobufs/rpc/signalv2_types.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ message RelaySignalv2ConnectRequest {
2525
// A user's ClaimGrants serialized in JSON
2626
string grants_json = 1;
2727
livekit.CreateRoomRequest create_room = 2;
28-
livekit.ConnectRequest connect_request = 3;
28+
livekit.Signalv2WireMessage wire_message = 3; // livekit.ConnectRequest is the first message in the envelope
2929
}
3030

3131
message RelaySignalv2ConnectResponse {
32-
livekit.ConnectResponse connect_response = 1;
32+
livekit.Signalv2WireMessage wire_message = 1; // livekit.ConnectResponse is the first message in the envelope
3333
}
3434

3535
message RelaySignalv2ParticipantRequest {

rpc/signalv2_types.pb.go

Lines changed: 23 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

signalling/signallingv2utils.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2023 LiveKit, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package signalling
16+
17+
import (
18+
"github.com/livekit/protocol/livekit"
19+
)
20+
21+
func GetConnectRequest(wireMessage *livekit.Signalv2WireMessage) *livekit.ConnectRequest {
22+
if wireMessage != nil {
23+
switch msg := wireMessage.GetMessage().(type) {
24+
case *livekit.Signalv2WireMessage_Envelope:
25+
for _, innerMsg := range msg.Envelope.GetClientMessages() {
26+
switch clientMessage := innerMsg.GetMessage().(type) {
27+
case *livekit.Signalv2ClientMessage_ConnectRequest:
28+
return clientMessage.ConnectRequest
29+
}
30+
}
31+
}
32+
}
33+
34+
return nil
35+
}
36+
37+
func WithoutConnectRequest(wireMessage *livekit.Signalv2WireMessage) *livekit.Signalv2WireMessage {
38+
var strippedWireMessage *livekit.Signalv2WireMessage
39+
if wireMessage != nil {
40+
switch msg := wireMessage.GetMessage().(type) {
41+
case *livekit.Signalv2WireMessage_Envelope:
42+
clientMessages := make(
43+
[]*livekit.Signalv2ClientMessage,
44+
0,
45+
len(msg.Envelope.GetClientMessages()),
46+
)
47+
for _, clientMessage := range msg.Envelope.GetClientMessages() {
48+
switch clientMessage.GetMessage().(type) {
49+
case *livekit.Signalv2ClientMessage_ConnectRequest:
50+
default:
51+
clientMessages = append(clientMessages, clientMessage)
52+
}
53+
}
54+
55+
if len(clientMessages) != 0 {
56+
strippedWireMessage = &livekit.Signalv2WireMessage{
57+
Message: &livekit.Signalv2WireMessage_Envelope{
58+
Envelope: &livekit.Envelope{
59+
ClientMessages: clientMessages,
60+
},
61+
},
62+
}
63+
}
64+
}
65+
}
66+
67+
return strippedWireMessage
68+
}
69+
70+
func GetConnectResponse(wireMessage *livekit.Signalv2WireMessage) *livekit.ConnectResponse {
71+
if wireMessage != nil {
72+
switch msg := wireMessage.GetMessage().(type) {
73+
case *livekit.Signalv2WireMessage_Envelope:
74+
for _, innerMsg := range msg.Envelope.GetServerMessages() {
75+
switch serverMessage := innerMsg.GetMessage().(type) {
76+
case *livekit.Signalv2ServerMessage_ConnectResponse:
77+
return serverMessage.ConnectResponse
78+
}
79+
}
80+
}
81+
}
82+
83+
return nil
84+
}

0 commit comments

Comments
 (0)