Skip to main content

Class: Voice

The Voice Class allows you to create WebRTC Voice Experiences from websites and applications using Twilio Voice WebRTC

Throughout this page, you will see voiceClient with a lowercase "v" and Voice with an uppercase "V".

Voice refers to the Voice object provided by the SDK.

voiceClient represents an instance of a Voice, created with the new keyword:

Instantiate a Voice Client

A new instance of Voice should be constructed by using the new keyword and passing the Config payload as the first argument.

No signaling channel will be opened when instantiating a new Voice Client. The signaling WebSocket will be opened when voiceClient.connect() is called.

The maximum number of characters for the identity provided in the Access Token is 121. The identity may only contain alpha-numeric and underscore characters. Other characters, including spaces, or exceeding the maximum number of characters, will result in not being able to place or receive calls.

Initiate a Basic Voice Client

const voiceClient = new Voice({
accountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
identity: "FIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
voiceAppSid: "APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
});

To see all of the possible properties, see the Config interface section.

Hierarchy

  • EventEmitter

    Voice

Accessors

call

get call(): undefined | Call

Returns the underlaying Twilio SDK Call for advanced configuration and usage

Returns undefined if there is no current call

    console.info(voiceClient.call?.codec)

Returns

undefined | Call


client

get client(): Device

Returns the underlaying Twilio SDK Device for advanced configuration and usage

    voiceClient.client.updateOptions({
edge: "ashburn"
})

Returns

Device


isSupported

get isSupported(): boolean

Returns if Voice Calling is Supported in the current Browser / Context

    console.info(voiceClient.isSupported)

Returns

boolean


ready

get ready(): boolean

Is the voiceClient ready?

    voiceClient.ready ? console.info("Ready") ? console.info("Not Ready")

Returns

boolean


status

get status(): undefined | State

Returns the underlaying Twilio SDK Device status (if any)

    console.info(voiceClient.status);

Returns

undefined | State

Methods

connect

connect(Payload): Promise<Call>

Make WebRTC Call to Twilio Application

  voiceClient.connect({ to: "+4477XXXX" });

Parameters

NameType
PayloadCallPayload

Returns

Promise<Call>

Promise containing the underlaying Twilio SDK Call Object


disconnect

disconnect(): Promise<void>

Disconnect Voice Call

  voiceClient.disconnect();

Returns

Promise<void>


init

init(): Promise<void>

Init the Voice Client

Should only be used if the Device is destroyed and a "re-init" is required for some bizare reason

    await voiceClient.init();

Returns

Promise<void>


updateToken

updateToken(newToken): void

Manually update Race Authentication Token

    voiceClient.on("voice#tokenAboutToExpire", () => {
// Get New Token
voiceClient.updateToken(newToken);
});

Parameters

NameType
newTokenstring

Returns

void


getDeviceInfo

Static getDeviceInfo(): Promise<DeviceInfo>

Get Available Input and Output Devices

    const devices = await Voice.getDeviceInfo();

Returns

Promise<DeviceInfo>

Device Info for Available Devices