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


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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.