Member Junction
    Preparing search index...

    Class RealtimeReconnectController

    Single I/O-free reconnect orchestrator shared by BaseRealtimeSession and BaseRealtimeClient.

    Unifies:

    1. Provider resumption handle tracking (RecordHandle, InvalidateHandle) with post-turn handle awareness,
    2. Proactive connection duration timers (soft turn-boundary window + hard buffer deadline, which an answer in progress may extend to just before the provider limit),
    3. Independent credential/relay refresh timer (ScheduleCredentialRefresh),
    4. Provider ConnectionEnding(timeLeftMs) notice (goAway / session.going_away) with scaled 1/3 margin,
    5. Reactive TriggerReconnect('connection-lost') trigger,
    6. Retry loop bounded by a recovery window (a planned move's window starts when its old connection ends) and MAX_REALTIME_RESUMPTION_ATTEMPTS, with capped backoff, an early retry on NotifyNetworkOnline, per-attempt timeout, Abandoned + AbortSignal cancellation, and Attempt-2 automatic fallback from native handle to RealtimeConversationMemory seed,
    7. Rapid-reconnect sliding-window circuit breaker (reconnect-loop-breaker).
    Index

    Constructors

    Accessors

    • get IsNativeLineageBroken(): boolean

      True once a session that previously held a native resumption handle (or non-empty history) fell back to text seeding on a reconnect, latching subsequent reconnects in this call to seed mode so pre-fallback history is never lost.

      Returns boolean

    • get IsReconnectCycleActive(): boolean

      True from the start of a reconnect cycle until it succeeds or fails, including while a planned move waits between attempts with the call live again on its old connection (when IsReconnecting reads false). A driver checks it to hand a loss of that old connection to the running cycle instead of treating it as the end of the call.

      Returns boolean

    Methods

    • Arms (or re-arms) the proactive soft and hard duration timers for the active connection. Re-arming mid-connection (for example when a dynamic video cap engages or clears) measures remaining time against when the current connection opened and preserves any active ConnectionEnding (goAway) deadline.

      Parameters

      • connectionLimitSeconds: number
      • bufferSeconds: number
      • softLeadCapSeconds: number = DEFAULT_REALTIME_SOFT_RECONNECT_WINDOW_SECONDS
      • OptionalconnectionDeadlineAtMs: number

        When the provider ends this connection regardless of its duration limit (epoch ms), such as the expiry of the credential a Gemini connection opened on. The earlier of the two is the limit the soft window, the hard point and the hard move's last call measure from.

      Returns void

    • Handles a provider connection-ending notice (goAway / session.going_away). Reconnects immediately if idle and ready; otherwise waits for the turn/handle boundary up to timeLeftMs - margin (where margin = clamp(round(timeLeftMs / 3), 1500, 10000)).

      Parameters

      • OptionaltimeLeftMs: number

      Returns void

    • The host reports the network is back (a browser online event): a reconnect waiting out a retry delay starts its next attempt now instead of at the end of the delay. Does nothing when no retry is waiting.

      Returns void

    • Records a provider resumption handle and whether the provider marked this point resumable.

      Parameters

      • handle: string
      • resumable: boolean = true

      Returns void

    • Schedules a proactive credential or relay-session refresh before expiresAtIso (or fallbackLifetimeSeconds), independent of connection reconnects.

      Parameters

      • expiresAtIso: string
      • onRefreshDue: () => void
      • leadTimeMs: number = DEFAULT_CREDENTIAL_REFRESH_LEAD_MS
      • OptionalfallbackLifetimeSeconds: number

      Returns void

    • Records that a tool result was sent on the active connection. When expectsReply is true (non-silent tool result), a soft-window or ConnectionEnding move waits for the model's post-tool turn (or a fresh trusted native handle that captures the tool output) rather than reconnecting in the gap between SendToolResult and the first model output frame.

      Parameters

      • expectsReply: boolean = true

      Returns void

    • Marks a turn as ended and triggers any queued soft-window or ConnectionEnding move when ready.

      Parameters

      • keepPostToolTurnWait: boolean = false

      Returns void

    • Marks a turn as open so soft-window and ConnectionEnding moves wait for the turn boundary, and a hard-point move waits for it until shortly before the provider limit.

      Returns void