5

I'm adapting Twilio's JS Quickstart and trying to provide a button that will mute a user's audio. From looking around online, my code looks like this:

function toggleAudio(){
  room.localParticipant.audioTracks.forEach(function(track) {
    console.log(track);
    track.disable();
  })
}

The console.log() spits out a LocalAudioTrackPublication, yet I get the following error:

Uncaught TypeError: track.disable is not a function

So I'm stumped. The docs imply that the .disable() method will do what I expect, yet apparently, it's not defined?

Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
Kevin Lewis
  • 1,070
  • 3
  • 10
  • 18

1 Answers1

8

It was such a ridiculously simple solution, as is always the case.

function toggleAudio(){
  room.localParticipant.audioTracks.forEach(function(track) {
    track.track.disable();
  })
}

The actual track is inside of the track property.

Kevin Lewis
  • 1,070
  • 3
  • 10
  • 18