Javascript: how to stop a screen share of a window without stopping that windows's own screen share?

82 views Asked by At

I have a web app that combines a screen share (getDisplayMedia) along with a couple of different camera views (getUserMedia) to form a composite view. You can then share that window to another application, such as Zoom. I recently added a record capability as well (share entire window via getDisplayMedia, then record via MediaRecorder), and it is working just fine. The problem is when the recording ends, and I want to stop the sharing of the window - the "outer" screen share. I call stop() on the track(s) for that share, but unfortunately, this also ends the screen sharing within the window. So I now have a big black box within my nice composite view. I can restart it manually, but I'm looking to avoid that.

I have noticed the same happens if I try to record the window using a third-party screen recording app (e.g., Screencastify) instead of using my own recording facility, so I'm think it might not be solvable. Or if it is, the solution will possibly have to do with how I set up the "inner" screen share, not in how I set up the "outer" screen share or do the recording. But I am not finding any information on this.

I am using the following to stop the outer screen share:

displayStream.getTracks().forEach(track => track.stop());

I've also added log statements to show me the value of the tracks. There is only one track for this "outer" share, and it's not the same as the track for the "inner" share.

If I don't explicitly stop the outer share, all appears OK - the inner share looks fine on screen, but then my next recording doesn't work - the inner share is frozen. So presumably it is accessing some stale data. I haven't really explored this avenue much, though.

0

There are 0 answers