# RoomClient: reconnecting event

> The reconnecting event of the RoomClient interface fires when the connection drops and the client starts reconnecting.

The **`reconnecting`** event of the [`RoomClient`](/docs/client/room-client) interface fires when the connection drops and the client starts reconnecting by itself.

## Syntax

```ts
addEventListener("reconnecting", (event) => {})
```

## Event type

A [`RoomCloseEvent`](/docs/client/room-close-event). It extends `Event` and adds these properties:

[`code`](/docs/client/room-close-event/code) Read only
: The close code the connection dropped with.

[`reason`](/docs/client/room-close-event/reason) Read only
: The close reason it dropped with.

[`wasClean`](/docs/client/room-close-event/wasclean) Read only
: Always `false` on `reconnecting`.

[`error`](/docs/client/room-close-event/error) Read only
: Always `undefined` on `reconnecting`.

## Description

The client reconnects after a drop with a close code it retries; [Errors and close codes](/docs/client/errors#close-codes) lists which. After 4008, when the room moved or restarted, its first attempt is at once; otherwise it tries again after a backoff of 250 ms doubling up to 10 s, with jitter. `reconnecting` fires once per drop, not once per attempt. A drop with a code the client doesn't retry fires a [`close` event](/docs/client/room-client/close-event) instead.

When it fires, [`readyState`](/docs/client/room-client/readystate) is `"reconnecting"`, or `"connecting"` if the client hadn't been ready yet. Calls in flight have rejected with an [`IrtError`](/docs/client/irt-error) named `NetworkError`, and messages sent until the client is back are dropped. [`asleep`](/docs/client/room-client/asleep) is `false` again.

The client is back when an [`open` event](/docs/client/room-client/open-event) fires with `reconnected` true.

## Examples

### Pausing input while reconnecting

A racing game stops sending steering while the client reconnects, and logs the code for the player's bug report.

```ts
// steering.ts
import { CloseCode, connect } from "@irtio/client";

const room = await connect("https://rooms.irt.io/my-game/track-3");
let steering = true;

room.addEventListener("reconnecting", (event) => {
  steering = false;
  const why = event.code === CloseCode.RoomMoved ? "the room moved" : event.reason;
  console.warn(`connection dropped with ${event.code} (${why}), reconnecting`);
});
room.addEventListener("open", () => {
  steering = true;
});

document.addEventListener("keydown", (key) => {
  if (steering) room.send({ type: "steer", key: key.code });
});
```

## See also

- [`RoomCloseEvent`](/docs/client/room-close-event)
- [`open` event](/docs/client/room-client/open-event)
- [`close` event](/docs/client/room-client/close-event)
- [Errors and close codes](/docs/client/errors#close-codes), for each code and whether the client reconnects
