A simple WebRTC video chat application using Firebase for signaling.
- Node.js and npm installed (for local development, if needed)
- A Firebase project (Firestore enabled)
- Firebase SDK included in your project
- Modern web browser (Chrome, Firefox, Edge, Safari)
- Camera and microphone access enabled in browser
- Internet connection
- User opens the app and clicks "Open camera & microphone" to grant access and see their local video.
- Caller clicks "Create room" to start a new video chat room. The app creates a Firestore room and stores the SDP offer and ICE candidates.
- Callee clicks "Join room" and enters the room ID. The app retrieves the offer, sets up the peer connection, creates an SDP answer, and exchanges ICE candidates.
- Both users see each other's video once the WebRTC connection is established and media streams are exchanged.
- Hangup closes the connection and deletes the room from Firestore.
public/index.html: Main HTML file, UI for video chat and room controls.public/app.js: Main JavaScript logic for WebRTC, Firebase signaling, and UI event handling.public/main.css: Basic styles for the app.firebase.json: Firebase project configuration.database.rules.json: Firestore security rules.firebase-debug.log: Firebase debug log (if present).
- Clone the repository.
- Set up your Firebase project and update the Firebase config in your HTML/JS files.
- Make sure Firestore is enabled and security rules allow signaling.
- Open
index.htmlin your browser, or serve with a local server (e.g., MAMP, http-server).
- Open the app in two browser windows/devices.
- Click "Open camera & microphone" in both.
- One user clicks "Create room" and shares the room ID.
- The other user clicks "Join room" and enters the room ID.
- Both users should see each other's video.
To convert this project to use WebSockets for signaling instead of Firebase:
- Use Node.js with the
wslibrary or any backend that supports WebSockets. - The server should accept connections and relay signaling messages (SDP offers/answers, ICE candidates) between peers in the same room.
- Delete all Firebase imports and Firestore logic from your JavaScript.
- Remove Firestore room creation, candidate storage, and snapshot listeners.
- In your frontend (
app.js), connect to the WebSocket server:const socket = new WebSocket('ws://YOUR_SERVER_ADDRESS');
- Listen for messages:
socket.onmessage = (event) => { const data = JSON.parse(event.data); // Handle offer, answer, ICE candidate };
- Send signaling data:
socket.send(JSON.stringify({ type: 'offer', offer: offer, room: roomId })); socket.send(JSON.stringify({ type: 'answer', answer: answer, room: roomId })); socket.send(JSON.stringify({ type: 'candidate', candidate: candidate, room: roomId }));
- When creating/joining a room, use the WebSocket to send/receive offers, answers, and ICE candidates.
- The server should forward these messages to the correct peer(s) in the room.
- Implement simple room management on the server (e.g., keep a map of room IDs to connected clients).
- On the client, keep the room ID and use it in all signaling messages.
- Run the WebSocket server.
- Open the app in two browser windows/devices.
- Connect both clients to the same room via WebSocket.
- Verify video/audio connection works as before.
For questions or improvements, feel free to open an issue or pull request.