O'Reilly logo

WebRTC Cookbook by Andrii Sergiienko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing a simple WebRTC chat using PeerJS

In this recipe, we will use the PeerJS WebRTC framework to create a simple web chat concept by utilizing data channels.

Getting ready

PeerJS requires developers to register before they can use its API. During the registration process (it is free), a developer gets a unique ID that can be used to work with the API. If you would like to use this framework and don't mind registering, then visit its home page at http://peerjs.com.

How to do it…

Using PeerJS is really simple, and a basic example can be performed using just one HTML file. In the following steps, you will find such an index file with comments in all the important places:

  1. Place the standard HTML headers:
    <!DOCTYPE html> <html> <head lang="en"> <meta ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required