# PresenceEvent

> The PresenceEvent interface of the Client API is the event a PresenceList fires as join, change or leave, with the player's presence entry.

The **`PresenceEvent`** interface of the [Client API](/docs/client) is the event a [`PresenceList`](/docs/client/presence-list) fires as its [`join`](/docs/client/presence-list/join-event), [`change`](/docs/client/presence-list/change-event) or [`leave`](/docs/client/presence-list/leave-event) event. It extends `Event`, and carries the player's entry.

## Constructor

```ts
new PresenceEvent(type, entry)
new PresenceEvent(type, entry, changed)
```

`type`
: `"join"`, `"change"` or `"leave"`.

`entry`
: The [`PresenceEntry`](/docs/client/presence-entry) the event is about.

`changed` Optional
: An array of the fields that changed. Defaults to an empty array.

The client creates the events it fires.

## Instance properties

All are read only. It also has `Event`'s properties, such as `type`.

[`PresenceEvent.entry`](#entry)
: The player's [`PresenceEntry`](/docs/client/presence-entry).

[`PresenceEvent.changed`](#changed)
: The fields that changed, on `change`.

## Description

Two properties of `PresenceEvent` have no page of their own.

### `entry`

`entry` is the player's entry as the list holds it. On `leave` it has the values it last had, and the list no longer returns it from [`get()`](/docs/client/presence-list/get).

### `changed`

`changed` is an array of `"name"`, `"status"` and `"connected"`. It lists the fields that changed on `change`, and is empty on `join` and `leave`.

## Examples

### Logging who joined and who left

The client logs each arrival and departure from one listener.

```ts
// door-log.ts
import { connect } from "@irtio/client";

const room = await connect("main");

for (const type of ["join", "leave"] as const) {
  room.presence.addEventListener(type, ({ entry }) => console.log(`${entry.name || entry.player}: ${type}`));
}
```

## See also

- [`PresenceList`](/docs/client/presence-list)
- [`PresenceEntry`](/docs/client/presence-entry)
- [Client API on one page](/docs/client/one-page#presence), the whole of `@irtio/client` on one page
