我进行了很多搜索,并尝试了很多事情。让我们以 this question中的情况为例。
Bob,Alice和Jane 正在参加会议。我希望 Bob (房间的主持人)能够静音 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
答案 0 :(得分:0)
在我看来,有些复制粘贴错误,但是我不熟悉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;
});
}
}
});