2

我做了很多搜索,尝试了很多东西。让我们从这个问题中获取相同的场景。

Bob、Alice 和 Jane正在开会。我希望Bob(房间的主人)能够将 Alice 静音,这样Alice的声音就不会通过房间,但Alice仍然可以听到所有其他参与者的声音(Bob 和 Jane

想象一下当你在开会时,有人打扰了直播的场景。所以我希望主持人能够静音或删除那个人的音轨。

到目前为止,我可以通过以下方式将本地参与者的音轨静音:

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

我们只需遍历本地参与者的 audioTracks,如果我想为特定用户这样做,我只需要知道他identity就可以了:

$(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;
            });
        }
    }
});

但它不起作用,当我尝试时,我从浏览器收到此错误

TypeError: audioTrack.enable is not a function
4

1 回答 1

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;
        });
    }
  }
});
于 2018-08-01T00:03:20.980 回答