Skip to content

Commit

Permalink
fix: getCapabilities not supported in Firefox
Browse files Browse the repository at this point in the history
Issue: #195
  • Loading branch information
gruhn committed Aug 7, 2020
1 parent 153c4a6 commit bf32fa0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/misc/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Camera {

getCapabilities() {
const [track] = this.stream.getVideoTracks();
return track.getCapabilities();
// Firefox does not yet support getCapabilities as of August 2020
return track?.getCapabilities?.() ?? {};
}
}

Expand Down Expand Up @@ -63,14 +64,6 @@ const narrowDownFacingMode = async camera => {
}
};

const INSECURE_CONTEXT = window.isSecureContext !== true;

const STREAM_API_NOT_SUPPORTED = !(
navigator &&
(navigator.getUserMedia ||
(navigator.mediaDevices && navigator.mediaDevices.getUserMedia))
);

const applyWebRTCShim = indempotent(() => {
const script = document.createElement("script");
script.src = "https://webrtc.github.io/adapter/adapter-7.6.3.js";
Expand All @@ -87,11 +80,11 @@ export default async function(videoEl, { camera, torch }) {
// So although `getUserMedia` already should have a built-in mechanism to
// detect insecure context (by throwing `NotAllowedError`), we have to do a
// manual check before even calling `getUserMedia`.
if (INSECURE_CONTEXT) {
if (window.isSecureContext !== true) {
throw new InsecureContextError();
}

if (STREAM_API_NOT_SUPPORTED) {
if (navigator?.mediaDevices?.getUserMedia === undefined) {
throw new StreamApiNotSupportedError();
}

Expand Down

0 comments on commit bf32fa0

Please sign in to comment.