waitForEnding

View as MarkdownOpen in Claude

Wait for the call to reach the ending state. Returns immediately if the call is already ending or past that state. A typed wait over waitFor().

Parameters

timeout
number | undefined

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

Returns

Promise<RelayEvent> — The state-change event.

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();
await call.hangup();
await call.waitForEnding();
console.log(call.state);
});
await client.run();