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 ...

Get Learning WebRTC now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.