I\'m currently writing a chrome extension which uses Chrome\'s DesktopCapture API. I\'m struggling to set a callback when someone clicks on \"Stop sharing\".
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.
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) => {..});
Now we have oninactive, You can use like this
stream.oninactive = () => {}