feat(sdk): Add WebSocket subscription support for real-time event streaming - #255
Open
Vincent6581 wants to merge 2 commits into
Open
feat(sdk): Add WebSocket subscription support for real-time event streaming#255Vincent6581 wants to merge 2 commits into
Vincent6581 wants to merge 2 commits into
Conversation
…eaming Adds an EventStream client that multiplexes typed subscriptions over a single WebSocket connection to an event relay. - EventStream.subscribe(eventType, callback, filter?) returning an unsubscribe function - Supported events: Transfer, Trade, DividendClaim, KYCUpdate, CustodyAttestation - Auto-reconnect with exponential backoff + jitter and configurable caps - Per-subscription filtering by token_address / user_address - Heartbeat ping/pong with stale-connection detection and forced reconnect - Injectable WebSocket implementation (browser global or the `ws` package) for testability - Lifecycle listeners: open, close, error, reconnecting, stale Files: - sdk/src/eventStream.ts (new) - sdk/src/types.ts: stream event / config / lifecycle types - sdk/src/index.ts: export EventStream and related types Closes Kevin737866#190
|
@Vincent6581 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Implements a WebSocket-based event subscription client (
EventStream) for real-time updates, per issue #190.The client opens a single WebSocket connection to an event relay and multiplexes any number of typed subscriptions over it, with reconnection, filtering and stale-detection handled transparently.
What's included
EventStreamclass withsubscribe(eventType, callback)subscribe(eventType, callback, filter?)returns an unsubscribe fnSTREAM_EVENT_TYPEStoken_address,user_addressEventFilter(single value or list), applied client-side and sent to the relayDesign notes
config.webSocketImplaccepts any browser-WebSocket-shaped constructor (thewspackage, or a mock WS server in tests). Falls back to the globalWebSocketwhen present.subscribe()call; subscriptions are re-registered automatically on every reconnect.stream.on('open' | 'close' | 'error' | 'reconnecting' | 'stale', listener).Math.random) so reconnection timing is testable.eventMatchesFilter()andcomputeBackoffDelay()are exposed for direct unit testing of the filter and backoff logic.Files changed
sdk/src/eventStream.ts(new) —EventStreamimplementationsdk/src/types.ts—StreamEvent,EventFilter,EventStreamConfig, lifecycle + WebSocket structural typessdk/src/index.ts— exportEventStreamand related typesUsage
Closes #190