/
options.ts
281 lines (242 loc) · 7.45 KB
/
options.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import { Track } from './Track';
export interface TrackPublishDefaults {
/**
* encoding parameters for camera track
*/
videoEncoding?: VideoEncoding;
/**
* encoding parameters for screen share track
*/
screenShareEncoding?: VideoEncoding;
/**
* codec, defaults to vp8
*/
videoCodec?: VideoCodec;
/**
* max audio bitrate, defaults to [[AudioPresets.speech]]
*/
audioBitrate?: number;
/**
* dtx (Discontinuous Transmission of audio), defaults to true
*/
dtx?: boolean;
/**
* use simulcast, defaults to true.
* When using simulcast, LiveKit will publish up to three versions of the stream
* at various resolutions.
*/
simulcast?: boolean;
/**
* custom video simulcast layers for camera tracks, defaults to h180, h360, h540
* You can specify up to two custom layers that will be used instead of
* the LiveKit default layers.
* Note: the layers need to be ordered from lowest to highest quality
*/
videoSimulcastLayers?: Array<VideoPreset>;
/**
* custom video simulcast layers for screen tracks
* Note: the layers need to be ordered from lowest to highest quality
*/
screenShareSimulcastLayers?: Array<VideoPreset>;
/**
* For local tracks, stop the underlying MediaStreamTrack when the track is muted (or paused)
* on some platforms, this option is necessary to disable the microphone recording indicator.
* Note: when this is enabled, and BT devices are connected, they will transition between
* profiles (e.g. HFP to A2DP) and there will be an audible difference in playback.
*
* defaults to false
*/
stopMicTrackOnMute?: boolean;
}
/**
* Options when publishing tracks
*/
export interface TrackPublishOptions extends TrackPublishDefaults {
/**
* set a track name
*/
name?: string;
/**
* Source of track, camera, microphone, or screen
*/
source?: Track.Source;
}
export interface CreateLocalTracksOptions {
/**
* audio track options, true to create with defaults. false if audio shouldn't be created
* default true
*/
audio?: boolean | AudioCaptureOptions;
/**
* video track options, true to create with defaults. false if video shouldn't be created
* default true
*/
video?: boolean | VideoCaptureOptions;
}
export interface VideoCaptureOptions {
/**
* A ConstrainDOMString object specifying a device ID or an array of device
* IDs which are acceptable and/or required.
*/
deviceId?: ConstrainDOMString;
/**
* a facing or an array of facings which are acceptable and/or required.
*/
facingMode?: 'user' | 'environment' | 'left' | 'right';
resolution?: VideoResolution;
}
export interface ScreenShareCaptureOptions {
/**
* true to capture audio shared. browser support for audio capturing in
* screenshare is limited: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#browser_compatibility
*/
audio?: boolean;
/** capture resolution, defaults to full HD */
resolution?: VideoResolution;
}
export interface AudioCaptureOptions {
/**
* specifies whether automatic gain control is preferred and/or required
*/
autoGainControl?: ConstrainBoolean;
/**
* the channel count or range of channel counts which are acceptable and/or required
*/
channelCount?: ConstrainULong;
/**
* A ConstrainDOMString object specifying a device ID or an array of device
* IDs which are acceptable and/or required.
*/
deviceId?: ConstrainDOMString;
/**
* whether or not echo cancellation is preferred and/or required
*/
echoCancellation?: ConstrainBoolean;
/**
* the latency or range of latencies which are acceptable and/or required.
*/
latency?: ConstrainDouble;
/**
* whether noise suppression is preferred and/or required.
*/
noiseSuppression?: ConstrainBoolean;
/**
* the sample rate or range of sample rates which are acceptable and/or required.
*/
sampleRate?: ConstrainULong;
/**
* sample size or range of sample sizes which are acceptable and/or required.
*/
sampleSize?: ConstrainULong;
}
export interface VideoResolution {
width: number;
height: number;
frameRate?: number;
aspectRatio?: number;
}
export interface VideoEncoding {
maxBitrate: number;
maxFramerate?: number;
}
export class VideoPreset {
encoding: VideoEncoding;
width: number;
height: number;
constructor(width: number, height: number, maxBitrate: number, maxFramerate?: number) {
this.width = width;
this.height = height;
this.encoding = {
maxBitrate,
maxFramerate,
};
}
get resolution(): VideoResolution {
return {
width: this.width,
height: this.height,
frameRate: this.encoding.maxFramerate,
aspectRatio: this.width / this.height,
};
}
}
export interface AudioPreset {
maxBitrate: number;
}
export type VideoCodec = 'vp8' | 'h264' | 'av1' | 'vp9';
export namespace AudioPresets {
export const telephone: AudioPreset = {
maxBitrate: 12_000,
};
export const speech: AudioPreset = {
maxBitrate: 20_000,
};
export const music: AudioPreset = {
maxBitrate: 32_000,
};
}
/**
* Sane presets for video resolution/encoding
*/
export const VideoPresets = {
h90: new VideoPreset(160, 90, 60_000, 15),
h180: new VideoPreset(320, 180, 120_000, 15),
h216: new VideoPreset(384, 216, 180_000, 15),
h360: new VideoPreset(640, 360, 300_000, 20),
h540: new VideoPreset(960, 540, 600_000, 25),
h720: new VideoPreset(1280, 720, 2_000_000, 30),
h1080: new VideoPreset(1920, 1080, 3_000_000, 30),
h1440: new VideoPreset(2560, 1440, 5_000_000, 30),
h2160: new VideoPreset(3840, 2160, 8_000_000, 30),
/** @deprecated */
qvga: new VideoPreset(320, 180, 120_000, 10),
/** @deprecated */
vga: new VideoPreset(640, 360, 300_000, 20),
/** @deprecated */
qhd: new VideoPreset(960, 540, 600_000, 25),
/** @deprecated */
hd: new VideoPreset(1280, 720, 2_000_000, 30),
/** @deprecated */
fhd: new VideoPreset(1920, 1080, 3_000_000, 30),
} as const;
/**
* Four by three presets
*/
export const VideoPresets43 = {
h120: new VideoPreset(160, 120, 80_000, 15),
h180: new VideoPreset(240, 180, 100_000, 15),
h240: new VideoPreset(320, 240, 150_000, 15),
h360: new VideoPreset(480, 360, 225_000, 20),
h480: new VideoPreset(640, 480, 300_000, 20),
h540: new VideoPreset(720, 540, 450_000, 25),
h720: new VideoPreset(960, 720, 1_500_000, 30),
h1080: new VideoPreset(1440, 1080, 2_500_000, 30),
h1440: new VideoPreset(1920, 1440, 3_500_000, 30),
/** @deprecated */
qvga: new VideoPreset(240, 180, 90_000, 10),
/** @deprecated */
vga: new VideoPreset(480, 360, 225_000, 20),
/** @deprecated */
qhd: new VideoPreset(720, 540, 450_000, 25),
/** @deprecated */
hd: new VideoPreset(960, 720, 1_500_000, 30),
/** @deprecated */
fhd: new VideoPreset(1440, 1080, 2_800_000, 30),
} as const;
export const ScreenSharePresets = {
h360fps3: new VideoPreset(640, 360, 200_000, 3),
h720fps5: new VideoPreset(1280, 720, 400_000, 5),
h720fps15: new VideoPreset(1280, 720, 1_000_000, 15),
h1080fps15: new VideoPreset(1920, 1080, 1_500_000, 15),
h1080fps30: new VideoPreset(1920, 1080, 3_000_000, 30),
/** @deprecated */
vga: new VideoPreset(640, 360, 200_000, 3),
/** @deprecated */
hd_8: new VideoPreset(1280, 720, 400_000, 5),
/** @deprecated */
hd_15: new VideoPreset(1280, 720, 1_000_000, 15),
/** @deprecated */
fhd_15: new VideoPreset(1920, 1080, 1_500_000, 15),
/** @deprecated */
fhd_30: new VideoPreset(1920, 1080, 3_000_000, 30),
} as const;