Mediensteuerung

Mit diesen APIs können Sie das lokale und entfernte Audioverhalten während eines aktiven Anrufs steuern.

Clientseitige vs. serverseitige Steuerelemente

Stummschalten und Rauschunterdrückung werden lokal auf dem Gerät angewendet – sie verhindern die Übertragung von Audiodaten oder filtern diese vor der Übertragung. Gehörschutz wird serverseitig angewendet – die Vonage-API unterdrückt den eingehenden Audiostream, bevor er den Client erreicht.

Verfügbarkeit der Plattform

Kontrolle Android iOS Web
Stummschalten / Stummschaltung aufheben Ja Ja Ja
Gehörschutz Ja Ja Ja
DTMF Ja Ja Ja
Rauschunterdrückung Ja Ja Nein

Stummschalten

Schalten Sie das lokale Mikrofon stumm, damit Ihr Gesprächspartner Sie nicht hören kann. Die Verbindung bleibt bestehen.

const callId = 'callId';
await client.mute(callId);
// Callback
 client.mute("callId") {
     it?.let { err ->
         // Handle Error in muting call
         println("Error in muting call: $err")
     }
 }

 // Coroutine
 try {
     client.mute("callId")
 } catch (e: Error) {
     // Handle Error in muting call
 }
client.mute("callId", it -> {
     if (it != null) {
         // Handle Error in muting call
         System.out.println("Error in muting call: " + it);
     }
     return null;
 });
// Callback
 client.mute("someCallId"){ error in
     if let error = error {
         print("Mute Failed with error: \(error)")
         return
     }
 }
 
 // Async Await
 Task.detached {
     do {
         try await client.mute("someCallId")
     } catch {
         print("Failed to mute \(error.localizedDescription)")
     }
 }
[client mute:@"someCallId" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"Mute Failed with error: %@", error);
     }
 }];

Aufheben der Stummschaltung

Aktivieren Sie das lokale Mikrofon nach dem Stummschalten wieder.

const callId = 'callId';
await client.unmute(callId);
// Callback
 client.unmute("callId") {
     it?.let { err ->
         // Handle Error in unmuting call
         println("Error in unmuting call: $err")
     }
 }

 // Coroutine
 try {
     client.unmute("callId")
 } catch (e: Error) {
     // Handle Error in unmuting call
 }
client.unmute("callId", it -> {
     if (it != null) {
         // Handle Error in unmuting call
         System.out.println("Error in unmuting call: " + it);
     }
     return null;
 });
// Callback
 client.unmute("someCallId"){ error in
     if let error = error {
         print("Unmute Failed with error: \(error)")
         return
     }
 }
 
 // Async Await
 Task.detached {
     do {
         try await client.unmute("someCallId")
     } catch {
         print("Failed to unmute \(error.localizedDescription)")
     }
 }
[client unmute:@"someCallId" callback:^(NSError * _Nullable error) {
         if(error){
             NSLog(@"Unmute Failed with error: %@", error);
         }
 }];

onMute-Update-Ereignis

Wird ausgelöst, wenn sich der Stummschaltstatus ändert, einschließlich Änderungen, die von der Gegenstelle oder vom Server ausgelöst werden.

client.on('mute', (callId, legId, mute) => {
  if (mute) {
    console.log(`Leg ${legId} of call ${callId} was muted`);
  } else {
    console.log(`Leg ${legId} of call ${callId} was unmuted`);
  }
});
 client.setOnMutedListener { call, legId, isMuted ->
     if (isMuted) {
         // leg is muted
         println("leg:$legId for call: $call was muted")
     } else {
         // leg is unmuted
         println("leg:$legId for call: $call was un-muted")
     }
 }
client.setOnMutedListener((call, legId, isMuted) -> {
     if (isMuted) {
         System.out.println("Leg " + legId + " for call " + call + " was muted");
     } else {
         System.out.println("Leg " + legId + " for call " + call + " was unmuted");
     }
     return null;
 });
