collab-project / videojs-record

video.js plugin for recording audio/video/image files
https://collab-project.github.io/videojs-record
MIT License
1.38k stars 313 forks source link

How to determine if the 'stop sharing button' is clicked #529

Open webdistortion opened 3 years ago

webdistortion commented 3 years ago

Feature request.

How to determine that someone clicked the stop sharing button From stackoverflow:

  // somebody clicked on "Stop sharing"
  stream.getVideoTracks()[0].onended = function () {
    // doWhatYouNeedToDo();
  };

Wondering if videojs-record currently exposes this, or if a pull request would be welcome to do so. I couldn't see a way in the documentation to achieve this, nor could I see where the stream was exposed in the Api? Is there a better method to achieve this?

Is this the relevant line number where a call to an event for this is necessary? https://github.com/collab-project/videojs-record/blob/master/src/js/videojs.record.js#L1606

thijstriemstra commented 3 years ago

Wondering if videojs-record currently exposes this, or if a pull request would be welcome to do so.

Sounds good!

thijstriemstra commented 3 years ago

Also see https://github.com/muaz-khan/RecordRTC/issues/583#issuecomment-565735551

YourMediaStream.getVideoTracks()[0].addEventListener(‘ended’, () => {
    /** any method you want to fire when the screen sharing is stopped */
});
squaloIT commented 3 years ago

Is this problem solved, still can't find a solution to this...

MauricioDinki commented 2 years ago

I found the solution, with a player like this

<video id="myScreen" playsinline class="video-js vjs-default-skin"></video>

Using the hook deviceReady you can catch the event

player.on('deviceReady', function () {
    const videoPlayer = document.getElementById('myScreen').getElementsByTagName('video')[0];
    const stream = videoPlayer.captureStream();
    stream.getVideoTracks()[0].addEventListener('ended', () => {
      close()
    })
  });
bilouStrike commented 7 months ago
// screen stream
try {
  const screenStream = await navigator.mediaDevices.getDisplayMedia(params);
  const videoTrack = screenStream.getVideoTracks()[0];
  videoTrack.onended = () => {
     yourCallBack(); // callback on user click on stop sharing
  };
} catch (error) {}