From ce1bf47b5c1d18c93b9077477561c3f9ba847f5b Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Mon, 13 Apr 2026 22:21:22 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20ensure=20num=5Fparticipants=20?= =?UTF-8?q?is=20accurate=20in=20webhook=20events=20(#4265)=20(#=E2=80=A6"?= =?UTF-8?q?=20(#4448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit cdb0769c38e237d1fae9d8ff2c1abeeeef52c5ed. --- pkg/rtc/room.go | 12 ++++-------- pkg/service/roommanager.go | 7 +++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index e7b4aaec..94e66fac 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -323,14 +323,6 @@ func (r *Room) ToProto() *livekit.Room { return r.protoProxy.Get() } -// ToProtoConsistent returns a room proto with participant counts computed -// directly from the current participants map, bypassing the batched proto -// proxy. Use this when an accurate num_participants is required immediately, -// e.g. for webhook or telemetry events. -func (r *Room) ToProtoConsistent() *livekit.Room { - return r.updateProto() -} - func (r *Room) Name() livekit.RoomName { return livekit.RoomName(r.protoRoom.Name) } @@ -1411,6 +1403,10 @@ func (r *Room) RemoveParticipant( delete(r.participantRequestSources, identity) delete(r.hasPublished, identity) delete(r.agentParticpants, identity) + if !p.Hidden() { + r.protoRoom.NumParticipants-- + } + immediateChange := false if p.IsRecorder() { activeRecording := false diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 33bfac44..26732495 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -569,8 +569,7 @@ func (r *RoomManager) StartSession( persistRoomForParticipantCount(room.ToProto()) clientMeta := &livekit.AnalyticsClientMeta{Region: r.currentNode.Region(), Node: string(r.currentNode.NodeID())} - // Use a consistent room proto so num_participants reflects the newly joined participant - r.telemetry.ParticipantJoined(ctx, room.ToProtoConsistent(), participant.ToProto(), pi.Client, clientMeta, true, participant.TelemetryGuard()) + r.telemetry.ParticipantJoined(ctx, protoRoom, participant.ToProto(), pi.Client, clientMeta, true, participant.TelemetryGuard()) participant.AddOnClose(types.ParticipantCloseKeyNormal, func(p types.LocalParticipant) { participantServerClosers.Close() @@ -578,8 +577,8 @@ func (r *RoomManager) StartSession( pLogger.Errorw("could not delete participant", err) } - // use consistent proto so num_participants is accurate for webhook - proto := room.ToProtoConsistent() + // update room store with new numParticipants + proto := room.ToProto() persistRoomForParticipantCount(proto) r.telemetry.ParticipantLeft(ctx, proto, p.ToProto(), true, participant.TelemetryGuard()) })