This project demonstrates a WebRTC connection between two HTML pages (index.html and index2.html). It is designed for debugging and understanding the fundamentals of WebRTC step by step.
- Overview
- Technical Explanation
- Project Setup
- How to Run the Project
- Usage Instructions
- Browser Compatibility
- Debugging Tools
The project involves establishing a peer-to-peer video connection using WebRTC. It includes functionalities to send offers, receive answers, manage ICE candidates, and dynamically change video resolutions.
- PeerConnection: The main object used to connect two peers (clients). It handles the connection and media streaming.
- ICE Candidates: Interactive Connectivity Establishment (ICE) candidates are network information that help establish a connection between peers. They are crucial for NAT traversal.
- Data Channel: A bi-directional channel that allows the transfer of arbitrary data between peers.
- Session Description Protocol (SDP): A format used to describe multimedia communication sessions, including codec, format information, and network data.
- Offer and Answer: The connection is initiated by sending an offer from
index.html. The offer is received byindex2.html, which responds with an answer. - ICE Candidates Exchange: After the answer is received, ICE candidates are exchanged between the two pages to establish the best possible connection.
- Video Streaming: Once the connection is established, video from
index.htmlis streamed toindex2.html. - Dynamic Resolution Change: The user can change the video resolution between 640p and 1080p using buttons provided in the interface.
To set up the project, ensure you have Node.js installed on your machine. The following packages are required:
- Express: A minimal and flexible Node.js web application framework.
- CORS: A package to enable Cross-Origin Resource Sharing.
-
Navigate to the directory where your
server.jsfile is located:cd path/to/your/project/server -
Install the required packages with:
npm install express cors
-
Ensure you are in the
serverdirectory:cd server -
Start the server:
node server.js
-
Open two browser tabs. In the first tab, open
index.htmllocated in thefrontend1directory. In the second tab, openindex2.htmllocated in the same directory.
- In
index.html, click the Send Offer button to initiate the WebRTC connection. - Switch to
index2.htmland click the Get Answer button to receive the offer and respond with an answer. - Back in
index.html, click Send ICE Candidate to send your ICE candidate to the server. - In
index2.html, click Get ICE Candidate to retrieve the ICE candidate from the server and add it to your connection. - You can get your ICE candidates in
index.htmlby clicking the Get ICE Candidate button. - Once connected, if you want to change the video resolution to 1080p, click the 1080p button in
index2.html. - In
index.html, click the corresponding button to adjust the video resolution.
This project has been developed and tested primarily in Google Chrome. Connection issues may arise when using other browsers. It's advisable to use Chrome for the best experience.
You can monitor the WebRTC connection status and view detailed logs using the built-in WebRTC Internals in Chrome. Access it by navigating to chrome://webrtc-internals/ in your browser.