Earmuff a call
This code snippet earmuffs and unearmuffs a call. When a call is earmuffed, the user cannot hear other participants, but other participants can hear the user.
Prerequisites
Create an Application
Check out Getting Started with Vonage CLI for more information on how to install and configure the CLI.
Use the following command to create a Vonage application:
Once you have the application, you then need to add the voice capabilities; make sure you replace the webhook URLs with your own:
The application is then created and has the required capabilities. Creating an application and adding application capabilities are covered in detail in the application overview.
Go to the Application's page on the Dashboard, and define a Name for your Application.

Make sure to click on the Generate public and private key button, and keep the file private.key around.
Then, enable the Voice capability. For the moment, leave everything by default.

Finally, click Save at the bottom of the page.
Rent a Number
You can rent a number using the Vonage CLI. The following command searches for an available number in the United States:
Use this command to purchase a number:
Specify an alternative two-character country code to purchase a number in another country.
In the Dashboard, go to the Buy Numbers page. Make sure to tick Voice in the search filter, and select the country you want to buy a number in.

You can then click the Buy button next to the number you want, and validate your purchase.
Congratulations! Your virtual number is now listed in Your Numbers
Link a Number
Now that you have both an application and a number, you need to link them together.
Now that you have both an application and a number, you need to link them together.
Go to the Application page, and click on the application you created earlier.

In the Voice section, click on the Link button next to the number you want to link.
Example
Replace the following variables in the example code:
| Key | Description |
|---|---|
VOICE_CALL_ID | The UUID of the call leg. |
Prerequisites
Execute the following command at your terminal prompt to create the JWT for authentication:
Run your code
Save this file to your machine and run it:
Prerequisites
Create a file named earmuff-a-call.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named EarmuffCall and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing EarmuffCall:
Prerequisites
Add the following to build.gradle:
Create a class named EarmuffCall and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing EarmuffCall:
Prerequisites
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Try it out
When you run the code the call identified by UUID will be earmuffed or unearmuffed.
Further Reading
- Conference Calling - This guide explains the two concepts Vonage associates with a call, a leg and a conversation.