livekit-client 0.17.5 → 0.17.6-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +26 -20
- package/dist/api/SignalClient.d.ts +1 -0
- package/dist/connect.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/livekit-client.esm.js +17344 -0
- package/dist/livekit-client.esm.js.map +1 -0
- package/dist/livekit-client.umd.js +17388 -0
- package/dist/livekit-client.umd.js.map +1 -0
- package/dist/logger.d.ts +22 -11
- package/dist/options.d.ts +4 -2
- package/dist/proto/google/protobuf/timestamp.d.ts +1 -1
- package/dist/proto/livekit_models.d.ts +4 -1
- package/dist/proto/livekit_rtc.d.ts +45 -2
- package/dist/room/DeviceManager.d.ts +1 -1
- package/dist/room/RTCEngine.d.ts +1 -1
- package/dist/room/Room.d.ts +2 -2
- package/dist/room/events.d.ts +1 -1
- package/dist/room/participant/LocalParticipant.d.ts +9 -5
- package/dist/room/participant/RemoteParticipant.d.ts +9 -0
- package/dist/room/track/RemoteAudioTrack.d.ts +11 -0
- package/dist/test/mocks.d.ts +11 -0
- package/package.json +40 -15
- package/.eslintrc.js +0 -17
- package/.gitmodules +0 -3
- package/dist/api/RequestQueue.js +0 -61
- package/dist/api/RequestQueue.js.map +0 -1
- package/dist/api/SignalClient.js +0 -428
- package/dist/api/SignalClient.js.map +0 -1
- package/dist/connect.js +0 -130
- package/dist/connect.js.map +0 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -24
- package/dist/logger.js.map +0 -1
- package/dist/options.js +0 -3
- package/dist/options.js.map +0 -1
- package/dist/proto/google/protobuf/timestamp.js +0 -108
- package/dist/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/proto/livekit_models.js +0 -2262
- package/dist/proto/livekit_models.js.map +0 -1
- package/dist/proto/livekit_rtc.js +0 -2544
- package/dist/proto/livekit_rtc.js.map +0 -1
- package/dist/room/DeviceManager.js +0 -62
- package/dist/room/DeviceManager.js.map +0 -1
- package/dist/room/PCTransport.js +0 -91
- package/dist/room/PCTransport.js.map +0 -1
- package/dist/room/RTCEngine.js +0 -562
- package/dist/room/RTCEngine.js.map +0 -1
- package/dist/room/Room.js +0 -767
- package/dist/room/Room.js.map +0 -1
- package/dist/room/errors.js +0 -68
- package/dist/room/errors.js.map +0 -1
- package/dist/room/events.js +0 -385
- package/dist/room/events.js.map +0 -1
- package/dist/room/participant/LocalParticipant.js +0 -647
- package/dist/room/participant/LocalParticipant.js.map +0 -1
- package/dist/room/participant/Participant.js +0 -189
- package/dist/room/participant/Participant.js.map +0 -1
- package/dist/room/participant/ParticipantTrackPermission.js +0 -16
- package/dist/room/participant/ParticipantTrackPermission.js.map +0 -1
- package/dist/room/participant/RemoteParticipant.js +0 -194
- package/dist/room/participant/RemoteParticipant.js.map +0 -1
- package/dist/room/participant/publishUtils.js +0 -189
- package/dist/room/participant/publishUtils.js.map +0 -1
- package/dist/room/participant/publishUtils.test.d.ts +0 -1
- package/dist/room/participant/publishUtils.test.js +0 -118
- package/dist/room/participant/publishUtils.test.js.map +0 -1
- package/dist/room/stats.js +0 -26
- package/dist/room/stats.js.map +0 -1
- package/dist/room/track/LocalAudioTrack.js +0 -153
- package/dist/room/track/LocalAudioTrack.js.map +0 -1
- package/dist/room/track/LocalTrack.js +0 -158
- package/dist/room/track/LocalTrack.js.map +0 -1
- package/dist/room/track/LocalTrackPublication.js +0 -64
- package/dist/room/track/LocalTrackPublication.js.map +0 -1
- package/dist/room/track/LocalVideoTrack.js +0 -297
- package/dist/room/track/LocalVideoTrack.js.map +0 -1
- package/dist/room/track/LocalVideoTrack.test.d.ts +0 -1
- package/dist/room/track/LocalVideoTrack.test.js +0 -68
- package/dist/room/track/LocalVideoTrack.test.js.map +0 -1
- package/dist/room/track/RemoteAudioTrack.js +0 -64
- package/dist/room/track/RemoteAudioTrack.js.map +0 -1
- package/dist/room/track/RemoteTrack.js +0 -49
- package/dist/room/track/RemoteTrack.js.map +0 -1
- package/dist/room/track/RemoteTrackPublication.js +0 -178
- package/dist/room/track/RemoteTrackPublication.js.map +0 -1
- package/dist/room/track/RemoteVideoTrack.js +0 -201
- package/dist/room/track/RemoteVideoTrack.js.map +0 -1
- package/dist/room/track/Track.js +0 -283
- package/dist/room/track/Track.js.map +0 -1
- package/dist/room/track/TrackPublication.js +0 -92
- package/dist/room/track/TrackPublication.js.map +0 -1
- package/dist/room/track/create.js +0 -131
- package/dist/room/track/create.js.map +0 -1
- package/dist/room/track/defaults.js +0 -21
- package/dist/room/track/defaults.js.map +0 -1
- package/dist/room/track/options.js +0 -100
- package/dist/room/track/options.js.map +0 -1
- package/dist/room/track/types.js +0 -3
- package/dist/room/track/types.js.map +0 -1
- package/dist/room/track/utils.js +0 -113
- package/dist/room/track/utils.js.map +0 -1
- package/dist/room/track/utils.test.d.ts +0 -1
- package/dist/room/track/utils.test.js +0 -85
- package/dist/room/track/utils.test.js.map +0 -1
- package/dist/room/utils.js +0 -79
- package/dist/room/utils.js.map +0 -1
- package/dist/version.js +0 -6
- package/dist/version.js.map +0 -1
- package/jest.config.js +0 -6
- package/src/api/RequestQueue.ts +0 -53
- package/src/api/SignalClient.ts +0 -499
- package/src/connect.ts +0 -100
- package/src/index.ts +0 -47
- package/src/logger.ts +0 -22
- package/src/options.ts +0 -149
- package/src/proto/google/protobuf/timestamp.ts +0 -232
- package/src/proto/livekit_models.ts +0 -2676
- package/src/proto/livekit_rtc.ts +0 -3269
- package/src/room/DeviceManager.ts +0 -57
- package/src/room/PCTransport.ts +0 -86
- package/src/room/RTCEngine.ts +0 -652
- package/src/room/Room.ts +0 -951
- package/src/room/errors.ts +0 -65
- package/src/room/events.ts +0 -424
- package/src/room/participant/LocalParticipant.ts +0 -734
- package/src/room/participant/Participant.ts +0 -269
- package/src/room/participant/ParticipantTrackPermission.ts +0 -32
- package/src/room/participant/RemoteParticipant.ts +0 -243
- package/src/room/participant/publishUtils.test.ts +0 -145
- package/src/room/participant/publishUtils.ts +0 -225
- package/src/room/stats.ts +0 -130
- package/src/room/track/LocalAudioTrack.ts +0 -137
- package/src/room/track/LocalTrack.ts +0 -161
- package/src/room/track/LocalTrackPublication.ts +0 -66
- package/src/room/track/LocalVideoTrack.test.ts +0 -70
- package/src/room/track/LocalVideoTrack.ts +0 -293
- package/src/room/track/RemoteAudioTrack.ts +0 -58
- package/src/room/track/RemoteTrack.ts +0 -62
- package/src/room/track/RemoteTrackPublication.ts +0 -198
- package/src/room/track/RemoteVideoTrack.ts +0 -235
- package/src/room/track/Track.ts +0 -343
- package/src/room/track/TrackPublication.ts +0 -120
- package/src/room/track/create.ts +0 -121
- package/src/room/track/defaults.ts +0 -23
- package/src/room/track/options.ts +0 -281
- package/src/room/track/types.ts +0 -20
- package/src/room/track/utils.test.ts +0 -93
- package/src/room/track/utils.ts +0 -115
- package/src/room/utils.ts +0 -70
- package/src/version.ts +0 -2
- package/tsconfig.eslint.json +0 -11
package/src/room/track/create.ts
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
import { TrackInvalidError } from '../errors';
|
2
|
-
import { mediaTrackToLocalTrack } from '../participant/publishUtils';
|
3
|
-
import { audioDefaults, videoDefaults } from './defaults';
|
4
|
-
import LocalAudioTrack from './LocalAudioTrack';
|
5
|
-
import LocalTrack from './LocalTrack';
|
6
|
-
import LocalVideoTrack from './LocalVideoTrack';
|
7
|
-
import {
|
8
|
-
AudioCaptureOptions, CreateLocalTracksOptions, ScreenShareCaptureOptions,
|
9
|
-
VideoCaptureOptions, VideoPresets,
|
10
|
-
} from './options';
|
11
|
-
import { Track } from './Track';
|
12
|
-
import { constraintsForOptions, mergeDefaultOptions } from './utils';
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Creates a local video and audio track at the same time. When acquiring both
|
16
|
-
* audio and video tracks together, it'll display a single permission prompt to
|
17
|
-
* the user instead of two separate ones.
|
18
|
-
* @param options
|
19
|
-
*/
|
20
|
-
export async function createLocalTracks(
|
21
|
-
options?: CreateLocalTracksOptions,
|
22
|
-
): Promise<Array<LocalTrack>> {
|
23
|
-
// set default options to true
|
24
|
-
options ??= {};
|
25
|
-
options.audio ??= true;
|
26
|
-
options.video ??= true;
|
27
|
-
|
28
|
-
const opts = mergeDefaultOptions(options, audioDefaults, videoDefaults);
|
29
|
-
const constraints = constraintsForOptions(opts);
|
30
|
-
const stream = await navigator.mediaDevices.getUserMedia(
|
31
|
-
constraints,
|
32
|
-
);
|
33
|
-
return stream.getTracks().map((mediaStreamTrack) => {
|
34
|
-
const isAudio = mediaStreamTrack.kind === 'audio';
|
35
|
-
let trackOptions = isAudio ? options!.audio : options!.video;
|
36
|
-
if (typeof trackOptions === 'boolean' || !trackOptions) {
|
37
|
-
trackOptions = {};
|
38
|
-
}
|
39
|
-
let trackConstraints: MediaTrackConstraints | undefined;
|
40
|
-
const conOrBool = isAudio ? constraints.audio : constraints.video;
|
41
|
-
if (typeof conOrBool !== 'boolean') {
|
42
|
-
trackConstraints = conOrBool;
|
43
|
-
}
|
44
|
-
const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints);
|
45
|
-
if (track.kind === Track.Kind.Video) {
|
46
|
-
track.source = Track.Source.Camera;
|
47
|
-
} else if (track.kind === Track.Kind.Audio) {
|
48
|
-
track.source = Track.Source.Microphone;
|
49
|
-
}
|
50
|
-
track.mediaStream = stream;
|
51
|
-
return track;
|
52
|
-
});
|
53
|
-
}
|
54
|
-
|
55
|
-
/**
|
56
|
-
* Creates a [[LocalVideoTrack]] with getUserMedia()
|
57
|
-
* @param options
|
58
|
-
*/
|
59
|
-
export async function createLocalVideoTrack(
|
60
|
-
options?: VideoCaptureOptions,
|
61
|
-
): Promise<LocalVideoTrack> {
|
62
|
-
const tracks = await createLocalTracks({
|
63
|
-
audio: false,
|
64
|
-
video: options,
|
65
|
-
});
|
66
|
-
return <LocalVideoTrack>tracks[0];
|
67
|
-
}
|
68
|
-
|
69
|
-
export async function createLocalAudioTrack(
|
70
|
-
options?: AudioCaptureOptions,
|
71
|
-
): Promise<LocalAudioTrack> {
|
72
|
-
const tracks = await createLocalTracks({
|
73
|
-
audio: options,
|
74
|
-
video: false,
|
75
|
-
});
|
76
|
-
return <LocalAudioTrack>tracks[0];
|
77
|
-
}
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Creates a screen capture tracks with getDisplayMedia().
|
81
|
-
* A LocalVideoTrack is always created and returned.
|
82
|
-
* If { audio: true }, and the browser supports audio capture, a LocalAudioTrack is also created.
|
83
|
-
*/
|
84
|
-
export async function createLocalScreenTracks(
|
85
|
-
options?: ScreenShareCaptureOptions,
|
86
|
-
): Promise<Array<LocalTrack>> {
|
87
|
-
if (options === undefined) {
|
88
|
-
options = {};
|
89
|
-
}
|
90
|
-
if (options.resolution === undefined) {
|
91
|
-
options.resolution = VideoPresets.fhd.resolution;
|
92
|
-
}
|
93
|
-
|
94
|
-
let videoConstraints: MediaTrackConstraints | boolean = true;
|
95
|
-
if (options.resolution) {
|
96
|
-
videoConstraints = {
|
97
|
-
width: options.resolution.width,
|
98
|
-
height: options.resolution.height,
|
99
|
-
};
|
100
|
-
}
|
101
|
-
// typescript definition is missing getDisplayMedia: https://github.com/microsoft/TypeScript/issues/33232
|
102
|
-
// @ts-ignore
|
103
|
-
const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
|
104
|
-
audio: options.audio ?? false,
|
105
|
-
video: videoConstraints,
|
106
|
-
});
|
107
|
-
|
108
|
-
const tracks = stream.getVideoTracks();
|
109
|
-
if (tracks.length === 0) {
|
110
|
-
throw new TrackInvalidError('no video track found');
|
111
|
-
}
|
112
|
-
const screenVideo = new LocalVideoTrack(tracks[0]);
|
113
|
-
screenVideo.source = Track.Source.ScreenShare;
|
114
|
-
const localTracks: Array<LocalTrack> = [screenVideo];
|
115
|
-
if (stream.getAudioTracks().length > 0) {
|
116
|
-
const screenAudio = new LocalAudioTrack(stream.getAudioTracks()[0]);
|
117
|
-
screenAudio.source = Track.Source.ScreenShareAudio;
|
118
|
-
localTracks.push(screenAudio);
|
119
|
-
}
|
120
|
-
return localTracks;
|
121
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AudioCaptureOptions, AudioPresets, ScreenSharePresets,
|
3
|
-
TrackPublishDefaults, VideoCaptureOptions, VideoPresets,
|
4
|
-
} from './options';
|
5
|
-
|
6
|
-
export const publishDefaults: TrackPublishDefaults = {
|
7
|
-
audioBitrate: AudioPresets.speech.maxBitrate,
|
8
|
-
dtx: true,
|
9
|
-
simulcast: true,
|
10
|
-
screenShareEncoding: ScreenSharePresets.h1080fps15.encoding,
|
11
|
-
stopMicTrackOnMute: false,
|
12
|
-
};
|
13
|
-
|
14
|
-
export const audioDefaults: AudioCaptureOptions = {
|
15
|
-
autoGainControl: true,
|
16
|
-
channelCount: 1,
|
17
|
-
echoCancellation: true,
|
18
|
-
noiseSuppression: true,
|
19
|
-
};
|
20
|
-
|
21
|
-
export const videoDefaults: VideoCaptureOptions = {
|
22
|
-
resolution: VideoPresets.h540.resolution,
|
23
|
-
};
|
@@ -1,281 +0,0 @@
|
|
1
|
-
import { Track } from './Track';
|
2
|
-
|
3
|
-
export interface TrackPublishDefaults {
|
4
|
-
/**
|
5
|
-
* encoding parameters for camera track
|
6
|
-
*/
|
7
|
-
videoEncoding?: VideoEncoding;
|
8
|
-
|
9
|
-
/**
|
10
|
-
* encoding parameters for screen share track
|
11
|
-
*/
|
12
|
-
screenShareEncoding?: VideoEncoding;
|
13
|
-
|
14
|
-
/**
|
15
|
-
* codec, defaults to vp8
|
16
|
-
*/
|
17
|
-
videoCodec?: VideoCodec;
|
18
|
-
|
19
|
-
/**
|
20
|
-
* max audio bitrate, defaults to [[AudioPresets.speech]]
|
21
|
-
*/
|
22
|
-
audioBitrate?: number;
|
23
|
-
|
24
|
-
/**
|
25
|
-
* dtx (Discontinuous Transmission of audio), defaults to true
|
26
|
-
*/
|
27
|
-
dtx?: boolean;
|
28
|
-
|
29
|
-
/**
|
30
|
-
* use simulcast, defaults to true.
|
31
|
-
* When using simulcast, LiveKit will publish up to three versions of the stream
|
32
|
-
* at various resolutions.
|
33
|
-
*/
|
34
|
-
simulcast?: boolean;
|
35
|
-
|
36
|
-
/**
|
37
|
-
* custom video simulcast layers for camera tracks, defaults to h180, h360, h540
|
38
|
-
* You can specify up to two custom layers that will be used instead of
|
39
|
-
* the LiveKit default layers.
|
40
|
-
* Note: the layers need to be ordered from lowest to highest quality
|
41
|
-
*/
|
42
|
-
videoSimulcastLayers?: Array<VideoPreset>;
|
43
|
-
|
44
|
-
/**
|
45
|
-
* custom video simulcast layers for screen tracks
|
46
|
-
* Note: the layers need to be ordered from lowest to highest quality
|
47
|
-
*/
|
48
|
-
screenShareSimulcastLayers?: Array<VideoPreset>;
|
49
|
-
|
50
|
-
/**
|
51
|
-
* For local tracks, stop the underlying MediaStreamTrack when the track is muted (or paused)
|
52
|
-
* on some platforms, this option is necessary to disable the microphone recording indicator.
|
53
|
-
* Note: when this is enabled, and BT devices are connected, they will transition between
|
54
|
-
* profiles (e.g. HFP to A2DP) and there will be an audible difference in playback.
|
55
|
-
*
|
56
|
-
* defaults to false
|
57
|
-
*/
|
58
|
-
stopMicTrackOnMute?: boolean;
|
59
|
-
}
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Options when publishing tracks
|
63
|
-
*/
|
64
|
-
export interface TrackPublishOptions extends TrackPublishDefaults {
|
65
|
-
/**
|
66
|
-
* set a track name
|
67
|
-
*/
|
68
|
-
name?: string;
|
69
|
-
|
70
|
-
/**
|
71
|
-
* Source of track, camera, microphone, or screen
|
72
|
-
*/
|
73
|
-
source?: Track.Source;
|
74
|
-
}
|
75
|
-
|
76
|
-
export interface CreateLocalTracksOptions {
|
77
|
-
/**
|
78
|
-
* audio track options, true to create with defaults. false if audio shouldn't be created
|
79
|
-
* default true
|
80
|
-
*/
|
81
|
-
audio?: boolean | AudioCaptureOptions;
|
82
|
-
|
83
|
-
/**
|
84
|
-
* video track options, true to create with defaults. false if video shouldn't be created
|
85
|
-
* default true
|
86
|
-
*/
|
87
|
-
video?: boolean | VideoCaptureOptions;
|
88
|
-
}
|
89
|
-
|
90
|
-
export interface VideoCaptureOptions {
|
91
|
-
/**
|
92
|
-
* A ConstrainDOMString object specifying a device ID or an array of device
|
93
|
-
* IDs which are acceptable and/or required.
|
94
|
-
*/
|
95
|
-
deviceId?: ConstrainDOMString;
|
96
|
-
|
97
|
-
/**
|
98
|
-
* a facing or an array of facings which are acceptable and/or required.
|
99
|
-
*/
|
100
|
-
facingMode?: 'user' | 'environment' | 'left' | 'right';
|
101
|
-
|
102
|
-
resolution?: VideoResolution;
|
103
|
-
}
|
104
|
-
|
105
|
-
export interface ScreenShareCaptureOptions {
|
106
|
-
/**
|
107
|
-
* true to capture audio shared. browser support for audio capturing in
|
108
|
-
* screenshare is limited: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#browser_compatibility
|
109
|
-
*/
|
110
|
-
audio?: boolean;
|
111
|
-
|
112
|
-
/** capture resolution, defaults to full HD */
|
113
|
-
resolution?: VideoResolution;
|
114
|
-
}
|
115
|
-
|
116
|
-
export interface AudioCaptureOptions {
|
117
|
-
/**
|
118
|
-
* specifies whether automatic gain control is preferred and/or required
|
119
|
-
*/
|
120
|
-
autoGainControl?: ConstrainBoolean;
|
121
|
-
|
122
|
-
/**
|
123
|
-
* the channel count or range of channel counts which are acceptable and/or required
|
124
|
-
*/
|
125
|
-
channelCount?: ConstrainULong;
|
126
|
-
|
127
|
-
/**
|
128
|
-
* A ConstrainDOMString object specifying a device ID or an array of device
|
129
|
-
* IDs which are acceptable and/or required.
|
130
|
-
*/
|
131
|
-
deviceId?: ConstrainDOMString;
|
132
|
-
|
133
|
-
/**
|
134
|
-
* whether or not echo cancellation is preferred and/or required
|
135
|
-
*/
|
136
|
-
echoCancellation?: ConstrainBoolean;
|
137
|
-
|
138
|
-
/**
|
139
|
-
* the latency or range of latencies which are acceptable and/or required.
|
140
|
-
*/
|
141
|
-
latency?: ConstrainDouble;
|
142
|
-
|
143
|
-
/**
|
144
|
-
* whether noise suppression is preferred and/or required.
|
145
|
-
*/
|
146
|
-
noiseSuppression?: ConstrainBoolean;
|
147
|
-
|
148
|
-
/**
|
149
|
-
* the sample rate or range of sample rates which are acceptable and/or required.
|
150
|
-
*/
|
151
|
-
sampleRate?: ConstrainULong;
|
152
|
-
|
153
|
-
/**
|
154
|
-
* sample size or range of sample sizes which are acceptable and/or required.
|
155
|
-
*/
|
156
|
-
sampleSize?: ConstrainULong;
|
157
|
-
}
|
158
|
-
|
159
|
-
export interface VideoResolution {
|
160
|
-
width: number;
|
161
|
-
height: number;
|
162
|
-
frameRate?: number;
|
163
|
-
aspectRatio?: number;
|
164
|
-
}
|
165
|
-
|
166
|
-
export interface VideoEncoding {
|
167
|
-
maxBitrate: number;
|
168
|
-
maxFramerate?: number;
|
169
|
-
}
|
170
|
-
|
171
|
-
export class VideoPreset {
|
172
|
-
encoding: VideoEncoding;
|
173
|
-
|
174
|
-
width: number;
|
175
|
-
|
176
|
-
height: number;
|
177
|
-
|
178
|
-
constructor(width: number, height: number, maxBitrate: number, maxFramerate?: number) {
|
179
|
-
this.width = width;
|
180
|
-
this.height = height;
|
181
|
-
this.encoding = {
|
182
|
-
maxBitrate,
|
183
|
-
maxFramerate,
|
184
|
-
};
|
185
|
-
}
|
186
|
-
|
187
|
-
get resolution(): VideoResolution {
|
188
|
-
return {
|
189
|
-
width: this.width,
|
190
|
-
height: this.height,
|
191
|
-
frameRate: this.encoding.maxFramerate,
|
192
|
-
aspectRatio: this.width / this.height,
|
193
|
-
};
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
export interface AudioPreset {
|
198
|
-
maxBitrate: number;
|
199
|
-
}
|
200
|
-
|
201
|
-
export type VideoCodec = 'vp8' | 'h264' | 'av1' | 'vp9';
|
202
|
-
|
203
|
-
export namespace AudioPresets {
|
204
|
-
export const telephone: AudioPreset = {
|
205
|
-
maxBitrate: 12_000,
|
206
|
-
};
|
207
|
-
export const speech: AudioPreset = {
|
208
|
-
maxBitrate: 20_000,
|
209
|
-
};
|
210
|
-
export const music: AudioPreset = {
|
211
|
-
maxBitrate: 32_000,
|
212
|
-
};
|
213
|
-
}
|
214
|
-
|
215
|
-
/**
|
216
|
-
* Sane presets for video resolution/encoding
|
217
|
-
*/
|
218
|
-
export const VideoPresets = {
|
219
|
-
h90: new VideoPreset(160, 90, 60_000, 15),
|
220
|
-
h180: new VideoPreset(320, 180, 120_000, 15),
|
221
|
-
h216: new VideoPreset(384, 216, 180_000, 15),
|
222
|
-
h360: new VideoPreset(640, 360, 300_000, 20),
|
223
|
-
h540: new VideoPreset(960, 540, 600_000, 25),
|
224
|
-
h720: new VideoPreset(1280, 720, 2_000_000, 30),
|
225
|
-
h1080: new VideoPreset(1920, 1080, 3_000_000, 30),
|
226
|
-
h1440: new VideoPreset(2560, 1440, 5_000_000, 30),
|
227
|
-
h2160: new VideoPreset(3840, 2160, 8_000_000, 30),
|
228
|
-
/** @deprecated */
|
229
|
-
qvga: new VideoPreset(320, 180, 120_000, 10),
|
230
|
-
/** @deprecated */
|
231
|
-
vga: new VideoPreset(640, 360, 300_000, 20),
|
232
|
-
/** @deprecated */
|
233
|
-
qhd: new VideoPreset(960, 540, 600_000, 25),
|
234
|
-
/** @deprecated */
|
235
|
-
hd: new VideoPreset(1280, 720, 2_000_000, 30),
|
236
|
-
/** @deprecated */
|
237
|
-
fhd: new VideoPreset(1920, 1080, 3_000_000, 30),
|
238
|
-
} as const;
|
239
|
-
|
240
|
-
/**
|
241
|
-
* Four by three presets
|
242
|
-
*/
|
243
|
-
export const VideoPresets43 = {
|
244
|
-
h120: new VideoPreset(160, 120, 80_000, 15),
|
245
|
-
h180: new VideoPreset(240, 180, 100_000, 15),
|
246
|
-
h240: new VideoPreset(320, 240, 150_000, 15),
|
247
|
-
h360: new VideoPreset(480, 360, 225_000, 20),
|
248
|
-
h480: new VideoPreset(640, 480, 300_000, 20),
|
249
|
-
h540: new VideoPreset(720, 540, 450_000, 25),
|
250
|
-
h720: new VideoPreset(960, 720, 1_500_000, 30),
|
251
|
-
h1080: new VideoPreset(1440, 1080, 2_500_000, 30),
|
252
|
-
h1440: new VideoPreset(1920, 1440, 3_500_000, 30),
|
253
|
-
/** @deprecated */
|
254
|
-
qvga: new VideoPreset(240, 180, 90_000, 10),
|
255
|
-
/** @deprecated */
|
256
|
-
vga: new VideoPreset(480, 360, 225_000, 20),
|
257
|
-
/** @deprecated */
|
258
|
-
qhd: new VideoPreset(720, 540, 450_000, 25),
|
259
|
-
/** @deprecated */
|
260
|
-
hd: new VideoPreset(960, 720, 1_500_000, 30),
|
261
|
-
/** @deprecated */
|
262
|
-
fhd: new VideoPreset(1440, 1080, 2_800_000, 30),
|
263
|
-
} as const;
|
264
|
-
|
265
|
-
export const ScreenSharePresets = {
|
266
|
-
h360fps3: new VideoPreset(640, 360, 200_000, 3),
|
267
|
-
h720fps5: new VideoPreset(1280, 720, 400_000, 5),
|
268
|
-
h720fps15: new VideoPreset(1280, 720, 1_000_000, 15),
|
269
|
-
h1080fps15: new VideoPreset(1920, 1080, 1_500_000, 15),
|
270
|
-
h1080fps30: new VideoPreset(1920, 1080, 3_000_000, 30),
|
271
|
-
/** @deprecated */
|
272
|
-
vga: new VideoPreset(640, 360, 200_000, 3),
|
273
|
-
/** @deprecated */
|
274
|
-
hd_8: new VideoPreset(1280, 720, 400_000, 5),
|
275
|
-
/** @deprecated */
|
276
|
-
hd_15: new VideoPreset(1280, 720, 1_000_000, 15),
|
277
|
-
/** @deprecated */
|
278
|
-
fhd_15: new VideoPreset(1920, 1080, 1_500_000, 15),
|
279
|
-
/** @deprecated */
|
280
|
-
fhd_30: new VideoPreset(1920, 1080, 3_000_000, 30),
|
281
|
-
} as const;
|
package/src/room/track/types.ts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import type LocalAudioTrack from './LocalAudioTrack';
|
2
|
-
import type LocalVideoTrack from './LocalVideoTrack';
|
3
|
-
import type RemoteAudioTrack from './RemoteAudioTrack';
|
4
|
-
import type RemoteVideoTrack from './RemoteVideoTrack';
|
5
|
-
|
6
|
-
export type RemoteTrack = RemoteAudioTrack | RemoteVideoTrack;
|
7
|
-
export type AudioTrack = RemoteAudioTrack | LocalAudioTrack;
|
8
|
-
export type VideoTrack = RemoteVideoTrack | LocalVideoTrack;
|
9
|
-
|
10
|
-
export type AdaptiveStreamSettings = {
|
11
|
-
/**
|
12
|
-
* Set a custom pixel density, defaults to 1
|
13
|
-
* When streaming videos on a ultra high definition screen this setting
|
14
|
-
* let's you account for the devicePixelRatio of those screens.
|
15
|
-
* Set it to `screen` to use the actual pixel density of the screen
|
16
|
-
* Note: this might significantly increase the bandwidth consumed by people
|
17
|
-
* streaming on high definition screens.
|
18
|
-
*/
|
19
|
-
pixelDensity?: number | 'screen'
|
20
|
-
};
|
@@ -1,93 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AudioCaptureOptions, VideoCaptureOptions, VideoPresets,
|
3
|
-
} from './options';
|
4
|
-
import { constraintsForOptions, mergeDefaultOptions } from './utils';
|
5
|
-
|
6
|
-
describe('mergeDefaultOptions', () => {
|
7
|
-
const audioDefaults: AudioCaptureOptions = {
|
8
|
-
autoGainControl: true,
|
9
|
-
channelCount: 2,
|
10
|
-
};
|
11
|
-
const videoDefaults: VideoCaptureOptions = {
|
12
|
-
deviceId: 'video123',
|
13
|
-
resolution: VideoPresets.fhd.resolution,
|
14
|
-
};
|
15
|
-
|
16
|
-
it('does not enable undefined options', () => {
|
17
|
-
const opts = mergeDefaultOptions(undefined, audioDefaults, videoDefaults);
|
18
|
-
expect(opts.audio).toEqual(undefined);
|
19
|
-
expect(opts.video).toEqual(undefined);
|
20
|
-
});
|
21
|
-
|
22
|
-
it('does not enable explicitly disabled', () => {
|
23
|
-
const opts = mergeDefaultOptions({
|
24
|
-
video: false,
|
25
|
-
});
|
26
|
-
expect(opts.audio).toEqual(undefined);
|
27
|
-
expect(opts.video).toEqual(false);
|
28
|
-
});
|
29
|
-
|
30
|
-
it('accepts true for options', () => {
|
31
|
-
const opts = mergeDefaultOptions({
|
32
|
-
audio: true,
|
33
|
-
}, audioDefaults, videoDefaults);
|
34
|
-
expect(opts.audio).toEqual(audioDefaults);
|
35
|
-
expect(opts.video).toEqual(undefined);
|
36
|
-
});
|
37
|
-
|
38
|
-
it('enables overriding specific fields', () => {
|
39
|
-
const opts = mergeDefaultOptions({
|
40
|
-
audio: { channelCount: 1 },
|
41
|
-
}, audioDefaults, videoDefaults);
|
42
|
-
const audioOpts = opts.audio as AudioCaptureOptions;
|
43
|
-
expect(audioOpts.channelCount).toEqual(1);
|
44
|
-
expect(audioOpts.autoGainControl).toEqual(true);
|
45
|
-
});
|
46
|
-
|
47
|
-
it('does not override explicit false', () => {
|
48
|
-
const opts = mergeDefaultOptions({
|
49
|
-
audio: { autoGainControl: false },
|
50
|
-
}, audioDefaults, videoDefaults);
|
51
|
-
const audioOpts = opts.audio as AudioCaptureOptions;
|
52
|
-
expect(audioOpts.autoGainControl).toEqual(false);
|
53
|
-
});
|
54
|
-
});
|
55
|
-
|
56
|
-
describe('constraintsForOptions', () => {
|
57
|
-
it('correctly enables audio bool', () => {
|
58
|
-
const constraints = constraintsForOptions({
|
59
|
-
audio: true,
|
60
|
-
});
|
61
|
-
expect(constraints.audio).toEqual(true);
|
62
|
-
expect(constraints.video).toEqual(false);
|
63
|
-
});
|
64
|
-
|
65
|
-
it('converts audio options correctly', () => {
|
66
|
-
const constraints = constraintsForOptions({
|
67
|
-
audio: {
|
68
|
-
noiseSuppression: true,
|
69
|
-
echoCancellation: false,
|
70
|
-
},
|
71
|
-
});
|
72
|
-
const audioOpts = constraints.audio as MediaTrackConstraints;
|
73
|
-
expect(Object.keys(audioOpts)).toEqual(['noiseSuppression', 'echoCancellation']);
|
74
|
-
expect(audioOpts.noiseSuppression).toEqual(true);
|
75
|
-
expect(audioOpts.echoCancellation).toEqual(false);
|
76
|
-
});
|
77
|
-
|
78
|
-
it('converts video options correctly', () => {
|
79
|
-
const constraints = constraintsForOptions({
|
80
|
-
video: {
|
81
|
-
resolution: VideoPresets.hd.resolution,
|
82
|
-
facingMode: 'user',
|
83
|
-
deviceId: 'video123',
|
84
|
-
},
|
85
|
-
});
|
86
|
-
const videoOpts = constraints.video as MediaTrackConstraints;
|
87
|
-
expect(Object.keys(videoOpts)).toEqual(['width', 'height', 'frameRate', 'aspectRatio', 'facingMode', 'deviceId']);
|
88
|
-
expect(videoOpts.width).toEqual(VideoPresets.hd.resolution.width);
|
89
|
-
expect(videoOpts.height).toEqual(VideoPresets.hd.resolution.height);
|
90
|
-
expect(videoOpts.frameRate).toEqual(VideoPresets.hd.resolution.frameRate);
|
91
|
-
expect(videoOpts.aspectRatio).toEqual(VideoPresets.hd.resolution.aspectRatio);
|
92
|
-
});
|
93
|
-
});
|
package/src/room/track/utils.ts
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
import { sleep } from '../utils';
|
2
|
-
import {
|
3
|
-
AudioCaptureOptions, CreateLocalTracksOptions,
|
4
|
-
VideoCaptureOptions,
|
5
|
-
} from './options';
|
6
|
-
import { AudioTrack } from './types';
|
7
|
-
|
8
|
-
export function mergeDefaultOptions(
|
9
|
-
options?: CreateLocalTracksOptions,
|
10
|
-
audioDefaults?: AudioCaptureOptions,
|
11
|
-
videoDefaults?: VideoCaptureOptions,
|
12
|
-
): CreateLocalTracksOptions {
|
13
|
-
const opts: CreateLocalTracksOptions = {
|
14
|
-
...options,
|
15
|
-
};
|
16
|
-
if (opts.audio === true) opts.audio = {};
|
17
|
-
if (opts.video === true) opts.video = {};
|
18
|
-
|
19
|
-
// use defaults
|
20
|
-
if (opts.audio) {
|
21
|
-
mergeObjectWithoutOverwriting(opts.audio as Record<string, unknown>,
|
22
|
-
audioDefaults as Record<string, unknown>);
|
23
|
-
}
|
24
|
-
if (opts.video) {
|
25
|
-
mergeObjectWithoutOverwriting(opts.video as Record<string, unknown>,
|
26
|
-
videoDefaults as Record<string, unknown>);
|
27
|
-
}
|
28
|
-
return opts;
|
29
|
-
}
|
30
|
-
|
31
|
-
function mergeObjectWithoutOverwriting(
|
32
|
-
mainObject: Record<string, unknown>,
|
33
|
-
objectToMerge: Record<string, unknown>,
|
34
|
-
): Record<string, unknown> {
|
35
|
-
Object.keys(objectToMerge).forEach((key) => {
|
36
|
-
if (mainObject[key] === undefined) mainObject[key] = objectToMerge[key];
|
37
|
-
});
|
38
|
-
return mainObject;
|
39
|
-
}
|
40
|
-
|
41
|
-
export function constraintsForOptions(options: CreateLocalTracksOptions): MediaStreamConstraints {
|
42
|
-
const constraints: MediaStreamConstraints = {};
|
43
|
-
|
44
|
-
if (options.video) {
|
45
|
-
// default video options
|
46
|
-
if (typeof options.video === 'object') {
|
47
|
-
const videoOptions: MediaTrackConstraints = {};
|
48
|
-
const target = videoOptions as Record<string, unknown>;
|
49
|
-
const source = options.video as Record<string, unknown>;
|
50
|
-
Object.keys(source).forEach((key) => {
|
51
|
-
switch (key) {
|
52
|
-
case 'resolution':
|
53
|
-
// flatten VideoResolution fields
|
54
|
-
mergeObjectWithoutOverwriting(target, source.resolution as Record<string, unknown>);
|
55
|
-
break;
|
56
|
-
default:
|
57
|
-
target[key] = source[key];
|
58
|
-
}
|
59
|
-
});
|
60
|
-
constraints.video = videoOptions;
|
61
|
-
} else {
|
62
|
-
constraints.video = options.video;
|
63
|
-
}
|
64
|
-
} else {
|
65
|
-
constraints.video = false;
|
66
|
-
}
|
67
|
-
|
68
|
-
if (options.audio) {
|
69
|
-
if (typeof options.audio === 'object') {
|
70
|
-
constraints.audio = options.audio;
|
71
|
-
} else {
|
72
|
-
constraints.audio = true;
|
73
|
-
}
|
74
|
-
} else {
|
75
|
-
constraints.audio = false;
|
76
|
-
}
|
77
|
-
return constraints;
|
78
|
-
}
|
79
|
-
/**
|
80
|
-
* This function detects silence on a given [[Track]] instance.
|
81
|
-
* Returns true if the track seems to be entirely silent.
|
82
|
-
*/
|
83
|
-
export async function detectSilence(
|
84
|
-
track: AudioTrack,
|
85
|
-
timeOffset = 200,
|
86
|
-
): Promise<boolean> {
|
87
|
-
const ctx = getNewAudioContext();
|
88
|
-
if (ctx) {
|
89
|
-
const analyser = ctx.createAnalyser();
|
90
|
-
analyser.fftSize = 2048;
|
91
|
-
|
92
|
-
const bufferLength = analyser.frequencyBinCount;
|
93
|
-
const dataArray = new Uint8Array(bufferLength);
|
94
|
-
const source = ctx.createMediaStreamSource(new MediaStream([track.mediaStreamTrack]));
|
95
|
-
|
96
|
-
source.connect(analyser);
|
97
|
-
await sleep(timeOffset);
|
98
|
-
analyser.getByteTimeDomainData(dataArray);
|
99
|
-
const someNoise = dataArray.some((sample) => sample !== 128 && sample !== 0);
|
100
|
-
ctx.close();
|
101
|
-
return !someNoise;
|
102
|
-
}
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* @internal
|
108
|
-
*/
|
109
|
-
export function getNewAudioContext(): AudioContext | void {
|
110
|
-
// @ts-ignore
|
111
|
-
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
112
|
-
if (AudioContext) {
|
113
|
-
return new AudioContext();
|
114
|
-
}
|
115
|
-
}
|