Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen for "Stop sharing" click in Chrome DesktopCapture API

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".

Stop sharing Screenshot

I tried using the onended EventHandler of the MediaStream, but the MediaStream's ended property is still set to true after clicking on the button.

The only difference I could find between the stream (before and after clicking the button) is that the videoTracks.readyState is set to ended.

Edit: I would also like to notice if the user closes the window they were streaming before.

like image 432
wpp Avatar asked Aug 05 '14 14:08

wpp


People also ask

How do I stop screen sharing on Chrome?

When your session is complete, click the Stop sharing my screen button to stop sharing your screen with the associate. Then, click the End call icon to exit the Hangout.

How do I stop a screen share in Webrtc?

According to MediaStream API, the stop() function should be called to stop sharing.


1 Answers

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.

like image 67
wpp Avatar answered Sep 23 '22 06:09

wpp