2

I made a lot of searches, and tried many things. Let's take the same scenario from this question.

Bob, Alice, and Jane are in a conference. I want Bob (the hoster of the room) to be able to mute Alice so sounds from Alice will not come through the room, but Alice still hear sounds from all other participants (Bob & Jane)

Imagine the scenario when you are in conference, and someone disturbs the Live. So I want the hoster to be able to mute or remove the audio track of that person.

So far, I can mute the audio tracks for the local participant with:

$(document).on("click",'.mute-audio',function(){
    if(room){
        let microEnabled = true;
        microEnabled = !microEnabled;
        room.localParticipant.audioTracks.forEach(function(audioTrack) {
            audioTrack.enable(microEnabled);
        });
    }
});

We simply iterate through audioTracks of the local participant, and if I want to do so for a specific User, I just need to know his identity and I am good to go:

$(document).on("click",'.mute-user',function(){
    var identity = $(this).data('identity'); // i.e the unique ID USER2323
    if(room){
        var user_to_mute;


        room.participants.audioTracks.forEach(function(participant) {
            audioTrack.enable(microEnabled);
            user_to_mute = participant;
            // We retrieve the target
            return;
        });

        let m_Enabled = true;
        m_Enabled = !m_Enabled;
        if(user_to_mute){
            user_to_mute.audioTracks.forEach(function(audioTrack) {
                audioTrack.enable(m_Enabled);
                // the error is here I think
                return;
            });
        }
    }
});

But it doesn't work, when I try I got this error from the browser

TypeError: audioTrack.enable is not a function
Lemayzeur
  • 8,297
  • 3
  • 23
  • 50

1 Answers1

0

It looks like some copy paste errors to me, but not being familiar with the API, I'm making a few assumptions:

$(document).on("click",'.mute-user',function(){
  var identity = $(this).data('identity'); // i.e the unique ID USER2323
  if(room){
    var user_to_mute;
    // in the next line, we remove .audioTracks, since it looks like
    // you want to iterate over participants, and removed audioTrack.enable
    // since it's not defined yet
    room.participants.forEach(function(participant) {
        if (identity == participant.identity) {
            // We retrieve the target
            user_to_mute = participant;
            return;
        }
    });

    let m_Enabled = true;
    m_Enabled = !m_Enabled;
    if(user_to_mute){
        user_to_mute.audioTracks.forEach(function(audioTrack) {
            audioTrack.enable(m_Enabled);
            return;
        });
    }
  }
});
dave
  • 62,300
  • 5
  • 72
  • 93
  • No it's not a copy/paste. this should work. `room.participants.forEach(function(participant) {` will iterate a participants array, when i get the `participant.identity` that mactches the code. I assign it to `user_to_mute`. and then I loop through `user_to_mute.audioTracks` and then **enable/disable** the `audio` as clearly mentioned in doc. It seems that this option is only available for local participant, not for remote participants – Lemayzeur Aug 01 '18 at 01:12