You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/src/accounts/webSocketAccountSubscriberV2.ts
+86-9Lines changed: 86 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
35
35
isUnsubscribing=false;
36
36
37
37
timeoutId?: ReturnType<typeofsetTimeout>;
38
+
pollingTimeoutId?: ReturnType<typeofsetTimeout>;
38
39
39
40
receivingData: boolean;
40
41
@@ -175,29 +176,102 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
175
176
}
176
177
177
178
if(this.receivingData){
179
+
if(this.resubOpts?.usePollingInsteadOfResub){
180
+
// Use polling instead of resubscribing
181
+
if(this.resubOpts?.logResubMessages){
182
+
console.log(
183
+
`[${this.logAccountName}] No ws data in ${this.resubOpts.resubTimeoutMs}ms, starting polling - listenerId=${this.listenerId}`
184
+
);
185
+
}
186
+
this.startPolling();
187
+
}else{
188
+
// Original resubscribe behavior
189
+
if(this.resubOpts?.logResubMessages){
190
+
console.log(
191
+
`No ws data from ${this.logAccountName} in ${this.resubOpts.resubTimeoutMs}ms, resubscribing - listenerId=${this.listenerId}, isUnsubscribing=${this.isUnsubscribing}`
`No ws data from ${this.logAccountName} in ${this.resubOpts.resubTimeoutMs}ms, resubscribing - listenerId=${this.listenerId}, isUnsubscribing=${this.isUnsubscribing}`
206
+
`[${this.logAccountName}] Timeout fired but receivingData=false, skipping resubscribe`
181
207
);
182
208
}
183
-
awaitthis.unsubscribe(true);
184
-
this.receivingData=false;
185
-
awaitthis.subscribe(this.onChange);
209
+
}
210
+
},
211
+
this.resubOpts?.resubTimeoutMs
212
+
);
213
+
}
214
+
215
+
privatestartPolling(): void{
216
+
constpollingInterval=this.resubOpts?.pollingIntervalMs||30000;// Default to 30s
0 commit comments