[WIP] RTC: Disconnect providers for single editor#76960
[WIP] RTC: Disconnect providers for single editor#76960shekharnwagh wants to merge 7 commits intoWordPress:trunkfrom
Conversation
8c9eff8 to
7a7ff78
Compare
Optimize resource usage for the common single-user editing case by deferring full sync provider connections until another editor is detected. This avoids unnecessary HTTP polling (or WebSocket connections for third-party providers) when only one user is editing.
The server-side Heartbeat handler (gutenberg_sync_heartbeat_presence) was added as scaffolding for provider-independent presence detection, but the client-side consumer (heartbeat-presence.ts) was removed during cleanup. The actual presence detection uses the sync endpoint with presence_only flag instead. Remove the dead code.
The awareness change handler fires on every awareness update including frequent cursor movements during active editing. Filter to only re-evaluate the downgrade timer when clients are actually added or removed, not on state updates. This avoids unnecessary iteration of all awareness states on every cursor move.
Fix a race condition where a collaborator leaving during async provider creation would never trigger a downgrade. startAwarenessMonitor now evaluates awareness.getStates() immediately after subscribing, catching collaborators that departed before the handler was registered.
Presence detection was coupled to the HTTP polling sync endpoint (/wp-sync/v1/updates), creating stale awareness entries that caused false collaborator detection after page refresh. This triggered unnecessary provider connections and the sync error modal for solo users.
Replace scattered cleanup logic with explicit state transition functions (enterStandby, enterConnected) and shared helpers (createProviders, clearEntityRuntime, destroyEntityProviders, destroyCollectionProviders). This makes it harder to miss cleanup steps when transitioning between standby and connected modes. Also fix the presence endpoint permission check — the old inline check only handled post types. Extract gutenberg_can_user_access_sync_room() to cover taxonomies, comments, and collections, matching the full sync endpoint's permission model.
7a7ff78 to
3cf5b99
Compare
|
My worry about using a rest endpoint for this kind of presence detection is that it'll run into the same issues as the polling provider. I don't think it should be introduced for something like the websocket provider that can already scale pretty well using websockets, for instance. What do you think about making the checkPresence provider specific? I'm envisioning that each provider will have their own server and client implementations just like we do for the http provider and the websocket provider. So they would implement their own way of doing this. We can offer an example within the two providers to show the best practice of doing this, and take advantage of the underlying transport mechanism of each provider. This feels similar to the collaborator limits in that it can be all client side and provider specific imo. This would mean that the code would reside within the websocket provider in VIP RTC plugin. |
What?
Closes
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Use of AI Tools