Menu

Expand
Rate this page:

Voice JavaScript SDK: Version 1.x (Deprecated)

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.

Overview

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.

Including the JavaScript SDK in your project

Using NPM (recommended)

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:

app.use('/js/twilio.min.js', (req, res) => {
  res.sendFile('./node_modules/twilio-client/dist/twilio.min.js');
});

Which you might include in your HTML’s <head> section:

<script type="text/javascript" src="/js/twilio.min.js"></script>

Using our CDN (not recommended)

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.

Building from source

You can also build twilio.js (the JavaScript SDK) from the source code.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...
        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        thanks-feedback-gif