Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entire screen sharing Media Stream getDiplayMedia()

I want to let the user share his screen, I use getDisplayMedia() to let the user start sharing and it let him choose entire screen or chrome … etc. so my question is: can I let the user always choose the entire screen, like not giving him the option of other type sharing like window … like putting constraints on it or something I tried displaySurface = 'monitor' but it didn't work

like image 437
fahmawiFloki Avatar asked Nov 28 '25 13:11

fahmawiFloki


1 Answers

You can do work around.

You can check displaySurface,if it is not monitor(entire screen) then you can reject the promise and inside reject handler you can stop and start again.

navigator.mediaDevices
  .getDisplayMedia()
  .then((strm) => {
    let displaySurface = strm.getVideoTracks()[0].getSettings().displaySurface;
    if (displaySurface !== 'monitor') {
      throw 'Selection of entire screen mandatory!';
    }
  })
  .catch((err) => console.error(err));//Here you can stop and start again
like image 200
Saptarsi Avatar answered Dec 02 '25 00:12

Saptarsi