[WIP] rtc: add RestartSessionTimer to re-anchor participant session duration (#4566)

* rtc: add RestartSessionTimer to re-anchor participant session duration

Exposes ParticipantImpl.RestartSessionTimer so the session timer can be
re-anchored to the actual join time. Duration is only ever emitted once
the participant becomes active, so re-anchoring at join keeps pre-join
wall-clock out of the reported/billed duration. Adds the method to the
LocalParticipant interface (fake regenerated) and a local protocol
replace to pick up SessionTimer.Reset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* tidy

* update protocol

* report ended at for inactive sessions

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Paul Wells <paulwe@gmail.com>
This commit is contained in:
shishirng
2026-06-11 10:02:25 -07:00
committed by GitHub
co-authored by Claude Opus 4.8 Paul Wells
parent 688cc66ed8
commit 08ab361e8e
3 changed files with 14 additions and 10 deletions
+11 -7
View File
@@ -405,19 +405,23 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
p.supervisor.OnPublicationError(p.onPublicationError)
}
var timerStarted bool
params.Reporter.RegisterFunc(func(ts time.Time, tx roomobs.ParticipantSessionTx) bool {
// Don't publish duration if participant never became active. Otherwise short-lived
// JOINING/JOINED -> DISCONNECTED transitions would still get rounded up to a
// minute by the session timer and inflate billed/reported duration.
if p.lastActiveAt.Load() == nil {
return !p.IsClosed()
}
if dts := p.disconnectedAt.Load(); dts != nil {
ts = *dts
tx.ReportEndTime(ts)
}
// Don't publish duration if participant never became active. Otherwise short-lived
// JOINING/JOINED -> DISCONNECTED transitions would still get rounded up to a
// minute by the session timer and inflate billed/reported duration.
if lastActive := p.lastActiveAt.Load(); lastActive == nil {
return !p.IsClosed()
} else if !timerStarted {
timerStarted = true
p.params.SessionTimer.Reset(*lastActive)
}
tx.ReportKindCode(roomobs.ParticipantKindCode(p.Kind()))
tx.ReportKindDetailsCodes(roomobs.ParticipantKindDetailsCodes(p.KindDetails()))