Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning WebRTC

You're reading from  Learning WebRTC

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781783983667
Pages 186 pages
Edition 1st Edition
Languages
Author (1):
Daniel M. Ristic Daniel M. Ristic
Profile icon Daniel M. Ristic

Table of Contents (16) Chapters

Learning WebRTC
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with WebRTC 2. Getting the User's Media 3. Creating a Basic WebRTC Application 4. Creating a Signaling Server 5. Connecting Clients Together 6. Sending Data with WebRTC 7. File Sharing 8. Advanced Security and Large-scale Optimization Answers to Self-test Questions Index

Identifying users


In a typical web application, the server will need a way to identify between connected clients. Most applications today use the one-identity rule and have each user login to a respective string-based identifier known as their username. We will also be using the same rule in our signaling application. It will not be as sophisticated as some of the methods used today since we will not even require a password from the user. We simply need an ID for each connection so we know where to send messages.

To start, we are going to change our connection handler a bit, to look similar to this:

connection.on(''message'', function (message) {
    var data;

    try {
      data = JSON.parse(message);
    } catch (e) {
      console.log(""Error parsing JSON"");
      data = {};
    }
});

This will change our WebSocket implementation to only accept JSON messages. Since WebSocket connections are limited to strings and binary data, we need a way to send structured data across the wire. JSON...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}