class MuteUpdateExampleDelegate: NSObject, VGVoiceClientDelegate {
     func voiceClient(_ client: VGVoiceClient, didReceiveMuteForCall callId: VGCallId, withLegId legId: VGCallId, andStatus isMuted: Bool) {
         if (isMuted) {
             print("Leg:\(legId) has been muted")
         } else {
             print("Leg:\(legId) has been unmuted")
         }
     }
     
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: VGCallId, from caller: String, with type: VGVoiceChannelType) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveHangupForCall callId: VGCallId, withQuality callQuality: VGRTCQuality, reason: VGHangupReason) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteCancelForCall callId: VGCallId, with reason: VGVoiceInviteCancelReason) {}
     func client(_ client: VGBaseClient, didReceiveSessionErrorWith reason: VGSessionErrorReason) {}
 }
- (void) voiceClient:(VGVoiceClient *)client didReceiveMuteForCall:(VGCallId)callId withLegId:(NSString *)legId andStatus:(Boolean)isMuted {

     if(isMuted){
         NSLog(@"Leg: %@ has been muted", legId);
     } else {
         NSLog(@"Leg: %@ has been unmuted", legId);
     }
 }

Ohrenschützer aktivieren

„Earmuff“ verhindert, dass der lokale Benutzer Audio vom Remote-Server hört. Im Gegensatz zu „mute“ wird „earmuff“ serverseitig angewendet – der Audiostream wird unterdrückt, bevor er den Client erreicht.

const callId = 'callId';
await client.enableEarmuff(callId);
 // Callback
 client.enableEarmuff("callId") {
     it?.let { err ->
         // Handle Error in enabling earmuff
         println("Error in enabling earmuff: $err")
     }
 }

 // Coroutine
 try {
     client.enableEarmuff("callId")
 } catch (e: Error) {
     // Handle Error in enabling earmuff
 }
 client.enableEarmuff("callId", it -> {
     if (it != null) {
         // Handle Error in enabling earmuff
         System.out.println("Error in enabling earmuff: " + it);
     }
     return null;
 });
// Callback
 client.enableEarmuff("someCallId"){ error in
     if let error = error {
         print("Enable Earmuff Failed with error: \(error)")
         return
     }
 }
 
 // Async Await
 Task.detached {
     do {
         try await client.enableEarmuff("someCallId")
     } catch {
         print("Failed to enableEarmuff \(error.localizedDescription)")
     }
 }
 [client enableEarmuff:@"someCallId" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"Enable Earmuff Failed with error: %@", error);
     }
 }];

Gehörschutz deaktivieren

Wiederherstellung des eingehenden Audiosignals nach dem Stummschalten.

const callId = 'callId';
await client.disableEarmuff(callId);
 // Callback
 client.disableEarmuff("callId") {
     it?.let { err ->
         // Handle Error in disabling earmuff
         println("Error in disabling earmuff: $err")
     }
 }

 // Coroutine
 try {
     client.disableEarmuff("callId")
 } catch (e: Error) {
     // Handle Error in disabling earmuff
 }
 client.disableEarmuff("callId", it -> {
     if (it != null) {
         // Handle Error in disabling earmuff
         System.out.println("Error in disabling earmuff: " + it);
     }
     return null;
 });
 // Callback
 client.disableEarmuff("someCallId"){ error in
     if let error = error {
         print("Disable Earmuff Failed with error: \(error)")
         return
     }
 }
 
 // Async Await
 Task.detached {
     do {
         try await client.disableEarmuff("someCallId")
     } catch {
         print("Failed to disableEarmuff \(error.localizedDescription)")
     }
 }
 [client disableEarmuff:@"someCallId" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"Disable Earmuff Failed with error: %@", error);
     }
 }];

onEarmuff-Update-Veranstaltung

Wird ausgelöst, wenn sich der Status des Ohrenschützers ändert.

