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

Taking a screenshot


Sometimes, it can be useful to be able to take screenshots from a video during videoconferencing. In this recipe, we will implement such a feature.

Getting ready

No specific preparation is necessary for this recipe. You can take any basic WebRTC videoconferencing application. We will add some code to the HTML and JavaScript parts of the application.

How to do it…

Follow these steps:

  1. First of all, add image and canvas objects to the web page of the application. We will use these objects to take screenshots and display them on the page:

    <img id="localScreenshot" src="">
    <canvas style="display:none;" id="localCanvas"></canvas>
  2. Next, you have to add a button to the web page. After clicking on this button, the appropriate function will be called to take the screenshot from the local stream video:

    <button onclick="btn_screenshot()" id="btn_screenshot">Make a screenshot</button>
  3. Finally, we need to implement the screenshot taking function:

    function btn_screenshot...