sends roominfo on join

This commit is contained in:
David Zhao
2020-12-27 22:38:13 -08:00
parent 94e2c782ee
commit 3fb606236e
7 changed files with 73 additions and 53 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ type Participant interface {
AddSubscriber(op Participant) error
RemoveSubscriber(peerId string)
SendJoinResponse(otherParticipants []Participant) error
SendJoinResponse(info *livekit.RoomInfo, otherParticipants []Participant) error
SendParticipantUpdate(participants []*livekit.ParticipantInfo) error
Start()
+2 -1
View File
@@ -318,11 +318,12 @@ func (p *ParticipantImpl) RemoveSubscriber(participantId string) {
}
// signal connection methods
func (p *ParticipantImpl) SendJoinResponse(otherParticipants []Participant) error {
func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.RoomInfo, otherParticipants []Participant) error {
// send Join response
return p.sigConn.WriteResponse(&livekit.SignalResponse{
Message: &livekit.SignalResponse_Join{
Join: &livekit.JoinResponse{
Room: roomInfo,
Participant: p.ToProto(),
OtherParticipants: ToProtoParticipants(otherParticipants),
},
+6 -3
View File
@@ -49,12 +49,15 @@ func (r *Room) GetParticipants() []Participant {
}
func (r *Room) ToRoomInfo(node *livekit.Node) *livekit.RoomInfo {
return &livekit.RoomInfo{
ri := &livekit.RoomInfo{
Sid: r.Sid,
Name: r.Name,
NodeIp: node.Ip,
CreationTime: r.CreationTime,
}
if node != nil {
ri.NodeIp = node.Ip
}
return ri
}
func (r *Room) Join(participant Participant) error {
@@ -103,7 +106,7 @@ func (r *Room) Join(participant Participant) error {
}
}
return participant.SendJoinResponse(otherParticipants)
return participant.SendJoinResponse(r.ToRoomInfo(nil), otherParticipants)
}
func (r *Room) RemoveParticipant(id string) {
+2 -1
View File
@@ -49,7 +49,8 @@ func TestRoomJoin(t *testing.T) {
rm.Join(p)
// expect new participant to get a JoinReply
participants := p.SendJoinResponseArgsForCall(0)
info, participants := p.SendJoinResponseArgsForCall(0)
assert.Equal(t, info.Sid, rm.Sid)
assert.Len(t, participants, numParticipants)
assert.Len(t, rm.GetParticipants(), numParticipants+1)
})
+16 -14
View File
@@ -139,10 +139,11 @@ type FakeParticipant struct {
removeSubscriberArgsForCall []struct {
arg1 string
}
SendJoinResponseStub func([]rtc.Participant) error
SendJoinResponseStub func(*livekit.RoomInfo, []rtc.Participant) error
sendJoinResponseMutex sync.RWMutex
sendJoinResponseArgsForCall []struct {
arg1 []rtc.Participant
arg1 *livekit.RoomInfo
arg2 []rtc.Participant
}
sendJoinResponseReturns struct {
result1 error
@@ -917,23 +918,24 @@ func (fake *FakeParticipant) RemoveSubscriberArgsForCall(i int) string {
return argsForCall.arg1
}
func (fake *FakeParticipant) SendJoinResponse(arg1 []rtc.Participant) error {
var arg1Copy []rtc.Participant
if arg1 != nil {
arg1Copy = make([]rtc.Participant, len(arg1))
copy(arg1Copy, arg1)
func (fake *FakeParticipant) SendJoinResponse(arg1 *livekit.RoomInfo, arg2 []rtc.Participant) error {
var arg2Copy []rtc.Participant
if arg2 != nil {
arg2Copy = make([]rtc.Participant, len(arg2))
copy(arg2Copy, arg2)
}
fake.sendJoinResponseMutex.Lock()
ret, specificReturn := fake.sendJoinResponseReturnsOnCall[len(fake.sendJoinResponseArgsForCall)]
fake.sendJoinResponseArgsForCall = append(fake.sendJoinResponseArgsForCall, struct {
arg1 []rtc.Participant
}{arg1Copy})
arg1 *livekit.RoomInfo
arg2 []rtc.Participant
}{arg1, arg2Copy})
stub := fake.SendJoinResponseStub
fakeReturns := fake.sendJoinResponseReturns
fake.recordInvocation("SendJoinResponse", []interface{}{arg1Copy})
fake.recordInvocation("SendJoinResponse", []interface{}{arg1, arg2Copy})
fake.sendJoinResponseMutex.Unlock()
if stub != nil {
return stub(arg1)
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1
@@ -947,17 +949,17 @@ func (fake *FakeParticipant) SendJoinResponseCallCount() int {
return len(fake.sendJoinResponseArgsForCall)
}
func (fake *FakeParticipant) SendJoinResponseCalls(stub func([]rtc.Participant) error) {
func (fake *FakeParticipant) SendJoinResponseCalls(stub func(*livekit.RoomInfo, []rtc.Participant) error) {
fake.sendJoinResponseMutex.Lock()
defer fake.sendJoinResponseMutex.Unlock()
fake.SendJoinResponseStub = stub
}
func (fake *FakeParticipant) SendJoinResponseArgsForCall(i int) []rtc.Participant {
func (fake *FakeParticipant) SendJoinResponseArgsForCall(i int) (*livekit.RoomInfo, []rtc.Participant) {
fake.sendJoinResponseMutex.RLock()
defer fake.sendJoinResponseMutex.RUnlock()
argsForCall := fake.sendJoinResponseArgsForCall[i]
return argsForCall.arg1
return argsForCall.arg1, argsForCall.arg2
}
func (fake *FakeParticipant) SendJoinResponseReturns(result1 error) {
+43 -31
View File
@@ -382,8 +382,9 @@ type JoinResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Participant *ParticipantInfo `protobuf:"bytes,1,opt,name=participant,proto3" json:"participant,omitempty"`
OtherParticipants []*ParticipantInfo `protobuf:"bytes,2,rep,name=other_participants,json=otherParticipants,proto3" json:"other_participants,omitempty"`
Room *RoomInfo `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
Participant *ParticipantInfo `protobuf:"bytes,2,opt,name=participant,proto3" json:"participant,omitempty"`
OtherParticipants []*ParticipantInfo `protobuf:"bytes,3,rep,name=other_participants,json=otherParticipants,proto3" json:"other_participants,omitempty"`
}
func (x *JoinResponse) Reset() {
@@ -418,6 +419,13 @@ func (*JoinResponse) Descriptor() ([]byte, []int) {
return file_rtc_proto_rawDescGZIP(), []int{4}
}
func (x *JoinResponse) GetRoom() *RoomInfo {
if x != nil {
return x.Room
}
return nil
}
func (x *JoinResponse) GetParticipant() *ParticipantInfo {
if x != nil {
return x.Participant
@@ -566,26 +574,28 @@ var file_rtc_proto_rawDesc = []byte{
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a,
0x03, 0x73, 0x64, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x64, 0x70, 0x22,
0x93, 0x01, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x3a, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e,
0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x47, 0x0a, 0x12,
0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e,
0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b,
0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e,
0x66, 0x6f, 0x52, 0x11, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69,
0x70, 0x61, 0x6e, 0x74, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x43, 0x6f,
0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x22, 0x51, 0x0a, 0x11, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69,
0x70, 0x61, 0x6e, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x3c, 0x0a, 0x0c, 0x70, 0x61,
0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69,
0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x70, 0x61, 0x72, 0x74,
0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68,
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2f, 0x6c,
0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0xba, 0x01, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x25, 0x0a, 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11,
0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x52, 0x6f, 0x6f, 0x6d, 0x49, 0x6e, 0x66,
0x6f, 0x52, 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x12, 0x3a, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69,
0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c,
0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61,
0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70,
0x61, 0x6e, 0x74, 0x12, 0x47, 0x0a, 0x12, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x72,
0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63,
0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x11, 0x6f, 0x74, 0x68, 0x65, 0x72,
0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x22, 0x0e, 0x0a, 0x0c,
0x4d, 0x65, 0x64, 0x69, 0x61, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x22, 0x51, 0x0a, 0x11,
0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74,
0x65, 0x12, 0x3c, 0x0a, 0x0c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74,
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69,
0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66,
0x6f, 0x52, 0x0c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x42,
0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69,
0x76, 0x65, 0x6b, 0x69, 0x74, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2d, 0x73, 0x65,
0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b,
0x69, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -610,7 +620,8 @@ var file_rtc_proto_goTypes = []interface{}{
(*MediaControl)(nil), // 5: livekit.MediaControl
(*ParticipantUpdate)(nil), // 6: livekit.ParticipantUpdate
(*TrackInfo)(nil), // 7: livekit.TrackInfo
(*ParticipantInfo)(nil), // 8: livekit.ParticipantInfo
(*RoomInfo)(nil), // 8: livekit.RoomInfo
(*ParticipantInfo)(nil), // 9: livekit.ParticipantInfo
}
var file_rtc_proto_depIdxs = []int32{
3, // 0: livekit.SignalRequest.offer:type_name -> livekit.SessionDescription
@@ -623,14 +634,15 @@ var file_rtc_proto_depIdxs = []int32{
2, // 7: livekit.SignalResponse.trickle:type_name -> livekit.Trickle
6, // 8: livekit.SignalResponse.update:type_name -> livekit.ParticipantUpdate
7, // 9: livekit.SignalResponse.trackPublished:type_name -> livekit.TrackInfo
8, // 10: livekit.JoinResponse.participant:type_name -> livekit.ParticipantInfo
8, // 11: livekit.JoinResponse.other_participants:type_name -> livekit.ParticipantInfo
8, // 12: livekit.ParticipantUpdate.participants:type_name -> livekit.ParticipantInfo
13, // [13:13] is the sub-list for method output_type
13, // [13:13] is the sub-list for method input_type
13, // [13:13] is the sub-list for extension type_name
13, // [13:13] is the sub-list for extension extendee
0, // [0:13] is the sub-list for field type_name
8, // 10: livekit.JoinResponse.room:type_name -> livekit.RoomInfo
9, // 11: livekit.JoinResponse.participant:type_name -> livekit.ParticipantInfo
9, // 12: livekit.JoinResponse.other_participants:type_name -> livekit.ParticipantInfo
9, // 13: livekit.ParticipantUpdate.participants:type_name -> livekit.ParticipantInfo
14, // [14:14] is the sub-list for method output_type
14, // [14:14] is the sub-list for method input_type
14, // [14:14] is the sub-list for extension type_name
14, // [14:14] is the sub-list for extension extendee
0, // [0:14] is the sub-list for field type_name
}
func init() { file_rtc_proto_init() }
+3 -2
View File
@@ -42,8 +42,9 @@ message SessionDescription {
}
message JoinResponse {
ParticipantInfo participant = 1;
repeated ParticipantInfo other_participants = 2;
RoomInfo room = 1;
ParticipantInfo participant = 2;
repeated ParticipantInfo other_participants = 3;
}
message MediaControl {