feat(sdk): implement subscribeToContract with WebSocket reconnect#35
Open
Depo-dev wants to merge 1 commit into
Open
feat(sdk): implement subscribeToContract with WebSocket reconnect#35Depo-dev wants to merge 1 commit into
Depo-dev wants to merge 1 commit into
Conversation
Adds src/subscription.ts: createSubscription() opens a native WebSocket
to {wsUrl}, calls onEvent for each valid inbound message (validated
against WsEventSchema and transformed to SorobanEvent), calls onError on
parse failures and connection errors, and reconnects with exponential
backoff (500ms initial, 30s max) on unexpected close. unsubscribe() closes
the socket and cancels any pending reconnect timer.
TridentClient.subscribeToContract() replaces http(s) with ws(s) in
apiUrl, appends contractId and optional topic0 to the query string, and
delegates to createSubscription.
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
TridentClient.subscribeToContract()with automatic reconnect.New file:
src/subscription.tscreateSubscription(wsUrl, params)function:WebSocketto{wsUrl}(derived by replacinghttp(s)://withws(s)://+/ws?contractId=...)WsEventSchema(snake_case, matches Go hub'sWriteJSON)SorobanEvent, callsonEventonErrorand logs; socket stays openonerror→ callsonError!wasClean) → schedules reconnect with exponential backoff (500ms → 30s)unsubscribe()→ setscancelled = true, clears reconnect timer, closes socketUpdated:
src/index.tssubscribeToContractreplaceshttps://→wss:///http://→ws://, appends params, callscreateSubscriptionqueryEvents+getEventByIdimplementation from feat(sdk): implement queryEvents and getEventById HTTP methods #18Verification
npm run lintpasses (zero TypeScript errors)Closes #19