@rabby-wallet/hyperliquid-sdk 1.1.0-beta.2 → 1.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -102,4 +102,10 @@ export declare class WebSocketClient {
102
102
  * Reset reconnection attempts and enable auto-reconnect
103
103
  */
104
104
  resetReconnectState(): void;
105
+ /**
106
+ * Handle application state change (for React Native)
107
+ * Call this method when the app state changes (e.g., active -> background, background -> active)
108
+ * @param state 'active' | 'background' | 'inactive'
109
+ */
110
+ handleAppStateChange(state: string): void;
105
111
  }
@@ -385,5 +385,32 @@ class WebSocketClient {
385
385
  this.reconnectAttempts = 0;
386
386
  this.isManualDisconnect = false;
387
387
  }
388
+ /**
389
+ * Handle application state change (for React Native)
390
+ * Call this method when the app state changes (e.g., active -> background, background -> active)
391
+ * @param state 'active' | 'background' | 'inactive'
392
+ */
393
+ handleAppStateChange(state) {
394
+ if (state === 'active') {
395
+ // App returned to foreground
396
+ if (!this.isConnected && !this.isManualDisconnect && this.config.autoReconnect) {
397
+ console.log('App returned to foreground, reconnecting WebSocket...');
398
+ this.reconnectAttempts = 0;
399
+ this.connect().catch(console.error);
400
+ }
401
+ }
402
+ else if (state === 'background') {
403
+ // App went to background
404
+ // Stop heartbeat and close connection to save resources
405
+ this.stopHeartbeat();
406
+ if (this.ws) {
407
+ // We don't set isManualDisconnect to true here because we want auto-reconnect
408
+ // to kick in when we come back to 'active' state
409
+ this.ws.close();
410
+ this.ws = null;
411
+ console.log('App backgrounded: WebSocket disconnected to save resources');
412
+ }
413
+ }
414
+ }
388
415
  }
389
416
  exports.WebSocketClient = WebSocketClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/hyperliquid-sdk",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.3",
4
4
  "description": "Simplified Hyperliquid Perpetuals Trading SDK for Frontend Applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",