How to listen for "Stop sharing" click in Chrome DesktopCapture API
I solved this issue by assigning an EventHandler on the videoTrack's onended
property:
// somebody clicked on "Stop sharing" stream.getVideoTracks()[0].onended = function () { // doWhatYouNeedToDo(); };
As far as my edit goes (noticing a closing window): it also fires the event.
Now we have oninactive, You can use like this
stream.oninactive = () => {}
stream.onended = () => { // Click on browser UI stop sharing button console.info("Recording has ended");};
Where to get stream? Using adapter.js (making universal Promise based API across browsers):
navigator.mediaDevices.getUserMedia(..).then((stream) => {..});