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

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 server will not be sufficient enough, but it will work well for integration during the next chapter.

This should be a good start to the offer and answer...