Once a screen share is started by "navigator.mediaDevices.getDisplayMedia()" and confirmed by user, there is a posibility in each browser to stop a screen share (for example Chrome - see pic).
How to attach a javascript handler on the event, when a screen share is stopped by this browser button?
CodePudding user response:
Have a look at this sample here: https://github.com/webrtc/samples/blob/gh-pages/src/content/getusermedia/getdisplaymedia/js/main.js#L31
on line 31 an event handler is attached to MediaStreamTrack
stream.getVideoTracks()[0].addEventListener('ended', () => {
console.log('The user has ended sharing the screen');
});
CodePudding user response:
You can use oninactive
event.
stream.oninactive = function () {
// Do staff.
}