Javascript – Handling camera permission when blocked mid stream

I want to handle a exception where the user allows the camera permission for video call but mid streaming to everyone, user decides to block permission through browser permissions.


function handleCameraPermission() {
  if (navigator.mediaDevices.getUserMedia) {
    // The browser supports `getUserMedia()`.
    navigator.mediaDevices.getUserMedia({
      video: true
    }).then(stream => {
      // The user has granted permission to access the camera.
      // Do something with the `stream` object.
      document.getElementById("video").srcObject = stream;
    }).catch(error => {
      // The user has denied permission to access the camera.
      // Display a message to the user explaining why they need to grant permission.
      alert("Please grant permission to access the camera in order to use this feature.");
    });
  } else {
    // The browser does not support `getUserMedia()`.
    // Display a message to the user explaining that their browser does not support this feature.
    alert("Your browser does not support the `getUserMedia()` method.");
  }
}

I have tried this code but this only works the first time when the user is asked for permission. I want to handle this exception at anytime. If there is any event which is triggered when the browser permission is blocked or any other way of handling this.