Fix pressing screenshare multiple times on Linux Wayland
This commit is contained in:
parent
f5a170818b
commit
ebf41fcf56
1 changed files with 12 additions and 3 deletions
|
@ -89,6 +89,8 @@ export type DesktopCapturerBaton = Readonly<{
|
|||
export class DesktopCapturer {
|
||||
private state: State;
|
||||
|
||||
private static getDisplayMediaPromise: Promise<MediaStream> | undefined;
|
||||
|
||||
private static isInitialized = false;
|
||||
|
||||
// For use as a key in weak maps
|
||||
|
@ -177,9 +179,15 @@ export class DesktopCapturer {
|
|||
private async getStream(): Promise<void> {
|
||||
liveCapturers.add(this);
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getDisplayMedia({
|
||||
// Only allow one global getDisplayMedia() request at a time
|
||||
if (!DesktopCapturer.getDisplayMediaPromise) {
|
||||
DesktopCapturer.getDisplayMediaPromise =
|
||||
navigator.mediaDevices.getDisplayMedia({
|
||||
video: true,
|
||||
});
|
||||
}
|
||||
const stream = await DesktopCapturer.getDisplayMediaPromise;
|
||||
DesktopCapturer.getDisplayMediaPromise = undefined;
|
||||
|
||||
const videoTrack = stream.getVideoTracks()[0];
|
||||
strictAssert(videoTrack, 'videoTrack does not exist');
|
||||
|
@ -219,6 +227,7 @@ export class DesktopCapturer {
|
|||
this.state = { step: Step.Error };
|
||||
} finally {
|
||||
liveCapturers.delete(this);
|
||||
DesktopCapturer.getDisplayMediaPromise = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue