Trevor
Trevor

Reputation: 13457

How to mute twilio calls in javascript

I am able to mute the sound going into the microphone, but not the sound coming out of the speakers. To be specific, I'm only trying to mute the Twilio call, not other sounds in the browser, and certainly not system sounds.

Upvotes: 3

Views: 4700

Answers (3)

Dave Glassborow
Dave Glassborow

Reputation: 3553

Its straightforward using the Javascript 1.4 library, without needing conference calls etc.

https://www.twilio.com/docs/api/client/connection

e.g.

Twilio.Device.activeConnection().mute(true);

Upvotes: 4

Ashutosh Jha
Ashutosh Jha

Reputation: 16357

Here is working example

  $scope.togglePublishAudio = function togglePublishAudio() {
      $log.debug('Toggling publish audio');

      if (activeRoom.localParticipant.media.isMuted === false) {        
        $scope.isMuted = true;        
        activeRoom.localParticipant.media.mute();
      } else {
        $scope.isMuted = false;
        activeRoom.localParticipant.media.unmute();
      }

    };

In new Version of twilio

  var localMedia = room.localParticipant;
  localMedia.tracks.forEach(function (track) {
    if (track.isEnabled) {
      track.disable();
      $scope.isPaused = true;
    } else {
      track.enable();
      $scope.isPaused = false;
    }
  });

Upvotes: 1

user2847518
user2847518

Reputation: 126

if the call is between 2 persons only, then this can be done by creating a conference in twilio and muting the other person during the call. This will make the server reject the voice input from the other party.

However, to completely stop the sound on your side local, i would suggest using javascript to alter the flash player privileges to restrict the hardware access when you want the call to be muted.

Upvotes: 1

Related Questions