OpenClaw SDK
    Preparing search index...

    Function createReconnectManager

    Reconnection Manager - Advanced Stand-alone Reconnection Control

    Use this when you need custom reconnection behavior outside of ConnectionManager's built-in reconnection.

    Use ConnectionManager's built-in reconnection if you need:

    • Simple automatic reconnection on disconnect
    • Configurable max attempts and delay
    • Standard Fibonacci backoff
    • Integration with connection lifecycle

    Use ReconnectManager stand-alone if you need:

    • Custom reconnection logic separate from ConnectionManager
    • Reconnection state tracking for external management
    • Event-driven reconnection workflows
    • Advanced retry strategies beyond standard backoff
    // Stand-alone usage for custom reconnection flow
    const reconnectMgr = createReconnectManager({
    maxAttempts: 10,
    initialDelayMs: 1000,
    maxDelayMs: 30000,
    });

    reconnectMgr.on("stateChange", (state) => {
    if (state.phase === "waiting") {
    console.log(`Reconnecting in ${state.delayMs}ms...`);
    }
    });
    • Create a reconnect manager.

      Parameters

      • Optionalconfig: Partial<ReconnectConfig>

        Optional reconnection configuration

      Returns ReconnectManager

      A new ReconnectManager instance

      import { createReconnectManager } from './managers/reconnect.js';

      const reconnectMgr = createReconnectManager({
      maxAttempts: 10,
      initialDelayMs: 1000,
      maxDelayMs: 30000,
      pauseOnAuthError: true
      });

      // Listen to reconnection events
      reconnectMgr.onEvent((event) => {
      console.log(`Reconnect ${event.state} (attempt ${event.attempt})`);
      });

      // Start reconnection
      await reconnectMgr.reconnect(
      () => client.connect(),
      () => authHandler.refreshToken()
      );