client.on('earmuff', (callId, legId, earmuff) => {
  if (earmuff) {
    console.log(`Leg ${legId} of call ${callId} had earmuff enabled`);
  } else {
    console.log(`Leg ${legId} of call ${callId} had earmuff disabled`);
  }
});
 client.setOnEarmuffListener {call, legId, earmuffStatus ->
     if (earmuffStatus) {
         // earmuff enabled
         println("earmuff is enabled for leg:$legId with Call $call")
     } else {
         // earmuff disabled
         println("earmuff is disabled for leg:$legId with Call $call")
     }
 }
 client.setOnEarmuffListener((call, legId, earmuffStatus) -> {
     if (earmuffStatus) {
         System.out.println("Leg " + legId + " for call " + call + " was earmuffed");
     } else {
         System.out.println("Leg " + legId + " for call " + call + " was unearmuffed");
     }
     return null;
 });
 class EarmuffListenerExampleDelegate : NSObject, VGVoiceClientDelegate {
     func voiceClient(_ client: VGVoiceClient, didReceiveEarmuffForCall callId: VGCallId, withLegId legId: VGCallId, andStatus earmuffStatus: Bool) {
         if (earmuffStatus) {
             print("Leg:\(legId) has enabled earmuff")
         } else {
             print("Leg:\(legId) has disabled earmuff")
         }
     }
     
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: VGCallId, from caller: String, with type: VGVoiceChannelType) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveHangupForCall callId: VGCallId, withQuality callQuality: VGRTCQuality, reason: VGHangupReason) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteCancelForCall callId: VGCallId, with reason: VGVoiceInviteCancelReason) {}
     func client(_ client: VGBaseClient, didReceiveSessionErrorWith reason: VGSessionErrorReason) {}
 }
 - (void)voiceClient:(VGVoiceClient *)client didReceiveEarmuffForCall:(VGCallId)callId withLegId:(NSString *)legId andStatus:(Boolean)earmuffStatus {
     if(earmuffStatus){
         NSLog(@"Leg: %@ has enabled earmuff", legId);
     } else {
         NSLog(@"Leg: %@ has disabled earmuff", legId);
     }
 }

DTMF senden

Senden Sie während eines aktiven Gesprächs Zweiklang-Mehrfrequenzsignale. Gültige Ziffern sind 0-9, *und #. DTMF wird häufig für die Navigation in IVR-Systemen und die Interaktion mit Telefonanlagen verwendet.

const callId = 'callId';
await client.sendDTMF(callId, '1234');
 // Callback
 client.sendDTMF("callId", "1234") {
     it?.let { err ->
         // Handle Error in sending DTMF
         println("Error in sending DTMF: $err")
     }
 }

 // Coroutine
 try {
     client.sendDTMF("callId", "1234")
 } catch (e: Error) {
     // Handle Error in sending DTMF
 }

 client.sendDTMF("callId", "1234", it -> {
     if (it != null) {
         // Handle Error in sending DTMF
         System.out.println("Error in sending DTMF: " + it);
     }
     return null;
 });
 // Callback
 client.sendDTMF("someCallId", withDigits: "1234"){ error in
     if let error = error {
         print("DTMF Failed with error: \(error)")
         return
     }
 }
 
 // Async Await
 Task.detached {
     do {
         try await client.sendDTMF("someCallId", withDigits: "1234")
     } catch {
         print("Failed to sendDTMF \(error.localizedDescription)")
     }
 }
 [client sendDTMF:@"someCallId" withDigits:@"1234" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"DTMF Failed with error: %@", error);
     }
 }];

onDTMF-Update-Ereignis

Löst aus, wenn DTMF-Ziffern vom Gegenüber empfangen werden.

