WebRTC Cookbook - Andrii Sergiienko - E-Book

WebRTC Cookbook E-Book

Andrii Sergiienko

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

If you are a JavaScript developer with a basic knowledge of WebRTC and software development, but want to explore how to use it in more depth, this book is for you.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 218

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

WebRTC Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Peer Connections
Introduction
Building a signaling server in Erlang
Getting ready
How to do it…
How it works…
There's more…
See also
Building a signaling server in Java
Getting ready
How to do it…
How it works…
There's more…
See also
Detecting WebRTC functions supported by a browser
Getting ready
How to do it…
How it works…
There's more…
See also
Making and answering calls
Getting ready
How to do it…
Making a call
Answering a call
How it works…
There's more…
See also
Implementing a chat using data channels
Getting ready
How to do it…
Creating the main HTML page of the application
Creating the JavaScript helper library
How it works…
There's more…
See also
Implementing a chat using a signaling server
How to do it…
How it works…
There's more…
See also
Configuring and using STUN
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring and using TURN
Getting ready
How to do it…
Installing the TURN server
Using TURN in WebRTC application
How it works…
There's more…
See also
2. Supporting Security
Introduction
Generating a self-signed certificate
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring a TURN server with authentication
Getting ready
How to do it…
Implementing the client-side code
Implementing the server-side code
How it works…
There's more…
See also
Configuring a web server to work over HTTPS
Getting ready
How to do it…
Configuring Nginx
Configuring Apache
Configuring IIS
There's more…
See also
Configuring a WebSockets proxy on the web server
Getting ready
How to do it…
Configuring Nginx
Configuring Apache
Configuring IIS
How it works…
There's more…
See also
Configuring a firewall
Getting ready
How to do it…
Configuring a firewall on a server
Configuring a firewall on a client
See also
3. Integrating WebRTC
Introduction
Integrating WebRTC with Asterisk
Getting ready
How to do it…
Installing libSRTP
Installing Asterisk
How it works…
There's more…
See also
Integrating WebRTC with FreeSWITCH
Getting ready
How to do it…
Installing FreeSWITCH
Enabling WebRTC
Starting FreeSWITCH
How it works…
There's more…
See also
Making calls from a web page
Getting ready
How to do it…
Installing sipML5
How it works…
There's more…
See also
Integration of WebRTC with web cameras
Getting ready
How to do it…
Configuring the webcam
Installing WebRTC media server
Time for magic
How it works…
There's more…
4. Debugging a WebRTC Application
Introduction
Working with a WebRTC statistics API
Getting ready
How to do it…
Checking estimated bandwidth
Checking packet loss
How it works…
There's more…
See also
Debugging with Chrome
Getting ready
How to do it…
Using webrtc-internals
Using Chrome logging mechanism
How it works…
There's more…
See also
Debugging TURN
Getting ready
How to do it…
How it works…
There's more…
See also
Debugging using Wireshark
Getting ready
How to do it…
How it works…
There's more…
See also
5. Working with Filters
Introduction
Working with colors and grayscale
How to do it…
How it works…
Working with brightness
How to do it…
How it works…
Working with contrast
How to do it…
How it works…
Working with saturation
How to do it…
How it works…
Working with hue
How to do it…
How it works…
Using the sepia filter
How to do it…
How it works…
Using the opacity filter
How to do it…
How it works…
Inverting colors
How to do it…
How it works…
Implementing the blur effect
How to do it…
How it works…
Implementing the dropped shadow effect
How to do it…
How it works…
Combining filters
How to do it…
How it works…
Custom video processing
How to do it…
How it works…
6. Native Applications
Introduction
Building a customized WebRTC demo for iOS
Getting ready
How to do it…
There's more…
Building a demo project for a iOS simulator
See also
Compiling and running an original demo for iOS
Getting ready
How to do it…
Building a demo project for an iOS device
Building a demo project for an iOS simulator
There's more…
See also
Compiling and running a demo for Android
Getting ready
Preparing the system
Installing Oracle JDK
Getting the WebRTC source code
Installing Android Developer Tools
How to do it…
Running on the Android simulator
Fixing a bug with GLSurfaceView
Running on a physical Android device
There's more…
See also
Building an OpenWebRTC library
Getting ready
How to do it…
There's more…
7. Third-party Libraries
Introduction
Building a video conference using SimpleWebRTC
Getting ready
How to do it…
How it works…
There's more…
Creating an application using RTCMultiConnection
Getting ready
How to do it…
How it works…
There's more…
Developing a simple WebRTC chat using PeerJS
Getting ready
How to do it…
How it works…
There's more…
Making a simple video chat with rtc.io
Getting ready
How to do it…
How it works…
There's more…
Using OpenTok to create a WebRTC application
Getting ready
How to do it…
How it works…
There's more…
Creating a multiuser conference using WebRTCO
Getting ready
How to do it…
How it works…
There's more…
8. Advanced Functions
Introduction
Visualizing a microphone's sound level
Getting ready
How to do it…
How it works…
See also
Muting a microphone
Getting ready
How to do it…
How it works…
There's more…
See also
Pausing a video
Getting ready
How to do it…
How it works…
See also
Taking a screenshot
Getting ready
How to do it…
How it works…
See also
Streaming media
Getting ready
How to do it…
How it works…
See also
Index

