简体   繁体   English

在Twilio Video快速入门中添加静音按钮

[英]Adding a mute button to Twilio Video Quickstart

I'm using this post as a guide on how to add a mute button to my Twilio video Quickstart application. 我将这篇文章用作如何在我的Twilio视频快速入门应用程序中添加静音按钮的指南。 I'm still not able to mute my local participant microphone, however. 但是,我仍然无法使本地参与者的麦克风静音。 I added the following code as a promise in my video connection, but it's not even logging the message to the console when I click on #button-mute. 我在视频连接中添加了以下代码作为承诺,但是当我单击#button-mute时,甚至没有将消息记录到控制台。

On connecting, the console outputs the following error: 连接时,控制台将输出以下错误:

TypeError: Cannot read property 'localParticipant' of undefined TypeError:无法读取未定义的属性“ localParticipant”

Video.connect(data.token, connectOptions).then(roomJoined, function(error) {
        log('Could not connect to Twilio: ' + error.message);
    }).then(room => {
        const localParticipant = room.localParticipant;

        $button-mute.on('click', event => {
            localParticipant.tracks.forEach((trackId, track) => {
                console.log('In mute function code');
                if (track.isEnabled) {
                    track.disable();
                } else {
                    track.enable();
                }
            })
        })
    });

Twilio developer evangelist here. Twilio开发人员布道者在这里。

The issue here seems to be the return value of your promise. 这里的问题似乎是您的承诺的回报价值。 The first part of your code here looks like this: 您的代码的第一部分如下所示:

Video.connect(data.token, connectOptions).then(roomJoined, function(error) {
    log('Could not connect to Twilio: ' + error.message);
}).then(room => {

If your roomJoined function doesn't return the room object then the following then will not have an argument of room and calling room.localParticipant will result in your error. 如果您roomJoined功能不返回room对象,然后下面then不会有争论room ,并呼吁room.localParticipant会导致你的错误。

Ensure that roomJoined returns the room object and it should work. 确保roomJoined返回了room对象并且它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM