automatic configuration of TURN, with per-room credentials. version 0.6.0

This commit is contained in:
David Zhao
2021-03-07 23:30:21 -08:00
parent 048cdf9751
commit e20c831c14
18 changed files with 220 additions and 79 deletions
+2 -1
View File
@@ -375,7 +375,7 @@ func (p *ParticipantImpl) RemoveSubscriber(participantId string) {
}
// signal connection methods
func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticipants []types.Participant) error {
func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticipants []types.Participant, iceServers []*livekit.ICEServer) error {
// send Join response
return p.writeMessage(&livekit.SignalResponse{
Message: &livekit.SignalResponse_Join{
@@ -384,6 +384,7 @@ func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticip
Participant: p.ToProto(),
OtherParticipants: ToProtoParticipants(otherParticipants),
ServerVersion: version.Version,
IceServers: iceServers,
},
},
})
+6 -4
View File
@@ -18,8 +18,9 @@ const (
type Room struct {
livekit.Room
config WebRTCConfig
lock sync.RWMutex
config WebRTCConfig
iceServers []*livekit.ICEServer
lock sync.RWMutex
// map of identity -> Participant
participants map[string]types.Participant
// time the first participant joined the room
@@ -36,10 +37,11 @@ type Room struct {
onClose func()
}
func NewRoom(room *livekit.Room, config WebRTCConfig, audioUpdateInterval uint32) *Room {
func NewRoom(room *livekit.Room, config WebRTCConfig, iceServers []*livekit.ICEServer, audioUpdateInterval uint32) *Room {
r := &Room{
Room: *room,
config: config,
iceServers: iceServers,
audioUpdateInterval: audioUpdateInterval,
lock: sync.RWMutex{},
participants: make(map[string]types.Participant),
@@ -179,7 +181,7 @@ func (r *Room) Join(participant types.Participant) error {
r.onParticipantChanged(participant)
}
return participant.SendJoinResponse(&r.Room, otherParticipants)
return participant.SendJoinResponse(&r.Room, otherParticipants, r.iceServers)
}
func (r *Room) RemoveParticipant(identity string) {
+10 -1
View File
@@ -6,6 +6,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc"
@@ -62,10 +63,11 @@ func TestRoomJoin(t *testing.T) {
rm.Join(pNew)
// expect new participant to get a JoinReply
info, participants := pNew.SendJoinResponseArgsForCall(0)
info, participants, iceServers := pNew.SendJoinResponseArgsForCall(0)
assert.Equal(t, info.Sid, rm.Sid)
assert.Len(t, participants, numParticipants)
assert.Len(t, rm.GetParticipants(), numParticipants+1)
require.NotEmpty(t, iceServers)
})
t.Run("subscribe to existing channels upon join", func(t *testing.T) {
@@ -265,6 +267,13 @@ func newRoomWithParticipants(t *testing.T, num int) *rtc.Room {
rm := rtc.NewRoom(
&livekit.Room{Name: "room"},
rtc.WebRTCConfig{},
[]*livekit.ICEServer{
{
Urls: []string{
"stun:stun.l.google.com:19302",
},
},
},
audioUpdateInterval,
)
for i := 0; i < num; i++ {
+1 -1
View File
@@ -41,7 +41,7 @@ type Participant interface {
AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error
AddSubscriber(op Participant) error
RemoveSubscriber(peerId string)
SendJoinResponse(info *livekit.Room, otherParticipants []Participant) error
SendJoinResponse(info *livekit.Room, otherParticipants []Participant, iceServers []*livekit.ICEServer) error
SendParticipantUpdate(participants []*livekit.ParticipantInfo) error
SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error
SetTrackMuted(trackId string, muted bool)
+15 -8
View File
@@ -206,11 +206,12 @@ type FakeParticipant struct {
sendActiveSpeakersReturnsOnCall map[int]struct {
result1 error
}
SendJoinResponseStub func(*livekit.Room, []types.Participant) error
SendJoinResponseStub func(*livekit.Room, []types.Participant, []*livekit.ICEServer) error
sendJoinResponseMutex sync.RWMutex
sendJoinResponseArgsForCall []struct {
arg1 *livekit.Room
arg2 []types.Participant
arg3 []*livekit.ICEServer
}
sendJoinResponseReturns struct {
result1 error
@@ -1353,24 +1354,30 @@ func (fake *FakeParticipant) SendActiveSpeakersReturnsOnCall(i int, result1 erro
}{result1}
}
func (fake *FakeParticipant) SendJoinResponse(arg1 *livekit.Room, arg2 []types.Participant) error {
func (fake *FakeParticipant) SendJoinResponse(arg1 *livekit.Room, arg2 []types.Participant, arg3 []*livekit.ICEServer) error {
var arg2Copy []types.Participant
if arg2 != nil {
arg2Copy = make([]types.Participant, len(arg2))
copy(arg2Copy, arg2)
}
var arg3Copy []*livekit.ICEServer
if arg3 != nil {
arg3Copy = make([]*livekit.ICEServer, len(arg3))
copy(arg3Copy, arg3)
}
fake.sendJoinResponseMutex.Lock()
ret, specificReturn := fake.sendJoinResponseReturnsOnCall[len(fake.sendJoinResponseArgsForCall)]
fake.sendJoinResponseArgsForCall = append(fake.sendJoinResponseArgsForCall, struct {
arg1 *livekit.Room
arg2 []types.Participant
}{arg1, arg2Copy})
arg3 []*livekit.ICEServer
}{arg1, arg2Copy, arg3Copy})
stub := fake.SendJoinResponseStub
fakeReturns := fake.sendJoinResponseReturns
fake.recordInvocation("SendJoinResponse", []interface{}{arg1, arg2Copy})
fake.recordInvocation("SendJoinResponse", []interface{}{arg1, arg2Copy, arg3Copy})
fake.sendJoinResponseMutex.Unlock()
if stub != nil {
return stub(arg1, arg2)
return stub(arg1, arg2, arg3)
}
if specificReturn {
return ret.result1
@@ -1384,17 +1391,17 @@ func (fake *FakeParticipant) SendJoinResponseCallCount() int {
return len(fake.sendJoinResponseArgsForCall)
}
func (fake *FakeParticipant) SendJoinResponseCalls(stub func(*livekit.Room, []types.Participant) error) {
func (fake *FakeParticipant) SendJoinResponseCalls(stub func(*livekit.Room, []types.Participant, []*livekit.ICEServer) error) {
fake.sendJoinResponseMutex.Lock()
defer fake.sendJoinResponseMutex.Unlock()
fake.SendJoinResponseStub = stub
}
func (fake *FakeParticipant) SendJoinResponseArgsForCall(i int) (*livekit.Room, []types.Participant) {
func (fake *FakeParticipant) SendJoinResponseArgsForCall(i int) (*livekit.Room, []types.Participant, []*livekit.ICEServer) {
fake.sendJoinResponseMutex.RLock()
defer fake.sendJoinResponseMutex.RUnlock()
argsForCall := fake.sendJoinResponseArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeParticipant) SendJoinResponseReturns(result1 error) {