feat: implement polling fallback for event communication #15
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
Implements polling-based event notification as a fallback for environments where WebSocket connections are blocked by network firewalls.
Background
In corporate or educational network environments, WebSocket connections (wss://) are often blocked by security policies. This PR adds a polling-based protocol that allows the Mesh extension to work in such environments while maintaining WebSocket support for environments where it's available.
Implementation
Protocol Selection (Host)
useWebSocketflag based on test resultProtocol Selection (Member)
useWebSocketflag fromjoinGroupresponseTwo Protocols
Protocol A: WebSocket (Existing)
fireEventsByNodemutation (None DataSource)onMessageInGroupsubscription (WebSocket)Protocol B: Polling (New)
recordEventsByNodemutation (saves to DynamoDB)getEventsSincequery (polling every 2 seconds)Key Technical Details
Server-side Timestamp Management
recordEventsByNodegenerates timestamps on the server side usingutil.time.nowISO8601()event.firedAtis not usedrecordEventsByNodecallsinceparameterCursor-based Pagination
Event.cursorfield contains Sort Key (SK)RecordEventsPayload.nextSincereturns next cursor valuesinceparameterChanges
Server-side (infra/mesh-v2)
useWebSocketparameter tocreateGroupmutationrecordEventsByNodemutation (new)getEventsSincequery (new)MESH_EVENT_TTL_SECONDS,MESH_POLLING_INTERVAL_SECONDSGroupandNodetypes withuseWebSocketandpollingIntervalSecondsfieldscursorfield toEventtypeClient-side (gui/scratch-vm)
testWebSocket()method to detect protocol availabilitycreateGroup()to includeuseWebSocketparameterjoinGroup()to retrieveuseWebSocketfrom responsestartPolling(),stopPolling(),pollEvents()FIRE_EVENTSorRECORD_EVENTSbased on protocolTest Coverage
Unit Tests (scratch-vm)
pollEventsfetches and handles events correctlyfireEventsBatchusesRECORD_EVENTSwhenuseWebSocketis falseIntegration Tests (mesh-v2)
useWebSocketflagConfiguration
Default Values
MESH_EVENT_TTL_SECONDS: 10 (events auto-delete after 10 seconds)MESH_POLLING_INTERVAL_SECONDS: 2 (poll every 2 seconds)Cost Optimization
Related Issue
Fixes #14
Sub-module PRs
🤖 Generated with Claude Code