I have created a Twilio video call app using the Serverless guide, everything is fine and good now I want to implement mute/unmute audio in this. Please help for this I'm new with node.js. Want to know that where I need to put code in conference.js.
This is guide, which I used to install and video call is working perfect.
Initiate a new project
twilio serverless:init example --template=video && cd example
- Start the server with the Twilio CLI:
twilio serverless:start
- Open the web page at https://localhost:3000/index.html to test the app
ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables.
Deploying
Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. More details in the docs.
With the Twilio CLI:
twilio serverless:deploy
First up, just to let you know, when making changes to the application that users interact with in the browser, you are not doing so in Node.js, but in JavaScript that is running in the browser.
To mute/unmute a participant's audio or video within a Twilio Video application you need to access the
LocalAudioTrackorLocalVideoTrackthat you want to mute and calldisable()on it. To unmute or re-enable the track you need to callenable()on it.But there's more to it than that. You will need to add buttons to the page in
conference.htmlthat will do the muting, and you will need to get access to the buttons in the JavaScript and listen to the click event so you can trigger the muting/unmuting.Once you have added the buttons and are listening to the click event, you will need to get access to the tracks. You can do this through the
roomobject that you have access to once the room has connected. With theroomobject you can access thelocalParticipantobject and then use that to access either thevideoTracksoraudioTracksproperty depending on whether you want to mute video or audio. BothvideoTracksandaudioTracksareMaps of Track SID andLocalTrackPublications. You can calltrackon a publication to get the underlying track and then callenable/disableon it.Here's an example of a function that would mute a
localParticipant's audio tracks. It assumes you've already placed a mute button on the page and got access to it in the JavaScript earlier. This code should go in conversation.js in the callback once the video has connected and you have access to theroomobject:You can repeat this for
videoTracksand also use the same pattern to callenableon the tracks to unmute them again.See how you do with that. If you have any more questions, please share the code you are using, the things you have tried and what is going wrong.