提问者:小点点

使用twilio:将房间中的特定参与者静音


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

鲍勃、爱丽丝和简正在开会。我希望鲍勃(房间的主人)能够让爱丽丝静音,这样爱丽丝的声音就不会通过房间,但是爱丽丝仍然能听到所有其他参与者的声音(鲍勃

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

到目前为止,我可以为本地参与者静音音轨:

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

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

$(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

共1个答案

匿名用户

对我来说,这看起来像是一些复制粘贴错误,但不熟悉API,我做了一些假设:

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