DefaultJoinerReconnectController

class DefaultJoinerReconnectController(roomId: RoomId, reconnectWindowMs: Long = DEFAULT_RECONNECT_WINDOW_MS, clock: () -> Long, scope: CoroutineScope) : JoinerReconnectController

Default implementation of JoinerReconnectController.

Each disconnected peer gets an independent coroutine timer. The timer uses delay so kotlinx.coroutines.test.runTest's virtual time governs expiry — no wall-clock dependency.

Per-peer windows are independent: one peer's window expiring does not affect another peer's window.

Calls are ordered by the instant they carry, not by when they arrive (#3673). A peer has one window here, and a room makes these calls outside its lock, so a call about a membership that has since ended can arrive after the newer membership's window opened.

  • An onPeerUnresponsive whose at is no later than the held window's detectedAt is ignored while that window is live: armed, and neither resumed, expired nor disarmed.

  • Once the held window has finished, an older or equal at opens a window as usual. It is what a clock that stepped back, or one too coarse to tell two drops apart, reports for the next drop. Refused, that drop would have no window, so nothing would expire its seat and no other member would be told. The cost is that the same episode reported again after a resume would re-open its spent window; a room reports each episode once.

  • An onPeerRecovered disarms the held window only when its at is strictly later than the window's detectedAt. A detector reports a recovery at least one poll after the drop it recovers from, so a recovery at the same instant is about the episode before.

Parameters

roomId

The Room this controller guards. A ProvenResume for a different Room holds no window here, so it is answered ResumeResult.WindowClosed; a room never builds one.

reconnectWindowMs

Duration of the reconnect window in millis. Defaults to DEFAULT_RECONNECT_WINDOW_MS (60 s).

clock

Injected clock returning epoch-millis. Must never be wired to System.currentTimeMillis() from commonMain production code; the JVM wiring layer (your dependency injection container) passes { System.currentTimeMillis() }. Tests pass a fixed or advancing value so no wall-clock coupling escapes. The ordering above assumes the instants handed to this controller do not run backwards. A wall clock can step back, and then a recovery reported after the step, at an instant before the held window opened, leaves that window armed: its expiry is refused by a room that holds the member connected, but it is not disarmed. A step back inside one episode can still leave a drop with no window: a window opens at t1, a recovery at r < t1 is ignored, the next drop at t2 <= t1 is ignored because the t1 window is still live, and the room refuses the t1 window's expiry as a stale episode, so no other member is told the seat is gone. Closing that needs an episode identity from the room, not an instant.

scope

Coroutine scope that owns per-peer timer jobs. Must outlive this controller; typically the Room's scope.

Constructors

Link copied to clipboard
constructor(roomId: RoomId, reconnectWindowMs: Long = DEFAULT_RECONNECT_WINDOW_MS, clock: () -> Long, scope: CoroutineScope)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun expire(peerId: PeerId, at: Long)

Force-expires the reconnect window for peerId before the timer fires.

Link copied to clipboard
open override fun onPeerRecovered(peerId: PeerId, at: Long)

peerId became responsive again without resuming — close its reconnect window, and close it without expiring it.

Link copied to clipboard
open override fun onPeerUnresponsive(peerId: PeerId, at: Long)

Opens (or refreshes) the reconnect window for peerId.

Link copied to clipboard
open suspend override fun tryResume(resume: ProvenResume, at: Long): ResumeResult.HostVerdict

Attempts to restore the held seat resume names.