Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Handle user-cancel and resume AudioContext
Richie McIlroye3c24e72c15b
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.tsindex 00447fac3..003cb92a6 100644--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts@@ -45,6 +45,7 @@ import type {} from "./web-recorder-types";import {detectCapabilities,+ isUserCancellationError,pickSupportedMimeType,type RecorderCapabilities,shouldRetryDisplayMediaWithoutPreferences,@@ -500,6 +501,9 @@ export const useWebRecorder = ({preferredDisplayRequest as DisplayMediaStreamOptions,);} catch (displayError) {+ if (isUserCancellationError(displayError)) {+ throw displayError;+ }if (shouldRetryDisplayMediaWithoutPreferences(displayError)) {console.warn("Display media preferences not supported, retrying without them",@@ -630,6 +634,10 @@ export const useWebRecorder = ({const audioCtx = new AudioContext();audioContextRef.current = audioCtx;+ if (audioCtx.state !== "running") {+ await audioCtx.resume();+ }+const systemSource = audioCtx.createMediaStreamSource(new MediaStream(systemAudioTracks),);diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/web-recorder-utils.ts b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/web-recorder-utils.tsindex d1e84e946..3902baaba 100644--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/web-recorder-utils.ts+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/web-recorder-utils.ts@@ -81,11 +81,19 @@ export const pickSupportedMimeType = (candidates: readonly string[]) => {);};+export const isUserCancellationError = (error: unknown): boolean => {+ if (!(error instanceof DOMException)) return false;+ return error.name === "NotAllowedError" || error.name === "AbortError";+};+export const shouldRetryDisplayMediaWithoutPreferences = (error: unknown) => {+ if (isUserCancellationError(error)) return false;+if (error instanceof DOMException) {return (error.name === "OverconstrainedError" ||- error.name === "NotSupportedError"+ error.name === "NotSupportedError" ||+ error.name === "InvalidAccessError");}