Skip to contentSkip to navigationSkip to topbar
On this page

Voice JavaScript SDK: Twilio in the browser


(information)

Info

You're viewing the documentation for the 2.X version of the Voice JavaScript SDK.


Overview

overview page anchor

The Twilio Voice JavaScript SDK allows you to make and receive voice calls with a web browser. This means that you can open inbound and outbound audio connections to Twilio for building softphones, walkie-talkies, conference calls, click-to-talk systems, and more, all from the web.


Follow these steps to install the Voice JavaScript SDK:

  1. Install the SDK using npm:
    npm install @twilio/voice-sdk
  2. Import the SDK to your JavaScript or TypeScript file:
    import { Device } from '@twilio/voice-sdk';

After you configure a device, the SDK establishes a connection to Twilio. Your microphone sends audio to Twilio, and Twilio returns audio that plays through your speakers. In the SDK, Twilio.Device represents the virtual device that manages these connections.

Diagram showing a browser connecting to Twilio, Twilio sending a webhook to a service, and the service returning TwiML.

When you initiate a call using Twilio.Device, you don't dial another phone directly. Instead, you connect to Twilio and instruct Twilio to fetch TwiML from your server to handle the call. Twilio processes the resulting TwiML in the same way that it processes voice traffic from a physical phone.

TwiML app

twiml-app page anchor

Twilio relies on a TwiML app(link takes you to an external page) in your account to determine how to interact with your server. When your application uses Twilio.Device to begin a call, Twilio sends an HTTP request to the application's VoiceUrl. You identify the application through the Access Token that you pass to the client. Twilio then executes the TwiML returned by the VoiceUrl to control the call.


The Voice JavaScript SDK supports the following browsers. Twilio tests the current (N) and the two previous (N-2) major versions.

ChromeFirefoxSafariEdge
Android
iOS
Linux
macOS
Windows
ChromeOS
(information)

Info

Mobile browsers lack the ability to receive or maintain call connectivity whilst in the background and they do not allow GSM call interruption handling. These lead to poor user experience. To create the best user experience, Twilio recommends understanding these limitations when creating mobile Voice Applications. Twilio also recommends evaluating the iOS and Android SDKs for creating mobile Voice Applications.

The Voice JavaScript SDK is compatible with the latest release of Electron(link takes you to an external page).


See the following table to learn more about the encryption protocols used by the Voice JavaScript SDK.

ChannelType
SignalingTLS (Secure WebSocket)
MediaDTLS-SRTP (AES_CM_128_HMAC_SHA1_80)

If you install version 2.1 or later of the Voice JavaScript SDK then you can implement Twilio Regions. Learn more by reading the guide to using the Voice JavaScript SDK with a non-US Twilio Region.


The Voice JavaScript SDK follows semantic versioning(link takes you to an external page).