mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 15:35:41 +00:00
take iceServers out of room (#151)
This commit is contained in:
1
.idea/watcherTasks.xml
generated
1
.idea/watcherTasks.xml
generated
@@ -2,6 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectTasksOptions">
|
||||
<enabled-global>
|
||||
<option value="go fmt" />
|
||||
<option value="goimports" />
|
||||
</enabled-global>
|
||||
</component>
|
||||
|
||||
@@ -28,7 +28,6 @@ const (
|
||||
type Room struct {
|
||||
Room *livekit.Room
|
||||
config WebRTCConfig
|
||||
iceServers []*livekit.ICEServer
|
||||
lock sync.RWMutex
|
||||
// map of identity -> Participant
|
||||
participants map[string]types.Participant
|
||||
@@ -55,11 +54,10 @@ type ParticipantOptions struct {
|
||||
AutoSubscribe bool
|
||||
}
|
||||
|
||||
func NewRoom(room *livekit.Room, config WebRTCConfig, iceServers []*livekit.ICEServer, audioConfig *config.AudioConfig) *Room {
|
||||
func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig) *Room {
|
||||
r := &Room{
|
||||
Room: proto.Clone(room).(*livekit.Room),
|
||||
config: config,
|
||||
iceServers: iceServers,
|
||||
audioConfig: audioConfig,
|
||||
statsReporter: stats.NewRoomStatsReporter(room.Name),
|
||||
participants: make(map[string]types.Participant),
|
||||
@@ -139,7 +137,7 @@ func (r *Room) LastLeftAt() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *Room) Join(participant types.Participant, opts *ParticipantOptions) error {
|
||||
func (r *Room) Join(participant types.Participant, opts *ParticipantOptions, iceServers []*livekit.ICEServer) error {
|
||||
if r.isClosed.Get() {
|
||||
stats.PromServiceOperationCounter.WithLabelValues("participant_join", "error", "room_closed").Add(1)
|
||||
return ErrRoomClosed
|
||||
@@ -223,7 +221,7 @@ func (r *Room) Join(participant types.Participant, opts *ParticipantOptions) err
|
||||
}
|
||||
})
|
||||
|
||||
if err := participant.SendJoinResponse(r.Room, otherParticipants, r.iceServers); err != nil {
|
||||
if err := participant.SendJoinResponse(r.Room, otherParticipants, iceServers); err != nil {
|
||||
stats.PromServiceOperationCounter.WithLabelValues("participant_join", "error", "send_response").Add(1)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ func init() {
|
||||
serverlogger.InitDevelopment("")
|
||||
}
|
||||
|
||||
var iceServersForRoom = []*livekit.ICEServer{{Urls: []string{"stun:stun.l.google.com:19302"}}}
|
||||
|
||||
func TestJoinedState(t *testing.T) {
|
||||
t.Run("new room should return joinedAt 0", func(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
|
||||
@@ -61,7 +63,7 @@ func TestRoomJoin(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
|
||||
pNew := newMockParticipant("new", types.DefaultProtocol, false)
|
||||
|
||||
rm.Join(pNew, nil)
|
||||
rm.Join(pNew, nil, iceServersForRoom)
|
||||
|
||||
// expect new participant to get a JoinReply
|
||||
info, participants, iceServers := pNew.SendJoinResponseArgsForCall(0)
|
||||
@@ -76,7 +78,7 @@ func TestRoomJoin(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: numExisting})
|
||||
p := newMockParticipant("new", types.DefaultProtocol, false)
|
||||
|
||||
err := rm.Join(p, &rtc.ParticipantOptions{AutoSubscribe: true})
|
||||
err := rm.Join(p, &rtc.ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||
require.NoError(t, err)
|
||||
|
||||
stateChangeCB := p.OnStateChangeArgsForCall(0)
|
||||
@@ -130,7 +132,7 @@ func TestRoomJoin(t *testing.T) {
|
||||
rm.Room.MaxParticipants = 1
|
||||
p := newMockParticipant("second", types.ProtocolVersion(0), false)
|
||||
|
||||
err := rm.Join(p, nil)
|
||||
err := rm.Join(p, nil, iceServersForRoom)
|
||||
require.Equal(t, rtc.ErrMaxParticipantsExceeded, err)
|
||||
})
|
||||
}
|
||||
@@ -211,7 +213,7 @@ func TestRoomClosure(t *testing.T) {
|
||||
require.Len(t, rm.GetParticipants(), 0)
|
||||
require.True(t, isClosed)
|
||||
|
||||
require.Equal(t, rtc.ErrRoomClosed, rm.Join(p, nil))
|
||||
require.Equal(t, rtc.ErrRoomClosed, rm.Join(p, nil, iceServersForRoom))
|
||||
})
|
||||
|
||||
t.Run("room does not close before empty timeout", func(t *testing.T) {
|
||||
@@ -485,7 +487,7 @@ func TestHiddenParticipants(t *testing.T) {
|
||||
defer rm.Close()
|
||||
|
||||
pNew := newMockParticipant("new", types.DefaultProtocol, false)
|
||||
rm.Join(pNew, nil)
|
||||
rm.Join(pNew, nil, iceServersForRoom)
|
||||
|
||||
// expect new participant to get a JoinReply
|
||||
info, participants, iceServers := pNew.SendJoinResponseArgsForCall(0)
|
||||
@@ -499,7 +501,7 @@ func TestHiddenParticipants(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, numHidden: 1})
|
||||
p := newMockParticipant("new", types.DefaultProtocol, false)
|
||||
|
||||
err := rm.Join(p, &rtc.ParticipantOptions{AutoSubscribe: true})
|
||||
err := rm.Join(p, &rtc.ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||
require.NoError(t, err)
|
||||
|
||||
stateChangeCB := p.OnStateChangeArgsForCall(0)
|
||||
@@ -545,13 +547,6 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *rtc.Room {
|
||||
rm := rtc.NewRoom(
|
||||
&livekit.Room{Name: "room"},
|
||||
rtc.WebRTCConfig{},
|
||||
[]*livekit.ICEServer{
|
||||
{
|
||||
Urls: []string{
|
||||
"stun:stun.l.google.com:19302",
|
||||
},
|
||||
},
|
||||
},
|
||||
&config.AudioConfig{
|
||||
UpdateInterval: audioUpdateInterval,
|
||||
SmoothIntervals: opts.audioSmoothIntervals,
|
||||
@@ -560,7 +555,7 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *rtc.Room {
|
||||
for i := 0; i < opts.num+opts.numHidden; i++ {
|
||||
identity := fmt.Sprintf("p%d", i)
|
||||
participant := newMockParticipant(identity, opts.protocol, i >= opts.num)
|
||||
err := rm.Join(participant, &rtc.ParticipantOptions{AutoSubscribe: true})
|
||||
err := rm.Join(participant, &rtc.ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||
participant.StateReturns(livekit.ParticipantInfo_ACTIVE)
|
||||
participant.IsReadyReturns(true)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -261,7 +261,7 @@ func (r *LocalRoomManager) StartSession(ctx context.Context, roomName string, pi
|
||||
opts := rtc.ParticipantOptions{
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
}
|
||||
if err := room.Join(participant, &opts); err != nil {
|
||||
if err := room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
||||
logger.Errorw("could not join room", err)
|
||||
return
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func (r *LocalRoomManager) getOrCreateRoom(ctx context.Context, roomName string)
|
||||
}
|
||||
|
||||
// construct ice servers
|
||||
room = rtc.NewRoom(ri, *r.rtcConfig, r.iceServersForRoom(ri), &r.config.Audio)
|
||||
room = rtc.NewRoom(ri, *r.rtcConfig, &r.config.Audio)
|
||||
room.OnClose(func() {
|
||||
if err := r.DeleteRoom(ctx, roomName); err != nil {
|
||||
logger.Errorw("could not delete room", err)
|
||||
|
||||
Reference in New Issue
Block a user