Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
WebRTC Blueprints
WebRTC Blueprints

WebRTC Blueprints: Develop your very own media applications and services using WebRTC

eBook
€18.99 €27.99
Paperback
€35.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

WebRTC Blueprints

Chapter 2. Using the WebRTC Data API

This chapter introduces the Data API topic of the WebRTC technology. You will learn what the Data API is and how to use it to develop rich media applications. For practice, we will develop a simple, peer-to-peer file sharing application. You will also get a brief introduction on using the HTML5 File API.

Introducing the Data API


The WebRTC Data API introduces the RTCDataChannel entity, which enables direct data connections between peers (just like for audio and video media channels), as we learned in Chapter 1, Developing a WebRTC Application.

Used in pair with RTCPeerConnection and utilizing the ICE framework, it makes it possible to link up direct data connections through firewalls and NATs. The Data API can be used to build powerful, low-latency applications such as games, remote desktops, desktop sharing, real-time private text chats, peer-to-peer file sharing, and torrents.

Data channels in WebRTC have built-in security. They are usually even faster than WebSocket connections (browser-to-server), because connections proceed between browsers without any point in the middle. Nevertheless, if you turn on the server, data will be transmitted via the server (consuming additional bandwidth on the server side). Also, connection establishment using data channels takes longer than when using...

Introducing HTML5


In this book, we will use the HTML5 API to perform different tasks with JavaScript while developing our demo applications.

HTML5 itself is the latest standard for HTML and you can find its home page at http://www.w3.org/TR/html5/.

Its ancestor HTML 4.01 came in 1999, and the Internet has changed significantly since then. HTML5 was designed to deliver rich content without the need for additional plugins. The current version delivers everything, from animation to graphics, music to movies, and can also be used to build complicated web applications.

HTML5 is also designed to be cross-platform. It is designed to work irrespective of whether you are using a PC, a Tablet, a Smartphone, or a Smart TV.

We will use HTML5 while working on our WebRTC applications; in this chapter, we will start with the HTML5 File API.

Introducing the HTML5 File API


Data channels help us to transmit data (files) between peers. Nevertheless, it doesn't provide any mechanism to read and write files. So, we need some mechanism to be able to read/write files.

For the purpose of filesystem access, we will use the HTML5 File API. It provides a standard way to interact with local files. Using this API, you can create and read files, create thumbnails for image files, save application preferences, and more. You can also verify on the client side; if a customer wants to upload the MIME type of file, you can restrict the uploading by the file size.

When reading files, we will use the FileReader object. It reads files asynchronously and provides the following four ways (methods) to read them:

  • readAsBinaryString: This will read a file into a binary string. Every byte is represented by an integer in the range from 0 to 255.

  • readAsText: This reads the file as a text string. By default, the result string is decoded as UTF-8. You can use...

Known limitations


WebRTC and its Data API are supported by major web browsers. Nevertheless, the WebRTC standard is not yet complete and web browsers can still behave in different ways.

Chrome versions lower than 31 uses the RTP data channel type by default; Firefox uses SCTP by default in all versions.

At the time of writing these lines, Chrome still has some traits in the data channel's implementation. They limit channel bandwidth, which can cause unexpected effects. To fix it, you can use a hack described in this chapter.

With some browsers (not having fully compliant support of the WebRTC API), you can face the unexpected behavior while transmitting big-sized files that cause weird errors.

Nevertheless, all these cases are temporary. You can check the current status of the data channel's implementation on the WebRTC home page at http://www.webrtc.org/home.

Also, you can check the browser's home page for more detailed information on supporting the WebRTC API for a particular browser's version...

Preparing the environment


The whole structure of our application will be the same as in the previous chapter.

We need to create a folder for the new application, for example, filesharing_app. Again, create a subfolder for the HTML/JavaScript part, for example, filesharing_app/www.

We still need a signaling server, and in this chapter we won't introduce any new functionality on the server side. So, you can take the signaling server from the previous chapter. It will work fine for the new application that we're going to develop. You can just copy the signaling server from my_rtc_project/apps/rtcserver and paste it to filesharing_app/apps/.

