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

Combining filters


All the filters described in this chapter can be combined and work together. In this recipe, we will cover this topic using a simple practical example—combining two filters: brightness and contrast.

How to do it…

Follow the given steps:

  1. Add two control objects to the page for each of the filters we plan to use:

    Brightness<br>
    <input type="range" oninput="doFilter('brightness', this.valueAsNumber);" value="0" step="0.1" min="0" max="10">
    <br>
    Contrast<br>
    <input type="range" oninput="doFilter('contrast', this.valueAsNumber);" value="0" step="0.1" min="0" max="10">
    <br>
  2. Add a global variable where we will store the values for each filter:

    var filters = {};
  3. Add an appropriate JavaScript function that will be called when value of the controls (introduced in the step 1) is changing:

    function doFilter(filtername, val) {
      filters[filtername] = val;
      var v = document.getElementById("localVideo");
      var f = "";
      for (var fname in filters) {
        f ...