Peer.js Enhances WebRTC, Allows For Peer-To-Peer Connections In The Browser
Peer.js – Client-Side with Server-Side-Support
Peer.js wraps WebRTC and allows for establishing peer connections between two clients based on unique IDs. The system needs a server-side installation, the so-called PeerServer, which can be established using node.js. On the client-side Peer.js is integrated as a library. The PeerServer is only needed to connect the peers, any communication that occurs after connect happens directly between the peers.
As WebRTC only sees lukewarm support even in Chrome, Peer.js today is nothing more than an experiment. Its perspectives are good though. I would go as far as proclaiming that its success is a mere matter of time. At least as far as the functionality is concerned. If it will be exactly Peer.js or coming under a different name still has to be seen..
Right at this moment the project has not a lot more to offer than a demo of a chat. You’ll need to know and enter the above-mentioned unique ID to connect. Handling of IDs would be a matter of programming of course, so let’s not bemoan this demo as desultory. As the project is a hatchling, a little patience should be expectable.
Peer.js – Basic Mode of Operation
Integration of Peer.js is no big thing. The bigger thing is to constitute the PeerServer. On the side of the client the script is implemented like this:
A peer gets defined this way:
And the peer with the desire to connect shows up like this:
If you want to approach Peer.js without having to put lots of effort into it, you will want to omit to establish a PeerServer on your own behalf. Thanks to the developers of Peer.js you can. They offer a PeerServer as a cloud service, free of charge for developers.
If you get eager to build your own eMule environment that way, calm down. The size of data to be shared via Peer.js is extremely limited. Only sizes less than 1 kB are working, yet not even reliably. Don’t blame Peer.js though. This is another flaw in the browser implementation of WebRTC.
- PeerJS — True peer-to-peer data in the browser | Peer.js Homepage
- PeerJS API Reference | Peer.js Github
- PeerJS: Peer-to-peer data in the browser | Peer.js Github
- WebRTC Specification | WebRTC.org