You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This is a "simple", but complete example of how to utilize WebRTC to do peer topeer voice and video chatting between two or more people.
Server Side
This example uses node.js and socket.io to create a "Signaling Server", whichruns on (or near) your web server to manage who should talk to who. The purposeof the signaling server is to relay information between peers while you aresetting them up to talk directly to each other.
Client Side
Included isclient.html which contains all of the logic to connect to thesignaling server, join a virtual group chat channel, connect with peers, andstream video and audio to all party members using the raw WebRTC API.
Running
Node.js signaling server
You'll need to installnode.js as well as theexpress andsocket.io libraries:
npm install -g socket.io express
Then simply run the signaling server:
node signaling-server.js
Web server
You'll also probably want to hostclient.html on a web server somewhere. You'll needto editclient.html and changeYOURSERVERNAMEHERE to be the hostname or IP ofthe signaling server.
Note: you can also simply open the file locally instead of using a web server,but at the time of writing this only firefox will let you access thewebcam/microphone from a file hosted off of your local machine.
Running the sample
Now navigate to wherever you stuckclient.html and you should be presented witha dialog asking permission to access your microphone / webcam. Once accepted,you should see a local stream appear on the page. Now open up the same page inanother browser, on the same computer or another, and watch as the magic of WebRTC takeseffect and both images and audio samples mysteriously move from one browser to the other.Repeat with as many browsers as you dare.
Note: At the time of writing this, only firefox and chrome support WebRTC,however both browsers support this on Windows, Linux, Mac, and Android, so lotsof fun can be had pointing everyones' phones, tablets, and laptops at thatclient.htmland bogging down your network with audio/video traffic.
Using things other than jQuery, node.js, and socket.io
The choice of node.js and socket.io is based purely on my familiarity with themand the fact that their fairly easy to understand even if you aren't familiarwith them. However, you can use any mechanisms you want for your signaling system, youjust need a way to exchange ICE candidates and session descriptions betweenclients.
The use of jQuery is even less important, I just like using it for DOMmanipulation, and we only do that to add and remove the
Adapter.js
You'll seeclient.html useadapter.js. This "library" just normalizes theWebRTC API, which will only be necessary while WebRTC is making its way throughthe standards process. Once everything is standardized and functions arede-prefixed in the browsers, this won't be necessary anymore.
About
Small but complete example of how to use WebRTC to setup voice and/or video chat between 2+ people.