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

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