问题
How do you mute and no-video the local participant? https://www.twilio.com/docs/api/video/getting-started
this code has been proposed elsewhere - but is this the track data?
var localMedia = conversation.localMedia;
localMedia.mute();
So would I get the tracks of the local participant
var tracks = Array.from(participant.tracks.values())
audioTrack.mute()? videoTrack.mute()?
document.getElementById('button-mute').onclick = function () {
log('Mute call...')
console.log('mute call')
// var localMedia = conversation.localMedia
// localMedia.mute()
}
document.getElementById('button-no-video').onclick = function () {
log('No Vid call...')
console.log('no vid')
}
回答1:
Twilio developer evangelist here.
You actually want to use the disable method on the local media tracks to mute them.
First, make sure you're using the Twilio Video Rooms API (you mention conversation in the question, the conversations API is deprecated).
Then, when you connect you can get hold of the local participants media tracks and disable or enable them when you like. Something like this:
Video.connect(token, { name: 'room-name' }).then(room => {
const localParticipant = room.localParticipant;
$button.on('click', event => {
localParticipant.tracks.forEach((trackId, track) => {
if (track.isEnabled) {
track.disable();
} else {
track.enable();
}
})
})
});
Let me know if that helps at all.
回答2:
Try following code, it worked for me.
// name is video or audio
vm.toggleMyDevices = function(kind){
var localMedia = activeRoom.localParticipant;
localMedia.tracks.forEach(function (track) {
console.log(track);
if(track.kind === kind){
if (track.isEnabled) {
track.disable();
$scope.isPaused = true;
} else {
track.enable();
$scope.isPaused = false;
}
}
},kind);
}
来源:https://stackoverflow.com/questions/45033029/twilio-video-no-video-and-mute-methods