Book Image

PhoneGap By Example

Book Image

PhoneGap By Example

Overview of this book

Table of Contents (17 chapters)
PhoneGap By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Building a real-time communication application with PeerJS


Now, we can do the same, but with the help of the PeerJS library. In the previous example, you may notice that we can do a call only between two peers. In the following example, we will show you how we can initiate a call between more than two peers.

PeerJS is a wrapper for the browser's WebRTC implementation. It is aimed to simplify the peer-to-peer connection management. PeerJS provides a functionality to list the connected clients.

Server side

We will create a simple Node.js application with peer module. For example, we will add two modules: peer and ip. We can do this with the following commands:

$ npm install peer --save
$ npm install ip --save

After this installation, the package.json file might look like this:

{
  "name": "pumpidu-peerjs",
  "version": "0.0.0",
  "description": "Run a PeerJS WebRTC server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": ...