Silenciar uma chamada
Este trecho de código ativa e desativa o modo de silêncio em uma chamada. Quando o modo de silêncio está ativado, o usuário não consegue ouvir os outros participantes, mas os outros participantes conseguem ouvir o usuário.
Exemplo
Substitua as seguintes variáveis no código de exemplo:
| Chave | Descrição |
|---|---|
VOICE_CALL_ID | The UUID of the call leg. |
Pré-requisitos
Execute o seguinte comando no prompt do terminal para criar o arquivo ` JWT ` para autenticação:
export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)Escreva o código
Adicione o seguinte ao arquivo ` earmuff-a-call.sh`:
curl -X PUT https://api.nexmo.com/v1/calls/$VOICE_CALL_ID \
-H "Authorization: Bearer $JWT"\
-H "Content-Type: application/json"\
-d '{"action": "earmuff"}'
sleep 5s
curl -X PUT https://api.nexmo.com/v1/calls/$VOICE_CALL_ID \
-H "Authorization: Bearer $JWT"\
-H "Content-Type: application/json"\
-d '{"action": "unearmuff"}'Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
npm install @vonage/server-sdkCrie um arquivo chamado ` earmuff-a-call.js ` e insira o seguinte código:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Escreva o código
Adicione o seguinte ao arquivo ` earmuff-a-call.js`:
vonage.voice.earmuffCall(VOICE_CALL_ID)
.then(() => console.log('Call earmuffed'))
.catch((error) => console.error(error));
const unearmuff = () => {
vonage.voice.unearmuffCall(VOICE_CALL_ID)
.then(() => console.log('Unearmuffed call'))
.catch((error) => console.error(error));
};
setTimeout(unearmuff, 3000); // delay 3 secondsExecute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
Adicione o seguinte ao arquivo ` build.gradle`:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Crie um arquivo chamado ` EarmuffCall ` e adicione o código a seguir ao método ` main `:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Escreva o código
Adicione o seguinte ao método ` main ` do arquivo ` EarmuffCall `:
val call = client.voice.call(VOICE_CALL_ID)
call.earmuff()
Thread.sleep(3000)
call.unearmuff()Execute seu código
Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.kt.voice ` pelo pacote que contém ` EarmuffCall`:
Pré-requisitos
Adicione o seguinte ao arquivo ` build.gradle`:
implementation 'com.vonage:server-sdk:9.3.1'Crie um arquivo chamado ` EarmuffCall ` e adicione o código a seguir ao método ` main `:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Escreva o código
Adicione o seguinte ao método ` main ` do arquivo ` EarmuffCall `:
client.getVoiceClient().earmuffCall(VOICE_CALL_ID);
Thread.sleep(3000);
client.getVoiceClient().unearmuffCall(VOICE_CALL_ID);Execute seu código
Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.voice ` pelo pacote que contém ` EarmuffCall`:
Pré-requisitos
Install-Package VonageEscreva o código
Adicione o seguinte ao arquivo ` EarmuffCall.cs`:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);
var command = new CallEditCommand() { Action = CallEditCommand.ActionType.earmuff };
var response = await client.VoiceClient.UpdateCallAsync(VOICE_CALL_ID, command);
Console.WriteLine($"Earmuff Call Command succeeded: {response}");
Thread.Sleep(3000);
command = new CallEditCommand() { Action = CallEditCommand.ActionType.unearmuff };
response = await client.VoiceClient.UpdateCallAsync(VOICE_CALL_ID, command);Pré-requisitos
composer require vonage/clientEscreva o código
Adicione o seguinte ao arquivo ` index.php`:
require_once __DIR__ . '/../../vendor/autoload.php';
$keypair = new \Vonage\Client\Credentials\Keypair(file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH), VONAGE_APPLICATION_ID);
$client = new \Vonage\Client($keypair);
$client->voice()->earmuffCall(UUID);
sleep(3);
$client->voice()->unearmuffCall(UUID);Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
pip install vonage python-dotenvEscreva o código
Adicione o seguinte ao arquivo ` earmuff-a-call.py`:
from vonage import Auth, Vonage
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
)
)
client.voice.earmuff(VOICE_CALL_ID)
sleep(3)
client.voice.unearmuff(VOICE_CALL_ID)Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
gem install vonageEscreva o código
Adicione o seguinte ao arquivo ` earmuff-a-call.rb`:
client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: VONAGE_PRIVATE_KEY
)
client.voice.earmuff(VOICE_CALL_ID)
sleep(3)
client.voice.unearmuff(VOICE_CALL_ID)Execute seu código
Salve este arquivo no seu computador e execute-o:
Experimente
Ao executar o código, a chamada identificada pelo UUID terá o bloqueio de som ativado ou desativado.
Leitura complementar
- Teleconferência - Este guia explica os dois Concepts que a Vonage associa a uma chamada: “leg” e “conversação”.