Building an Internet-Connected Phone with PeerJS

One of WebRTC's main issues is that it is pretty complicated to use and develop with — handling the signalling service and knowing when to call the right endpoint can get confusing. But there is some good news; PeerJS is a WebRTC framework that abstracts away all of the ice and signalling logic so that you can focus on the functionality of your application. There are two parts to PeerJS, the client-side framework and the server.

In this series of articles we will create a simple phone application using PeerJS. We’ll be using both the server and the client-side framework, but most of our work will be involved with handling the client-side code.

Prerequisites

This is an intermediate level tutorial; before attempting it you should already be comfortable with:

Before you get started, you'll want to make sure you've installed node and Yarn (the instructions in later articles assume Yarn, but you can feel free to use npm or annother manager if you'd prefer).

Note: If you learn better by following step-by-step code, we've also provided this tutorial in code, which you can use instead.

Table of Contents

  1. Setup
  2. Connect Peers
    1. Get Microphone Permission
    2. Showing and hiding HTML
    3. Create a Peer Connection
    4. Creating a Call
    5. Answer a Call
    6. End a Call
  3. Deployment and Further Reading

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Build_a_phone_with_peerjs