We will also need the WebRTC API JavaScript adapter that we developed in the previous chapter. The adapter library can be used from the previous chapter with no change, so we need not pay much attention to it in this chapter.

So, take the signaling server application and the myrtcadapter.js library from the application we developed in the previous chapter.

A simple file-sharing service – the browser application


The client code of our new application is very similar to the previous application in some parts. Nevertheless, it will be significantly different in the core side, so we will rework it and discuss it in detail in this chapter.

The WebRTC API wrapper

We developed a wrapper for the WebRTC API in the previous chapter, so now it will be even easier to do the same for our new application. Now we will add some new code relevant to the Data API and for HTML5-specific API functions, which will be useful for file I/O operations, by performing the following steps:

  1. Create the www/myrtclib.js file as we already did in Chapter 1, Developing a WebRTC Application. We need to declare an entity to control the WebRTC peer connection API. Using the myrtcadapter.js library, we will detect the browser type and version, and assign a relevant API function to this entity.

  2. We also need to detect the web browser's version in order to handle it appropriately by...

Developing the main page of the application


As we did in the previous Chapter 1, Developing a WebRTC Application, we need an index.html page where we will implement the UI visible for customers and some additional JavaScript code to implement the client application. This can be done by performing the following steps:

  1. Create the index page at www/index.html as follows:

    <!DOCTYPE html>
    <html>
    <head>
        <title>My WebRTC file sharing application</title>
    <style type="text/css">
  2. Include the following two JavaScript libraries:

    </style>
        <script type="text/javascript" src="myrtclib.js"></script>
        <script type="text/javascript" src="myrtcadapter.js"></script>
    </head>
    
    <body onLoad="onPageLoad();">
    <div id='status'></div>
  3. Using this object, we will handle the list of files chosen by the customer. Using this list, we will send files one by one to the peer by using the following code:

    <div>
        <input...

Running the application


Now we're ready to test our file-sharing application. This can be done by performing the following steps:

  1. Go to the project's root folder and compile the signaling server using the following command:

    rebar clean
    rebar get-deps
    rebar compile
    
  2. If you're under the Linux box, start the signaling server using the following command:

    erl -pa deps/*/ebin apps/*/ebin -sasl errlog_type error -s rtcserver_app
    
  3. If you're using the Windows box, use the following command to start the signaling server:

    erl -pa deps/cowboy/ebin deps/cowlib/ebin deps/gproc/ebin deps/jsonerl/ebin deps/ranch/ebin apps/rtcserver/ebin -sasl errlog_type error -s rtcserver_app
    
  4. Now, point your web browser to the domain or IP address where the application is accessible. You should see two buttons and a link (URL). In the following screenshot, you can see Chrome and the main page of the application:

  5. Open the link in another web browser or any other computer; you should see a similar page there. I used Firefox...

Summary


We developed a simple peer-to-peer file-sharing application using the WebRTC DataChannel API. Using it, two peers can establish a direct connection between each other and send files to each other. You can choose just one file to transmit or you can select a list of files and they will be transmitted one by one.

You also got a brief practical introduction to the HTML5 File API and learned how to use it to work with the filesystem from JavaScript.

In the next chapter, we will delve deeply into the WebRTC API and develop an application that will be able to stream a prerecorded peer-to-peer video. This application will also be able to share a desktop to the remote peer.

Left arrow icon Right arrow icon

What you will learn

  • Create video conference web services that work without installing plugins or additional thirdparty software
  • Use ICE and STUN to pass through NAT and firewalls
  • Learn how to create and use direct peertopeer data channels to secure exchange data
  • Build a crossplatform signalling server for WebRTC applications
  • Work with user files from JavaScript code using the modern HTML5 File API
  • Install and configure your own TURN/STUN server
  • Integrate your application with a TURN server using authentication
  • Make your application more secure and safe using HTTPS
  • Develop your own secure web applications and services with practical projects

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 15, 2014
Length: 176 pages
Edition :
Language : English
ISBN-13 : 9781783983117
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 15, 2014
Length: 176 pages
Edition :
Language : English
ISBN-13 : 9781783983117
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 104.97
Getting Started with WebRTC
€26.99
WebRTC Blueprints
€35.99
WebRTC Integrator's Guide
€41.99
Total 104.97 Stars icon
Banner background image

