Send full update after joining when there are missed updates
This commit is contained in:
+24
-9
@@ -40,14 +40,15 @@ type ParticipantParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ParticipantImpl struct {
|
type ParticipantImpl struct {
|
||||||
params ParticipantParams
|
params ParticipantParams
|
||||||
id string
|
id string
|
||||||
publisher *PCTransport
|
publisher *PCTransport
|
||||||
subscriber *PCTransport
|
subscriber *PCTransport
|
||||||
isClosed utils.AtomicFlag
|
isClosed utils.AtomicFlag
|
||||||
permission *livekit.ParticipantPermission
|
permission *livekit.ParticipantPermission
|
||||||
state atomic.Value // livekit.ParticipantInfo_State
|
state atomic.Value // livekit.ParticipantInfo_State
|
||||||
rtcpCh chan []rtcp.Packet
|
updateAfterActive atomic.Value // bool
|
||||||
|
rtcpCh chan []rtcp.Packet
|
||||||
|
|
||||||
// reliable and unreliable data channels
|
// reliable and unreliable data channels
|
||||||
reliableDC *webrtc.DataChannel
|
reliableDC *webrtc.DataChannel
|
||||||
@@ -94,6 +95,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
connectedAt: time.Now(),
|
connectedAt: time.Now(),
|
||||||
}
|
}
|
||||||
p.state.Store(livekit.ParticipantInfo_JOINING)
|
p.state.Store(livekit.ParticipantInfo_JOINING)
|
||||||
|
p.updateAfterActive.Store(false)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
p.publisher, err = NewPCTransport(TransportParams{
|
p.publisher, err = NewPCTransport(TransportParams{
|
||||||
@@ -147,6 +149,10 @@ func (p *ParticipantImpl) State() livekit.ParticipantInfo_State {
|
|||||||
return p.state.Load().(livekit.ParticipantInfo_State)
|
return p.state.Load().(livekit.ParticipantInfo_State)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) UpdateAfterActive() bool {
|
||||||
|
return p.updateAfterActive.Load().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) ProtocolVersion() types.ProtocolVersion {
|
func (p *ParticipantImpl) ProtocolVersion() types.ProtocolVersion {
|
||||||
return p.params.ProtocolVersion
|
return p.params.ProtocolVersion
|
||||||
}
|
}
|
||||||
@@ -468,10 +474,19 @@ func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticip
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.ParticipantInfo) error {
|
func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.ParticipantInfo) error {
|
||||||
|
participantsToUpdate := participants
|
||||||
|
if p.State() == livekit.ParticipantInfo_JOINING {
|
||||||
|
// have not fully joined, it will not know how to handle updates
|
||||||
|
// make a note so that Room could resend updates once fully joined
|
||||||
|
p.updateAfterActive.Store(true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
p.updateAfterActive.Store(false)
|
||||||
return p.writeMessage(&livekit.SignalResponse{
|
return p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Update{
|
Message: &livekit.SignalResponse_Update{
|
||||||
Update: &livekit.ParticipantUpdate{
|
Update: &livekit.ParticipantUpdate{
|
||||||
Participants: participants,
|
Participants: participantsToUpdate,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -167,6 +167,10 @@ func (r *Room) Join(participant types.Participant, opts *ParticipantOptions) err
|
|||||||
r.broadcastParticipantState(p, true)
|
r.broadcastParticipantState(p, true)
|
||||||
|
|
||||||
if p.State() == livekit.ParticipantInfo_ACTIVE {
|
if p.State() == livekit.ParticipantInfo_ACTIVE {
|
||||||
|
if p.UpdateAfterActive() {
|
||||||
|
_ = p.SendParticipantUpdate(ToProtoParticipants(r.GetParticipants()))
|
||||||
|
}
|
||||||
|
|
||||||
// subscribe participant to existing publishedTracks
|
// subscribe participant to existing publishedTracks
|
||||||
r.subscribeToExistingTracks(p)
|
r.subscribeToExistingTracks(p)
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ type Participant interface {
|
|||||||
AddSubscribedTrack(participantId string, st SubscribedTrack)
|
AddSubscribedTrack(participantId string, st SubscribedTrack)
|
||||||
RemoveSubscribedTrack(participantId string, st SubscribedTrack)
|
RemoveSubscribedTrack(participantId string, st SubscribedTrack)
|
||||||
SubscriberPC() *webrtc.PeerConnection
|
SubscriberPC() *webrtc.PeerConnection
|
||||||
|
UpdateAfterActive() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishedTrack is the main interface representing a track published to the room
|
// PublishedTrack is the main interface representing a track published to the room
|
||||||
|
|||||||
@@ -371,6 +371,16 @@ type FakeParticipant struct {
|
|||||||
toProtoReturnsOnCall map[int]struct {
|
toProtoReturnsOnCall map[int]struct {
|
||||||
result1 *livekit.ParticipantInfo
|
result1 *livekit.ParticipantInfo
|
||||||
}
|
}
|
||||||
|
UpdateAfterActiveStub func() bool
|
||||||
|
updateAfterActiveMutex sync.RWMutex
|
||||||
|
updateAfterActiveArgsForCall []struct {
|
||||||
|
}
|
||||||
|
updateAfterActiveReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
updateAfterActiveReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
invocations map[string][][]interface{}
|
invocations map[string][][]interface{}
|
||||||
invocationsMutex sync.RWMutex
|
invocationsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
@@ -2348,6 +2358,59 @@ func (fake *FakeParticipant) ToProtoReturnsOnCall(i int, result1 *livekit.Partic
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) UpdateAfterActive() bool {
|
||||||
|
fake.updateAfterActiveMutex.Lock()
|
||||||
|
ret, specificReturn := fake.updateAfterActiveReturnsOnCall[len(fake.updateAfterActiveArgsForCall)]
|
||||||
|
fake.updateAfterActiveArgsForCall = append(fake.updateAfterActiveArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.UpdateAfterActiveStub
|
||||||
|
fakeReturns := fake.updateAfterActiveReturns
|
||||||
|
fake.recordInvocation("UpdateAfterActive", []interface{}{})
|
||||||
|
fake.updateAfterActiveMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) UpdateAfterActiveCallCount() int {
|
||||||
|
fake.updateAfterActiveMutex.RLock()
|
||||||
|
defer fake.updateAfterActiveMutex.RUnlock()
|
||||||
|
return len(fake.updateAfterActiveArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) UpdateAfterActiveCalls(stub func() bool) {
|
||||||
|
fake.updateAfterActiveMutex.Lock()
|
||||||
|
defer fake.updateAfterActiveMutex.Unlock()
|
||||||
|
fake.UpdateAfterActiveStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) UpdateAfterActiveReturns(result1 bool) {
|
||||||
|
fake.updateAfterActiveMutex.Lock()
|
||||||
|
defer fake.updateAfterActiveMutex.Unlock()
|
||||||
|
fake.UpdateAfterActiveStub = nil
|
||||||
|
fake.updateAfterActiveReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) UpdateAfterActiveReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.updateAfterActiveMutex.Lock()
|
||||||
|
defer fake.updateAfterActiveMutex.Unlock()
|
||||||
|
fake.UpdateAfterActiveStub = nil
|
||||||
|
if fake.updateAfterActiveReturnsOnCall == nil {
|
||||||
|
fake.updateAfterActiveReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.updateAfterActiveReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
||||||
fake.invocationsMutex.RLock()
|
fake.invocationsMutex.RLock()
|
||||||
defer fake.invocationsMutex.RUnlock()
|
defer fake.invocationsMutex.RUnlock()
|
||||||
@@ -2435,6 +2498,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.subscriberPCMutex.RUnlock()
|
defer fake.subscriberPCMutex.RUnlock()
|
||||||
fake.toProtoMutex.RLock()
|
fake.toProtoMutex.RLock()
|
||||||
defer fake.toProtoMutex.RUnlock()
|
defer fake.toProtoMutex.RUnlock()
|
||||||
|
fake.updateAfterActiveMutex.RLock()
|
||||||
|
defer fake.updateAfterActiveMutex.RUnlock()
|
||||||
copiedInvocations := map[string][][]interface{}{}
|
copiedInvocations := map[string][][]interface{}{}
|
||||||
for key, value := range fake.invocations {
|
for key, value := range fake.invocations {
|
||||||
copiedInvocations[key] = value
|
copiedInvocations[key] = value
|
||||||
|
|||||||
Reference in New Issue
Block a user