Add null reference checks for new code looking for window.navigator.mediaDevices

This commit is contained in:
Adam Weeden 2023-03-24 10:23:59 -04:00
parent 79009e87cd
commit a1cffcc6d2
2 changed files with 7 additions and 0 deletions

1
.gitignore vendored
View File

@ -65,3 +65,4 @@ nativefier*.tgz
.actrc
tsconfig.tsbuildinfo
scripts

View File

@ -66,6 +66,9 @@ async function getDisplayMedia(
sourceId: number | string,
): Promise<MediaStream> {
type OriginalVideoPropertyType = boolean | MediaTrackConstraints | undefined;
if (!window?.navigator?.mediaDevices) {
throw Error('window.navigator.mediaDevices is not present');
}
// Electron supports an outdated specification for mediaDevices,
// see https://www.electronjs.org/docs/latest/api/desktop-capturer/
const stream = await window.navigator.mediaDevices.getUserMedia({
@ -262,6 +265,9 @@ function setupScreenSharePicker(
function setDisplayMediaPromise(): void {
// Since no implementation for `getDisplayMedia` exists in Electron we write our own.
if (!window?.navigator?.mediaDevices) {
return;
}
window.navigator.mediaDevices.getDisplayMedia = (): Promise<MediaStream> => {
return new Promise((resolve, reject) => {
const sources = ipcRenderer.invoke(