client.on('dtmf', (callId, legId, dtmf) => {
  console.log(`Leg ${legId} of call ${callId} sent DTMF ${dtmf}`);
});
 client.setOnDTMFListener {call, legId, digits ->
     println("Received DTMF digits: $digits for leg:$legId with Call $call")
 }
 client.setOnDTMFListener((call, legId, dtmf) -> {
     System.out.println("Leg " + legId + " for call " + call + " sent DTMF: " + dtmf);
     return null;
 });
 class DTMFListenerExampleDelegate : NSObject, VGVoiceClientDelegate {
     func voiceClient(_ client: VGVoiceClient, didReceiveDTMFForCall callId: VGCallId, withLegId legId: VGCallId, andDigits digits: String) {
         print("Leg:\(legId) has sent DTMF: \(digits)")
     }
     
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: VGCallId, from caller: String, with type: VGVoiceChannelType) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveHangupForCall callId: VGCallId, withQuality callQuality: VGRTCQuality, reason: VGHangupReason) {}
     func voiceClient(_ client: VGVoiceClient, didReceiveInviteCancelForCall callId: VGCallId, with reason: VGVoiceInviteCancelReason) {}
     func client(_ client: VGBaseClient, didReceiveSessionErrorWith reason: VGSessionErrorReason) {}
 }
 - (void)voiceClient:(VGVoiceClient *)client didReceiveDTMFForCall:(VGCallId)callId withLegId:(NSString *)legId andDigits:(NSString *)digits {
     NSLog(@"Leg %@ has sent DTMF: %@", legId, digits);
 }

Rauschunterdrückung aktivieren (Android/iOS)

Aktivieren Sie die geräteinterne Rauschunterdrückung, um Hintergrundgeräusche aus dem lokalen Mikrofoneingang herauszufiltern. Nicht im Web verfügbar.

 // Callback
 client.enableNoiseSuppression("callId") { err ->
     err?.let {
         println("Error enabling noise suppression: $it")
     } ?: println("Noise suppression successfully enabled")
 }

 // Coroutine
 try {
     client.enableNoiseSuppression("callId")
 } catch (e: Error) {
     println("Error enabling noise suppression: $e")
 }
 client.enableNoiseSuppression("callId", err -> {
     if(err != null){
         System.out.println("Error enabling noise suppression: " + err);
     }
     System.out.println("Noise suppression successfully enabled");
     return null;
 });
 // Callback
 client.enableNoiseSuppression("someCallId"){ error in
     if let error = error {
         print("Failed to enable noise suppression: \(error.localizedDescription)")
     } else {
         print("Noise suppression successfully enabled")
     }
 }

 // Async Await
 Task.detached {
     do {
         try await client.enableNoiseSuppression("someCallId")
         print("Noise suppression successfully enabled")
     }
     catch {
         print("Failed to enable noise suppression: \(error.localizedDescription)")
     }
 }
 [client enableNoiseSuppression:@"someCallId" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"Failed to enable noise suppression: %@", error);
     } else {
         NSLog(@"Noise suppression successfully enabled");
     }
 }];

Rauschunterdrückung deaktivieren (Android/iOS)

Die geräteinterne Rauschunterdrückung deaktivieren.

 // Callback
 client.disableNoiseSuppression("callId") { err ->
     err?.let {
         println("Error disabling noise suppression: $it")
     } ?: println("Noise suppression successfully disabled")
 }

 // Coroutine
 try {
     client.disableNoiseSuppression("callId")
     println("Noise suppression successfully disabled")
 } catch (e: Error) {
     println("Error disabling noise suppression: $e")
 }
 client.disableNoiseSuppression("callId", err -> {
     if(err != null){
         System.out.println("Error disabling noise suppression: " + err);
     }
     System.out.println("Noise suppression successfully disabled");
     return null;
 });
 // Callback
 client.disableNoiseSuppression("someCallId"){ error in
     if let error = error {
         print("Failed to disable noise suppression: \(error.localizedDescription)")
     } else {
         print("Noise suppression successfully disabled")
     }
 }

 // Async Await
 Task.detached {
     do {
         try await client.disableNoiseSuppression("someCallId")
         print("Noise suppression successfully disabled")
     }
     catch {
         print("Failed to disable noise suppression: \(error.localizedDescription)")
     }
 }
 [client disableNoiseSuppression:@"someCallId" callback:^(NSError * _Nullable error) {
     if(error){
         NSLog(@"Failed to disable noise suppression: %@", error);
     } else {
         NSLog(@"Noise suppression successfully disabled");
     }
 }];