WebRTC Cookbook

WebRTC Cookbook

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: February 2015

Production reference: 1200215

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78328-445-0

www.packtpub.com

Credits

Author

Andrii Sergiienko

Reviewers

Pasquale Boemio

Jose López

Marcos de Vera Piquero

Commissioning Editor

Usha Iyer

Acquisition Editor

Sam Wood

Content Development Editor

Rahul Nair

Technical Editor

Siddhi Rane

Copy Editor

Neha Vyas

Project Coordinator

Judie Jose

Proofreaders

Ting Baker

Simran Bhogal

Maria Gould

Paul Hindle

Indexer

Hemangini Bari

Production Coordinator

Melwyn Dsa

Cover Work

Melwyn Dsa

About the Author

Andrii Sergiienko is a computer software developer from Ukraine and is passionate about information technologies. From his early childhood, he was interested in computer programming and hardware. He took his first step into these fields more than 20 years ago. He has experience of a wide set of languages and technologies including C, C++, Java, assembly language, Erlang, JavaScript, PHP, Riak, shell scripting, computer networks, and security.

During his career he worked for both small, local companies such as domestic ISP and large, worldwide corporations such as Hewlett Packard. He also started his own projects—some of them were relatively successful.

Today, he is the owner and inspirer of OSLIKAS OÜ, a computer software company with headquarters in Estonia. The company (http://www.oslikas.com) focuses on modern IT technologies and solutions.

Working on this book was a really great and interesting experience for me. All this would be impossible without the help of certain people. And now is the time for me to say thank you to them.

First of all, I would like to thank my parents Olga and Alexander for my happy childhood that established the foundation for my life and career.

I would like to say thank you to my wife Inna for her patience, encouragement, and support during this process.

I would like to thank the Packt Publishing team as well. These guys are doing really great work and making the world a better place. We contacted some of them directly during the work, and others stayed behind the scenes. However, I know that a lot of people spent part of their lives to make this book possible. Thank you all.

About the Reviewers

Pasquale Boemio fell in love with Linux and the open source philosophy at the age of 12. Following this passion, he studied computer engineering at University of Naples Federico II from where he graduated with a master's degree.

Currently, he is working as a researcher in the Department of Electrical Engineering and Information Technology (DIETI) in the University of Naples Federico II, contributing to the development of real-time communication technologies. His efforts in this field are concretized by supporting the Meetecho project (www.meetecho.com).

Meetecho is a university spin-off and a tool for the collaborative work currently used by the Internet Engineering Task Force (IETF) to provide remote participation to the working groups. Meetecho leverages some state-of-the-art technologies (such as WebRTC and Docker) to implement a comprehensive architecture that can be lightweight and portable. Meetecho's best project is the Janus WebRTC Gateway (http://janus.conf.meetecho.com/), mentioned later in this book, which allows a user the ability to integrate different, real-time technologies without any pains.

In his spare time, Pasquale works on some personal open source projects (https://github.com/helloIAmPau) and helps the community by giving his contributions to cool projects found on the GitHub platform.

He has already worked with Packt Publishing by reviewing WebRTC Integrator's Guide, a useful guide for anyone who needs to integrate WebRTC with a retro technology such as SIP.

Jose López was born in Galicia, Spain. He is a telecommunications engineer with a large amount of experience in software development, and is also focused on real-time audio/video communications. He started working for Quobis Networks in 2013, a leading company in WebRTC solutions.

Marcos de Vera Piquero is a software engineer who has mainly worked with Python and CoffeeScript. His area of development is now focused on the server side of real-time multimedia applications at Quobis, his current employer. He's also a free software enthusiast and is trying to make it a real alternative.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

WebRTC is a relatively new and revolutionary technology that opens new horizons in the area of interactive applications and services. Most of the popular web browsers support it natively (such as Chrome and Firefox) or via extensions (such as Safari). Mobile platforms such as Android and iOS allow you to develop native WebRTC applications.

This book covers a wide set of topics on how to develop software using a WebRTC stack. Using practical recipes, it considers basic concepts, security, debugging, integration with other technologies, and other important themes of the development process in a friendly manner.

You will not only learn about WebRTC-specific features, but also attendant technologies (CSS3, HTML5, and WebSockets), and how to use them along with WebRTC.

What this book covers

Chapter 1, Peer Connections, introduces you to the very basic concepts of WebRTC. This includes practical recipes on peer connections. You will also find simple demo applications in this chapter.

Chapter 2, Supporting Security, leads you through various security-related topics and covers how to secure a typical WebRTC application's infrastructure components: SSL/TLS certificates, WebSockets, web servers, STUN/TURN, data channels, and more.

Chapter 3, Integrating WebRTC, considers integrating a WebRTC application with other technologies and third-party software. This chapter describes practical cases and solutions on integration.

Chapter 4, Debugging a WebRTC Application, is dedicated to application debugging—an important topic of the software development process. In this chapter, you will learn about the topics relating to debugging in the scope of WebRTC.

Chapter 5, Working with Filters, teaches you how to use CSS3 filters with WebRTC applications. This chapter also covers custom image processing.

Chapter 6, Native Applications, contains practical, step-by-step recipes dedicated to developing native WebRTC applications on mobile platforms.

Chapter 7, Third-party Libraries, describes general use cases and practical solutions based on third-party WebRTC frameworks and services.

Chapter 8, Advanced Functions, covers how to use advanced WebRTC features. It contains practical recipes on file transferring, streaming, audio/video controlling, and more.

What you need for this book

To use the recipes and codes provided and considered in this book, you will need a few pieces of software installed:

Java SE 7: Note that for Android-related recipes from Chapter 6, Native Applications, you need Java SE 6 as well—the installation and configuration process is described in detail in this chapter.Erlang OTP 17: If you're familiar with this programming language, you can use this. If not, you can skip it—all Erlang examples are also provided in Java.Mac OS X and Xcode: Use this for recipes dedicated to developing WebRTC applications on iOS.Android and iOS: Use this for Chapter 6, Native Applications, which covers how to develop WebRTC applications for mobile platforms.Linux: Ubuntu is recommended.Chrome and Firefox: These are still the most WebRTC-friendly web browsers.

Specific requirements and configurations along with suggested solutions are considered in particular chapters.

Who this book is for

This book is written as a set of ready-to-use, practical recipes that cover a variety of topics related to developing WebRTC applications and services. It is assumed that you are familiar, in general, with WebRTC and its basic concepts.

Most of the provided recipes are written in JavaScript. However, server-side parts of applications are implemented in Erlang and Java. So, you are assumed to have at least basic experience with one of these technologies.

Working on some cases described in this book, you will have to deal with a Linux-based OS. All recipes are provided as a step-by-step guide. Although, if you have experience of working with and configuring Linux-based boxes, it would be useful.

So, this book is for someone who is familiar, in general, with the WebRTC stack, and who has at least basic skills in software development.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/4450OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the ErrataSubmissionForm link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Peer Connections

In this chapter, we will cover the following topics:

Building a signaling server in ErlangBuilding a signaling server in JavaDetecting WebRTC functions supported by a browserMaking and answering callsImplementing a chat using data channelsImplementing a chat using a signaling serverConfiguring and using STUNConfiguring and using TURN

Introduction

This chapter covers the basic concepts of how to use WebRTC when developing rich media web applications and services.

With simple and short recipes, you will learn how to create your own signaling server. The key data that needs to be exchanged by peers before they establish a direct connection is called the session description—it specifies the peers' configuration. Signaling server is a component in an application's infrastructure that is accessible by all peers and serves to exchange multimedia's session description. The way peers should exchange data is not described by WebRTC standards, so you should make the decision on your own regarding the protocol and mechanism you will use for this task.

You can build a signaling server using any programming language and technology you like. In general, the signaling protocol can be non-technical and is possible to implement in away where the peers would use just a sheet of paper to exchange necessary data between each other. In this chapter, we use WebSocket to implement signaling, although you can use any other protocol.

The signaling stage is represented in the schema that is shown in the following diagram:

In this chapter, you will find two recipes that are dedicated to signaling server development: Building a signaling server in Erlang and Building a signaling server in Java. Java is probably the most popular and known technology, and it would be easy to get into this topic using Java, even if you don't have programming experience with this technology. Erlang is not widely known yet. Nonetheless, this is a very mature technology, very suitable for writing lightweight and extremely fast server applications with perfect scalability. So, by learning signaling server, you will find simple solutions in Erlang as well.

This chapter also covers the basic use case of how to use WebRTC data channels: file transferring and peer-to-peer chat.

You will also learn how to configure and use Session Traversal Utilities for NAT (STUN) and Traversal Using Relays around NAT (TURN) services, and of course, this chapter covers making peer-to-peer calls using WebRTC.

Note that in this chapter, we will cover the process of making computer-to-computer calls. If you want to know more about how to use WebRTC with VoIP and SIP, and how to make phone calls from a web page, refer to the Chapter 3, Integrating WebRTC.