Skip to content

Commit bf32fa0

Browse files
committed
fix: getCapabilities not supported in Firefox
Issue: #195
1 parent 153c4a6 commit bf32fa0

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/misc/camera.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Camera {
1919

2020
getCapabilities() {
2121
const [track] = this.stream.getVideoTracks();
22-
return track.getCapabilities();
22+
// Firefox does not yet support getCapabilities as of August 2020
23+
return track?.getCapabilities?.() ?? {};
2324
}
2425
}
2526

@@ -63,14 +64,6 @@ const narrowDownFacingMode = async camera => {
6364
}
6465
};
6566

66-
const INSECURE_CONTEXT = window.isSecureContext !== true;
67-
68-
const STREAM_API_NOT_SUPPORTED = !(
69-
navigator &&
70-
(navigator.getUserMedia ||
71-
(navigator.mediaDevices && navigator.mediaDevices.getUserMedia))
72-
);
73-
7467
const applyWebRTCShim = indempotent(() => {
7568
const script = document.createElement("script");
7669
script.src = "https://webrtc.github.io/adapter/adapter-7.6.3.js";
@@ -87,11 +80,11 @@ export default async function(videoEl, { camera, torch }) {
8780
// So although `getUserMedia` already should have a built-in mechanism to
8881
// detect insecure context (by throwing `NotAllowedError`), we have to do a
8982
// manual check before even calling `getUserMedia`.
90-
if (INSECURE_CONTEXT) {
83+
if (window.isSecureContext !== true) {
9184
throw new InsecureContextError();
9285
}
9386

94-
if (STREAM_API_NOT_SUPPORTED) {
87+
if (navigator?.mediaDevices?.getUserMedia === undefined) {
9588
throw new StreamApiNotSupportedError();
9689
}
9790

0 commit comments

Comments
 (0)