livekit-client 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) 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 +33 -9
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +70 -41
  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/constants.d.ts +0 -1
  10. package/dist/src/e2ee/constants.d.ts.map +1 -1
  11. package/dist/src/e2ee/types.d.ts +1 -0
  12. package/dist/src/e2ee/types.d.ts.map +1 -1
  13. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  14. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
  15. package/dist/src/index.d.ts +7 -6
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/room/PCTransport.d.ts.map +1 -1
  18. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  19. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  20. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  21. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  22. package/dist/ts4.2/src/e2ee/constants.d.ts +0 -1
  23. package/dist/ts4.2/src/e2ee/types.d.ts +1 -0
  24. package/dist/ts4.2/src/index.d.ts +7 -6
  25. package/package.json +1 -1
  26. package/src/e2ee/constants.ts +1 -5
  27. package/src/e2ee/types.ts +1 -0
  28. package/src/e2ee/worker/FrameCryptor.ts +12 -0
  29. package/src/e2ee/worker/ParticipantKeyHandler.ts +4 -2
  30. package/src/e2ee/worker/e2ee.worker.ts +24 -3
  31. package/src/index.ts +32 -29
  32. package/src/room/PCTransport.ts +6 -18
  33. package/src/room/RTCEngine.ts +4 -3
  34. package/src/room/participant/LocalParticipant.ts +21 -6
  35. package/src/room/participant/publishUtils.ts +38 -11
  36. package/src/room/track/LocalTrack.ts +11 -9
@@ -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