-
Notifications
You must be signed in to change notification settings - Fork 2.1k
useScreenCapture fixes #5793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
useScreenCapture fixes #5793
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff output filesdiff --git a/packages/@uppy/components/lib/hooks/screencapture.js b/packages/@uppy/components/lib/hooks/screencapture.js
index 9c3456c..6fde81e 100644
--- a/packages/@uppy/components/lib/hooks/screencapture.js
+++ b/packages/@uppy/components/lib/hooks/screencapture.js
@@ -44,10 +44,10 @@ export function createScreenCaptureController(uppy, onSubmit) {
const getVideoProps = () => {
const ref = document.getElementById(videoId);
const {
- status,
recordedVideo,
capturedScreenshotUrl,
} = plugin.getPluginState();
+ const status = plugin.getStatus();
if (status === "captured" && recordedVideo) {
if (ref) {
ref.srcObject = null;
@@ -86,45 +86,33 @@ export function createScreenCaptureController(uppy, onSubmit) {
};
};
const getScreenshotButtonProps = () => {
- const {
- status,
- } = plugin.getPluginState();
return {
type: "button",
onClick: async () => {
await plugin.captureScreenshot();
},
- disabled: status !== "ready",
+ disabled: plugin.getStatus() !== "ready",
};
};
const getRecordButtonProps = () => {
- const {
- status,
- } = plugin.getPluginState();
return {
type: "button",
onClick: () => {
plugin.startRecording();
},
- disabled: status !== "ready",
+ disabled: plugin.getStatus() !== "ready",
};
};
const getStopRecordingButtonProps = () => {
- const {
- status,
- } = plugin.getPluginState();
return {
type: "button",
onClick: () => {
plugin.stopRecording();
},
- disabled: status !== "recording",
+ disabled: plugin.getStatus() !== "recording",
};
};
const getSubmitButtonProps = () => {
- const {
- status,
- } = plugin.getPluginState();
return {
type: "button",
onClick: () => {
@@ -132,19 +120,16 @@ export function createScreenCaptureController(uppy, onSubmit) {
plugin.stop();
onSubmit == null || onSubmit();
},
- disabled: !(status === "captured"),
+ disabled: plugin.getStatus() !== "captured",
};
};
const getDiscardButtonProps = () => {
- const {
- status,
- } = plugin.getPluginState();
return {
type: "button",
onClick: () => {
plugin.discardRecordedMedia();
},
- disabled: !(status === "captured"),
+ disabled: plugin.getStatus() !== "captured",
};
};
const getSnapshot = () => ({
diff --git a/packages/@uppy/screen-capture/lib/ScreenCapture.d.ts b/packages/@uppy/screen-capture/lib/ScreenCapture.d.ts
index fe4ac0c..f4ec6b7 100644
--- a/packages/@uppy/screen-capture/lib/ScreenCapture.d.ts
+++ b/packages/@uppy/screen-capture/lib/ScreenCapture.d.ts
@@ -42,7 +42,6 @@ export type ScreenCaptureState = {
recordedVideo: string | null;
screenRecError: string | null;
capturedScreenshotUrl: string | null;
- status: ScreenCaptureStatus;
};
export default class ScreenCapture<M extends Meta, B extends Body> extends UIPlugin<Opts, M, B, ScreenCaptureState> {
static VERSION: any;
@@ -66,6 +65,7 @@ export default class ScreenCapture<M extends Meta, B extends Body> extends UIPlu
constructor(uppy: Uppy<M, B>, opts?: ScreenCaptureOptions);
install(): null | undefined;
uninstall(): void;
+ getStatus(): ScreenCaptureStatus;
start(): Promise<void>;
selectVideoStreamSource(): Promise<MediaStream | false>;
selectAudioStreamSource(): Promise<MediaStream | false>;
diff --git a/packages/@uppy/screen-capture/lib/ScreenCapture.js b/packages/@uppy/screen-capture/lib/ScreenCapture.js
index eeeee1d..abec826 100644
--- a/packages/@uppy/screen-capture/lib/ScreenCapture.js
+++ b/packages/@uppy/screen-capture/lib/ScreenCapture.js
@@ -86,7 +86,6 @@ export default class ScreenCapture extends UIPlugin {
recordedVideo: null,
screenRecError: null,
capturedScreenshotUrl: null,
- status: "init",
});
}
install() {
@@ -97,7 +96,6 @@ export default class ScreenCapture extends UIPlugin {
this.setPluginState({
streamActive: false,
audioStreamActive: false,
- status: "init",
});
const {
target,
@@ -113,6 +111,20 @@ export default class ScreenCapture extends UIPlugin {
}
this.unmount();
}
+ getStatus() {
+ const {
+ recording,
+ recordedVideo,
+ capturedScreenshotUrl,
+ screenRecError,
+ streamActive,
+ } = this.getPluginState();
+ if (recording) return "recording";
+ if (recordedVideo || capturedScreenshotUrl) return "captured";
+ if (screenRecError) return "error";
+ if (streamActive) return "ready";
+ return "init";
+ }
start() {
if (!this.mediaDevices) {
return Promise.reject(new Error("Screen recorder access not supported"));
@@ -139,14 +151,12 @@ export default class ScreenCapture extends UIPlugin {
});
this.setPluginState({
streamActive: true,
- status: "ready",
screenRecError: null,
});
return videoStream;
}).catch(err => {
this.setPluginState({
screenRecError: err,
- status: "error",
});
this.userDenied = true;
setTimeout(() => {
@@ -202,13 +212,11 @@ export default class ScreenCapture extends UIPlugin {
this.recorder.start();
this.setPluginState({
recording: true,
- status: "recording",
});
}).catch(err => {
this.uppy.log(err, "error");
this.setPluginState({
screenRecError: err.message,
- status: "error",
});
});
}
@@ -223,9 +231,6 @@ export default class ScreenCapture extends UIPlugin {
if (this.parent && this.parent.hideAllPanels) {
this.parent.hideAllPanels();
}
- this.setPluginState({
- status: "init",
- });
} else if (recording) {
this.uppy.log("Capture stream inactive — stop recording");
this.stopRecording();
@@ -253,7 +258,6 @@ export default class ScreenCapture extends UIPlugin {
this.capturedMediaFile = file;
this.setPluginState({
recordedVideo: URL.createObjectURL(file.data),
- status: "captured",
});
}).then(() => {
this.recordingChunks = null;
@@ -279,7 +283,6 @@ export default class ScreenCapture extends UIPlugin {
this.setPluginState({
recordedVideo: null,
capturedScreenshotUrl: null,
- status: this.getPluginState().streamActive ? "ready" : "init",
});
}
submit() {
@@ -337,7 +340,6 @@ export default class ScreenCapture extends UIPlugin {
audioStreamActive: false,
recordedVideo: null,
capturedScreenshotUrl: null,
- status: "init",
});
this.captureActive = false;
}
@@ -416,7 +418,6 @@ export default class ScreenCapture extends UIPlugin {
const screenshotUrl = URL.createObjectURL(blob);
this.setPluginState({
capturedScreenshotUrl: screenshotUrl,
- status: "captured",
});
resolve();
} catch (err) { |
Murderlon
approved these changes
Jun 26, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR encorporates changes suggested in #5791 , into screen-capture plugin.