TelnyxRTC client connects your application to the Telnyx backend,
enabling you to make outgoing calls and handle incoming calls.
Examples
Hierarchy
-
default↳TelnyxRTC
Table of contents
Constructors
Accessors
Methods
- checkPermissions
- connect
- disableMicrophone
- disableWebcam
- disconnect
- enableMicrophone
- enableWebcam
- getAudioInDevices
- getAudioOutDevices
- getDeviceResolutions
- getDevices
- getVideoDevices
- logout
- newCall
- off
- on
- setAudioSettings
- setVideoSettings
- webRTCInfo
- webRTCSupportedBrowserList
Constructors
constructor
• new TelnyxRTC(options)
Creates a new TelnyxRTC instance with the provided options.
Parameters
| Name | Type | Description |
|---|---|---|
options | IClientOptions | Options for initializing a client |
Examples
Authenticating with a JSON Web Token:
Custom ringtone and ringback
Custom ringback and ringtone files can be a wav/mp3 in your local public folder or a file hosted on a CDN, ex: https://cdn.company.com/sounds/call.mp3. To use theringbackFile, make sure the “Generate Ringback Tone” option is disabled
in your Telnyx Portal connection
configuration (Inbound tab.)
To hear/view calls in the browser, you’ll need to specify an HTML media element:
Overrides
TelnyxRTCClient.constructorAccessors
connected
•get connected(): boolean
true if the client is connected to the Telnyx RTC server
Returns
boolean
Example
Inherited from
TelnyxRTCClient.connectedlocalElement
•get localElement(): string | Function | HTMLMediaElement
Gets the local html element.
Returns
string | Function | HTMLMediaElement
Example
Inherited from
TelnyxRTCClient.localElement •set localElement(tag): void
Sets the local html element that will receive the local stream.
Parameters
| Name | Type |
|---|---|
tag | string | Function | HTMLMediaElement |
Returns
void
Example
Inherited from
TelnyxRTCClient.localElementmediaConstraints
•get mediaConstraints(): Object
Audio and video constraints currently used by the client.
Returns
Object
| Name | Type |
|---|---|
audio | boolean | MediaTrackConstraints |
video | boolean | MediaTrackConstraints |
Examples
Inherited from
TelnyxRTCClient.mediaConstraintsremoteElement
•get remoteElement(): string | Function | HTMLMediaElement
Gets the remote html element.
Returns
string | Function | HTMLMediaElement
Example
Inherited from
TelnyxRTCClient.remoteElement •set remoteElement(tag): void
Sets the remote html element that will receive the remote stream.
Parameters
| Name | Type |
|---|---|
tag | string | Function | HTMLMediaElement |
Returns
void
Example
Inherited from
TelnyxRTCClient.remoteElementspeaker
•get speaker(): string
Default audio output device, if set by client.
Returns
string
Example
Inherited from
TelnyxRTCClient.speaker •set speaker(deviceId): void
Sets the default audio output device for subsequent calls.
Parameters
| Name | Type |
|---|---|
deviceId | string |
Returns
void
Example
Inherited from
TelnyxRTCClient.speakerMethods
checkPermissions
▸ checkPermissions(audio?, video?): Promise<boolean>
Checks if the browser has the permission to access mic and/or webcam
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
audio | boolean | true | Whether to check for microphone permissions. |
video | boolean | true | Whether to check for webcam permissions. |
Returns
Promise<boolean>
Examples
Checking for audio and video permissions:
Inherited from
TelnyxRTCClient.checkPermissionsconnect
▸ connect():Promise<void>
Creates a new connection for exchanging data with the WebRTC server
Returns
Promise<void>
Examples
Inherited from
TelnyxRTCClient.connectdisableMicrophone
▸ disableMicrophone():void
Disables use of the microphone in subsequent calls.
Note: This setting will be ignored if audio: true is
specified when creating a new call.
Returns
void
Examples
video: true is
specified before disabling the microphone.
Inherited from
TelnyxRTCClient.disableMicrophonedisableWebcam
▸ disableWebcam():void
Disables use of the webcam in subsequent calls.
Note: This method will disable the video even if video: true is specified.
Returns
void
Examples
Deprecated
Inherited from
TelnyxRTCClient.disableWebcamdisconnect
▸ disconnect():Promise<void>
Disconnect all active calls
Returns
Promise<void>
Examples
Inherited from
TelnyxRTCClient.disconnectenableMicrophone
▸ enableMicrophone():void
Enables use of the microphone in subsequent calls.
Note: This setting will be ignored if audio: false is
specified when creating a new call.
Returns
void
Examples
Inherited from
TelnyxRTCClient.enableMicrophoneenableWebcam
▸ enableWebcam():void
Enables use of the webcam in subsequent calls.
Note: This setting will be ignored if video: false is
specified when creating a new call.
Returns
void
Examples
Deprecated
Inherited from
TelnyxRTCClient.enableWebcamgetAudioInDevices
▸ getAudioInDevices():Promise<MediaDeviceInfo[]>
Returns the audio input devices supported by the browser.
Returns
Promise<MediaDeviceInfo[]>
Promise with an array of MediaDeviceInfo
Examples
Using async/await:
Promises:
Inherited from
TelnyxRTCClient.getAudioInDevicesgetAudioOutDevices
▸ getAudioOutDevices():Promise<MediaDeviceInfo[]>
Returns the audio output devices supported by the browser.
Browser Compatibility Note: Firefox has yet to fully implement
audio output devices. As of v63, this feature is behind the
user preference media.setsinkid.enabled.
See: https://bugzilla.mozilla.org/show_bug.cgi?id=1152401#c98
Returns
Promise<MediaDeviceInfo[]>
Promise with an array of MediaDeviceInfo
Examples
Using async/await:
Promises:
Inherited from
TelnyxRTCClient.getAudioOutDevicesgetDeviceResolutions
▸ getDeviceResolutions(deviceId): Promise<any[]>
Returns supported resolution for the given webcam.
Parameters
| Name | Type | Description |
|---|---|---|
deviceId | string | the deviceId from your webcam. |
Returns
Promise<any[]>
Examples
If deviceId is null
-
if
deviceIdisnulland you don’t have a webcam connected to your computer, it will throw an error with the message"Requested device not found". -
if
deviceIdisnulland you have one or more webcam connected to your computer, it will return a list of resolutions from the default device set up in your operating system.
Promises:
deviceId is not null
it will return a list of resolutions from the deviceId sent.
Using async/await:
Promises:
Deprecated
Inherited from
TelnyxRTCClient.getDeviceResolutionsgetDevices
▸ getDevices():Promise<MediaDeviceInfo[]>
Returns a list of devices supported by the browser
Returns
Promise<MediaDeviceInfo[]>
Examples
Using async/await:
Promises:
Inherited from
TelnyxRTCClient.getDevicesgetVideoDevices
▸ getVideoDevices():Promise<MediaDeviceInfo[]>
Returns a list of video devices supported by the browser (i.e. webcam).
Returns
Promise<MediaDeviceInfo[]>
Promise with an array of MediaDeviceInfo
Examples
Using async/await:
Promises:
Deprecated
Inherited from
TelnyxRTCClient.getVideoDeviceslogout
▸ logout():void
Alias for .disconnect()
Returns
void
Deprecated
Inherited from
TelnyxRTCClient.logoutnewCall
▸ newCall(options): Call
Makes a new outbound call.
Parameters
| Name | Type | Description |
|---|---|---|
options | ICallOptions | Options object for a new call. |
Returns
Call
The new outbound Call object.
Examples
Making an outbound call to +1 856-444-0362 using default values from the client:
callerNumber when dialing a SIP address:
Error handling
An error will be thrown ifdestinationNumber is not specified.
Setting Custom Headers
Setting Preferred Codec
You can passpreferred_codecs to the newCall method to set codec preference during the call.
preferred_codecs is a sub-array of the codecs returned by RTCRtpReceiver.getCapabilities(‘audio’)
ICE Candidate Prefetching
ICE candidate prefetching can be enabled by passingprefetchIceCandidates to the newCall method.
example:
Overrides
TelnyxRTCClient.newCalloff
▸ off(eventName, callback?): TelnyxRTC
Removes an event handler that were attached with .on().
If no handler parameter is passed, all listeners for that event will be removed.
Parameters
| Name | Type | Description |
|---|---|---|
eventName | string | Event name. |
callback? | Function | Function handler to be removed. |
Returns
TelnyxRTC
The client object itself.
Note: a handler will be removed from the stack by reference
so make sure to use the same reference in both .on() and .off() methods.
Examples
Subscribe to the telnyx.error and then, remove the event handler.
Inherited from
TelnyxRTCClient.offon
▸ on(eventName, callback): TelnyxRTC
Attaches an event handler for a specific type of event.
Events
telnyx.ready | The client is authenticated and available to use |
telnyx.error | An error occurred at the session level |
telnyx.notification | An update to the call or session |
telnyx.socket.open | The WebSocket connection has been made |
telnyx.socket.close | The WebSocket connection is set to close |
telnyx.socket.error | An error occurred at the WebSocket level |
telnyx.socket.message | The client has received a message through WebSockets |
Parameters
| Name | Type | Description |
|---|---|---|
eventName | string | Event name. |
callback | Function | Function to call when the event comes. |
Returns
TelnyxRTC
The client object itself.
Examples
Subscribe to the telnyx.ready and telnyx.error events.
Inherited from
TelnyxRTCClient.onsetAudioSettings
▸ setAudioSettings(settings): Promise<MediaTrackConstraints>
Sets the default audio constraints for your client. See here for further details.
Note: It’s a common behaviour, in WebRTC applications,
to persist devices user’s selection to then reuse them across visits.
Due to a Webkit’s security protocols, Safari generates random deviceId on each page load.
To avoid this issue you can specify two additional properties
micId and micLabel in the constraints input parameter.
The client will use these values to assure the microphone you want to use is available
by matching both id and label with the device list retrieved from the browser.
Parameters
| Name | Type | Description |
|---|---|---|
settings | IAudioSettings | MediaTrackConstraints object with the addition of micId and micLabel. |
Returns
Promise<MediaTrackConstraints>
Promise<MediaTrackConstraints> Audio constraints applied to the client.
Examples
Set microphone by id and label with the echoCancellation flag turned off:
Inherited from
TelnyxRTCClient.setAudioSettingssetVideoSettings
▸ setVideoSettings(settings): Promise<MediaTrackConstraints>
Sets the default video constraints for your client. See here for further details.
Note: It’s a common behaviour, in WebRTC applications,
to persist devices user’s selection to then reuse them across visits.
Due to a Webkit’s security protocols, Safari generates random deviceId on each page load.
To avoid this issue you can specify two additional properties
camId and camLabel in the constraints input parameter.
The client will use these values to assure the webcam you want to use is available
by matching both id and label with the device list retrieved from the browser.
Parameters
| Name | Type | Description |
|---|---|---|
settings | IVideoSettings | MediaTrackConstraints object with the addition of camId and camLabel. |
Returns
Promise<MediaTrackConstraints>
Promise<MediaTrackConstraints> Video constraints applied to the client.
Examples
Set webcam by id and label with 720p resolution.
Deprecated
Inherited from
TelnyxRTCClient.setVideoSettingswebRTCInfo
▸Static webRTCInfo(): string | IWebRTCInfo
Checks if the running browser has support for TelnyRTC
Returns
string | IWebRTCInfo
An object with WebRTC browser support information or a string error message.
Examples
Check if your browser supports TelnyxRTC
Error handling
An error message will be returned if your browser doesn’t support TelnyxRTCwebRTCSupportedBrowserList
▸Static webRTCSupportedBrowserList(): IWebRTCSupportedBrowser[]
Returns the WebRTC supported browser list.
The following table indicates the browsers supported by TelnyxRTC.
We support the most recent (N) versions of these browsers unless otherwise indicated.
| Chrome | Firefox | Safari | Edge | |
|---|---|---|---|---|
| Android | [-] | [-] | [ ] | [ ] |
| iOS | [ ] | [ ] | [x] | [ ] |
| Linux | [x] | [-] | [ ] | [ ] |
| MacOS | [x] | [-] | [x] | [-] |
| Windows | [x] | [-] | [ ] | [-] |
Legend
[x] supports audio and video [-] supports only audio [ ] not supportedReturns
IWebRTCSupportedBrowser[]
An array with supported operational systems and browsers.
Examples