title: Build a Zoom Clone with Node JS (peer to peer connection)
body: <p>I have tried to create zoom clone using nodejs i have successfully displayed my video in the web page and created id for each person joining the link but while displaying the joined person in the main page is not working.</p>
  <p>I'm use peerjs library to call the user and display him in the web page.</p>
  <p><strong>server.js</strong></p>
  <pre><code>const express = require('express');
  
  const app = express();
  
  const server = require('http').Server(app);
  
  const io = require('socket.io')(server);
  
  const {v4:uuidv4} = require('uuid');
  
  const { ExpressPeerServer} = require('peer');
  
  const peerServer = ExpressPeerServer(server, {
      debug:true
  });
  
  const { response } = require('express');
  
  app.use('/peerjs',peerServer);
  
  app.set('view engine','ejs');
  app.use(express.static('public'))
  
  
  app.get('/', (req, res) =&gt; {
      res.redirect(`/${uuidv4()}`);
  })
  
  
  app.get('/:room',(req, res)=&gt;{
      res.render('room',{ roomId:req.params.room })
  })
  
   io.on('connection', socket =&gt; {
      socket.on('join-room' , (roomId,userId) =&gt; {
          socket.join(roomId);
          socket.to(roomId).broadcast.emit('user-connected',userId);
       })
  })
  
  server.listen(3035);
  
  </code></pre>
  <p><strong>room.ejs</strong></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;title&gt;Zoom CLone&lt;/title&gt;
      &lt;script src=&quot;https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;/socket.io/socket.io.js&quot;&gt;&lt;/script&gt;
      &lt;script&gt;
          const ROOM_ID = &quot;&lt;%= roomId %&gt;&quot;
      &lt;/script&gt;
      &lt;style&gt;
          #video-grid{
              display: flex;
              justify-content: center;
  
          }
          video{
              height: 300px;
              width: 400px;
              object-fit: cover;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id=&quot;video-grid&quot;&gt;&lt;/div&gt;
      &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;    
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>script.js</strong></p>
  <pre><code>const socket = io('/')
  const videoGrid = document.getElementById('video-grid');
  const myVideo=document.createElement('video');
  myVideo.muted = true;
  
  var peer = new Peer(undefined, {
      host:'/',
      port:'3031'
  })
  // const peer = new Peer(undefined, {
  //     path: '/peerjs',
  //     host: '/',
  //     port: '3001'
  //   })
  
  peer.on('open',id =&gt; {
      socket.emit('join-room', ROOM_ID, id);
  })
  
  let myVideoStream
  navigator.mediaDevices.getUserMedia({
      video:true,
      audio:true
  }).then(stream =&gt; {
      myVideoStream=stream;
      addVideostream(myVideo,stream)
  
      peer.on('call', call =&gt; {
          call.answer(stream)
          const video = document.createElement('video')
          call.on('stream',userVideoStream =&gt; {
              addVideoStream(video, userVideoStream)
          })
      })
      socket.on('user-connected',(userId) =&gt; {
          connectToNewUser(userId, stream);
      })
  })
  
  
    
  const connectToNewUser = (userId, stream) =&gt; {
      const call = peer.call(userId, stream)
      const video = document.createElement('video')
      call.on('stream', userVideoStream =&gt; {
          addVideostream(video, userVideoStream)
      })
      call.on('close', () =&gt; {
        video.remove()
      })
  }
  
  const addVideostream = (video,stream) =&gt;{
      video.srcObject = stream;
      video.addEventListener('loadedmetadata',() =&gt; {
          video.play();
      })
      videoGrid.append(video);
  }
  </code></pre>
  <p>there is also no error in the code, I also checked in the console.
  Only problem is the person connected with the link video is not displayed on the main(Host) page.</p>