livekit-client 2.0.6 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/dist/livekit-client.e2ee.worker.js +1 -1
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs +27 -3
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +74 -35
  6. package/dist/livekit-client.esm.mjs.map +1 -1
  7. package/dist/livekit-client.umd.js +1 -1
  8. package/dist/livekit-client.umd.js.map +1 -1
  9. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  10. package/dist/src/index.d.ts +7 -6
  11. package/dist/src/index.d.ts.map +1 -1
  12. package/dist/src/room/PCTransport.d.ts.map +1 -1
  13. package/dist/src/room/Room.d.ts.map +1 -1
  14. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  15. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  16. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  17. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  18. package/dist/src/room/track/options.d.ts +6 -0
  19. package/dist/src/room/track/options.d.ts.map +1 -1
  20. package/dist/src/room/track/utils.d.ts.map +1 -1
  21. package/dist/ts4.2/src/index.d.ts +7 -6
  22. package/dist/ts4.2/src/room/track/options.d.ts +6 -0
  23. package/package.json +1 -1
  24. package/src/e2ee/worker/FrameCryptor.ts +12 -0
  25. package/src/e2ee/worker/e2ee.worker.ts +24 -3
  26. package/src/index.ts +32 -29
  27. package/src/room/PCTransport.ts +6 -18
  28. package/src/room/Room.ts +1 -0
  29. package/src/room/participant/LocalParticipant.ts +31 -3
  30. package/src/room/participant/publishUtils.ts +38 -11
  31. package/src/room/track/LocalTrack.ts +11 -9
  32. package/src/room/track/RemoteAudioTrack.ts +1 -1
  33. package/src/room/track/options.ts +7 -0
  34. package/src/room/track/utils.ts +1 -0
@@ -1,4 +1,5 @@
1
1
  import log from '../../logger';
2
+ import { getBrowser } from '../../utils/browserParser';
2
3
  import { TrackInvalidError } from '../errors';
3
4
  import LocalAudioTrack from '../track/LocalAudioTrack';
4
5
  import LocalVideoTrack from '../track/LocalVideoTrack';
@@ -11,7 +12,14 @@ import type {
11
12
  } from '../track/options';
12
13
  import { ScreenSharePresets, VideoPreset, VideoPresets, VideoPresets43 } from '../track/options';
13
14
  import type { LoggerOptions } from '../types';
14
- import { getReactNativeOs, isFireFox, isReactNative, isSVCCodec } from '../utils';
15
+ import {
16
+ compareVersions,
17
+ getReactNativeOs,
18
+ isFireFox,
19
+ isReactNative,
20
+ isSVCCodec,
21
+ isSafari,
22
+ } from '../utils';
15
23
 
16
24
  /** @internal */
