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

Using the opacity filter


In this recipe, we will cover how to use the opacity filter. You will probably rarely use it, but it can be used for implementing interesting features, such as picture in picture.

How to do it…

Follow these steps:

  1. Add a control element to the main web page of your application—using this object we will control the video's opacity:

    Opacity
    <input type="range" oninput="changeOpacity(this.valueAsNumber);" value="1" step="0.1" min="0" max="1">
  2. Add an appropriate JavaScript function:

    function changeOpacity(val) {
      var v = document.getElementById("localVideo");
      v.style.webkitFilter="opacity(" + val + ")";
    };

    Here localVideo is the ID property of the HTML video tag for the local video playback.

  3. Navigate your web browser to the web page. You will first see an unprocessed video from the web camera, with no filter applied. The following screenshot depicts this stage:

  4. On the left-hand side of the page, you can see a control described as Opacity. Try to move it to the left and...