> ## Documentation Index
> Fetch the complete documentation index at: https://docs.evox.wraithesports.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle and events

> Handle plugin session, action binding and device events in a safe order.

After registering its event handlers, the plugin calls `client.start()`. With `host.hello` the host sends the protocol range, the authoritative plugin identity, the granted capabilities and the request limits.

## Plugin events

* `plugin.start`, `plugin.stop`, `plugin.suspend`, `plugin.resume`.
* `device.connected` and `device.disconnected`.

## Action events

* `action.willAppear` and `action.willDisappear`.
* `action.keyDown` and `action.keyUp`.
* `action.dialDown`, `action.dialUp` and `action.dialRotate`.
* `action.settingsChanged`.

Each `bindingInstanceId` is valid only for that context. After `willDisappear`, a display call may be rejected with `CONTEXT_EXPIRED`.

```js theme={}
client.on('action.keyDown', async (event) => {
  if (event.context?.actionId !== 'counter') return;
  await client.setTitle(event.context.bindingInstanceId, '1');
});

client.on('action.willDisappear', (event) => {
  counters.delete(event.context?.bindingInstanceId);
});
```

When the plugin shuts down, run the handler cleanup functions and the `client.dispose()` call.
