Voice JavaScript SDK: Reference Components
Info
You're viewing the documentation for the 2.X version of the Voice JavaScript SDK. View the Migration Guide to learn how to migrate from 1.X to 2.X or view the 1.x-specific documentation.
While the quickstarts enable you to quickly set up a functional application for making and receiving phone calls via a web browser in just a few minutes, the reference components offer flexible building blocks for your Twilio Voice applications. Designed around common Twilio Voice use cases, these components leverage Web Components to showcase integrated backend and frontend implementations. You can easily incorporate these components into your application or use them as a foundation for your development needs.
Before proceeding, take a moment to explore how the JavaScript SDK works and review the getting started page to familiarize yourself with key concepts.
The reference components demonstrate several common Twilio Voice use cases. For detailed implementation guidance, visit the Twilio Voice JavaScript Reference Components repository. These use cases include:
- Dialer Component
- Make outgoing calls
- Receive incoming calls
- Basic Call Control Component (leveraging Conference)
- Perform cold and warm transfers
- Add or remove participants from a call
- Hold and Resume a call
- Mute and Unmute a call
- Monitoring calls (leveraging Conference)
- Callee call progress
- Conference call status
- Quality metrics
- Warnings
- Errors
- Clone the Twilio Voice JavaScript Reference Components GitHub repository.
git clone https://github.com/twilio/twilio-voice-js-reference-components.git
- Create a
.env
file and initialize the following environment variables under thetwilio-voice-js-reference-components
folder. Go through the quickstarts for more information about these variables.
1# Port number to run the server on2PORT=303034# Twilio account sid5ACCOUNT_SID=ACxxxxxxxxxxxxxx67# Twilio API key8API_KEY_SID=SKxxxxxxxxxxxxxx910# Twilio API secret11API_KEY_SECRET=xxxxxxxxxxxxxx1213# Twilio TwiML App sid where the Voice Request URL is set to14# https://yourdomain/twilio-voice-dialer/twiml15APP_SID=APxxxxxxxxxxxxxx1617# Twilio auth token18AUTH_TOKEN=xxxxxxxxxxxxxx1920# Caller ID21CALLER_ID=+112345678902223# Callback base URL24CALLBACK_BASE_URL=https://foo.ngrok.dev2526# Default identity to use27DEFAULT_IDENTITY=alice
- Install the dependencies.
npm install
- Start the local server under the
twilio-voice-js-reference-components
folder.
npm start
- Access the following components under the following urls.
- Dialer related components, access http://localhost:3030/twilio-voice-dialer?identity=bob.
- Call control related components, access http://localhost:3030/twilio-voice-basic-call-control?identity=bob.
- Monitoring related components, access http://localhost:3030/twilio-voice-monitoring?identity=bob.