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
voiceClientwith a lowercase "v" andVoicewith an uppercase "V".
Voicerefers to theVoiceobject provided by the SDK.
voiceClientrepresents an instance of aVoice, created with thenewkeyword:
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
undefinedif 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
| Name | Type |
|---|---|
Payload | CallPayload |
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
Deviceis 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
| Name | Type |
|---|---|
newToken | string |
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