Revert "Cache data synchronously for processing in worker." (#2425)
This commit is contained in:
+32
-52
@@ -118,7 +118,7 @@ type Room struct {
|
|||||||
|
|
||||||
trailer []byte
|
trailer []byte
|
||||||
|
|
||||||
onParticipantChanged func(p types.LocalParticipant, pi *livekit.ParticipantInfo)
|
onParticipantChanged func(p types.LocalParticipant)
|
||||||
onRoomUpdated func()
|
onRoomUpdated func()
|
||||||
onClose func()
|
onClose func()
|
||||||
|
|
||||||
@@ -347,13 +347,11 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
|||||||
pw := r.addParticipantWorkerLocked(participant)
|
pw := r.addParticipantWorkerLocked(participant)
|
||||||
|
|
||||||
participant.OnStateChange(func(p types.LocalParticipant, state livekit.ParticipantInfo_State) {
|
participant.OnStateChange(func(p types.LocalParticipant, state livekit.ParticipantInfo_State) {
|
||||||
ri := r.ToProto()
|
|
||||||
pi := p.ToProto()
|
|
||||||
pw.eventsQueue.Enqueue(func() {
|
pw.eventsQueue.Enqueue(func() {
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(p, pi)
|
r.onParticipantChanged(p)
|
||||||
}
|
}
|
||||||
r.broadcastParticipantState(p, pi, broadcastOptions{skipSource: true})
|
r.broadcastParticipantState(p, broadcastOptions{skipSource: true})
|
||||||
|
|
||||||
if state == livekit.ParticipantInfo_ACTIVE {
|
if state == livekit.ParticipantInfo_ACTIVE {
|
||||||
// subscribe participant to existing published tracks
|
// subscribe participant to existing published tracks
|
||||||
@@ -370,8 +368,8 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.telemetry.ParticipantActive(context.Background(),
|
r.telemetry.ParticipantActive(context.Background(),
|
||||||
ri,
|
r.ToProto(),
|
||||||
pi,
|
p.ToProto(),
|
||||||
meta,
|
meta,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
@@ -385,29 +383,23 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
|||||||
})
|
})
|
||||||
// it's important to set this before connection, we don't want to miss out on any published tracks
|
// it's important to set this before connection, we don't want to miss out on any published tracks
|
||||||
participant.OnTrackPublished(func(p types.LocalParticipant, t types.MediaTrack) {
|
participant.OnTrackPublished(func(p types.LocalParticipant, t types.MediaTrack) {
|
||||||
pi := p.ToProto()
|
|
||||||
ti := t.ToProto()
|
|
||||||
pw.eventsQueue.Enqueue(func() {
|
pw.eventsQueue.Enqueue(func() {
|
||||||
r.onTrackPublished(p, pi, t, ti)
|
r.onTrackPublished(p, t)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
participant.OnTrackUpdated(func(p types.LocalParticipant, t types.MediaTrack) {
|
participant.OnTrackUpdated(func(p types.LocalParticipant, t types.MediaTrack) {
|
||||||
pi := p.ToProto()
|
|
||||||
pw.eventsQueue.Enqueue(func() {
|
pw.eventsQueue.Enqueue(func() {
|
||||||
r.onTrackUpdated(p, pi, t)
|
r.onTrackUpdated(p, t)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
participant.OnTrackUnpublished(func(p types.LocalParticipant, t types.MediaTrack) {
|
participant.OnTrackUnpublished(func(p types.LocalParticipant, t types.MediaTrack) {
|
||||||
pi := p.ToProto()
|
|
||||||
ti := t.ToProto()
|
|
||||||
pw.eventsQueue.Enqueue(func() {
|
pw.eventsQueue.Enqueue(func() {
|
||||||
r.onTrackUnpublished(p, pi, t, ti)
|
r.onTrackUnpublished(p, t)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
participant.OnParticipantUpdate(func(p types.LocalParticipant) {
|
participant.OnParticipantUpdate(func(p types.LocalParticipant) {
|
||||||
pi := p.ToProto()
|
|
||||||
pw.eventsQueue.Enqueue(func() {
|
pw.eventsQueue.Enqueue(func() {
|
||||||
r.onParticipantUpdate(p, pi)
|
r.onParticipantUpdate(p)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
participant.OnDataPacket(r.onDataPacket)
|
participant.OnDataPacket(r.onDataPacket)
|
||||||
@@ -468,7 +460,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
|||||||
r.participantRequestSources[participant.Identity()] = requestSource
|
r.participantRequestSources[participant.Identity()] = requestSource
|
||||||
|
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(participant, participant.ToProto())
|
r.onParticipantChanged(participant)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.AfterFunc(time.Minute, func() {
|
time.AfterFunc(time.Minute, func() {
|
||||||
@@ -645,11 +637,10 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity, pID livek
|
|||||||
r.leftAt.Store(time.Now().Unix())
|
r.leftAt.Store(time.Now().Unix())
|
||||||
|
|
||||||
if sendUpdates {
|
if sendUpdates {
|
||||||
pi := p.ToProto()
|
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(p, pi)
|
r.onParticipantChanged(p)
|
||||||
}
|
}
|
||||||
r.broadcastParticipantState(p, pi, broadcastOptions{skipSource: true})
|
r.broadcastParticipantState(p, broadcastOptions{skipSource: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,7 +826,7 @@ func (r *Room) OnClose(f func()) {
|
|||||||
r.onClose = f
|
r.onClose = f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) OnParticipantChanged(f func(p types.LocalParticipant, pi *livekit.ParticipantInfo)) {
|
func (r *Room) OnParticipantChanged(f func(participant types.LocalParticipant)) {
|
||||||
r.onParticipantChanged = f
|
r.onParticipantChanged = f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,14 +988,9 @@ func (r *Room) createJoinResponseLocked(participant types.LocalParticipant, iceS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// a ParticipantImpl in the room added a new track, subscribe other participants to it
|
// a ParticipantImpl in the room added a new track, subscribe other participants to it
|
||||||
func (r *Room) onTrackPublished(
|
func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.MediaTrack) {
|
||||||
participant types.LocalParticipant,
|
|
||||||
pi *livekit.ParticipantInfo,
|
|
||||||
track types.MediaTrack,
|
|
||||||
ti *livekit.TrackInfo,
|
|
||||||
) {
|
|
||||||
// publish participant update, since track state is changed
|
// publish participant update, since track state is changed
|
||||||
r.broadcastParticipantState(participant, pi, broadcastOptions{skipSource: true})
|
r.broadcastParticipantState(participant, broadcastOptions{skipSource: true})
|
||||||
|
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
// subscribe all existing participants to this MediaTrack
|
// subscribe all existing participants to this MediaTrack
|
||||||
@@ -1033,7 +1019,7 @@ func (r *Room) onTrackPublished(
|
|||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
|
|
||||||
if onParticipantChanged != nil {
|
if onParticipantChanged != nil {
|
||||||
onParticipantChanged(participant, pi)
|
onParticipantChanged(participant)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.trackManager.AddTrack(track, participant.Identity(), participant.ID())
|
r.trackManager.AddTrack(track, participant.Identity(), participant.ID())
|
||||||
@@ -1086,51 +1072,42 @@ func (r *Room) onTrackPublished(
|
|||||||
context.Background(),
|
context.Background(),
|
||||||
participant.ID(),
|
participant.ID(),
|
||||||
participant.Identity(),
|
participant.Identity(),
|
||||||
ti,
|
track.ToProto(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) onTrackUpdated(
|
func (r *Room) onTrackUpdated(p types.LocalParticipant, _ types.MediaTrack) {
|
||||||
p types.LocalParticipant,
|
|
||||||
pi *livekit.ParticipantInfo,
|
|
||||||
_ types.MediaTrack,
|
|
||||||
) {
|
|
||||||
// send track updates to everyone, especially if track was updated by admin
|
// send track updates to everyone, especially if track was updated by admin
|
||||||
r.broadcastParticipantState(p, pi, broadcastOptions{})
|
r.broadcastParticipantState(p, broadcastOptions{})
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(p, pi)
|
r.onParticipantChanged(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) onTrackUnpublished(
|
func (r *Room) onTrackUnpublished(p types.LocalParticipant, track types.MediaTrack) {
|
||||||
p types.LocalParticipant,
|
|
||||||
pi *livekit.ParticipantInfo,
|
|
||||||
track types.MediaTrack,
|
|
||||||
ti *livekit.TrackInfo,
|
|
||||||
) {
|
|
||||||
r.telemetry.TrackUnpublished(
|
r.telemetry.TrackUnpublished(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
p.ID(),
|
p.ID(),
|
||||||
p.Identity(),
|
p.Identity(),
|
||||||
ti,
|
track.ToProto(),
|
||||||
!p.IsClosed(),
|
!p.IsClosed(),
|
||||||
)
|
)
|
||||||
|
|
||||||
r.trackManager.RemoveTrack(track)
|
r.trackManager.RemoveTrack(track)
|
||||||
if !p.IsClosed() {
|
if !p.IsClosed() {
|
||||||
r.broadcastParticipantState(p, pi, broadcastOptions{skipSource: true})
|
r.broadcastParticipantState(p, broadcastOptions{skipSource: true})
|
||||||
}
|
}
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(p, pi)
|
r.onParticipantChanged(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) onParticipantUpdate(p types.LocalParticipant, pi *livekit.ParticipantInfo) {
|
func (r *Room) onParticipantUpdate(p types.LocalParticipant) {
|
||||||
r.protoProxy.MarkDirty(false)
|
r.protoProxy.MarkDirty(false)
|
||||||
// immediately notify when permissions or metadata changed
|
// immediately notify when permissions or metadata changed
|
||||||
r.broadcastParticipantState(p, pi, broadcastOptions{immediate: true})
|
r.broadcastParticipantState(p, broadcastOptions{immediate: true})
|
||||||
if r.onParticipantChanged != nil {
|
if r.onParticipantChanged != nil {
|
||||||
r.onParticipantChanged(p, pi)
|
r.onParticipantChanged(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1165,13 +1142,16 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// broadcast an update about participant p
|
// broadcast an update about participant p
|
||||||
func (r *Room) broadcastParticipantState(p types.LocalParticipant, pi *livekit.ParticipantInfo, opts broadcastOptions) {
|
func (r *Room) broadcastParticipantState(p types.LocalParticipant, opts broadcastOptions) {
|
||||||
|
pi := p.ToProto()
|
||||||
|
|
||||||
if p.Hidden() {
|
if p.Hidden() {
|
||||||
if !opts.skipSource {
|
if !opts.skipSource {
|
||||||
// send update only to hidden participant
|
// send update only to hidden participant
|
||||||
err := p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi})
|
err := p.SendParticipantUpdate([]*livekit.ParticipantInfo{pi})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.GetLogger().Errorw("could not send update to participant", err)
|
r.Logger.Errorw("could not send update to participant", err,
|
||||||
|
"participant", p.Identity(), "pID", p.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ func TestRoomJoin(t *testing.T) {
|
|||||||
t.Run("participant state change is broadcasted to others", func(t *testing.T) {
|
t.Run("participant state change is broadcasted to others", func(t *testing.T) {
|
||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: numParticipants})
|
||||||
var changedParticipant types.Participant
|
var changedParticipant types.Participant
|
||||||
rm.OnParticipantChanged(func(participant types.LocalParticipant, _pi *livekit.ParticipantInfo) {
|
rm.OnParticipantChanged(func(participant types.LocalParticipant) {
|
||||||
changedParticipant = participant
|
changedParticipant = participant
|
||||||
})
|
})
|
||||||
participants := rm.GetParticipants()
|
participants := rm.GetParticipants()
|
||||||
|
|||||||
@@ -577,10 +577,10 @@ func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName livekit.Room
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
newRoom.OnParticipantChanged(func(p types.LocalParticipant, pi *livekit.ParticipantInfo) {
|
newRoom.OnParticipantChanged(func(p types.LocalParticipant) {
|
||||||
if pi.State != livekit.ParticipantInfo_DISCONNECTED {
|
if !p.IsDisconnected() {
|
||||||
if err := r.roomStore.StoreParticipant(ctx, roomName, pi); err != nil {
|
if err := r.roomStore.StoreParticipant(ctx, roomName, p.ToProto()); err != nil {
|
||||||
p.GetLogger().Errorw("could not handle participant change", err)
|
newRoom.Logger.Errorw("could not handle participant change", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user