forked from mebjas/html5-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
53 lines (50 loc) · 1.72 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @fileoverview
* Utils used by {@class Html5Qrcode} & {@class Html5QrcodeScanner}
*
* @author mebjas <[email protected]>
*
* The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
* http://www.denso-wave.com/qrcode/faqpatent-e.html
*/
import { Logger } from "./core";
/**
* Utils around {@interface MediaTrackConstraints} for video.
*/
export class VideoConstraintsUtil {
public static isMediaStreamConstraintsValid(
videoConstraints: MediaTrackConstraints,
logger: Logger): boolean {
if (typeof videoConstraints !== "object") {
const typeofVideoConstraints = typeof videoConstraints;
logger.logError(
"videoConstraints should be of type object, the "
+ `object passed is of type ${typeofVideoConstraints}.`,
/* experimental= */ true);
return false;
}
// TODO(mebjas): Make this validity check more sophisticuated
// Following keys are audio controls, audio controls are not supported.
const bannedKeys = [
"autoGainControl",
"channelCount",
"echoCancellation",
"latency",
"noiseSuppression",
"sampleRate",
"sampleSize",
"volume"
];
const bannedkeysSet = new Set(bannedKeys);
const keysInVideoConstraints = Object.keys(videoConstraints);
for (const key of keysInVideoConstraints) {
if (bannedkeysSet.has(key)) {
logger.logError(
`${key} is not supported videoConstaints.`,
/* experimental= */ true);
return false;
}
}
return true;
}
}