Use publisher PC as default with publish-only connections (#198)
This commit is contained in:
+13
-5
@@ -155,7 +155,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
|
|
||||||
primaryPC := p.publisher.pc
|
primaryPC := p.publisher.pc
|
||||||
|
|
||||||
if p.ProtocolVersion().SubscriberAsPrimary() {
|
if p.SubscriberAsPrimary() {
|
||||||
primaryPC = p.subscriber.pc
|
primaryPC = p.subscriber.pc
|
||||||
ordered := true
|
ordered := true
|
||||||
// also create data channels for subs
|
// also create data channels for subs
|
||||||
@@ -505,7 +505,11 @@ func (p *ParticipantImpl) RemoveSubscriber(participantId string) {
|
|||||||
|
|
||||||
// signal connection methods
|
// signal connection methods
|
||||||
|
|
||||||
func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticipants []*livekit.ParticipantInfo, iceServers []*livekit.ICEServer) error {
|
func (p *ParticipantImpl) SendJoinResponse(
|
||||||
|
roomInfo *livekit.Room,
|
||||||
|
otherParticipants []*livekit.ParticipantInfo,
|
||||||
|
iceServers []*livekit.ICEServer,
|
||||||
|
) error {
|
||||||
// send Join response
|
// send Join response
|
||||||
return p.writeMessage(&livekit.SignalResponse{
|
return p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Join{
|
Message: &livekit.SignalResponse_Join{
|
||||||
@@ -516,7 +520,7 @@ func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticip
|
|||||||
ServerVersion: version.Version,
|
ServerVersion: version.Version,
|
||||||
IceServers: iceServers,
|
IceServers: iceServers,
|
||||||
// indicates both server and client support subscriber as primary
|
// indicates both server and client support subscriber as primary
|
||||||
SubscriberPrimary: p.ProtocolVersion().SubscriberAsPrimary(),
|
SubscriberPrimary: p.SubscriberAsPrimary(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -574,13 +578,13 @@ func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error {
|
|||||||
|
|
||||||
var dc *webrtc.DataChannel
|
var dc *webrtc.DataChannel
|
||||||
if dp.Kind == livekit.DataPacket_RELIABLE {
|
if dp.Kind == livekit.DataPacket_RELIABLE {
|
||||||
if p.ProtocolVersion().SubscriberAsPrimary() {
|
if p.SubscriberAsPrimary() {
|
||||||
dc = p.reliableDCSub
|
dc = p.reliableDCSub
|
||||||
} else {
|
} else {
|
||||||
dc = p.reliableDC
|
dc = p.reliableDC
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if p.ProtocolVersion().SubscriberAsPrimary() {
|
if p.SubscriberAsPrimary() {
|
||||||
dc = p.lossyDCSub
|
dc = p.lossyDCSub
|
||||||
} else {
|
} else {
|
||||||
dc = p.lossyDC
|
dc = p.lossyDC
|
||||||
@@ -753,6 +757,10 @@ func (p *ParticipantImpl) Hidden() bool {
|
|||||||
return p.params.Hidden
|
return p.params.Hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) SubscriberAsPrimary() bool {
|
||||||
|
return p.ProtocolVersion().SubscriberAsPrimary() && p.CanSubscribe()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
||||||
return p.subscriber.pc
|
return p.subscriber.pc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,36 @@ func TestConnectionQuality(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSubscriberAsPrimary(t *testing.T) {
|
||||||
|
t.Run("protocol 4 uses subs as primary", func(t *testing.T) {
|
||||||
|
p := newParticipantForTest("test")
|
||||||
|
p.SetPermission(&livekit.ParticipantPermission{
|
||||||
|
CanSubscribe: true,
|
||||||
|
CanPublish: true,
|
||||||
|
})
|
||||||
|
require.True(t, p.SubscriberAsPrimary())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("protocol 2 uses pub as primary", func(t *testing.T) {
|
||||||
|
p := newParticipantForTest("test")
|
||||||
|
p.params.ProtocolVersion = 2
|
||||||
|
p.SetPermission(&livekit.ParticipantPermission{
|
||||||
|
CanSubscribe: true,
|
||||||
|
CanPublish: true,
|
||||||
|
})
|
||||||
|
require.False(t, p.SubscriberAsPrimary())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("publisher only uses pub as primary", func(t *testing.T) {
|
||||||
|
p := newParticipantForTest("test")
|
||||||
|
p.SetPermission(&livekit.ParticipantPermission{
|
||||||
|
CanSubscribe: false,
|
||||||
|
CanPublish: true,
|
||||||
|
})
|
||||||
|
require.False(t, p.SubscriberAsPrimary())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func newParticipantForTest(identity string) *ParticipantImpl {
|
func newParticipantForTest(identity string) *ParticipantImpl {
|
||||||
conf, _ := config.NewConfig("", nil)
|
conf, _ := config.NewConfig("", nil)
|
||||||
// disable mux, it doesn't play too well with unit test
|
// disable mux, it doesn't play too well with unit test
|
||||||
@@ -285,7 +315,7 @@ func newParticipantForTest(identity string) *ParticipantImpl {
|
|||||||
Identity: identity,
|
Identity: identity,
|
||||||
Config: rtcConf,
|
Config: rtcConf,
|
||||||
Sink: &routingfakes.FakeMessageSink{},
|
Sink: &routingfakes.FakeMessageSink{},
|
||||||
ProtocolVersion: 0,
|
ProtocolVersion: 4,
|
||||||
ThrottleConfig: conf.RTC.PLIThrottle,
|
ThrottleConfig: conf.RTC.PLIThrottle,
|
||||||
})
|
})
|
||||||
return p
|
return p
|
||||||
|
|||||||
+1
-1
@@ -222,7 +222,7 @@ func (r *Room) Join(participant types.Participant, opts *ParticipantOptions, ice
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if participant.ProtocolVersion().SubscriberAsPrimary() {
|
if participant.SubscriberAsPrimary() {
|
||||||
// initiates sub connection as primary
|
// initiates sub connection as primary
|
||||||
participant.Negotiate()
|
participant.Negotiate()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ type Participant interface {
|
|||||||
CanSubscribe() bool
|
CanSubscribe() bool
|
||||||
CanPublishData() bool
|
CanPublishData() bool
|
||||||
Hidden() bool
|
Hidden() bool
|
||||||
|
SubscriberAsPrimary() bool
|
||||||
|
|
||||||
Start()
|
Start()
|
||||||
Close() error
|
Close() error
|
||||||
|
|||||||
@@ -446,6 +446,16 @@ type FakeParticipant struct {
|
|||||||
stateReturnsOnCall map[int]struct {
|
stateReturnsOnCall map[int]struct {
|
||||||
result1 livekit.ParticipantInfo_State
|
result1 livekit.ParticipantInfo_State
|
||||||
}
|
}
|
||||||
|
SubscriberAsPrimaryStub func() bool
|
||||||
|
subscriberAsPrimaryMutex sync.RWMutex
|
||||||
|
subscriberAsPrimaryArgsForCall []struct {
|
||||||
|
}
|
||||||
|
subscriberAsPrimaryReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
subscriberAsPrimaryReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
SubscriberMediaEngineStub func() *webrtc.MediaEngine
|
SubscriberMediaEngineStub func() *webrtc.MediaEngine
|
||||||
subscriberMediaEngineMutex sync.RWMutex
|
subscriberMediaEngineMutex sync.RWMutex
|
||||||
subscriberMediaEngineArgsForCall []struct {
|
subscriberMediaEngineArgsForCall []struct {
|
||||||
@@ -2864,6 +2874,59 @@ func (fake *FakeParticipant) StateReturnsOnCall(i int, result1 livekit.Participa
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) SubscriberAsPrimary() bool {
|
||||||
|
fake.subscriberAsPrimaryMutex.Lock()
|
||||||
|
ret, specificReturn := fake.subscriberAsPrimaryReturnsOnCall[len(fake.subscriberAsPrimaryArgsForCall)]
|
||||||
|
fake.subscriberAsPrimaryArgsForCall = append(fake.subscriberAsPrimaryArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.SubscriberAsPrimaryStub
|
||||||
|
fakeReturns := fake.subscriberAsPrimaryReturns
|
||||||
|
fake.recordInvocation("SubscriberAsPrimary", []interface{}{})
|
||||||
|
fake.subscriberAsPrimaryMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) SubscriberAsPrimaryCallCount() int {
|
||||||
|
fake.subscriberAsPrimaryMutex.RLock()
|
||||||
|
defer fake.subscriberAsPrimaryMutex.RUnlock()
|
||||||
|
return len(fake.subscriberAsPrimaryArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) SubscriberAsPrimaryCalls(stub func() bool) {
|
||||||
|
fake.subscriberAsPrimaryMutex.Lock()
|
||||||
|
defer fake.subscriberAsPrimaryMutex.Unlock()
|
||||||
|
fake.SubscriberAsPrimaryStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) SubscriberAsPrimaryReturns(result1 bool) {
|
||||||
|
fake.subscriberAsPrimaryMutex.Lock()
|
||||||
|
defer fake.subscriberAsPrimaryMutex.Unlock()
|
||||||
|
fake.SubscriberAsPrimaryStub = nil
|
||||||
|
fake.subscriberAsPrimaryReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) SubscriberAsPrimaryReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.subscriberAsPrimaryMutex.Lock()
|
||||||
|
defer fake.subscriberAsPrimaryMutex.Unlock()
|
||||||
|
fake.SubscriberAsPrimaryStub = nil
|
||||||
|
if fake.subscriberAsPrimaryReturnsOnCall == nil {
|
||||||
|
fake.subscriberAsPrimaryReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.subscriberAsPrimaryReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeParticipant) SubscriberMediaEngine() *webrtc.MediaEngine {
|
func (fake *FakeParticipant) SubscriberMediaEngine() *webrtc.MediaEngine {
|
||||||
fake.subscriberMediaEngineMutex.Lock()
|
fake.subscriberMediaEngineMutex.Lock()
|
||||||
ret, specificReturn := fake.subscriberMediaEngineReturnsOnCall[len(fake.subscriberMediaEngineArgsForCall)]
|
ret, specificReturn := fake.subscriberMediaEngineReturnsOnCall[len(fake.subscriberMediaEngineArgsForCall)]
|
||||||
@@ -3124,6 +3187,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.startMutex.RUnlock()
|
defer fake.startMutex.RUnlock()
|
||||||
fake.stateMutex.RLock()
|
fake.stateMutex.RLock()
|
||||||
defer fake.stateMutex.RUnlock()
|
defer fake.stateMutex.RUnlock()
|
||||||
|
fake.subscriberAsPrimaryMutex.RLock()
|
||||||
|
defer fake.subscriberAsPrimaryMutex.RUnlock()
|
||||||
fake.subscriberMediaEngineMutex.RLock()
|
fake.subscriberMediaEngineMutex.RLock()
|
||||||
defer fake.subscriberMediaEngineMutex.RUnlock()
|
defer fake.subscriberMediaEngineMutex.RUnlock()
|
||||||
fake.subscriberPCMutex.RLock()
|
fake.subscriberPCMutex.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user