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