Skip to content
10 changes: 5 additions & 5 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
const abortController = new AbortController();

// in order to catch device changes prior to room connection we need to register the event in the constructor
navigator.mediaDevices?.addEventListener('devicechange', this.handleDeviceChange, {
navigator.mediaDevices?.addEventListener?.('devicechange', this.handleDeviceChange, {
signal: abortController.signal,
});

Expand Down Expand Up @@ -1615,7 +1615,7 @@
window.removeEventListener('beforeunload', this.onPageLeave);
window.removeEventListener('pagehide', this.onPageLeave);
window.removeEventListener('freeze', this.onPageLeave);
navigator.mediaDevices?.removeEventListener('devicechange', this.handleDeviceChange);
navigator.mediaDevices?.removeEventListener?.('devicechange', this.handleDeviceChange);
}
} finally {
this.setAndEmitConnectionState(ConnectionState.Disconnected);
Expand Down Expand Up @@ -2499,8 +2499,7 @@
}),
new LocalVideoTrack(
publishOptions.useRealTracks
? (
await window.navigator.mediaDevices.getUserMedia({ video: true })
? (await window.navigator.mediaDevices?.getUserMedia?.({ video: true }) ?? new MediaStream()

Check failure on line 2502 in src/room/Room.ts

View workflow job for this annotation

GitHub Actions / test

Replace `await·window.navigator.mediaDevices?.getUserMedia?.({·video:·true·})·??` with `⏎················(await·window.navigator.mediaDevices?.getUserMedia?.({·video:·true·}))·??⏎···············`
).getVideoTracks()[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The getUserMedia calls with ?? new MediaStream() fallback (lines 2502, 2529)
ensure we don't get undefined when calling .getVideoTracks()[0] in non-secure contexts
where mediaDevices?.getUserMedia?.() returns undefined due to optional chaining.

Copy link
Contributor

@lukasIO lukasIO Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of falling back to new MediaStream() we could simply check for publishOptions.useRealTracks && window.navigator.mediaDevices?.getUserMedia above

: createDummyVideoStreamTrack(
160 * (participantOptions.aspectRatios[0] ?? 1),
Expand Down Expand Up @@ -2528,7 +2527,8 @@
}),
new LocalAudioTrack(
publishOptions.useRealTracks
? (await navigator.mediaDevices.getUserMedia({ audio: true })).getAudioTracks()[0]
? (await navigator.mediaDevices?.getUserMedia?.({ audio: true }) ?? new MediaStream()

Check failure on line 2530 in src/room/Room.ts

View workflow job for this annotation

GitHub Actions / test

Replace `await·navigator.mediaDevices?.getUserMedia?.({·audio:·true·}` with `⏎················(await·navigator.mediaDevices?.getUserMedia?.({·audio:·true·})`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

).getAudioTracks()[0]
: getEmptyAudioStreamTrack(),
undefined,
false,
Expand Down
Loading