Skip to content

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 1 commit into from
Jun 26, 2025
Merged

Conversation

qxprakash
Copy link
Collaborator

This PR encorporates changes suggested in #5791 , into screen-capture plugin.

Copy link
Contributor

Diff output files
diff --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 Murderlon merged commit 044358a into transloadit:main Jun 26, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants