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



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

鲍勃、爱丽丝和简正在开会。我希望Bob(房间的主人(能够将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

对我来说,这看起来像是一些复制粘贴错误,但由于不熟悉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;
});
}
}
});

最新更新