( mode: Exclude<RecordingMode, "tab" | "camera">, includeAudio: boolean, )
| 414 | navigator.mediaDevices.getDisplayMedia(options as DisplayMediaStreamOptions); |
| 415 | |
| 416 | const getDisplayStream = async ( |
| 417 | mode: Exclude<RecordingMode, "tab" | "camera">, |
| 418 | includeAudio: boolean, |
| 419 | ) => { |
| 420 | const preferences = DISPLAY_MODE_PREFERENCES[mode]; |
| 421 | const video = DISPLAY_MEDIA_VIDEO_CONSTRAINTS; |
| 422 | |
| 423 | try { |
| 424 | return await requestDisplayMedia({ |
| 425 | ...preferences, |
| 426 | video, |
| 427 | audio: includeAudio, |
| 428 | }); |
| 429 | } catch (error) { |
| 430 | if (isUserCancellationError(error)) throw error; |
| 431 | |
| 432 | // Some browsers/OSes reject the advanced surface preferences |
| 433 | // (monitorTypeSurfaces, surfaceSwitching, preferCurrentTab, …) or a |
| 434 | // system-audio request the picker cannot satisfy. Fall back the way the |
| 435 | // dashboard recorder does instead of failing the whole capture. |
| 436 | if (shouldRetryDisplayMediaWithoutPreferences(error)) { |
| 437 | try { |
| 438 | return await requestDisplayMedia({ video, audio: includeAudio }); |
| 439 | } catch (retryError) { |
| 440 | if ( |
| 441 | includeAudio && |
| 442 | shouldRetryDisplayMediaWithoutPreferences(retryError) |
| 443 | ) { |
| 444 | return requestDisplayMedia({ video, audio: false }); |
| 445 | } |
| 446 | throw retryError; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (includeAudio) { |
| 451 | try { |
| 452 | return await requestDisplayMedia({ |
| 453 | ...preferences, |
| 454 | video, |
| 455 | audio: false, |
| 456 | }); |
| 457 | } catch { |
| 458 | throw error; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | throw error; |
| 463 | } |
| 464 | }; |
| 465 | |
| 466 | const getMainStream = async (request: StartRecordingRequest) => { |
| 467 | if (request.mode === "tab") { |
no test coverage detected