const express = require('express'); const http = require('http'); const socketIo = require('socket.io'); const app = express(); const server = http.createServer(app); const io = socketIo(server); // Serve static files (HTML, JS) app.use(express.static(__dirname)); // Socket.io connection io.on('connection', (socket) => { console.log('A user connected'); socket.on('joinRoom', (data) => { socket.join(data.room); // Join the room }); // Handle offer socket.on('offer', (offer) => { socket.to('voice-room').emit('offer', offer); // Send the offer to the other user in the room }); // Handle answer socket.on('answer', (answer) => { socket.to('voice-room').emit('answer', answer); // Send answer to the other user }); // Handle ICE candidates socket.on('iceCandidate', (candidate) => { socket.to('voice-room').emit('iceCandidate', candidate); // Forward ICE candidate to the other user }); // Handle disconnect socket.on('disconnect', () => { console.log('A user disconnected'); }); }); // Start the server on port 3000 server.listen(3000, () => { console.log('Server is running on http://localhost:3000'); });