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

Hanging up a call


Our last bit is not part of the WebRTC specification, but is still a good feature to have—hanging up. This will allow our users to disconnect from another user so they are available to call someone else. This will also notify our server to disconnect any user references we have in our code. You can add the ""leave"" handler as detailed in the following code:

case ""leave"":
        console.log(""Disconnecting user from"", data.name);
        var conn = users[data.name];
        conn.otherName = null;

        if (conn != null) {
          sendTo(conn, {
            type: ""leave""
          });
        }

        break;

This will also notify the other user of the leave event so they can disconnect their peer connection accordingly. Another thing we have to do is handle the case of when a user drops their connection from the signaling server. This means we can no longer serve them and that we need to terminate their calls. We can change the close handler we used before to...