forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: implement polling fallback for event communication #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
- Added testWebSocket to detect protocol availability - Implemented polling fallback in MeshV2Service - Updated gql-operations.js with new polling mutations and queries - Exported GRAPHQL_ENDPOINT from mesh-client.js - Added unit tests for polling functionality Co-Authored-By: Gemini <noreply@google.com>
- Change GetEventsSince type from AWSDateTime! to String! - Improve testWebSocket URL construction to support custom domains
- Added 'cursor' field to GET_EVENTS_SINCE query to correctly update lastFetchTime - Added guard in pollEvents to prevent execution if lastFetchTime is null
- Set lastFetchTime to createdAt in createGroup - Set lastFetchTime to current time in joinGroup - Remove redundant initializations in startPolling and fireEventsBatch
- Added getForcePollingFromUrl to utils.js - Use forcePolling setting in MeshV2Service to bypass WebSocket test - Override useWebSocket to false if forcePolling is enabled during group join
- Updated JOIN_GROUP, RENEW_HEARTBEAT, and SEND_MEMBER_HEARTBEAT queries to include createdAt - Initialize lastFetchTime to empty string in constructor - Use node.createdAt from server when joining group - Use event.cursor to update lastFetchTime during polling - Added fallback for lastFetchTime in pollEvents to avoid GraphQL error - Updated tests with createdAt mock data
- Set lastFetchTime to current client time just before createGroup/joinGroup mutations - Reverted server-side createdAt dependency in GraphQL queries - Ensure stopPolling is called during cleanup to minimize requests - Updated tests to match reverted schema
- Removed hallucinated handleEvent call - Filter out self-fired events in pollEvents - Sort and queue other nodes' events with correct offsets for playback - Update lastFetchTime consistently from the latest polled event
- Added _queueEventsForPlayback private method - Simplified pollEvents and handleBatchEvent by using the new method - Ensured consistent sorting, offset calculation, and playback start trigger
- Update lastFetchTime in fireEventsBatch - Check pendingBroadcasts in pollEvents test
- Add queryCount tracking to pollEvents - Add tests for self-event filtering and lastFetchTime fallback
- Matched client operations with updated server schema - Ensured consistency across all group-related GraphQL operations
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
Client-side implementation of polling-based event notification fallback for Mesh v2. Adds WebSocket connection testing and automatic protocol switching to support environments where WebSocket connections are blocked.
Implementation Details
WebSocket Connection Test
Added
testWebSocket()method to detect WebSocket availability:Protocol Selection
Host (Group Creation)
testWebSocket()useWebSocketflag based on test resultcreateGroupmutationMember (Group Join)
useWebSocketflag fromjoinGroupresponsePolling Implementation
Start Polling
Poll Events
Event Transmission Protocol Switching
Cursor Management
lastFetchTime: Stores last cursor (or initial ISO timestamp)Event.cursorafter each pollingsinceparameter in nextgetEventsSincecallGraphQL Operations
Added new operations to
gql-operations.js:RECORD_EVENTS: Mutation for recording events (polling)GET_EVENTS_SINCE: Query for retrieving events (polling)Testing
Unit Tests
New test file:
test/unit/mesh_service_v2_polling.jspollEventsfetches and handles events correctlyfireEventsBatchusesRECORD_EVENTSwhenuseWebSocketis falselastFetchTimeis updated with cursor valueTest Coverage
Configuration
Default Values
pollingIntervalSeconds)Cost Optimization
Breaking Changes
None. This is a backward-compatible addition.
Related
🤖 Generated with Claude Code