run

View as MarkdownOpen in Claude

Async entry point that connects to RELAY and runs the event loop until interrupted. This is the recommended way to start a RelayClient for long-running services. It calls connect() internally and automatically reconnects with exponential backoff (1 second initial delay, up to 30 seconds maximum) if the connection is lost.

The method awaits until shutdown is requested. Press Ctrl+C to trigger a clean shutdown — the client handles SIGINT and SIGTERM gracefully.

For async contexts where you need manual control over the connection lifecycle, use connect() and disconnect() directly.

Parameters

None.

Returns

Promise<void> — resolves when the client is stopped via Ctrl+C or a programmatic shutdown.

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 const action = await call.play([{ type: 'tts', text: 'Welcome! Goodbye.' }]);
12 await action.wait();
13 await call.hangup();
14});
15
16// Awaits forever, reconnects on connection loss
17await client.run();