代码之家  ›  专栏  ›  技术社区  ›  Lemayzeur

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

  •  2
  • Lemayzeur  · 技术社区  · 8 年前

    this question .

    鲍勃、爱丽丝和简 我们正在开会。我想要 所以听起来 爱丽丝 不会穿过房间,但是 爱丽丝 鲍勃和简 )

    想象一下,当你在开会时,有人打扰了现场。所以我希望主人能够静音或删除该人的音频轨道。

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

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

    我们只需遍历本地参与者的音频轨迹,如果我想为特定用户这样做,我只需要知道他的音频轨迹 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
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   dave    8 年前

    在我看来,这是一些复制粘贴错误,但由于不熟悉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;
            });
        }
      }
    });
    
    推荐文章