Answering a call

Answering the response is just as easy as offer. We follow a similar pattern and let the clients do most of the work. Our server will simply let any message pass through as answer to the other user. We can add this in after the offer handling case:

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

        if (conn != null) {
          connection.otherName = data.name;
          sendTo(conn, {
            type: ""answer"",
            answer: data.answer
          });
        }

        break;

You can see how similar the code looks in the preceding listing. Note, we are also relying on answer to come from the other user. If a user were to send answer first, instead of offer, it could potentially mess up our server implementation. There are many use cases where this ...

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.