PeerJS - WebRTC video chat

PeerJS is a service which makes it easier to build a chat room using the upcoming present WebRTC's PeerConnection API. The PeerConnection API proposes to be able to send data, video etc from one user-agent to another without the need for it going through a server. PeerJS handles this handshake with a simple Socket.IO backend server.

Demo Code

The above demo takes just a few steps to implement. Firstly embed the Peer.JS script

Next, create a unique id with Math.random() for the chat room, you could hard code this if you like, but anyway, i'm generating it like so...

connect with video. Call the library Peer and invoke a new session. Append the video tag (defined by the id 'myvideo'). Connect to the "room" we spoke about earlier. Then listen for new media streams from other people in the same chat room.

send data Send data to the room. createDataChannel has been proposed but is not implemented. The relay server works pretty well though

Lastly, because chatting to yourself can bring about men in white coats, i've added a link to share the page with friends (to test you can just open in a new tab).

[Optionally]. If the user-agent doesn't support WebRTC then lets so something