rtc: split EndSession out of MoveToRoom (#4917)
* rtc: split EndSession out of MoveToRoom A participant's session in a room can end without the participant closing: today on a move, and next on a room re-key, where a room ended by the sweeper while participants were joining restarts under a new room id with the same participants in it. EndSession is the room-independent half of MoveToRoom: report the published tracks unpublished, report the session end, run the caller's leave under the ending session's telemetry guard, then take a fresh guard and reset the deferred resolvers for the next session. The guard matters: ParticipantLeft releases it and the telemetry service refuses to open a stats worker for a released guard, so without a fresh one the next session's join would silently get no worker. MoveToRoom keeps the subscriber teardown and the onClose fan-out, passed in as the leave. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * rtc: rename EndSession to LeaveSession, add JoinSession EndSession read as terminal, but the participant survives it and joins another session, so name the pair for what happens to the participant: LeaveSession and JoinSession. JoinSession is the other half that review pointed out was missing from the API: the caller reports the join, then the published tracks are reported published again under the new session, pairing the unpublish LeaveSession reported. Without it the re-publish lived only in the caller, with nothing in OSS proving the two halves balance. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
93f5b3eb61
commit
6cfd19bd9b
+60
-26
@@ -4344,6 +4344,55 @@ func (p *ParticipantImpl) SupportsMoving() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LeaveSession takes the participant out of its session in its current room without
|
||||
// closing the participant, for it to join another session (see JoinSession): its
|
||||
// published tracks are reported unpublished, the session end is reported, and the
|
||||
// telemetry guard and deferred resolvers are reset for the next session. `leave` runs in
|
||||
// between, while the left session's guard is still in place, for the caller to report the
|
||||
// leave.
|
||||
func (p *ParticipantImpl) LeaveSession(leave func()) {
|
||||
for _, track := range p.GetPublishedTracks() {
|
||||
p.GetTelemetryListener().OnTrackUnpublished(
|
||||
p.ID(),
|
||||
p.Identity(),
|
||||
track.ToProto(),
|
||||
track.(types.LocalMediaTrack).Published(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
p.params.Reporter.ReportEndTime(time.Now())
|
||||
|
||||
if leave != nil {
|
||||
leave()
|
||||
}
|
||||
|
||||
p.lock.Lock()
|
||||
p.telemetryGuard = &telemetry.ReferenceGuard{}
|
||||
p.lock.Unlock()
|
||||
|
||||
p.params.LoggerResolver.Reset()
|
||||
p.params.ReporterResolver.Reset()
|
||||
}
|
||||
|
||||
// JoinSession takes the participant, after LeaveSession, into the session its current
|
||||
// room now serves: `join` runs first, for the caller to report the join, then the
|
||||
// published tracks are reported published again, in that order as on a fresh join.
|
||||
func (p *ParticipantImpl) JoinSession(join func()) {
|
||||
if join != nil {
|
||||
join()
|
||||
}
|
||||
|
||||
for _, track := range p.GetPublishedTracks() {
|
||||
p.GetTelemetryListener().OnTrackPublished(
|
||||
p.ID(),
|
||||
p.Identity(),
|
||||
track.ToProto(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) MoveToRoom(params types.MoveToRoomParams) {
|
||||
for _, track := range p.GetPublishedTracks() {
|
||||
for _, sub := range track.GetAllSubscribers() {
|
||||
@@ -4353,38 +4402,23 @@ func (p *ParticipantImpl) MoveToRoom(params types.MoveToRoomParams) {
|
||||
// clear the subscriber node max quality/audio codecs as the remote quality notify
|
||||
// from source room would not reach the moving out participant.
|
||||
track.(types.LocalMediaTrack).ClearSubscriberNodes()
|
||||
|
||||
trackInfo := track.ToProto()
|
||||
p.GetTelemetryListener().OnTrackUnpublished(
|
||||
p.ID(),
|
||||
p.Identity(),
|
||||
trackInfo,
|
||||
track.(types.LocalMediaTrack).Published(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
p.params.Reporter.ReportEndTime(time.Now())
|
||||
p.SubscriptionManager.ClearAllSubscriptions()
|
||||
p.LeaveSession(func() {
|
||||
p.SubscriptionManager.ClearAllSubscriptions()
|
||||
|
||||
// fire onClose callback for original room
|
||||
p.lock.Lock()
|
||||
onClose := p.onClose
|
||||
p.onClose = make(map[string]func(types.LocalParticipant))
|
||||
p.lock.Unlock()
|
||||
for _, cb := range onClose {
|
||||
cb(p)
|
||||
}
|
||||
// fire onClose callback for original room
|
||||
p.lock.Lock()
|
||||
onClose := p.onClose
|
||||
p.onClose = make(map[string]func(types.LocalParticipant))
|
||||
p.lock.Unlock()
|
||||
for _, cb := range onClose {
|
||||
cb(p)
|
||||
}
|
||||
})
|
||||
|
||||
p.params.Logger.Infow("move participant to new room", "newRoomName", params.RoomName, "newID", params.ParticipantID)
|
||||
|
||||
p.lock.Lock()
|
||||
p.telemetryGuard = &telemetry.ReferenceGuard{}
|
||||
p.lock.Unlock()
|
||||
|
||||
p.params.LoggerResolver.Reset()
|
||||
p.params.ReporterResolver.Reset()
|
||||
|
||||
p.setListener(params.Listener)
|
||||
p.setTelemetryListener(params.TelemetryListener)
|
||||
p.participantHelper.Store(params.Helper)
|
||||
|
||||
Reference in New Issue
Block a user