livekit-client 1.0.4 → 1.1.0
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/dist/livekit-client.esm.mjs +49 -38
- 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/room/participant/LocalParticipant.d.ts +4 -4
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/room/participant/LocalParticipant.ts +74 -33
@@ -4,7 +4,7 @@ import { DataChannelInfo, TrackPublishedResponse } from '../../proto/livekit_rtc
|
|
4
4
|
import RTCEngine from '../RTCEngine';
|
5
5
|
import LocalTrack from '../track/LocalTrack';
|
6
6
|
import LocalTrackPublication from '../track/LocalTrackPublication';
|
7
|
-
import { CreateLocalTracksOptions, ScreenShareCaptureOptions, TrackPublishOptions } from '../track/options';
|
7
|
+
import { AudioCaptureOptions, CreateLocalTracksOptions, ScreenShareCaptureOptions, TrackPublishOptions, VideoCaptureOptions } from '../track/options';
|
8
8
|
import { Track } from '../track/Track';
|
9
9
|
import Participant from './Participant';
|
10
10
|
import { ParticipantTrackPermission } from './ParticipantTrackPermission';
|
@@ -33,19 +33,19 @@ export default class LocalParticipant extends Participant {
|
|
33
33
|
* If a track has already published, it'll mute or unmute the track.
|
34
34
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
35
35
|
*/
|
36
|
-
setCameraEnabled(enabled: boolean): Promise<LocalTrackPublication | undefined>;
|
36
|
+
setCameraEnabled(enabled: boolean, options?: VideoCaptureOptions): Promise<LocalTrackPublication | undefined>;
|
37
37
|
/**
|
38
38
|
* Enable or disable a participant's microphone track.
|
39
39
|
*
|
40
40
|
* If a track has already published, it'll mute or unmute the track.
|
41
41
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
42
42
|
*/
|
43
|
-
setMicrophoneEnabled(enabled: boolean): Promise<LocalTrackPublication | undefined>;
|
43
|
+
setMicrophoneEnabled(enabled: boolean, options?: AudioCaptureOptions): Promise<LocalTrackPublication | undefined>;
|
44
44
|
/**
|
45
45
|
* Start or stop sharing a participant's screen
|
46
46
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
47
47
|
*/
|
48
|
-
setScreenShareEnabled(enabled: boolean): Promise<LocalTrackPublication | undefined>;
|
48
|
+
setScreenShareEnabled(enabled: boolean, options?: ScreenShareCaptureOptions): Promise<LocalTrackPublication | undefined>;
|
49
49
|
/** @internal */
|
50
50
|
setPermissions(permissions: ParticipantPermission): boolean;
|
51
51
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"LocalParticipant.d.ts","sourceRoot":"","sources":["../../../../src/room/participant/LocalParticipant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAc,eAAe,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAEL,eAAe,EAGf,sBAAsB,EAEvB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,qBAAqB,MAAM,gCAAgC,CAAC;AAKnE,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAEzB,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAA0B,MAAM,8BAA8B,CAAC;AAElG,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAGpD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,WAAW;IACvD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAEhD,WAAW,EAAE,GAAG,CAAC,MAAM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WlB;IAEF,OAAO,CAAC,qBAAqB,CAG3B;IAEF,OAAO,CAAC,sBAAsB,CAG5B;IAEF,OAAO,CAAC,6BAA6B,CAiBnC;IAEF,OAAO,CAAC,2BAA2B,CAUjC;IAEF,OAAO,CAAC,gBAAgB,CAKtB;IAEF,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,iBAAiB;IA4CzB,gBAAgB;IAChB,mBAAmB,IAAI,sBAAsB,EAAE;IAa/C,gBAAgB;IAChB,gBAAgB,IAAI,eAAe,EAAE;CAoBtC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "livekit-client",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.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",
|
@@ -43,6 +43,7 @@
|
|
43
43
|
"devDependencies": {
|
44
44
|
"@babel/core": "^7.17.9",
|
45
45
|
"@babel/preset-env": "^7.16.11",
|
46
|
+
"@changesets/changelog-github": "^0.4.4",
|
46
47
|
"@changesets/cli": "^2.22.0",
|
47
48
|
"@rollup/plugin-babel": "^5.3.1",
|
48
49
|
"@rollup/plugin-commonjs": "^21.0.3",
|
@@ -20,10 +20,12 @@ import LocalVideoTrack, {
|
|
20
20
|
videoLayersFromEncodings,
|
21
21
|
} from '../track/LocalVideoTrack';
|
22
22
|
import {
|
23
|
+
AudioCaptureOptions,
|
23
24
|
CreateLocalTracksOptions,
|
24
25
|
ScreenShareCaptureOptions,
|
25
26
|
ScreenSharePresets,
|
26
27
|
TrackPublishOptions,
|
28
|
+
VideoCaptureOptions,
|
27
29
|
VideoCodec,
|
28
30
|
} from '../track/options';
|
29
31
|
import { Track } from '../track/Track';
|
@@ -117,8 +119,11 @@ export default class LocalParticipant extends Participant {
|
|
117
119
|
* If a track has already published, it'll mute or unmute the track.
|
118
120
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
119
121
|
*/
|
120
|
-
setCameraEnabled(
|
121
|
-
|
122
|
+
setCameraEnabled(
|
123
|
+
enabled: boolean,
|
124
|
+
options?: VideoCaptureOptions,
|
125
|
+
): Promise<LocalTrackPublication | undefined> {
|
126
|
+
return this.setTrackEnabled(Track.Source.Camera, enabled, options);
|
122
127
|
}
|
123
128
|
|
124
129
|
/**
|
@@ -127,16 +132,22 @@ export default class LocalParticipant extends Participant {
|
|
127
132
|
* If a track has already published, it'll mute or unmute the track.
|
128
133
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
129
134
|
*/
|
130
|
-
setMicrophoneEnabled(
|
131
|
-
|
135
|
+
setMicrophoneEnabled(
|
136
|
+
enabled: boolean,
|
137
|
+
options?: AudioCaptureOptions,
|
138
|
+
): Promise<LocalTrackPublication | undefined> {
|
139
|
+
return this.setTrackEnabled(Track.Source.Microphone, enabled, options);
|
132
140
|
}
|
133
141
|
|
134
142
|
/**
|
135
143
|
* Start or stop sharing a participant's screen
|
136
144
|
* Resolves with a `LocalTrackPublication` instance if successful and `undefined` otherwise
|
137
145
|
*/
|
138
|
-
setScreenShareEnabled(
|
139
|
-
|
146
|
+
setScreenShareEnabled(
|
147
|
+
enabled: boolean,
|
148
|
+
options?: ScreenShareCaptureOptions,
|
149
|
+
): Promise<LocalTrackPublication | undefined> {
|
150
|
+
return this.setTrackEnabled(Track.Source.ScreenShare, enabled, options);
|
140
151
|
}
|
141
152
|
|
142
153
|
/** @internal */
|
@@ -155,16 +166,32 @@ export default class LocalParticipant extends Participant {
|
|
155
166
|
* Resolves with LocalTrackPublication if successful and void otherwise
|
156
167
|
*/
|
157
168
|
private async setTrackEnabled(
|
158
|
-
source: Track.Source,
|
169
|
+
source: Extract<Track.Source, Track.Source.Camera>,
|
159
170
|
enabled: boolean,
|
160
|
-
|
171
|
+
options?: VideoCaptureOptions,
|
172
|
+
): Promise<LocalTrackPublication | undefined>;
|
173
|
+
private async setTrackEnabled(
|
174
|
+
source: Extract<Track.Source, Track.Source.Microphone>,
|
175
|
+
enabled: boolean,
|
176
|
+
options?: AudioCaptureOptions,
|
177
|
+
): Promise<LocalTrackPublication | undefined>;
|
178
|
+
private async setTrackEnabled(
|
179
|
+
source: Extract<Track.Source, Track.Source.ScreenShare>,
|
180
|
+
enabled: boolean,
|
181
|
+
options?: ScreenShareCaptureOptions,
|
182
|
+
): Promise<LocalTrackPublication | undefined>;
|
183
|
+
private async setTrackEnabled(
|
184
|
+
source: Track.Source,
|
185
|
+
enabled: true,
|
186
|
+
options?: VideoCaptureOptions | AudioCaptureOptions | ScreenShareCaptureOptions,
|
187
|
+
) {
|
161
188
|
log.debug('setTrackEnabled', { source, enabled });
|
162
189
|
let track = this.getTrack(source);
|
163
190
|
if (enabled) {
|
164
191
|
if (track) {
|
165
192
|
await track.unmute();
|
166
193
|
} else {
|
167
|
-
let
|
194
|
+
let localTracks: Array<LocalTrack> | undefined;
|
168
195
|
if (this.pendingPublishing.has(source)) {
|
169
196
|
log.info('skipping duplicate published source', { source });
|
170
197
|
// no-op it's already been requested
|
@@ -174,23 +201,32 @@ export default class LocalParticipant extends Participant {
|
|
174
201
|
try {
|
175
202
|
switch (source) {
|
176
203
|
case Track.Source.Camera:
|
177
|
-
|
178
|
-
video: true,
|
204
|
+
localTracks = await this.createTracks({
|
205
|
+
video: (options as VideoCaptureOptions | undefined) ?? true,
|
179
206
|
});
|
207
|
+
|
180
208
|
break;
|
181
209
|
case Track.Source.Microphone:
|
182
|
-
|
183
|
-
audio: true,
|
210
|
+
localTracks = await this.createTracks({
|
211
|
+
audio: (options as AudioCaptureOptions | undefined) ?? true,
|
184
212
|
});
|
185
213
|
break;
|
186
214
|
case Track.Source.ScreenShare:
|
187
|
-
|
215
|
+
localTracks = await this.createScreenTracks({
|
216
|
+
...(options as ScreenShareCaptureOptions | undefined),
|
217
|
+
});
|
188
218
|
break;
|
189
219
|
default:
|
190
220
|
throw new TrackInvalidError(source);
|
191
221
|
}
|
192
|
-
|
193
|
-
|
222
|
+
const publishPromises: Array<Promise<LocalTrackPublication>> = [];
|
223
|
+
for (const localTrack of localTracks) {
|
224
|
+
publishPromises.push(this.publishTrack(localTrack));
|
225
|
+
}
|
226
|
+
const publishedTracks = await Promise.all(publishPromises);
|
227
|
+
// for screen share publications including audio, this will only return the screen share publication, not the screen share audio one
|
228
|
+
// revisit if we want to return an array of tracks instead for v2
|
229
|
+
[track] = publishedTracks;
|
194
230
|
} catch (e) {
|
195
231
|
if (e instanceof Error && !(e instanceof TrackInvalidError)) {
|
196
232
|
this.emit(ParticipantEvent.MediaDevicesError, e);
|
@@ -204,6 +240,10 @@ export default class LocalParticipant extends Participant {
|
|
204
240
|
// screenshare cannot be muted, unpublish instead
|
205
241
|
if (source === Track.Source.ScreenShare) {
|
206
242
|
track = this.unpublishTrack(track.track);
|
243
|
+
const screenAudioTrack = this.getTrack(Track.Source.ScreenShareAudio);
|
244
|
+
if (screenAudioTrack && screenAudioTrack.track) {
|
245
|
+
this.unpublishTrack(screenAudioTrack.track);
|
246
|
+
}
|
207
247
|
} else {
|
208
248
|
await track.mute();
|
209
249
|
}
|
@@ -794,35 +834,36 @@ export default class LocalParticipant extends Participant {
|
|
794
834
|
const cap = RTCRtpSender.getCapabilities(kind);
|
795
835
|
if (!cap) return;
|
796
836
|
log.debug('get capabilities', cap);
|
797
|
-
|
798
|
-
const
|
837
|
+
const matched: RTCRtpCodecCapability[] = [];
|
838
|
+
const partialMatched: RTCRtpCodecCapability[] = [];
|
839
|
+
const unmatched: RTCRtpCodecCapability[] = [];
|
799
840
|
cap.codecs.forEach((c) => {
|
800
841
|
const codec = c.mimeType.toLowerCase();
|
842
|
+
if (codec === 'audio/opus') {
|
843
|
+
matched.push(c);
|
844
|
+
return;
|
845
|
+
}
|
801
846
|
const matchesVideoCodec = codec === `video/${videoCodec}`;
|
802
|
-
|
803
|
-
|
804
|
-
codecs.push(c);
|
847
|
+
if (!matchesVideoCodec) {
|
848
|
+
unmatched.push(c);
|
805
849
|
return;
|
806
850
|
}
|
807
851
|
// for h264 codecs that have sdpFmtpLine available, use only if the
|
808
852
|
// profile-level-id is 42e01f for cross-browser compatibility
|
809
|
-
if (videoCodec === 'h264'
|
810
|
-
if (
|
811
|
-
|
812
|
-
|
853
|
+
if (videoCodec === 'h264') {
|
854
|
+
if (c.sdpFmtpLine && c.sdpFmtpLine.includes('profile-level-id=42e01f')) {
|
855
|
+
matched.push(c);
|
856
|
+
} else {
|
857
|
+
partialMatched.push(c);
|
813
858
|
}
|
814
|
-
}
|
815
|
-
if (matchesVideoCodec || codec === 'audio/opus') {
|
816
|
-
selected = c;
|
817
859
|
return;
|
818
860
|
}
|
819
|
-
|
861
|
+
|
862
|
+
matched.push(c);
|
820
863
|
});
|
821
864
|
|
822
|
-
if (
|
823
|
-
|
824
|
-
codecs.unshift(selected);
|
825
|
-
transceiver.setCodecPreferences(codecs);
|
865
|
+
if ('setCodecPreferences' in transceiver) {
|
866
|
+
transceiver.setCodecPreferences(matched.concat(partialMatched, unmatched));
|
826
867
|
}
|
827
868
|
}
|
828
869
|
|