+18
-12
@@ -534,9 +534,13 @@ func (p *ParticipantImpl) handleMigrateMutedTrack() {
|
||||
p.mutedTrackNotFired = append(p.mutedTrackNotFired, addedTracks...)
|
||||
p.pendingTracksLock.Unlock()
|
||||
|
||||
for _, t := range addedTracks {
|
||||
p.handleTrackPublished(t)
|
||||
}
|
||||
// launch callbacks in goroutine since they could block
|
||||
// callbacks handle webhooks as well as db persistence
|
||||
go func() {
|
||||
for _, t := range addedTracks {
|
||||
p.handleTrackPublished(t)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) removeMutedTrackNotFired(mt *MediaTrack) {
|
||||
@@ -579,7 +583,7 @@ func (p *ParticipantImpl) SetMigrateInfo(
|
||||
for _, t := range mediaTracks {
|
||||
ti := t.GetTrack()
|
||||
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), nil)
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid))
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
|
||||
p.pendingTracks[t.GetCid()] = &pendingTrackInfo{trackInfos: []*livekit.TrackInfo{ti}, migrated: true}
|
||||
@@ -1404,14 +1408,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
}
|
||||
|
||||
p.params.Telemetry.TrackPublishRequested(context.Background(), p.ID(), p.Identity(), ti)
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid), func(t types.LocalMediaTrack) {
|
||||
p.params.Telemetry.TrackPublished(
|
||||
context.Background(),
|
||||
t.PublisherID(),
|
||||
t.PublisherIdentity(),
|
||||
t.ToProto(),
|
||||
)
|
||||
})
|
||||
p.supervisor.AddPublication(livekit.TrackID(ti.Sid))
|
||||
p.supervisor.SetPublicationMute(livekit.TrackID(ti.Sid), ti.Muted)
|
||||
if p.getPublishedTrackBySignalCid(req.Cid) != nil || p.getPublishedTrackBySdpCid(req.Cid) != nil || p.pendingTracks[req.Cid] != nil {
|
||||
if p.pendingTracks[req.Cid] == nil {
|
||||
@@ -1643,6 +1640,15 @@ func (p *ParticipantImpl) handleTrackPublished(track types.MediaTrack) {
|
||||
if onTrackPublished != nil {
|
||||
onTrackPublished(p, track)
|
||||
}
|
||||
|
||||
// send webhook after callbacks are complete, persistence and state handling happens
|
||||
// in `onTrackPublished` cb
|
||||
p.params.Telemetry.TrackPublished(
|
||||
context.Background(),
|
||||
p.ID(),
|
||||
p.Identity(),
|
||||
track.ToProto(),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) hasPendingMigratedTrack() bool {
|
||||
|
||||
@@ -75,7 +75,7 @@ func (p *ParticipantSupervisor) SetPublisherPeerConnectionConnected(isConnected
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, onSuccess func(track types.LocalMediaTrack)) {
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID) {
|
||||
p.lock.Lock()
|
||||
pm, ok := p.publications[trackID]
|
||||
if !ok {
|
||||
@@ -85,7 +85,6 @@ func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, onSucces
|
||||
TrackID: trackID,
|
||||
IsPeerConnectionConnected: p.isPublisherConnected,
|
||||
Logger: p.params.Logger,
|
||||
OnSuccess: onSuccess,
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ type PublicationMonitorParams struct {
|
||||
TrackID livekit.TrackID
|
||||
IsPeerConnectionConnected bool
|
||||
Logger logger.Logger
|
||||
OnSuccess func(t types.LocalMediaTrack)
|
||||
}
|
||||
|
||||
type PublicationMonitor struct {
|
||||
@@ -168,12 +167,6 @@ func (p *PublicationMonitor) update() {
|
||||
return
|
||||
}
|
||||
|
||||
if pub.isStart && p.publishedTrack != nil {
|
||||
if p.params.OnSuccess != nil {
|
||||
p.params.OnSuccess(p.publishedTrack)
|
||||
}
|
||||
}
|
||||
|
||||
if (pub.isStart && p.publishedTrack == nil) || (!pub.isStart && p.publishedTrack != nil) {
|
||||
// put it back as the condition is not satisfied
|
||||
p.desiredPublishes.PushFront(pub)
|
||||
|
||||
Reference in New Issue
Block a user