***

title: waitForEnded
slug: /reference/typescript/relay/call/wait-for-ended
description: Wait for a call to reach the ended state.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[relayevent]: /docs/server-sdks/reference/typescript/relay/events

Wait for the call to reach the `ended` state. This is a convenience method
equivalent to waiting for a `calling.call.state` event with `state === "ended"`.

## **Parameters**

<ParamField path="timeout" type="number | undefined" toc={true}>
  Maximum milliseconds to wait. Throws an `Error` if exceeded. `undefined`
  waits indefinitely.
</ParamField>

## **Returns**

`Promise<`[`RelayEvent`][relayevent]`>` -- The state-change event indicating the call has ended.

## **Example**

```typescript {16}
import { RelayClient } from '@signalwire/sdk';

const client = new RelayClient({
  project: process.env.SIGNALWIRE_PROJECT_ID!,
  token: process.env.SIGNALWIRE_TOKEN!,
  contexts: ['default']
});

client.onCall(async (call) => {
  await call.answer();

  const action = await call.play([{ type: 'tts', text: 'Goodbye!' }]);
  await action.wait();
  await call.hangup();

  const event = await call.waitForEnded();
  console.log(`Call ${call.callId} has ended: ${JSON.stringify(event.params)}`);
});

await client.run();
```