├── LICENSE ├── README.md ├── client.html ├── package.json ├── run-signaling-server.sh ├── signaling-server.js └── ssl ├── server-cert.pem ├── server-csr.pem └── server-key.pem /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | This is a "simple", but complete example of how to utilize WebRTC to do peer to 5 | peer voice and video chatting between two or more people. 6 | 7 | ### Server Side 8 | This example uses node.js and socket.io to create a "Signaling Server", which 9 | runs on (or near) your web server to manage who should talk to who. The purpose 10 | of the signaling server is to relay information between peers while you are 11 | setting them up to talk directly to each other. 12 | 13 | 14 | ### Client Side 15 | Included is `client.html` which contains all of the logic to connect to the 16 | signaling server, join a virtual group chat channel, connect with peers, and 17 | stream video and audio to all party members using the raw WebRTC API. 18 | 19 | 20 | Running 21 | ======= 22 | 23 | ### Node.js signaling server 24 | You'll need to install `node.js` for the signaling server portion of this code to run. 25 | 26 | Once node.js is installed, install the packages we need for this demo 27 | ``` 28 | npm install 29 | ``` 30 | 31 | Then simply run the signaling server: 32 | ``` 33 | npm run start 34 | ``` 35 | 36 | ### Running the sample 37 | All modern browsers require webrtc stuff to be run over SSL, so this sample uses 38 | a self signed certificate for the signaling server and host of client.html. Because 39 | of this, you'll be presented with a certificate warning when you open the page, simply 40 | click advanced to click accept and the browser should connect to your server. 41 | 42 | Head to https://localhost:8080/ , or if you are accessing the server from another device, 43 | simply replace `localhost` with the IP or hostname of the server (and click through all 44 | of the certificate warning stuff.) 45 | 46 | At this point you should be presented with a dialog asking permission to access 47 | your microphone / webcam. Once accepted, you should see a local stream appear 48 | on the page. Now open up the same page in another browser, on the same computer 49 | or another, and watch as the magic of WebRTC takes effect and both images and 50 | audio samples mysteriously move from one browser to the other. Repeat with as 51 | many browsers as you dare. 52 | 53 | 54 | Note: At the time of writing this, only firefox and chrome support WebRTC, 55 | however both browsers support this on Windows, Linux, Mac, and Android, so lots 56 | of fun can be had pointing everyones' phones, tablets, and laptops at that `client.html` 57 | and bogging down your network with audio/video traffic. 58 | 59 | 60 | Using things other than jQuery, node.js, and socket.io 61 | ============================================= 62 | The choice of node.js and socket.io is based purely on my familiarity with them 63 | and the fact that their fairly easy to understand even if you aren't familiar 64 | with them. However, you can use any mechanisms you want for your signaling system, you 65 | just need a way to exchange ICE candidates and session descriptions between 66 | clients. 67 | 68 | The use of jQuery is even less important, I just like using it for DOM 69 | manipulation, and we only do that to add and remove the