Skip to content

Commit 7986394

Browse files
committed
fix(@init): capabilities empty on some devices
According to https://oberhofer.co/mediastreamtrack-and-its-capabilities/#queryingcapabilities on some devices, getCapabilities only returns a non-empty object aftersome delay. There is no appropriate event so we have to add some constant timeout.
1 parent 1b247ae commit 7986394

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/misc/camera.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import adapterFactory from "webrtc-adapter/src/js/adapter_factory.js";
22
import { StreamApiNotSupportedError, InsecureContextError } from "./errors.js";
33
import { imageDataFromVideo } from "./image-data.js";
4-
import { eventOn } from "callforth";
4+
import { eventOn, timeout } from "callforth";
55

66
class Camera {
77
constructor(videoEl, stream) {
@@ -19,11 +19,12 @@ class Camera {
1919

2020
getCapabilities() {
2121
const [track] = this.stream.getVideoTracks();
22-
2322
return track.getCapabilities();
2423
}
2524
}
2625

26+
const isEmptyObject = object => Object.keys(object).length === 0;
27+
2728
const INSECURE_CONTEXT = window.isSecureContext !== true;
2829

2930
const STREAM_API_NOT_SUPPORTED = !(
@@ -80,5 +81,10 @@ export default async function(constraints, videoEl, advancedConstraints) {
8081
}
8182
}
8283

84+
// According to: https://oberhofer.co/mediastreamtrack-and-its-capabilities/#queryingcapabilities
85+
// On some devices, getCapabilities only returns a non-empty object after
86+
// some delay. There is no appropriate event so we have to add a constant timeout
87+
await timeout(500);
88+
8389
return new Camera(videoEl, stream);
8490
}

0 commit comments

Comments
 (0)