Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning WebRTC

You're reading from   Learning WebRTC Develop interactive real-time communication applications with WebRTC

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781783983667
Length 186 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel M. Ristic Daniel M. Ristic
Author Profile Icon Daniel M. Ristic
Daniel M. Ristic
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with WebRTC FREE CHAPTER 2. Getting the User's Media 3. Creating a Basic WebRTC Application 4. Creating a Signaling Server 5. Connecting Clients Together 6. Sending Data with WebRTC 7. File Sharing 8. Advanced Security and Large-scale Optimization A. Answers to Self-test Questions Index

Hanging up a call


The last feature we will implement is the ability to hang up an in-progress call. This will notify the other user of our intention to close the call and stop transmitting information. It will take just a few additional lines to our JavaScript:

hangUpButton.addEventListener("click", function () {
  send({
    type: "leave"
  });

  onLeave();
});

function onLeave() {
  connectedUser = null;
  theirVideo.src = null;
  yourConnection.close();
  yourConnection.onicecandidate = null;
  yourConnection.onaddstream = null;
  setupPeerConnection(stream);
};

When the user clicks on the Hang Up button, it will send a message to the other user and destroy the connection locally. There are a few things required to successfully destroy the connection and also allow another call to be made in the future:

  1. First off, we need to notify our server that we are no longer communicating.

  2. Secondly, we need to tell RTCPeerConnection to close, and this will stop transmitting our stream data to the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime