waitForEnded

View as MarkdownOpen in Claude

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

timeout
number | undefined

Maximum milliseconds to wait. Throws an Error if exceeded. undefined waits indefinitely.

Returns

Promise<RelayEvent> — The state-change event indicating the call has ended.

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 await call.answer();
11
12 const action = await call.play([{ type: 'tts', text: 'Goodbye!' }]);
13 await action.wait();
14 await call.hangup();
15
16 const event = await call.waitForEnded();
17 console.log(`Call ${call.callId} has ended: ${JSON.stringify(event.params)}`);
18});
19
20await client.run();