-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweb-capabilities.ts
More file actions
98 lines (92 loc) · 2.75 KB
/
web-capabilities.ts
File metadata and controls
98 lines (92 loc) · 2.75 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { CpuInfo } from './cpu-info';
/**
* Used by the {@link WebCapabilities} class to mark features as "not capable", "capable", or
* "unknown". A feature marked as "unknown" means that there is not enough information to determine
* whether the machine is currently capable of that feature.
*/
export enum CapabilityState {
NOT_CAPABLE = 'not capable',
CAPABLE = 'capable',
UNKNOWN = 'unknown',
}
/**
* A class that checks whether the machine is capable of certain features based on the available
* information.
*/
export class WebCapabilities {
/**
* Checks whether the machine is capable of background noise removal.
*
* @returns A {@link CapabilityState}.
*/
static isCapableOfBackgroundNoiseRemoval(): CapabilityState {
const numCores = CpuInfo.getNumLogicalCores();
if (numCores === undefined) {
return CapabilityState.UNKNOWN;
}
if (numCores < 2) {
return CapabilityState.NOT_CAPABLE;
}
return CapabilityState.CAPABLE;
}
/**
* Checks whether the machine is capable of virtual background.
*
* @returns A {@link CapabilityState}.
*/
static isCapableOfVirtualBackground(): CapabilityState {
const numCores = CpuInfo.getNumLogicalCores();
if (numCores === undefined) {
return CapabilityState.UNKNOWN;
}
if (numCores < 2) {
return CapabilityState.NOT_CAPABLE;
}
return CapabilityState.CAPABLE;
}
/**
* Checks whether the machine is capable of receiving 1080p video.
*
* @returns A {@link CapabilityState}.
*/
static isCapableOfReceiving1080pVideo(): CapabilityState {
const numCores = CpuInfo.getNumLogicalCores();
if (numCores === undefined) {
return CapabilityState.UNKNOWN;
}
if (numCores < 2) {
return CapabilityState.NOT_CAPABLE;
}
return CapabilityState.CAPABLE;
}
/**
* Checks whether the machine is capable of sending 1080p video.
*
* @returns A {@link CapabilityState}.
*/
static isCapableOfSending1080pVideo(): CapabilityState {
const numCores = CpuInfo.getNumLogicalCores();
if (numCores === undefined) {
return CapabilityState.UNKNOWN;
}
if (numCores < 8) {
return CapabilityState.NOT_CAPABLE;
}
return CapabilityState.CAPABLE;
}
/**
* Checks whether the browser supports encoded stream transforms.
*
* @returns A {@link CapabilityState}.
*/
static supportsEncodedStreamTransforms(): CapabilityState {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (window as any).RTCRtpScriptTransform &&
window.RTCRtpSender &&
'transform' in RTCRtpSender.prototype &&
window.RTCRtpReceiver &&
'transform' in RTCRtpReceiver.prototype
? CapabilityState.CAPABLE
: CapabilityState.NOT_CAPABLE;
}
}