How to listen for “Stop sharing” click in Chrome DesktopCapture API

后端 未结 3 1786
囚心锁ツ
囚心锁ツ 2020-12-29 07:13

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

相关标签:
3条回答
  • 2020-12-29 08:04

    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.

    0 讨论(0)
  • 2020-12-29 08:16
    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) => {..});
    
    0 讨论(0)
  • 2020-12-29 08:17

    Now we have oninactive, You can use like this

    stream.oninactive = () => {}
    
    0 讨论(0)
提交回复
热议问题