Helpers accessible from other packages. (#2233)
This commit is contained in:
@@ -83,7 +83,7 @@ func TestJoinedState(t *testing.T) {
|
|||||||
func TestRoomJoin(t *testing.T) {
|
func TestRoomJoin(t *testing.T) {
|
||||||
t.Run("joining returns existing participant data", func(t *testing.T) {
|
t.Run("joining returns existing participant data", func(t *testing.T) {
|
||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
|
||||||
pNew := newMockParticipant("new", types.CurrentProtocol, false, false)
|
pNew := NewMockParticipant("new", types.CurrentProtocol, false, false)
|
||||||
|
|
||||||
_ = rm.Join(pNew, nil, nil, iceServersForRoom)
|
_ = rm.Join(pNew, nil, nil, iceServersForRoom)
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ func TestRoomJoin(t *testing.T) {
|
|||||||
t.Run("subscribe to existing channels upon join", func(t *testing.T) {
|
t.Run("subscribe to existing channels upon join", func(t *testing.T) {
|
||||||
numExisting := 3
|
numExisting := 3
|
||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: numExisting})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: numExisting})
|
||||||
p := newMockParticipant("new", types.CurrentProtocol, false, false)
|
p := NewMockParticipant("new", types.CurrentProtocol, false, false)
|
||||||
|
|
||||||
err := rm.Join(p, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
err := rm.Join(p, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -154,7 +154,7 @@ func TestRoomJoin(t *testing.T) {
|
|||||||
rm.lock.Lock()
|
rm.lock.Lock()
|
||||||
rm.protoRoom.MaxParticipants = 1
|
rm.protoRoom.MaxParticipants = 1
|
||||||
rm.lock.Unlock()
|
rm.lock.Unlock()
|
||||||
p := newMockParticipant("second", types.ProtocolVersion(0), false, false)
|
p := NewMockParticipant("second", types.ProtocolVersion(0), false, false)
|
||||||
|
|
||||||
err := rm.Join(p, nil, nil, iceServersForRoom)
|
err := rm.Join(p, nil, nil, iceServersForRoom)
|
||||||
require.Equal(t, ErrMaxParticipantsExceeded, err)
|
require.Equal(t, ErrMaxParticipantsExceeded, err)
|
||||||
@@ -414,7 +414,7 @@ func TestNewTrack(t *testing.T) {
|
|||||||
pub := participants[2].(*typesfakes.FakeLocalParticipant)
|
pub := participants[2].(*typesfakes.FakeLocalParticipant)
|
||||||
|
|
||||||
// pub adds track
|
// pub adds track
|
||||||
track := newMockTrack(livekit.TrackType_VIDEO, "webcam")
|
track := NewMockTrack(livekit.TrackType_VIDEO, "webcam")
|
||||||
trackCB := pub.OnTrackPublishedArgsForCall(0)
|
trackCB := pub.OnTrackPublishedArgsForCall(0)
|
||||||
require.NotNil(t, trackCB)
|
require.NotNil(t, trackCB)
|
||||||
trackCB(pub, track)
|
trackCB(pub, track)
|
||||||
@@ -653,7 +653,7 @@ func TestHiddenParticipants(t *testing.T) {
|
|||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, numHidden: 1})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, numHidden: 1})
|
||||||
defer rm.Close()
|
defer rm.Close()
|
||||||
|
|
||||||
pNew := newMockParticipant("new", types.CurrentProtocol, false, false)
|
pNew := NewMockParticipant("new", types.CurrentProtocol, false, false)
|
||||||
rm.Join(pNew, nil, nil, iceServersForRoom)
|
rm.Join(pNew, nil, nil, iceServersForRoom)
|
||||||
|
|
||||||
// expect new participant to get a JoinReply
|
// expect new participant to get a JoinReply
|
||||||
@@ -667,7 +667,7 @@ func TestHiddenParticipants(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("hidden participant subscribes to tracks", func(t *testing.T) {
|
t.Run("hidden participant subscribes to tracks", func(t *testing.T) {
|
||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
|
||||||
hidden := newMockParticipant("hidden", types.CurrentProtocol, true, false)
|
hidden := NewMockParticipant("hidden", types.CurrentProtocol, true, false)
|
||||||
|
|
||||||
err := rm.Join(hidden, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
err := rm.Join(hidden, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -689,7 +689,7 @@ func TestRoomUpdate(t *testing.T) {
|
|||||||
p1 := rm.GetParticipants()[0].(*typesfakes.FakeLocalParticipant)
|
p1 := rm.GetParticipants()[0].(*typesfakes.FakeLocalParticipant)
|
||||||
require.Equal(t, 0, p1.SendRoomUpdateCallCount())
|
require.Equal(t, 0, p1.SendRoomUpdateCallCount())
|
||||||
|
|
||||||
p2 := newMockParticipant("p2", types.CurrentProtocol, false, false)
|
p2 := NewMockParticipant("p2", types.CurrentProtocol, false, false)
|
||||||
require.NoError(t, rm.Join(p2, nil, nil, iceServersForRoom))
|
require.NoError(t, rm.Join(p2, nil, nil, iceServersForRoom))
|
||||||
|
|
||||||
// p1 should have received an update
|
// p1 should have received an update
|
||||||
@@ -743,7 +743,7 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *Room {
|
|||||||
)
|
)
|
||||||
for i := 0; i < opts.num+opts.numHidden; i++ {
|
for i := 0; i < opts.num+opts.numHidden; i++ {
|
||||||
identity := livekit.ParticipantIdentity(fmt.Sprintf("p%d", i))
|
identity := livekit.ParticipantIdentity(fmt.Sprintf("p%d", i))
|
||||||
participant := newMockParticipant(identity, opts.protocol, i >= opts.num, true)
|
participant := NewMockParticipant(identity, opts.protocol, i >= opts.num, true)
|
||||||
err := rm.Join(participant, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
err := rm.Join(participant, nil, &ParticipantOptions{AutoSubscribe: true}, iceServersForRoom)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
participant.StateReturns(livekit.ParticipantInfo_ACTIVE)
|
participant.StateReturns(livekit.ParticipantInfo_ACTIVE)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package rtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
@@ -27,7 +28,7 @@ func init() {
|
|||||||
prometheus.Init("test", livekit.NodeType_SERVER, "test")
|
prometheus.Init("test", livekit.NodeType_SERVER, "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.ProtocolVersion, hidden bool, publisher bool) *typesfakes.FakeLocalParticipant {
|
func NewMockParticipant(identity livekit.ParticipantIdentity, protocol types.ProtocolVersion, hidden bool, publisher bool) *typesfakes.FakeLocalParticipant {
|
||||||
p := &typesfakes.FakeLocalParticipant{}
|
p := &typesfakes.FakeLocalParticipant{}
|
||||||
sid := utils.NewGuid(utils.ParticipantPrefix)
|
sid := utils.NewGuid(utils.ParticipantPrefix)
|
||||||
p.IDReturns(livekit.ParticipantID(sid))
|
p.IDReturns(livekit.ParticipantID(sid))
|
||||||
@@ -44,6 +45,12 @@ func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.Pro
|
|||||||
State: livekit.ParticipantInfo_JOINED,
|
State: livekit.ParticipantInfo_JOINED,
|
||||||
IsPublisher: publisher,
|
IsPublisher: publisher,
|
||||||
})
|
})
|
||||||
|
p.ToProtoWithVersionReturns(&livekit.ParticipantInfo{
|
||||||
|
Sid: sid,
|
||||||
|
Identity: string(identity),
|
||||||
|
State: livekit.ParticipantInfo_JOINED,
|
||||||
|
IsPublisher: publisher,
|
||||||
|
}, utils.TimedVersion{})
|
||||||
|
|
||||||
p.SetMetadataCalls(func(m string) {
|
p.SetMetadataCalls(func(m string) {
|
||||||
var f func(participant types.LocalParticipant)
|
var f func(participant types.LocalParticipant)
|
||||||
@@ -71,11 +78,12 @@ func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.Pro
|
|||||||
p.AddTrackCalls(func(req *livekit.AddTrackRequest) {
|
p.AddTrackCalls(func(req *livekit.AddTrackRequest) {
|
||||||
updateTrack()
|
updateTrack()
|
||||||
})
|
})
|
||||||
|
p.GetLoggerReturns(logger.GetLogger())
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockTrack(kind livekit.TrackType, name string) *typesfakes.FakeMediaTrack {
|
func NewMockTrack(kind livekit.TrackType, name string) *typesfakes.FakeMediaTrack {
|
||||||
t := &typesfakes.FakeMediaTrack{}
|
t := &typesfakes.FakeMediaTrack{}
|
||||||
t.IDReturns(livekit.TrackID(utils.NewGuid(utils.TrackPrefix)))
|
t.IDReturns(livekit.TrackID(utils.NewGuid(utils.TrackPrefix)))
|
||||||
t.KindReturns(kind)
|
t.KindReturns(kind)
|
||||||
Reference in New Issue
Block a user