Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix(linux): move fallback out of audio-only branch and surface audio downgrade

Amaan9c4cb60974e5
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index 3475a84a..8edd3d5f 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -1128,48 +1128,61 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
cursor: "never" as const,
};
- if (wantsAudioCapture) {
- let screenMediaStream: MediaStream;
- const useLinuxPortal = selectedSource.id === "screen:linux-portal";
- const acquireLinuxPortalStream = async (withAudio: boolean): Promise<MediaStream> => {
- try {
- return await mediaDevices.getDisplayMedia({
- audio: withAudio,
- video: {
- displaySurface: "monitor",
- width: { ideal: TARGET_WIDTH, max: TARGET_WIDTH },
- height: { ideal: TARGET_HEIGHT, max: TARGET_HEIGHT },
- frameRate: { ideal: TARGET_FRAME_RATE, max: TARGET_FRAME_RATE },
- cursor: "never",
- },
- selfBrowserSurface: "exclude",
- surfaceSwitching: "exclude",
- });
- } catch (err) {
- console.warn("Linux portal failed, falling back to desktop capture:", err);
- const sources = await window.electronAPI.getSources({ types: ["screen"] });
- if (!sources.length) {
- throw new Error("No screen sources available");
- }
+ const acquireLinuxPortalStream = async (withAudio: boolean): Promise<MediaStream> => {
+
+ try {
+ return await mediaDevices.getDisplayMedia({
+ audio: withAudio,
+ video: {
+ displaySurface: "monitor",
+ width: { ideal: TARGET_WIDTH, max: TARGET_WIDTH },
+ height: { ideal: TARGET_HEIGHT, max: TARGET_HEIGHT },
+ frameRate: { ideal: TARGET_FRAME_RATE, max: TARGET_FRAME_RATE },
+ cursor: "never",
+ },
+ selfBrowserSurface: "exclude",
+ surfaceSwitching: "exclude",
+ });
+ }
+
+ catch (err) {
+ console.warn("Linux portal failed, falling back to desktop capture(no audio):", err);
+ if (withAudio) {
+ alert("System audio is not supported in fallback mode. Recording will continue without audio.");
+ }
- const source = sources[0];
-
- return await navigator.mediaDevices.getUserMedia({
- audio: false, //intentional
- video: {
- mandatory: {
- chromeMediaSource: "desktop",
- chromeMediaSourceId: source.id,
- maxWidth: TARGET_WIDTH,
- maxHeight: TARGET_HEIGHT,
- maxFrameRate: TARGET_FRAME_RATE,
- },
- },
- } as any);
+
+ const sources = await window.electronAPI.getSources({ types: ["screen"] });
+
+ if (!sources.length) {
+ throw new Error("No screen sources available");
}
- };
+
+ const source = sources[0];
+ console.log("Using fallback source:", source);
+
+
+
+ return await navigator.mediaDevices.getUserMedia({
+ audio: false, //intentional
+ video: {
+ mandatory: {
+ chromeMediaSource: "desktop",
+ chromeMediaSourceId: source.id,
+ maxWidth: TARGET_WIDTH,
+ maxHeight: TARGET_HEIGHT,
+ maxFrameRate: TARGET_FRAME_RATE,
+ },
+ },
+ } as any);
+ }
+ };
+
+ let screenMediaStream: MediaStream;
+ const useLinuxPortal = selectedSource.id === "screen:linux-portal";
+
if (systemAudioEnabled) {
try {
screenMediaStream = useLinuxPortal
@@ -1273,26 +1286,10 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
} else if (micAudioTrack) {
stream.current.addTrack(micAudioTrack);
}
- } else {
- const mediaStream = await mediaDevices.getDisplayMedia({
- audio: false,
- video: {
- displaySurface: selectedSource.id?.startsWith("window:")
- ? "window"
- : "monitor",
- width: { ideal: TARGET_WIDTH, max: TARGET_WIDTH },
- height: { ideal: TARGET_HEIGHT, max: TARGET_HEIGHT },
- frameRate: { ideal: TARGET_FRAME_RATE, max: TARGET_FRAME_RATE },
- cursor: "never",
- },
- selfBrowserSurface: "exclude",
- surfaceSwitching: "exclude",
- });
-
- stream.current = mediaStream;
- videoTrack = mediaStream.getVideoTracks()[0];
- }
+
+
+
if (!stream.current || !videoTrack) {
throw new Error("Media stream is not available.");
}