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""


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 ...

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.