17
25
  export function mediaTrackToLocalTrack(
@@ -125,8 +133,6 @@ export function computeVideoEncodings(
125
133
  );
126
134
 
127
135
  if (scalabilityMode && isSVCCodec(videoCodec)) {
128
- log.debug(`using svc with scalabilityMode ${scalabilityMode}`);
129
-
130
136
  const sm = new ScalabilityMode(scalabilityMode);
131
137
 
132
138
  const encodings: RTCRtpEncodingParameters[] = [];
@@ -134,17 +140,37 @@ export function computeVideoEncodings(
134
140
  if (sm.spatial > 3) {
135
141
  throw new Error(`unsupported scalabilityMode: ${scalabilityMode}`);
136
142
  }
137
- for (let i = 0; i < sm.spatial; i += 1) {
143
+ // Before M113 in Chrome, defining multiple encodings with an SVC codec indicated
144
+ // that SVC mode should be used. Safari still works this way.
145
+ // This is a bit confusing but is due to how libwebrtc interpreted the encodings field
146
+ // before M113.
147
+ // Announced here: https://groups.google.com/g/discuss-webrtc/c/-QQ3pxrl-fw?pli=1
148
+ const browser = getBrowser();
149
+ if (
150
+ isSafari() ||
151
+ (browser?.name === 'Chrome' && compareVersions(browser?.version, '113') < 0)
152
+ ) {
153
+ for (let i = 0; i < sm.spatial; i += 1) {
154
+ // in legacy SVC, scaleResolutionDownBy cannot be set
155
+ encodings.push({
156
+ rid: videoRids[2 - i],
157
+ maxBitrate: videoEncoding.maxBitrate / 3 ** i,
158
+ maxFramerate: original.encoding.maxFramerate,
159
+ });
160
+ }
161
+ // legacy SVC, scalabilityMode is set only on the first encoding
162
+ /* @ts-ignore */
163
+ encodings[0].scalabilityMode = scalabilityMode;
164
+ } else {
138
165
  encodings.push({
139
- rid: videoRids[2 - i],
140
- maxBitrate: videoEncoding.maxBitrate / 3 ** i,
141
- /* @ts-ignore */
166
+ maxBitrate: videoEncoding.maxBitrate,
142
167
  maxFramerate: original.encoding.maxFramerate,
168
+ /* @ts-ignore */
169
+ scalabilityMode: scalabilityMode,
143
170
  });
144
171
  }
145
- /* @ts-ignore */
146
- encodings[0].scalabilityMode = scalabilityMode;
147
- log.debug('encodings', encodings);
172
+
173
+ log.debug(`using svc encoding`, { encodings });
148
174
  return encodings;
149
175
  }
150
176
 
@@ -174,7 +200,7 @@ export function computeVideoEncodings(
174
200
  // to disable when CPU constrained.
175
201
  // So encodings should be ordered in increasing spatial
176
202
  // resolution order.
177
- // 2. ion-sfu translates rids into layers. So, all encodings
203
+ // 2. livekit-server translates rids into layers. So, all encodings
178
204
  // should have the base layer `q` and then more added
179
205
  // based on other conditions.
180
206
  const size = Math.max(width, height);
@@ -246,6 +272,7 @@ export function determineAppropriateEncoding(
246
272
  break;
247
273
  }
248
274
  }
275
+
249
276
  // presets are based on the assumption of vp8 as a codec
250
277
  // for other codecs we adjust the maxBitrate if no specific videoEncoding has been provided
251
278
  // users should override these with ones that are optimized for their use case
@@ -448,6 +448,13 @@ export default abstract class LocalTrack<
448
448
  const unlock = await this.processorLock.lock();
449
449
  try {
450
450
  this.log.debug('setting up processor', this.logContext);
451
+ const processorOptions = {
452
+ kind: this.kind,
453
+ track: this._mediaStreamTrack,
454
+ element: this.processorElement,
455
+ audioContext: this.audioContext,
456
+ };
457
+ await processor.init(processorOptions);
451
458
  if (this.processor) {
452
459
  await this.stopProcessor();
453
460
  }
@@ -466,14 +473,6 @@ export default abstract class LocalTrack<
466
473
  this.log.error('failed to play processor element', { ...this.logContext, error }),
467
474
  );
468
475
 
469
- const processorOptions = {
470
- kind: this.kind,
471
- track: this._mediaStreamTrack,
472
- element: this.processorElement,
473
- audioContext: this.audioContext,
474
- };
475
-
476
- await processor.init(processorOptions);
477
476
  this.processor = processor;
478
477
  if (this.processor.processedTrack) {
479
478
  for (const el of this.attachedElements) {
@@ -510,7 +509,10 @@ export default abstract class LocalTrack<
510
509
  this.processor = undefined;
511
510
  this.processorElement?.remove();
512
511
  this.processorElement = undefined;
513
- await this.restart();
512
+ // apply original track constraints in case the processor changed them
513
+ await this._mediaStreamTrack.applyConstraints(this._constraints);
514
+ // force re-setting of the mediaStreamTrack on the sender
515
+ await this.setMediaStreamTrack(this._mediaStreamTrack, true);
514
516
  this.emit(TrackEvent.TrackProcessorUpdate);
515
517
  }
516
518
 
@@ -1,6 +1,6 @@
1
1
  import { TrackEvent } from '../events';
2
- import { computeBitrate } from '../stats';
3
2
  import type { AudioReceiverStats } from '../stats';
3
+ import { computeBitrate } from '../stats';
4
4
  import type { LoggerOptions } from '../types';
5
5
  import { isReactNative, supportsSetSinkId } from '../utils';
6
6
  import RemoteTrack from './RemoteTrack';
@@ -190,6 +190,13 @@ export interface ScreenShareCaptureOptions {
190
190
  * local speakers when the tab is captured.
191
191
  */
192
192
  suppressLocalAudioPlayback?: boolean;
193
+
194
+ /**
195
+ * Experimental option to instruct the browser to offer the current tab as the most prominent capture source
196
+ * @experimental
197
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#prefercurrenttab
198
+ */
199
+ preferCurrentTab?: boolean;
193
200
  }
194
201
 
195
202
  export interface AudioCaptureOptions {
@@ -183,6 +183,7 @@ export function screenCaptureToDisplayMediaStreamOptions(
183
183
  selfBrowserSurface: options.selfBrowserSurface,
184
184
  surfaceSwitching: options.surfaceSwitching,
185
185
  systemAudio: options.systemAudio,
186
+ preferCurrentTab: options.preferCurrentTab,
186
187
  };
187
188
  }
188
189