feat(web): realtime WebSocket sync for web editor#10
Open
ZenithDevHQ wants to merge 6 commits into
Open
Conversation
Design for two-way realtime sync between the web editor and plugin using Cloudflare Durable Objects as a WebSocket relay. Covers message protocol, conflict detection, undo history, and three-codebase changes.
- Add TRACK_CREATE, TRACK_DELETE, TRACK_MODIFY to EventType enum - Create TrackCreateEvent with PRE/POST pattern (matching GroupCreateEvent) - Create TrackDeleteEvent with PRE/POST pattern (matching GroupDeleteEvent) - Create TrackModifyEvent for track group list changes - Add EventBus to TrackManagerImpl constructor, fire events on CRUD - Pass eventBus to TrackManagerImpl in HyperPerms.enable()
Adds a ThreadLocal flag and applyChangesFromWebSocket() method so EventBus listeners can detect when changes originate from a WebSocket message and avoid firing events back to the relay.
- Add nullable wsUrl field to SessionCreateResponse - Update WebEditorService.createSession() to extract wsUrl from JSON
Add WebSocketSessionClient for bidirectional event bridging between the Minecraft plugin and the web editor via Cloudflare Durable Objects. Includes auto-reconnect with exponential backoff, ping/pong keepalive, batch.apply handling, session.sync, and EventBus subscription for all permission/group/track/user change events. Integrate WS lifecycle into WebEditorService, add config options (websocketEnabled, reconnect params, ping timeout), update editor/apply commands for WS-first with REST fallback, and add shutdown cleanup.
bce7b16 to
1d9385a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds bidirectional realtime WebSocket sync between the HyperPerms plugin and the web editor, enabling live permission editing with instant feedback. Changes made in the web editor are applied to the server in real-time, and changes made via commands or other sources are reflected back to the editor immediately.
Architecture
The plugin connects to a Cloudflare Durable Object (deployed separately) via WebSocket, which acts as a relay between the plugin and the web editor. This gives us:
What's included
Event System Additions
TrackCreateEvent,TrackDeleteEvent,TrackModifyEvent- new track lifecycle events following the existing PRE/POST pattern used byGroupCreateEvent/GroupDeleteEventEventBusintegration inTrackManagerImplto fire events on track CRUD operationsTRACK_CREATE,TRACK_DELETE,TRACK_MODIFYentries inEventTypeenumWebSocket Echo Prevention
ChangeApplier.applyChangesFromWebSocket()wraps change application with a ThreadLocal flagChangeApplier.isApplyingFromWebSocket()to skip re-broadcasting changes that originated from the WebSocket relayWebSocket Client (
WebSocketSessionClient)java.net.http.HttpClient.newWebSocketBuilder(), reuses the existingHttpClientfromWebEditorServicebatch.applymessages: deserializes ops intoChangeobjects, applies viaChangeApplier, returns success/failure counts with undo IDsession.syncrequests by serializing current state viaSessionData.fromHyperPerms()Service Integration
WebEditorServicegainsconnectWebSocket(),disconnectWebSocket(),getActiveWsClient()lifecycle methodsSessionCreateResponsenow includes thewsUrlfield returned by the APICommand Updates
EditorSubCommand: displays "Live connection established" when WS connects after session creationApplySubCommand: sendsbatch.applyover WebSocket when connected, falls back to REST otherwiseConfiguration
websocketEnabled(default:true) - master toggle for WebSocket featureswebsocketReconnectMaxAttempts(default:10) - max reconnect attempts before giving upwebsocketReconnectMaxDelaySeconds(default:30) - cap on exponential backoff delaywebsocketPingTimeoutSeconds(default:90) - time without ping before triggering reconnectShutdown
HyperPerms.disable()callswebEditorService.disconnectWebSocket()for clean shutdownFiles Changed
TrackCreateEvent.javaTrackDeleteEvent.javaTrackModifyEvent.javaHyperPermsEvent.javaTrackManagerImpl.javaChangeApplier.javaWebSocketSessionClient.javaWebEditorService.javaSessionCreateResponse.javaWebEditorConfig.javaHyperPermsConfig.javaEditorSubCommand.javaApplySubCommand.javaHyperPerms.javaTest Plan
Live connection establishedmessage in console)websocketEnabled: false, verify REST apply still works