0

Here is an image

and width and height are not 0, but when i print it in console, it returns 0.

Here is code how I print it:

const video = document.getElementById("remoteVideo");
video.addEventListener('play', () => {
      setInterval(async () => {
      console.log(video.width);
      console.log(video.height);
      }, 100)
    });

Here is full html:

<!DOCTYPE html>
<html lang="en"></html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css">
      html { height: 100%; }
      body { height: 100%; margin: 0; background: #111; text-align: center; }
      #remoteVideo { height: 70%; margin-top: 5%; background: #000; }
      #localVideo { width: 20%; position: absolute; right: 1.1em; bottom: 1em; border: 1px solid #333; background: #000; }
      #callButton { position: absolute; display: none; left: 50%; font-size: 2em; bottom: 5%; border-radius: 1em; }
  </style>
  <script defer src="static/face-api.min.js"></script>

</head>
<body>

    <video id="localVideo" autoplay muted></video>
    <video id="remoteVideo" autoplay></video>
    <button id="callButton" onclick="createOffer()">✆</button>

    <script src="/socket.io/socket.io.js"></script>
    <script defer src="static/script.js"></script>
</body>
</html>

What am i doing wrong?

mplungjan
  • 169,008
  • 28
  • 173
  • 236

1 Answers1

0

You can use

getBoundingClientRect without the async

and here is how you could have posted your question in a Minimal, Reproducible Example using https://www.pexels.com/videos/

const video = document.getElementById("remoteVideo");
video.addEventListener('play', () => {
    console.log(video.getBoundingClientRect() );
});
html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  background: yellow;
  text-align: center;
}

#remoteVideo {
  height: 70%;
  margin-top: 5%;
  background: red;
}

#localVideo {
  width: 20%;
  position: absolute;
  right: 1.1em;
  bottom: 1em;
  border: 1px solid #333;
  background: pink;
}

#callButton {
  position: absolute;
  display: none;
  left: 50%;
  font-size: 2em;
  bottom: 5%;
  border-radius: 1em;
}
<video id="localVideo" src="https://player.vimeo.com/external/357005099.sd.mp4?s=a95b2118e2fa52097ad9933b56d50ebcc9f2f1c9&profile_id=139&oauth2_token_id=57447761" autoplay muted>Video</video>
<video id="remoteVideo" autoplay src="https://player.vimeo.com/external/340284081.sd.mp4?s=00350f6e127d8ac3777d74528fa439944f7d9f2c&profile_id=139&oauth2_token_id=57447761">Video</video>
<button id="callButton" onclick="createOffer()">Button ✆</button>
mplungjan
  • 169,008
  • 28
  • 173
  • 236