【问题标题】:With twilio: Mute a specific participant in a room使用 twilio:将房间中的特定参与者静音
【发布时间】:2018-07-31 23:41:51
【问题描述】:

我进行了很多搜索,并尝试了很多东西。让我们以 this question 的相同场景为例。

Bob、Alice 和 Jane 正在开会。我希望 Bob(房间的主人)能够将 Alice 静音,这样 Alice 的声音就不会穿过房间,但 Alice strong>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);
        });
    }
});

我们只是遍历本地参与者的音频轨道,如果我想为特定用户这样做,我只需要知道他的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

【问题讨论】:

    标签: javascript twilio twilio-api twilio-functions


    【解决方案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;
            });
        }
      }
    });
    

    【讨论】:

    • 不,这不是复制/粘贴。这应该工作。当我得到匹配代码的participant.identity 时,room.participants.forEach(function(participant) { 将迭代一个参与者数组。我将其分配给user_to_mute。然后我循环遍历user_to_mute.audioTracks,然后启用/禁用 audio,正如文档中明确提到的那样。看来这个选项只对本地参与者可用,对远程参与者不可用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多