livekit-client 1.4.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/livekit-client.esm.mjs +2478 -5368
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts +3 -2
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/connectionHelper/ConnectionCheck.d.ts +25 -0
- package/dist/src/connectionHelper/ConnectionCheck.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/src/connectionHelper/checks/Checker.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/src/connectionHelper/checks/publishAudio.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/src/connectionHelper/checks/publishVideo.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/src/connectionHelper/checks/reconnect.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/src/connectionHelper/checks/turn.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/src/connectionHelper/checks/webrtc.d.ts.map +1 -0
- package/dist/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -0
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/logger.d.ts +3 -3
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/options.d.ts +4 -1
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +4 -4
- package/dist/src/proto/google/protobuf/timestamp.d.ts.map +1 -1
- package/dist/src/proto/livekit_models.d.ts +4 -4
- package/dist/src/proto/livekit_models.d.ts.map +1 -1
- package/dist/src/proto/livekit_rtc.d.ts +12 -4
- package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
- package/dist/src/room/DeviceManager.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +4 -3
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +27 -4
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/events.d.ts +9 -1
- package/dist/src/room/events.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/Participant.d.ts +1 -1
- package/dist/src/room/participant/Participant.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrackPublication.d.ts +2 -0
- package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts +2 -1
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/src/room/track/TrackPublication.d.ts +1 -1
- package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/options.d.ts +3 -3
- package/dist/src/room/track/options.d.ts.map +1 -1
- package/dist/src/room/track/types.d.ts +3 -3
- package/dist/src/room/track/types.d.ts.map +1 -1
- package/dist/src/room/types.d.ts +13 -0
- package/dist/src/room/types.d.ts.map +1 -0
- package/dist/src/room/utils.d.ts +44 -0
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/ts4.2/src/api/SignalClient.d.ts +86 -0
- package/dist/ts4.2/src/connectionHelper/ConnectionCheck.d.ts +25 -0
- package/dist/ts4.2/src/connectionHelper/checks/Checker.d.ts +59 -0
- package/dist/ts4.2/src/connectionHelper/checks/publishAudio.d.ts +6 -0
- package/dist/ts4.2/src/connectionHelper/checks/publishVideo.d.ts +6 -0
- package/dist/ts4.2/src/connectionHelper/checks/reconnect.d.ts +6 -0
- package/dist/ts4.2/src/connectionHelper/checks/turn.d.ts +6 -0
- package/dist/ts4.2/src/connectionHelper/checks/webrtc.d.ts +6 -0
- package/dist/ts4.2/src/connectionHelper/checks/websocket.d.ts +6 -0
- package/dist/ts4.2/src/index.d.ts +31 -0
- package/dist/ts4.2/src/logger.d.ts +26 -0
- package/dist/ts4.2/src/options.d.ts +94 -0
- package/dist/ts4.2/src/proto/google/protobuf/timestamp.d.ts +141 -0
- package/dist/ts4.2/src/proto/livekit_models.d.ts +1421 -0
- package/dist/ts4.2/src/proto/livekit_rtc.d.ts +7122 -0
- package/dist/ts4.2/src/room/DefaultReconnectPolicy.d.ts +8 -0
- package/dist/ts4.2/src/room/DeviceManager.d.ts +9 -0
- package/dist/ts4.2/src/room/PCTransport.d.ts +33 -0
- package/dist/ts4.2/src/room/RTCEngine.d.ts +97 -0
- package/dist/ts4.2/src/room/ReconnectPolicy.d.ts +23 -0
- package/dist/ts4.2/src/room/Room.d.ts +220 -0
- package/dist/ts4.2/src/room/defaults.d.ts +8 -0
- package/dist/ts4.2/src/room/errors.d.ts +39 -0
- package/dist/ts4.2/src/room/events.d.ts +426 -0
- package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +141 -0
- package/dist/ts4.2/src/room/participant/Participant.d.ts +92 -0
- package/dist/ts4.2/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
- package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +52 -0
- package/dist/ts4.2/src/room/participant/publishUtils.d.ts +19 -0
- package/dist/ts4.2/src/room/stats.d.ts +67 -0
- package/dist/ts4.2/src/room/track/LocalAudioTrack.d.ts +25 -0
- package/dist/ts4.2/src/room/track/LocalTrack.d.ts +42 -0
- package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +38 -0
- package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +53 -0
- package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +53 -0
- package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +15 -0
- package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +61 -0
- package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +52 -0
- package/dist/ts4.2/src/room/track/Track.d.ts +122 -0
- package/dist/ts4.2/src/room/track/TrackPublication.d.ts +68 -0
- package/dist/ts4.2/src/room/track/create.d.ts +24 -0
- package/dist/ts4.2/src/room/track/options.d.ts +241 -0
- package/dist/ts4.2/src/room/track/types.d.ts +23 -0
- package/dist/ts4.2/src/room/track/utils.d.ts +14 -0
- package/dist/ts4.2/src/room/types.d.ts +13 -0
- package/dist/ts4.2/src/room/utils.d.ts +79 -0
- package/dist/ts4.2/src/test/MockMediaStreamTrack.d.ts +26 -0
- package/dist/ts4.2/src/test/mocks.d.ts +11 -0
- package/dist/ts4.2/src/version.d.ts +3 -0
- package/package.json +32 -22
- package/src/api/SignalClient.ts +41 -17
- package/src/connectionHelper/ConnectionCheck.ts +90 -0
- package/src/connectionHelper/checks/Checker.ts +164 -0
- package/src/connectionHelper/checks/publishAudio.ts +33 -0
- package/src/connectionHelper/checks/publishVideo.ts +33 -0
- package/src/connectionHelper/checks/reconnect.ts +45 -0
- package/src/connectionHelper/checks/turn.ts +53 -0
- package/src/connectionHelper/checks/webrtc.ts +18 -0
- package/src/connectionHelper/checks/websocket.ts +22 -0
- package/src/index.ts +8 -1
- package/src/options.ts +5 -1
- package/src/proto/livekit_rtc.ts +12 -1
- package/src/room/DeviceManager.ts +0 -17
- package/src/room/RTCEngine.ts +35 -26
- package/src/room/Room.ts +231 -63
- package/src/room/events.ts +9 -0
- package/src/room/participant/LocalParticipant.ts +18 -11
- package/src/room/participant/publishUtils.ts +1 -1
- package/src/room/track/LocalAudioTrack.ts +1 -1
- package/src/room/track/LocalTrack.ts +4 -0
- package/src/room/track/LocalVideoTrack.ts +1 -1
- package/src/room/track/RemoteTrackPublication.ts +20 -0
- package/src/room/track/RemoteVideoTrack.ts +4 -0
- package/src/room/track/Track.ts +1 -0
- package/src/room/types.ts +12 -0
- package/src/room/utils.ts +150 -12
@@ -0,0 +1,24 @@
|
|
1
|
+
import LocalAudioTrack from './LocalAudioTrack';
|
2
|
+
import type LocalTrack from './LocalTrack';
|
3
|
+
import LocalVideoTrack from './LocalVideoTrack';
|
4
|
+
import { AudioCaptureOptions, CreateLocalTracksOptions, ScreenShareCaptureOptions, VideoCaptureOptions } from './options';
|
5
|
+
/**
|
6
|
+
* Creates a local video and audio track at the same time. When acquiring both
|
7
|
+
* audio and video tracks together, it'll display a single permission prompt to
|
8
|
+
* the user instead of two separate ones.
|
9
|
+
* @param options
|
10
|
+
*/
|
11
|
+
export declare function createLocalTracks(options?: CreateLocalTracksOptions): Promise<Array<LocalTrack>>;
|
12
|
+
/**
|
13
|
+
* Creates a [[LocalVideoTrack]] with getUserMedia()
|
14
|
+
* @param options
|
15
|
+
*/
|
16
|
+
export declare function createLocalVideoTrack(options?: VideoCaptureOptions): Promise<LocalVideoTrack>;
|
17
|
+
export declare function createLocalAudioTrack(options?: AudioCaptureOptions): Promise<LocalAudioTrack>;
|
18
|
+
/**
|
19
|
+
* Creates a screen capture tracks with getDisplayMedia().
|
20
|
+
* A LocalVideoTrack is always created and returned.
|
21
|
+
* If { audio: true }, and the browser supports audio capture, a LocalAudioTrack is also created.
|
22
|
+
*/
|
23
|
+
export declare function createLocalScreenTracks(options?: ScreenShareCaptureOptions): Promise<Array<LocalTrack>>;
|
24
|
+
//# sourceMappingURL=create.d.ts.map
|
@@ -0,0 +1,241 @@
|
|
1
|
+
import type { Track } from './Track';
|
2
|
+
export interface TrackPublishDefaults {
|
3
|
+
/**
|
4
|
+
* encoding parameters for camera track
|
5
|
+
*/
|
6
|
+
videoEncoding?: VideoEncoding;
|
7
|
+
/**
|
8
|
+
* @experimental
|
9
|
+
*/
|
10
|
+
backupCodec?: {
|
11
|
+
codec: BackupVideoCodec;
|
12
|
+
encoding: VideoEncoding;
|
13
|
+
} | false;
|
14
|
+
/**
|
15
|
+
* encoding parameters for screen share track
|
16
|
+
*/
|
17
|
+
screenShareEncoding?: VideoEncoding;
|
18
|
+
/**
|
19
|
+
* codec, defaults to vp8; for svc codecs, auto enable vp8
|
20
|
+
* as backup. (TBD)
|
21
|
+
*/
|
22
|
+
videoCodec?: VideoCodec;
|
23
|
+
/**
|
24
|
+
* max audio bitrate, defaults to [[AudioPresets.speech]]
|
25
|
+
*/
|
26
|
+
audioBitrate?: number;
|
27
|
+
/**
|
28
|
+
* dtx (Discontinuous Transmission of audio), defaults to true
|
29
|
+
*/
|
30
|
+
dtx?: boolean;
|
31
|
+
/**
|
32
|
+
* red (Redundant Audio Data), defaults to true
|
33
|
+
*/
|
34
|
+
red?: boolean;
|
35
|
+
/**
|
36
|
+
* stereo audio track. defaults determined by capture channel count.
|
37
|
+
*/
|
38
|
+
forceStereo?: boolean;
|
39
|
+
/**
|
40
|
+
* use simulcast, defaults to true.
|
41
|
+
* When using simulcast, LiveKit will publish up to three versions of the stream
|
42
|
+
* at various resolutions.
|
43
|
+
*/
|
44
|
+
simulcast?: boolean;
|
45
|
+
/**
|
46
|
+
* scalability mode for svc codecs, defaults to 'L3T3'.
|
47
|
+
* for svc codecs, simulcast is disabled.
|
48
|
+
*/
|
49
|
+
scalabilityMode?: ScalabilityMode;
|
50
|
+
/**
|
51
|
+
* custom video simulcast layers for camera tracks, defaults to h180, h360, h540
|
52
|
+
* You can specify up to two custom layers that will be used instead of
|
53
|
+
* the LiveKit default layers.
|
54
|
+
* Note: the layers need to be ordered from lowest to highest quality
|
55
|
+
*/
|
56
|
+
videoSimulcastLayers?: Array<VideoPreset>;
|
57
|
+
/**
|
58
|
+
* custom video simulcast layers for screen tracks
|
59
|
+
* Note: the layers need to be ordered from lowest to highest quality
|
60
|
+
*/
|
61
|
+
screenShareSimulcastLayers?: Array<VideoPreset>;
|
62
|
+
/**
|
63
|
+
* For local tracks, stop the underlying MediaStreamTrack when the track is muted (or paused)
|
64
|
+
* on some platforms, this option is necessary to disable the microphone recording indicator.
|
65
|
+
* Note: when this is enabled, and BT devices are connected, they will transition between
|
66
|
+
* profiles (e.g. HFP to A2DP) and there will be an audible difference in playback.
|
67
|
+
*
|
68
|
+
* defaults to false
|
69
|
+
*/
|
70
|
+
stopMicTrackOnMute?: boolean;
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Options when publishing tracks
|
74
|
+
*/
|
75
|
+
export interface TrackPublishOptions extends TrackPublishDefaults {
|
76
|
+
/**
|
77
|
+
* set a track name
|
78
|
+
*/
|
79
|
+
name?: string;
|
80
|
+
/**
|
81
|
+
* Source of track, camera, microphone, or screen
|
82
|
+
*/
|
83
|
+
source?: Track.Source;
|
84
|
+
}
|
85
|
+
export interface CreateLocalTracksOptions {
|
86
|
+
/**
|
87
|
+
* audio track options, true to create with defaults. false if audio shouldn't be created
|
88
|
+
* default true
|
89
|
+
*/
|
90
|
+
audio?: boolean | AudioCaptureOptions;
|
91
|
+
/**
|
92
|
+
* video track options, true to create with defaults. false if video shouldn't be created
|
93
|
+
* default true
|
94
|
+
*/
|
95
|
+
video?: boolean | VideoCaptureOptions;
|
96
|
+
}
|
97
|
+
export interface VideoCaptureOptions {
|
98
|
+
/**
|
99
|
+
* A ConstrainDOMString object specifying a device ID or an array of device
|
100
|
+
* IDs which are acceptable and/or required.
|
101
|
+
*/
|
102
|
+
deviceId?: ConstrainDOMString;
|
103
|
+
/**
|
104
|
+
* a facing or an array of facings which are acceptable and/or required.
|
105
|
+
*/
|
106
|
+
facingMode?: 'user' | 'environment' | 'left' | 'right';
|
107
|
+
resolution?: VideoResolution;
|
108
|
+
}
|
109
|
+
export interface ScreenShareCaptureOptions {
|
110
|
+
/**
|
111
|
+
* true to capture audio shared. browser support for audio capturing in
|
112
|
+
* screenshare is limited: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#browser_compatibility
|
113
|
+
*/
|
114
|
+
audio?: boolean | AudioCaptureOptions;
|
115
|
+
/** capture resolution, defaults to full HD */
|
116
|
+
resolution?: VideoResolution;
|
117
|
+
}
|
118
|
+
export interface AudioCaptureOptions {
|
119
|
+
/**
|
120
|
+
* specifies whether automatic gain control is preferred and/or required
|
121
|
+
*/
|
122
|
+
autoGainControl?: ConstrainBoolean;
|
123
|
+
/**
|
124
|
+
* the channel count or range of channel counts which are acceptable and/or required
|
125
|
+
*/
|
126
|
+
channelCount?: ConstrainULong;
|
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
|
+
* whether or not echo cancellation is preferred and/or required
|
134
|
+
*/
|
135
|
+
echoCancellation?: ConstrainBoolean;
|
136
|
+
/**
|
137
|
+
* the latency or range of latencies which are acceptable and/or required.
|
138
|
+
*/
|
139
|
+
latency?: ConstrainDouble;
|
140
|
+
/**
|
141
|
+
* whether noise suppression is preferred and/or required.
|
142
|
+
*/
|
143
|
+
noiseSuppression?: ConstrainBoolean;
|
144
|
+
/**
|
145
|
+
* the sample rate or range of sample rates which are acceptable and/or required.
|
146
|
+
*/
|
147
|
+
sampleRate?: ConstrainULong;
|
148
|
+
/**
|
149
|
+
* sample size or range of sample sizes which are acceptable and/or required.
|
150
|
+
*/
|
151
|
+
sampleSize?: ConstrainULong;
|
152
|
+
}
|
153
|
+
export interface AudioOutputOptions {
|
154
|
+
/**
|
155
|
+
* deviceId to output audio
|
156
|
+
*
|
157
|
+
* Only supported on browsers where `setSinkId` is available
|
158
|
+
*/
|
159
|
+
deviceId?: string;
|
160
|
+
}
|
161
|
+
export interface VideoResolution {
|
162
|
+
width: number;
|
163
|
+
height: number;
|
164
|
+
frameRate?: number;
|
165
|
+
aspectRatio?: number;
|
166
|
+
}
|
167
|
+
export interface VideoEncoding {
|
168
|
+
maxBitrate: number;
|
169
|
+
maxFramerate?: number;
|
170
|
+
}
|
171
|
+
export declare class VideoPreset {
|
172
|
+
encoding: VideoEncoding;
|
173
|
+
width: number;
|
174
|
+
height: number;
|
175
|
+
constructor(width: number, height: number, maxBitrate: number, maxFramerate?: number);
|
176
|
+
get resolution(): VideoResolution;
|
177
|
+
}
|
178
|
+
export interface AudioPreset {
|
179
|
+
maxBitrate: number;
|
180
|
+
}
|
181
|
+
declare const codecs: readonly [
|
182
|
+
"vp8",
|
183
|
+
"h264",
|
184
|
+
"av1"
|
185
|
+
];
|
186
|
+
declare const backupCodecs: readonly [
|
187
|
+
"vp8",
|
188
|
+
"h264"
|
189
|
+
];
|
190
|
+
export type VideoCodec = typeof codecs[number];
|
191
|
+
export type BackupVideoCodec = typeof backupCodecs[number];
|
192
|
+
export declare function isBackupCodec(codec: string): codec is BackupVideoCodec;
|
193
|
+
/**
|
194
|
+
* scalability modes for svc, only supprot l3t3 now.
|
195
|
+
*/
|
196
|
+
export type ScalabilityMode = 'L3T3';
|
197
|
+
export declare namespace AudioPresets {
|
198
|
+
const telephone: AudioPreset;
|
199
|
+
const speech: AudioPreset;
|
200
|
+
const music: AudioPreset;
|
201
|
+
const musicStereo: AudioPreset;
|
202
|
+
const musicHighQuality: AudioPreset;
|
203
|
+
const musicHighQualityStereo: AudioPreset;
|
204
|
+
}
|
205
|
+
/**
|
206
|
+
* Sane presets for video resolution/encoding
|
207
|
+
*/
|
208
|
+
export declare const VideoPresets: {
|
209
|
+
readonly h90: VideoPreset;
|
210
|
+
readonly h180: VideoPreset;
|
211
|
+
readonly h216: VideoPreset;
|
212
|
+
readonly h360: VideoPreset;
|
213
|
+
readonly h540: VideoPreset;
|
214
|
+
readonly h720: VideoPreset;
|
215
|
+
readonly h1080: VideoPreset;
|
216
|
+
readonly h1440: VideoPreset;
|
217
|
+
readonly h2160: VideoPreset;
|
218
|
+
};
|
219
|
+
/**
|
220
|
+
* Four by three presets
|
221
|
+
*/
|
222
|
+
export declare const VideoPresets43: {
|
223
|
+
readonly h120: VideoPreset;
|
224
|
+
readonly h180: VideoPreset;
|
225
|
+
readonly h240: VideoPreset;
|
226
|
+
readonly h360: VideoPreset;
|
227
|
+
readonly h480: VideoPreset;
|
228
|
+
readonly h540: VideoPreset;
|
229
|
+
readonly h720: VideoPreset;
|
230
|
+
readonly h1080: VideoPreset;
|
231
|
+
readonly h1440: VideoPreset;
|
232
|
+
};
|
233
|
+
export declare const ScreenSharePresets: {
|
234
|
+
readonly h360fps3: VideoPreset;
|
235
|
+
readonly h720fps5: VideoPreset;
|
236
|
+
readonly h720fps15: VideoPreset;
|
237
|
+
readonly h1080fps15: VideoPreset;
|
238
|
+
readonly h1080fps30: VideoPreset;
|
239
|
+
};
|
240
|
+
export {};
|
241
|
+
//# sourceMappingURL=options.d.ts.map
|
@@ -0,0 +1,23 @@
|
|
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
|
+
export type AudioTrack = RemoteAudioTrack | LocalAudioTrack;
|
6
|
+
export type VideoTrack = RemoteVideoTrack | LocalVideoTrack;
|
7
|
+
export type AdaptiveStreamSettings = {
|
8
|
+
/**
|
9
|
+
* Set a custom pixel density, defaults to 1
|
10
|
+
* When streaming videos on a ultra high definition screen this setting
|
11
|
+
* let's you account for the devicePixelRatio of those screens.
|
12
|
+
* Set it to `screen` to use the actual pixel density of the screen
|
13
|
+
* Note: this might significantly increase the bandwidth consumed by people
|
14
|
+
* streaming on high definition screens.
|
15
|
+
*/
|
16
|
+
pixelDensity?: number | 'screen';
|
17
|
+
/**
|
18
|
+
* If true, video gets paused when switching to another tab.
|
19
|
+
* Defaults to true.
|
20
|
+
*/
|
21
|
+
pauseVideoInBackground?: boolean;
|
22
|
+
};
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { AudioCaptureOptions, CreateLocalTracksOptions, VideoCaptureOptions } from './options';
|
2
|
+
import type { AudioTrack } from './types';
|
3
|
+
export declare function mergeDefaultOptions(options?: CreateLocalTracksOptions, audioDefaults?: AudioCaptureOptions, videoDefaults?: VideoCaptureOptions): CreateLocalTracksOptions;
|
4
|
+
export declare function constraintsForOptions(options: CreateLocalTracksOptions): MediaStreamConstraints;
|
5
|
+
/**
|
6
|
+
* This function detects silence on a given [[Track]] instance.
|
7
|
+
* Returns true if the track seems to be entirely silent.
|
8
|
+
*/
|
9
|
+
export declare function detectSilence(track: AudioTrack, timeOffset?: number): Promise<boolean>;
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
export declare function getNewAudioContext(): AudioContext | void;
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { ClientInfo } from '../proto/livekit_models';
|
2
|
+
import type LocalAudioTrack from './track/LocalAudioTrack';
|
3
|
+
import type RemoteAudioTrack from './track/RemoteAudioTrack';
|
4
|
+
export declare function unpackStreamId(packed: string): string[];
|
5
|
+
export declare function sleep(duration: number): Promise<void>;
|
6
|
+
/** @internal */
|
7
|
+
export declare function supportsTransceiver(): boolean;
|
8
|
+
/** @internal */
|
9
|
+
export declare function supportsAddTrack(): boolean;
|
10
|
+
export declare function supportsAdaptiveStream(): boolean;
|
11
|
+
export declare function supportsDynacast(): boolean;
|
12
|
+
export declare function supportsAV1(): boolean;
|
13
|
+
export declare function supportsSetSinkId(elm?: HTMLMediaElement): boolean;
|
14
|
+
export declare function supportsSetCodecPreferences(transceiver: RTCRtpTransceiver): boolean;
|
15
|
+
export declare function isBrowserSupported(): boolean;
|
16
|
+
export declare function isFireFox(): boolean;
|
17
|
+
export declare function isSafari(): boolean;
|
18
|
+
export declare function isMobile(): boolean;
|
19
|
+
export declare function isWeb(): boolean;
|
20
|
+
export declare function compareVersions(v1: string, v2: string): number;
|
21
|
+
export declare const getResizeObserver: () => ResizeObserver;
|
22
|
+
export declare const getIntersectionObserver: () => IntersectionObserver;
|
23
|
+
export interface ObservableMediaElement extends HTMLMediaElement {
|
24
|
+
handleResize: (entry: ResizeObserverEntry) => void;
|
25
|
+
handleVisibilityChanged: (entry: IntersectionObserverEntry) => void;
|
26
|
+
}
|
27
|
+
export declare function getClientInfo(): ClientInfo;
|
28
|
+
export declare function getEmptyVideoStreamTrack(): MediaStreamTrack;
|
29
|
+
export declare function createDummyVideoStreamTrack(width?: number, height?: number, enabled?: boolean, paintContent?: boolean): MediaStreamTrack;
|
30
|
+
export declare function getEmptyAudioStreamTrack(): MediaStreamTrack;
|
31
|
+
export declare class Future<T> {
|
32
|
+
promise: Promise<T>;
|
33
|
+
resolve?: (arg: T) => void;
|
34
|
+
reject?: (e: any) => void;
|
35
|
+
onFinally?: () => void;
|
36
|
+
constructor(futureBase?: (resolve: (arg: T) => void, reject: (e: any) => void) => void, onFinally?: () => void);
|
37
|
+
}
|
38
|
+
export type AudioAnalyserOptions = {
|
39
|
+
/**
|
40
|
+
* If set to true, the analyser will use a cloned version of the underlying mediastreamtrack, which won't be impacted by muting the track.
|
41
|
+
* Useful for local tracks when implementing things like "seems like you're muted, but trying to speak".
|
42
|
+
* Defaults to false
|
43
|
+
*/
|
44
|
+
cloneTrack?: boolean;
|
45
|
+
/**
|
46
|
+
* see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize
|
47
|
+
*/
|
48
|
+
fftSize?: number;
|
49
|
+
/**
|
50
|
+
* see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant
|
51
|
+
*/
|
52
|
+
smoothingTimeConstant?: number;
|
53
|
+
/**
|
54
|
+
* see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/minDecibels
|
55
|
+
*/
|
56
|
+
minDecibels?: number;
|
57
|
+
/**
|
58
|
+
* see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/maxDecibels
|
59
|
+
*/
|
60
|
+
maxDecibels?: number;
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* Creates and returns an analyser web audio node that is attached to the provided track.
|
64
|
+
* Additionally returns a convenience method `calculateVolume` to perform instant volume readings on that track.
|
65
|
+
* Call the returned `cleanup` function to close the audioContext that has been created for the instance of this helper
|
66
|
+
*/
|
67
|
+
export declare function createAudioAnalyser(track: LocalAudioTrack | RemoteAudioTrack, options?: AudioAnalyserOptions): {
|
68
|
+
calculateVolume: () => number;
|
69
|
+
analyser: AnalyserNode;
|
70
|
+
cleanup: () => void;
|
71
|
+
};
|
72
|
+
export declare class Mutex {
|
73
|
+
private _locking;
|
74
|
+
private _locks;
|
75
|
+
constructor();
|
76
|
+
isLocked(): boolean;
|
77
|
+
lock(): Promise<() => void>;
|
78
|
+
}
|
79
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export default class MockMediaStreamTrack implements MediaStreamTrack {
|
2
|
+
contentHint: string;
|
3
|
+
enabled: boolean;
|
4
|
+
id: string;
|
5
|
+
kind: string;
|
6
|
+
label: string;
|
7
|
+
muted: boolean;
|
8
|
+
onended: ((this: MediaStreamTrack, ev: Event) => any) | null;
|
9
|
+
onmute: ((this: MediaStreamTrack, ev: Event) => any) | null;
|
10
|
+
onunmute: ((this: MediaStreamTrack, ev: Event) => any) | null;
|
11
|
+
readyState: MediaStreamTrackState;
|
12
|
+
isolated: boolean;
|
13
|
+
onisolationchange: ((this: MediaStreamTrack, ev: Event) => any) | null;
|
14
|
+
applyConstraints(constraints?: MediaTrackConstraints): Promise<void>;
|
15
|
+
clone(): MediaStreamTrack;
|
16
|
+
getCapabilities(): MediaTrackCapabilities;
|
17
|
+
getConstraints(): MediaTrackConstraints;
|
18
|
+
getSettings(): MediaTrackSettings;
|
19
|
+
stop(): void;
|
20
|
+
addEventListener<K extends keyof MediaStreamTrackEventMap>(type: K, listener: (this: MediaStreamTrack, ev: MediaStreamTrackEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
21
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
22
|
+
removeEventListener<K extends keyof MediaStreamTrackEventMap>(type: K, listener: (this: MediaStreamTrack, ev: MediaStreamTrackEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
23
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
24
|
+
dispatchEvent(event: Event): boolean;
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=MockMediaStreamTrack.d.ts.map
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { SignalClient } from '../api/SignalClient';
|
2
|
+
import RTCEngine from '../room/RTCEngine';
|
3
|
+
declare const mocks: {
|
4
|
+
SignalClient: jest.MockedClass<typeof SignalClient>;
|
5
|
+
RTCEngine: jest.MockedClass<typeof RTCEngine>;
|
6
|
+
MockLocalVideoTrack: {
|
7
|
+
stop: jest.Mock<any, any>;
|
8
|
+
};
|
9
|
+
};
|
10
|
+
export default mocks;
|
11
|
+
//# sourceMappingURL=mocks.d.ts.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "livekit-client",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.6.0",
|
4
4
|
"description": "JavaScript/TypeScript client SDK for LiveKit",
|
5
5
|
"main": "./dist/livekit-client.umd.js",
|
6
6
|
"unpkg": "./dist/livekit-client.umd.js",
|
@@ -15,11 +15,18 @@
|
|
15
15
|
"src"
|
16
16
|
],
|
17
17
|
"types": "dist/src/index.d.ts",
|
18
|
+
"typesVersions": {
|
19
|
+
"<4.8": {
|
20
|
+
"./dist/src/index.d.ts": [
|
21
|
+
"./dist/src/ts4.2/index.d.ts"
|
22
|
+
]
|
23
|
+
}
|
24
|
+
},
|
18
25
|
"repository": "git@github.com:livekit/client-sdk-js.git",
|
19
26
|
"author": "David Zhao <david@davidzhao.com>",
|
20
27
|
"license": "Apache-2.0",
|
21
28
|
"scripts": {
|
22
|
-
"build": "rollup --config",
|
29
|
+
"build": "rollup --config --bundleConfigAsCjs && yarn downlevel-dts",
|
23
30
|
"build:watch": "rollup --watch --config rollup.config.js",
|
24
31
|
"build-docs": "typedoc",
|
25
32
|
"proto": "protoc --plugin=node_modules/ts-proto/protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true --ts_proto_out=./src/proto --ts_proto_opt=outputClientImpl=false,useOptionals=messages,oneof=unions -I./protocol ./protocol/livekit_rtc.proto ./protocol/livekit_models.proto",
|
@@ -29,7 +36,8 @@
|
|
29
36
|
"deploy": "gh-pages -d example/dist",
|
30
37
|
"format": "prettier --write src example/sample.ts",
|
31
38
|
"format:check": "prettier --check src",
|
32
|
-
"release": "yarn build && changeset publish"
|
39
|
+
"release": "yarn build && changeset publish",
|
40
|
+
"downlevel-dts": "downlevel-dts ./dist/ ./dist/ts4.2 --to=4.2"
|
33
41
|
},
|
34
42
|
"dependencies": {
|
35
43
|
"async-await-queue": "^1.2.1",
|
@@ -43,38 +51,40 @@
|
|
43
51
|
"webrtc-adapter": "^8.1.1"
|
44
52
|
},
|
45
53
|
"devDependencies": {
|
46
|
-
"@babel/core": "7.
|
47
|
-
"@babel/preset-env": "7.
|
54
|
+
"@babel/core": "7.20.5",
|
55
|
+
"@babel/preset-env": "7.20.2",
|
48
56
|
"@changesets/changelog-github": "0.4.7",
|
49
|
-
"@changesets/cli": "2.25.
|
50
|
-
"@rollup/plugin-babel": "
|
51
|
-
"@rollup/plugin-commonjs": "
|
52
|
-
"@rollup/plugin-json": "
|
53
|
-
"@rollup/plugin-node-resolve": "
|
54
|
-
"@types/jest": "29.
|
57
|
+
"@changesets/cli": "2.25.2",
|
58
|
+
"@rollup/plugin-babel": "6.0.3",
|
59
|
+
"@rollup/plugin-commonjs": "23.0.4",
|
60
|
+
"@rollup/plugin-json": "5.0.2",
|
61
|
+
"@rollup/plugin-node-resolve": "15.0.1",
|
62
|
+
"@types/jest": "29.2.4",
|
55
63
|
"@types/sdp-transform": "2.4.5",
|
56
64
|
"@types/ua-parser-js": "0.7.36",
|
57
65
|
"@types/ws": "8.5.3",
|
58
|
-
"@typescript-eslint/eslint-plugin": "5.
|
59
|
-
"@typescript-eslint/parser": "5.
|
60
|
-
"
|
66
|
+
"@typescript-eslint/eslint-plugin": "5.46.0",
|
67
|
+
"@typescript-eslint/parser": "5.46.0",
|
68
|
+
"downlevel-dts": "^0.11.0",
|
69
|
+
"eslint": "8.29.0",
|
61
70
|
"eslint-config-airbnb-typescript": "17.0.0",
|
62
71
|
"eslint-config-prettier": "8.5.0",
|
63
72
|
"eslint-plugin-import": "2.26.0",
|
64
73
|
"gh-pages": "4.0.0",
|
65
|
-
"jest": "29.1
|
66
|
-
"prettier": "2.
|
67
|
-
"rollup": "
|
74
|
+
"jest": "29.3.1",
|
75
|
+
"prettier": "2.8.1",
|
76
|
+
"rollup": "3.7.0",
|
77
|
+
"rollup-plugin-delete": "^2.0.0",
|
68
78
|
"rollup-plugin-filesize": "9.1.2",
|
69
79
|
"rollup-plugin-re": "1.0.7",
|
70
80
|
"rollup-plugin-terser": "7.0.2",
|
71
|
-
"rollup-plugin-typescript2": "0.34.
|
81
|
+
"rollup-plugin-typescript2": "0.34.1",
|
72
82
|
"ts-jest": "29.0.3",
|
73
|
-
"ts-proto": "1.
|
74
|
-
"typedoc": "0.23.
|
83
|
+
"ts-proto": "1.135.0",
|
84
|
+
"typedoc": "0.23.21",
|
75
85
|
"typedoc-plugin-no-inherit": "1.4.0",
|
76
|
-
"typescript": "4.
|
77
|
-
"vite": "3.
|
86
|
+
"typescript": "4.9.4",
|
87
|
+
"vite": "3.2.5"
|
78
88
|
},
|
79
89
|
"browserslist": [
|
80
90
|
"safari >= 11",
|
package/src/api/SignalClient.ts
CHANGED
@@ -30,7 +30,7 @@ import {
|
|
30
30
|
UpdateTrackSettings,
|
31
31
|
} from '../proto/livekit_rtc';
|
32
32
|
import { ConnectionError, ConnectionErrorReason } from '../room/errors';
|
33
|
-
import { getClientInfo, sleep } from '../room/utils';
|
33
|
+
import { getClientInfo, Mutex, sleep } from '../room/utils';
|
34
34
|
|
35
35
|
// internal options
|
36
36
|
interface ConnectOpts {
|
@@ -139,12 +139,15 @@ export class SignalClient {
|
|
139
139
|
|
140
140
|
private pingInterval: ReturnType<typeof setInterval> | undefined;
|
141
141
|
|
142
|
+
private closingLock: Mutex;
|
143
|
+
|
142
144
|
constructor(useJSON: boolean = false) {
|
143
145
|
this.isConnected = false;
|
144
146
|
this.isReconnecting = false;
|
145
147
|
this.useJSON = useJSON;
|
146
148
|
this.requestQueue = new Queue();
|
147
149
|
this.queuedRequests = [];
|
150
|
+
this.closingLock = new Mutex();
|
148
151
|
}
|
149
152
|
|
150
153
|
async join(
|
@@ -190,9 +193,9 @@ export class SignalClient {
|
|
190
193
|
const clientInfo = getClientInfo();
|
191
194
|
const params = createConnectionParams(token, clientInfo, opts);
|
192
195
|
|
193
|
-
return new Promise<JoinResponse | void>((resolve, reject) => {
|
194
|
-
const abortHandler = () => {
|
195
|
-
this.close();
|
196
|
+
return new Promise<JoinResponse | void>(async (resolve, reject) => {
|
197
|
+
const abortHandler = async () => {
|
198
|
+
await this.close();
|
196
199
|
reject(new ConnectionError('room connection has been cancelled'));
|
197
200
|
};
|
198
201
|
|
@@ -202,7 +205,7 @@ export class SignalClient {
|
|
202
205
|
abortSignal?.addEventListener('abort', abortHandler);
|
203
206
|
log.debug(`connecting to ${url + params}`);
|
204
207
|
if (this.ws) {
|
205
|
-
this.close();
|
208
|
+
await this.close();
|
206
209
|
}
|
207
210
|
this.ws = new WebSocket(url + params);
|
208
211
|
this.ws.binaryType = 'arraybuffer';
|
@@ -277,7 +280,11 @@ export class SignalClient {
|
|
277
280
|
}
|
278
281
|
resolve(resp.message.join);
|
279
282
|
} else {
|
280
|
-
reject(
|
283
|
+
reject(
|
284
|
+
new ConnectionError(
|
285
|
+
`did not receive join response, got ${resp.message?.$case} instead`,
|
286
|
+
),
|
287
|
+
);
|
281
288
|
}
|
282
289
|
return;
|
283
290
|
}
|
@@ -301,16 +308,33 @@ export class SignalClient {
|
|
301
308
|
});
|
302
309
|
}
|
303
310
|
|
304
|
-
close() {
|
305
|
-
|
306
|
-
|
307
|
-
this.
|
308
|
-
this.ws
|
309
|
-
|
310
|
-
|
311
|
+
async close() {
|
312
|
+
const unlock = await this.closingLock.lock();
|
313
|
+
try {
|
314
|
+
this.isConnected = false;
|
315
|
+
if (this.ws) {
|
316
|
+
this.ws.onclose = null;
|
317
|
+
this.ws.onmessage = null;
|
318
|
+
this.ws.onopen = null;
|
319
|
+
|
320
|
+
// calling `ws.close()` only starts the closing handshake (CLOSING state), prefer to wait until state is actually CLOSED
|
321
|
+
const closePromise = new Promise((resolve) => {
|
322
|
+
if (this.ws) {
|
323
|
+
this.ws.onclose = resolve;
|
324
|
+
} else {
|
325
|
+
resolve(true);
|
326
|
+
}
|
327
|
+
});
|
328
|
+
|
329
|
+
this.ws.close();
|
330
|
+
// 250ms grace period for ws to close gracefully
|
331
|
+
await Promise.race([closePromise, sleep(250)]);
|
332
|
+
}
|
333
|
+
this.ws = undefined;
|
334
|
+
this.clearPingInterval();
|
335
|
+
} finally {
|
336
|
+
unlock();
|
311
337
|
}
|
312
|
-
this.ws = undefined;
|
313
|
-
this.clearPingInterval();
|
314
338
|
}
|
315
339
|
|
316
340
|
// initial offer after joining
|
@@ -441,8 +465,8 @@ export class SignalClient {
|
|
441
465
|
if (this.signalLatency) {
|
442
466
|
await sleep(this.signalLatency);
|
443
467
|
}
|
444
|
-
if (!this.ws) {
|
445
|
-
log.error(
|
468
|
+
if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
|
469
|
+
log.error(`cannot send signal request before connected, type: ${message?.$case}`);
|
446
470
|
return;
|
447
471
|
}
|
448
472
|
|