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