You're viewing the 1.X version of the Voice JavaScript SDK (formerly called Twilio Client). Click here for information on how to migrate to the 2.X version.
The Voice JavaScript SDK allows you to make voice calls to and from a web browser via a TwiML Voice application.
This means you can open inbound and outbound audio connections to Twilio for building soft phones, walkie-talkies, conference calls, click-to-talk systems, and more, all from the browser.
Want to get started right away? Jump straight in with our Twilio Voice JavaScript Quickstart.
When you include the Voice JavaScript SDK in a web application you get access to these objects:
Twilio.Device
: This object is your main entry point for creating outbound connections, accepting incoming connections, and setting up your connection event handlers.
Twilio.Connection
: This object lets you interact with the call as it is happening. You can do things like mute/unmute, disconnect the call, or send DTMF tones using the connection.
We recommend using the twilio-client NPM module to include the JavaScript SDK as a dependency into your application:
> npm install twilio-client --save
For React or other modern frameworks, twilio-client
can be used directly in your application code:
> const { Device } = require('twilio-client');
For more static or traditional web applications, the SDK can be deployed alongside your app and included in your HTML. For example, in express:
1app.use('/js/twilio.min.js', (req, res) => {2res.sendFile('./node_modules/twilio-client/dist/twilio.min.js');3});
Which you might include in your HTML's <head>
section:
<script type="text/javascript" src="/js/twilio.min.js"></script>
You can link directly to the Voice JavaScript SDK library by including it in the <head>
of your HTML:
<script type="text/javascript" src="https://sdk.twilio.com/js/client/v1.13/twilio.min.js"></script>
This approach is provided to make getting started easier. However, it is not recommended in production. By linking directly to our CDN in production, any patch-level (non-breaking) changes made to the SDK will automatically be applied. In the case of any unintentional negative side-effects introduced by the update, your users may notice the issue before you do.
For production, we recommend pulling twilio-client
from NPM, where your application's tests can be run using any new versions of the SDK before getting pushed to production.
You should use HTTPS to serve your page. In order to use this method, your page must be served over HTTPS.
You can also build twilio.js
(the JavaScript SDK) from the source code.