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) {