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

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_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();