TelnyxRTC
TheTelnyxRTC class is the main entry point for the Telnyx WebRTC JS SDK. It manages the WebSocket connection to Telnyx’s signaling server and provides methods to create calls, handle events, and control the client lifecycle.
Constructor
connect() to establish the WebSocket connection.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options | IClientOptions | Yes | Client configuration |
Methods
connect()
Opens a WebSocket connection to rtc.telnyx.com and authenticates using the configured credentials.
telnyx.ready on success or telnyx.error on failure.
disconnect()
Closes the WebSocket connection and cleans up all active calls.
Always call
disconnect() when the user leaves your app to avoid zombie WebSocket connections. See Best Practices → Connection Lifecycle.newCall(options)
Creates and places a new outbound call.
| Parameter | Type | Required | Description |
|---|---|---|---|
options | ICallOptions | Yes | Call configuration |
off(event, handler)
Removes an event listener.
removeAllListeners()
Removes all event listeners from the client.
Properties
connection
Provides helpers to check the current connection state.
| Property | Type | Description |
|---|---|---|
connecting | boolean | True during WebSocket handshake |
connected | boolean | True when authenticated and ready |
closed | boolean | True when disconnected |
isAlive | boolean | True if connection is active |
calls
An array of all active Call objects.
Events
Register event listeners usingclient.on(eventName, handler):
Connection Events
| Event | Payload | Description |
|---|---|---|
telnyx.ready | — | Client connected and authenticated. Wait for this before making calls. |
telnyx.error | ClientErrorEvent | Connection or authentication error. See Error Handling. |
telnyx.warning | ClientWarningEvent | Non-fatal warning (e.g., token expiring, quality degradation). See Warning Codes. |
telnyx.socket.close | CloseEvent | WebSocket closed. SDK will attempt reconnection automatically. |
telnyx.socket.error | Event | WebSocket error. |
Call Events
| Event | Payload | Description |
|---|---|---|
telnyx.notification | INotification | Call state updates, media events, and SDK notifications. This is the primary event for handling call lifecycle. |
Stats Events
| Event | Payload | Description |
|---|---|---|
telnyx.stats.frame | StatsFrame | Periodic WebRTC stats (RTT, jitter, packet loss). Emitted every callReportInterval ms. |
telnyx.stats.report | StatsReport | End-of-call summary report. Emitted when a call ends. |
Typical Usage
Reconnection
The SDK automatically reconnects when the WebSocket drops. You don’t need to handle this manually in most cases. For advanced reconnection handling, see Reconnection & Recovery. Key configuration:| Option | Default | Description |
|---|---|---|
keepConnectionAliveOnSocketClose | false | Keep PeerConnection alive during reconnect |
mediaPermissionsRecovery | — | Auto-recover media permissions for inbound calls |
See Also
- IClientOptions — Full configuration reference
- Call Class — Call control methods
- Error Handling — Error and warning codes
- Best Practices — Production deployment guide
- Authentication — JWT generation and token refresh