Skip to content

Commit

Permalink
fix(ScreenshotStream): do nothing when start() is called after record…
Browse files Browse the repository at this point in the history
…ing has started
  • Loading branch information
Nate Lanza committed May 23, 2024
1 parent 31a7795 commit c4ee691
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/core/src/provenance/screenshot-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,28 @@ export function intitializeScreenshotStream(): ScreenshotStream {
}
}

/**
* False if the MediaStream has not been initialized via start(), or has been stopped.
* True if we have a MediaStream and can capture screenshots.
* @returns Whether a screenshot can be captured.
*/
function canCapture(): boolean {
return video !== null;
}

/**
* Starts the media stream needed to capture screenshots on-demand.
* Will prompt the user for permission to capture the screen.
* Immediately captures a first screenshot.
* Does nothing if the stream is already started.
* @throws Error if unable to start the recording; usually due to the user denying permission.
* @param callback Optional callback to run after the stream is started.
*/
async function start(callback?: () => void): Promise<void> {
if (canCapture()) {
return;
}

video = document.createElement('video');
video.autoplay = true;
video.muted = true;
Expand Down Expand Up @@ -110,15 +124,6 @@ export function intitializeScreenshotStream(): ScreenshotStream {
}
}

/**
* False if the MediaStream has not been initialized via start(), or has been stopped.
* True if we have a MediaStream and can capture screenshots.
* @returns Whether a screenshot can be captured.
*/
function canCapture(): boolean {
return video !== null;
}

/**
* Captures a screenshot and stores it in the screenshots array.
* Also pushes the screenshot to the newScreenshotCallback if available.
Expand Down

0 comments on commit c4ee691

Please sign in to comment.