Book Image

WebRTC Cookbook

By : Andrii Sergiienko
Book Image

WebRTC Cookbook

By: Andrii Sergiienko

Overview of this book

Table of Contents (15 chapters)
WebRTC Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Muting a microphone


Usually, voice calling software has a microphone muting feature. So, you can enable or disable your microphone during the call, deciding whether the remote peer should hear your voice or not. In this recipe, we will implement such a feature for a WebRTC application.

Getting ready

For this example, you don't need any preliminary specific steps. Use your development environment as you usually do.

How to do it…

Follow these steps:

  1. For this feature, you need to add a button element to your HTML page. This button will enable or disable the microphone:

    <button id="mute_btn" onclick="muteBtnClick()">Mute Mic</button>
  2. You also need to set up a handler for the onclick event of the element—it will do the actual work. The following code is an example of such a handler:

    function muteBtnClick() {
  3. We will update our button with the microphone state, so we need to get the button ID:

         var btn = document.getElementById("mute_btn");
  4. Before we can decide whether we want to mute or...