connect

View as MarkdownOpen in Claude

Establish a WebSocket connection to SignalWire RELAY and authenticate. This method connects to wss://<host>, sends a signalwire.connect authentication request, subscribes to the configured contexts, and starts the internal ping loop.

For most use cases, prefer run() which calls connect() internally and adds automatic reconnection. Use connect() directly only when you need manual control over the connection lifecycle.

Parameters

None.

Returns

Promise<void>

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
9await client.connect();
10// Connected and authenticated -- do work here
11const call = await client.dial(
12 [[{ type: 'phone', params: { to_number: '+15559876543', from_number: '+15551234567' } }]],
13);
14await call.hangup();
15await client.disconnect();