livekit-client 2.1.5 → 2.2.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.
Files changed (47) hide show
  1. package/dist/livekit-client.esm.mjs +149 -64
  2. package/dist/livekit-client.esm.mjs.map +1 -1
  3. package/dist/livekit-client.umd.js +1 -1
  4. package/dist/livekit-client.umd.js.map +1 -1
  5. package/dist/src/index.d.ts +2 -2
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/room/RTCEngine.d.ts +2 -2
  8. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  9. package/dist/src/room/Room.d.ts +4 -1
  10. package/dist/src/room/Room.d.ts.map +1 -1
  11. package/dist/src/room/events.d.ts +12 -1
  12. package/dist/src/room/events.d.ts.map +1 -1
  13. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  14. package/dist/src/room/participant/Participant.d.ts +6 -3
  15. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  16. package/dist/src/room/participant/RemoteParticipant.d.ts +3 -3
  17. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  18. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  19. package/dist/src/room/track/LocalTrack.d.ts +1 -1
  20. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  21. package/dist/src/room/track/LocalVideoTrack.d.ts +1 -1
  22. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  23. package/dist/src/room/track/create.d.ts.map +1 -1
  24. package/dist/src/room/track/options.d.ts +9 -0
  25. package/dist/src/room/track/options.d.ts.map +1 -1
  26. package/dist/ts4.2/src/index.d.ts +2 -2
  27. package/dist/ts4.2/src/room/RTCEngine.d.ts +2 -2
  28. package/dist/ts4.2/src/room/Room.d.ts +4 -1
  29. package/dist/ts4.2/src/room/events.d.ts +12 -1
  30. package/dist/ts4.2/src/room/participant/Participant.d.ts +7 -3
  31. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +3 -3
  32. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -1
  33. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +1 -1
  34. package/dist/ts4.2/src/room/track/options.d.ts +9 -0
  35. package/package.json +1 -1
  36. package/src/index.ts +2 -1
  37. package/src/room/RTCEngine.ts +23 -6
  38. package/src/room/Room.ts +39 -10
  39. package/src/room/events.ts +14 -1
  40. package/src/room/participant/LocalParticipant.ts +36 -25
  41. package/src/room/participant/Participant.ts +14 -1
  42. package/src/room/participant/RemoteParticipant.ts +17 -4
  43. package/src/room/participant/publishUtils.ts +4 -0
  44. package/src/room/track/LocalTrack.ts +13 -9
  45. package/src/room/track/LocalVideoTrack.ts +4 -1
  46. package/src/room/track/create.ts +37 -27
  47. package/src/room/track/options.ts +15 -0
@@ -14,6 +14,7 @@ import type {
14
14
  VideoCaptureOptions,
15
15
  } from './options';
16
16
  import { ScreenSharePresets } from './options';
17
+ import type { TrackProcessor } from './processor/types';
17
18
  import {
18
19
  constraintsForOptions,
19
20
  mergeDefaultOptions,
@@ -51,35 +52,44 @@ export async function createLocalTracks(
51
52
  }
52
53
 
53
54
  const stream = await mediaPromise;
54
- return stream.getTracks().map((mediaStreamTrack) => {
55
- const isAudio = mediaStreamTrack.kind === 'audio';
56
- let trackOptions = isAudio ? options!.audio : options!.video;
57
- if (typeof trackOptions === 'boolean' || !trackOptions) {
58
- trackOptions = {};
59
- }
60
- let trackConstraints: MediaTrackConstraints | undefined;
61
- const conOrBool = isAudio ? constraints.audio : constraints.video;
62
- if (typeof conOrBool !== 'boolean') {
63
- trackConstraints = conOrBool;
64
- }
55
+ return Promise.all(
56
+ stream.getTracks().map(async (mediaStreamTrack) => {
57
+ const isAudio = mediaStreamTrack.kind === 'audio';
58
+ let trackOptions = isAudio ? options!.audio : options!.video;
59
+ if (typeof trackOptions === 'boolean' || !trackOptions) {
60
+ trackOptions = {};
61
+ }
62
+ let trackConstraints: MediaTrackConstraints | undefined;
63
+ const conOrBool = isAudio ? constraints.audio : constraints.video;
64
+ if (typeof conOrBool !== 'boolean') {
65
+ trackConstraints = conOrBool;
66
+ }
65
67
 
66
- // update the constraints with the device id the user gave permissions to in the permission prompt
67
- // otherwise each track restart (e.g. mute - unmute) will try to initialize the device again -> causing additional permission prompts
68
- if (trackConstraints) {
69
- trackConstraints.deviceId = mediaStreamTrack.getSettings().deviceId;
70
- } else {
71
- trackConstraints = { deviceId: mediaStreamTrack.getSettings().deviceId };
72
- }
68
+ // update the constraints with the device id the user gave permissions to in the permission prompt
69
+ // otherwise each track restart (e.g. mute - unmute) will try to initialize the device again -> causing additional permission prompts
70
+ if (trackConstraints) {
71
+ trackConstraints.deviceId = mediaStreamTrack.getSettings().deviceId;
72
+ } else {
73
+ trackConstraints = { deviceId: mediaStreamTrack.getSettings().deviceId };
74
+ }
73
75
 
74
- const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints);
75
- if (track.kind === Track.Kind.Video) {
76
- track.source = Track.Source.Camera;
77
- } else if (track.kind === Track.Kind.Audio) {
78
- track.source = Track.Source.Microphone;
79
- }
80
- track.mediaStream = stream;
81
- return track;
82
- });
76
+ const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints);
77
+ if (track.kind === Track.Kind.Video) {
78
+ track.source = Track.Source.Camera;
79
+ } else if (track.kind === Track.Kind.Audio) {
80
+ track.source = Track.Source.Microphone;
81
+ }
82
+ track.mediaStream = stream;
83
+ if (trackOptions.processor) {
84
+ if (track instanceof LocalAudioTrack) {
85
+ await track.setProcessor(trackOptions.processor as TrackProcessor<Track.Kind.Audio>);
86
+ } else if (track instanceof LocalVideoTrack) {
87
+ await track.setProcessor(trackOptions.processor as TrackProcessor<Track.Kind.Video>);
88
+ }
89
+ }
90
+ return track;
91
+ }),
92
+ );
83
93
  }
84
94
 
85
95
  /**
@@ -1,4 +1,9 @@
1
1
  import type { Track } from './Track';
2
+ import type {
3
+ AudioProcessorOptions,
4
+ TrackProcessor,
5
+ VideoProcessorOptions,
6
+ } from './processor/types';
2
7
 
3
8
  export interface TrackPublishDefaults {
4
9
  /**
@@ -152,6 +157,11 @@ export interface VideoCaptureOptions {
152
157
  facingMode?: 'user' | 'environment' | 'left' | 'right';
153
158
 
154
159
  resolution?: VideoResolution;
160
+
161
+ /**
162
+ * initialize the track with a given processor
163
+ */
164
+ processor?: TrackProcessor<Track.Kind.Video, VideoProcessorOptions>;
155
165
  }
156
166
 
157
167
  export interface ScreenShareCaptureOptions {
@@ -245,6 +255,11 @@ export interface AudioCaptureOptions {
245
255
  * sample size or range of sample sizes which are acceptable and/or required.
246
256
  */
247
257
  sampleSize?: ConstrainULong;
258
+
259
+ /**
260
+ * initialize the track with a given processor
261
+ */
262
+ processor?: TrackProcessor<Track.Kind.Audio, AudioProcessorOptions>;
248
263
  }
249
264
 
250
265
  export interface AudioOutputOptions {