Table of Contents

5 Chapters
Developing a WebRTC Application Chevron down icon Chevron up icon
Using the WebRTC Data API Chevron down icon Chevron up icon
The Media Streaming and Screen Casting Services Chevron down icon Chevron up icon
Security and Authentication Chevron down icon Chevron up icon
Mobile Platforms Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(9 Ratings)
5 star 66.7%
4 star 11.1%
3 star 11.1%
2 star 0%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




Lantre Barr Aug 13, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
WebRTC Blueprints is a hard core guide for building upon previous knowledge of WebRTC. While it's not for newbies, it goes in depth to show you how to get started with your first implementation of WebRTC from the ground up.It gives you step by step instructions using each element of the WebRTC API, to help you bring it all together at the end. WebRTC Blueprints takes it one step further by including mobile into the mix. Mobile still has a long way to go but it a good starting point for those interested in building native applications using WebRTC.Overall, I am pleased with WebRTC Blueprints and recommend it as read after you are familiar with WebRTC.--Lantre Barr, Founder & CEO of Blacc Spot Media - A WebRTC Development Agency in Atlanta, Ga
Amazon Verified review Amazon
Tsahi Levent-Levi Aug 05, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book isn't for those who are new to WebRTC.It is intended for those who have been playing with it a bit, have the basics covered and have written their first "hello world" example with WebRTC already.It takes a brave approach and covers issues that other books dealing with WebRTC today shy away from. This takes it to the cutting edge, which sometimes means the information found in the book would be a bit outdated (WebRTC hasn't finalized its spec yet).That said, this is the only book that handles the installation, configuration and security implications of deploying TURN servers and the use of WebRTC's screen casting technology.
Amazon Verified review Amazon
GSM Aug 13, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book for web developers wanting to get into the world of audio/video/data streaming using the open source webRTC technology.This is not for the newbie web programmer, and a previous knowledge on "communications" will help you navigating some of the more technical topics of the book (e.g. SDP,...) but the author provides a clear structure and it tries to simplify some of the complexities around streaming audio and video across the web, and it's related technologies.And it also covers mobile apps, which is a plus !
Amazon Verified review Amazon
howlowck Aug 13, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book throws you in the deep end from the get-go. At the end of the first chapter, you will have build a WebRTC application, something that is usually accomplished at the end of a book on WebRTC.The book uses Erlang, a language that only a percentage of web developers know about, to build its webRTC servers. So if you are only curious about webRTC, or only care about consuming webRTC on the client side, then this book is probably not right for you. If you don't know Erlang, you'd have to be comfortable with the language to know the server side. However for the concepts that the book explains, the content is very VERY thorough and does not keep any gaps in its explanation.
Amazon Verified review Amazon
ACE Jul 22, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's an excellent book on how to actually build your own WebRTC Server & Service from scratch. This book will put everything together if you have or have-not read any of the other WebRTC books. This book covers all of the required components to make it work. The best part is that everything is Open Source.I would re-arrange some of the chapters though. For example, the Introductory sections in Chapter 2, I believe, should be at the beginning of Chapter 1.The downside to this book is that the author assumes a certain level of Unix/Linux expertise. This book is definitely not for anyone at the beginner level. But, if you know what WebRTC or HTML5 is, then you should have some Unix experience under your belt. If its been awhile, then this is a good way to get reacquainted.I highly recommend this book. Again, it really does cover everything you'll need and how to do it. Depending on how much time you've got and your level of expertise, you could actually have a WebRTC Service up and running in a day to a week.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.