stream

View as MarkdownOpen in Claude

Start streaming call audio to a WebSocket endpoint. Returns a StreamAction that you can use to stop the stream or wait for it to finish.

This method emits calling.call.stream events. See Call Events for payload details.

Parameters

url
stringRequired

WebSocket URL to stream audio to (e.g., "wss://example.com/stream").

name
string | undefined

A name for this stream, useful for identifying multiple concurrent streams.

codec
string | undefined

Audio codec for the stream.

  • "PCMU" — G.711 mu-law (default for North America)
  • "PCMA" — G.711 A-law (default for international)
  • "OPUS" — Opus codec (higher quality, variable bitrate)
track
string | undefined

Which audio track to stream.

  • "inbound" — audio received from the caller
  • "outbound" — audio sent to the caller
  • "both" — audio in both directions
statusUrl
string | undefined

URL to receive stream status webhooks.

statusUrlMethod
string | undefined

HTTP method for status webhooks.

  • "GET" — send status updates via GET request
  • "POST" — send status updates via POST request
authorizationBearerToken
string | undefined

Bearer token for authenticating with the WebSocket server.

customParameters
Record<string, unknown> | undefined

Custom key-value pairs sent with the stream start message.

controlId
string | undefined

Custom control ID. Auto-generated if not provided.

onCompleted
(event: RelayEvent) => void | Promise<void>

Callback invoked when the stream ends.

Returns

Promise<StreamAction> — An action handle with stop() and wait() methods.

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 // Stream audio to an external service for real-time processing
13 const action = await call.stream(
14 'wss://example.com/audio-stream',
15 { track: 'inbound', codec: 'PCMU', customParameters: { session_id: 'abc123' } }
16 );
17
18 // The stream runs until stopped or the call ends
19 await call.waitForEnded();
20});
21
22await client.run();