Book Image

Learning WebRTC

By : Daniel M. Ristic
Book Image

Learning WebRTC

By: Daniel M. Ristic

Overview of this book

Table of Contents (16 chapters)
Learning WebRTC
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling ICE candidates


The final piece of the WebRTC signaling puzzle is handling ICE candidates between users. Here, we use the same technique as before to pass messages between users. The difference in the candidate message is that it might happen multiple times per user and in any order between the two users. Thankfully, our server is designed in a way that can handle this easily. You can add this candidate handler code to your file:

case ""candidate"":
        console.log(""Sending candidate to"", data.name);
        var conn = users[data.name];

        if (conn != null) {
          sendTo(conn, {
            type: ""candidate"",
            candidate: data.candidate
          });
        }

        break;

Since the call is already set up, we do not need to add the other user's name in this function either. Go ahead and test this one on your own using the terminal WebSocket client. It should work similarly to the offer and answer functions, passing messages between the two.