This repository contains some HTML5 experiments using WebRTC and WebSockets.
-
Install WebSocket-Node:
npm install websocket
-
Start the web server
node ws/server.js [host][:port]
(defaults to127.0.0.1:8090
) -
Open a browser and navigate to http://host:port (default: http://localhost:8090)
-
Open another window and do the same.
-
Press call from one of the windows.
-
Talk to yourself or a colleague.
-
Hang up
-
Web socket connection created to support exchanging signaling messages (the "signaling socket"). I use WebSocket-Node for the server and at present the server supports two users at once.
-
One of two users initiates a call by pressing a button (say Alice)
-
Alice's
start
function is called is with initiator set to true -
Alice creates a peer connection and an offer
-
The resulting session description (containing the offer) is sent via the signaling socket to Bob (message type is "offer")
-
Bob receives the message and calls
start
with initiator not set -
Bob sets his peer connection's remote description to the description just received and then creates an answer.
-
The resulting session description is sent to Alice with message type set to "answer".
-
Alice receives the answer and sets her peer connection's remote description to the received description.
Any time the remote description is set on a peer connection, the onaddstream
will fire as soon as possible. In this example, the audio elements source will
be set to the passed stream in that callback.
onremovestream
is called when a stream is removed and the remote description
is set again. It is not used in this example.
See WebRTC draft for all the gory details.
I believe that while the above signaling exchange is happening, Alice and Bob also exchange ICE candidates and try to find an a transport address that "works." This is a complex topic: see RFC 5245. Also useful is An Offer/Answer Model with the Session Description Protocol (SDP)
This implementation uses WebRTC Basics from HTML5 Rocks as a guide and ultimately the webrtc-samples project form Google.
These two demos were my main guides:
- https://code.google.com/p/webrtc-samples/source/browse/trunk/demos/html/pc1.html
- https://code.google.com/p/webrtc-samples/source/browse/trunk/apprtc/index.html
See the LICENSE file.