livekit-client 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -221,7 +221,8 @@ export declare enum RoomEvent {
221
221
  */
222
222
  SignalConnected = "signalConnected",
223
223
  /**
224
- * Recording of a room has started/stopped.
224
+ * Recording of a room has started/stopped. Room.isRecording will be updated too.
225
+ * args: (isRecording: boolean)
225
226
  */
226
227
  RecordingStatusChanged = "recordingStatusChanged"
227
228
  }
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/room/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,oBAAY,SAAS;IACnB;;OAEG;IACH,SAAS,cAAc;IAEvB;;;OAGG;IACH,YAAY,iBAAiB;IAE7B;;OAEG;IACH,WAAW,gBAAgB;IAE3B;;;OAGG;IACH,YAAY,iBAAiB;IAE7B;;;;OAIG;IACH,sBAAsB,2BAA2B;IAEjD;;OAEG;IACH,YAAY,2BAA2B;IAEvC;;OAEG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;;OAMG;IACH,oBAAoB,yBAAyB;IAE7C;;;;;OAKG;IACH,uBAAuB,4BAA4B;IAEnD;;;;;;;;OAQG;IACH,cAAc,mBAAmB;IAEjC;;;;;OAKG;IACH,eAAe,oBAAoB;IAEnC;;;;OAIG;IACH,uBAAuB,4BAA4B;IAEnD;;;;OAIG;IACH,gBAAgB,qBAAqB;IAErC;;;;;OAKG;IACH,iBAAiB,sBAAsB;IAEvC;;;;OAIG;IACH,UAAU,eAAe;IAEzB;;;;OAIG;IACH,YAAY,iBAAiB;IAE7B;;;;;OAKG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;;;;OAQG;IACH,qBAAqB,0BAA0B;IAE/C;;;;;;;OAOG;IACH,qBAAqB,0BAA0B;IAE/C;;;;;;;;OAQG;IACH,0BAA0B,+BAA+B;IAEzD;;;;;;;OAOG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;;OAMG;IACH,YAAY,iBAAiB;IAE7B;;;;;;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;IACzB,SAAS,cAAc;IACvB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,eAAe,oBAAoB;IACnC,oBAAoB,yBAAyB;IAC7C,kBAAkB,uBAAuB;CAC1C;AAED,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB;;OAEG;IACH,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,gBAAgB;IAChB,cAAc,mBAAmB;IACjC,gBAAgB;IAChB,kBAAkB,uBAAuB;IACzC,gBAAgB;IAChB,oBAAoB,yBAAyB;IAC7C,gBAAgB;IAChB,mBAAmB,wBAAwB;IAC3C;;;OAGG;IACH,oBAAoB,yBAAyB;IAC7C,gBAAgB;IAChB,iBAAiB,sBAAsB;IACvC,gBAAgB;IAChB,sBAAsB,2BAA2B;IACjD,gBAAgB;IAChB,eAAe,oBAAoB;IACnC,gBAAgB;IAChB,eAAe,oBAAoB;IACnC;;;OAGG;IACH,cAAc,mBAAmB;IACjC;;;OAGG;IACH,eAAe,oBAAoB;IACnC;;;OAGG;IACH,6BAA6B,kCAAkC;IAC/D;;OAEG;IACH,yBAAyB,8BAA8B;CACxD"}
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/room/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,oBAAY,SAAS;IACnB;;OAEG;IACH,SAAS,cAAc;IAEvB;;;OAGG;IACH,YAAY,iBAAiB;IAE7B;;OAEG;IACH,WAAW,gBAAgB;IAE3B;;;OAGG;IACH,YAAY,iBAAiB;IAE7B;;;;OAIG;IACH,sBAAsB,2BAA2B;IAEjD;;OAEG;IACH,YAAY,2BAA2B;IAEvC;;OAEG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;;OAMG;IACH,oBAAoB,yBAAyB;IAE7C;;;;;OAKG;IACH,uBAAuB,4BAA4B;IAEnD;;;;;;;;OAQG;IACH,cAA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AEG;IACH,yBAAyB,8BAA8B;CACxD"}
@@ -17,6 +17,7 @@ export default class LocalVideoTrack extends LocalTrack {
17
17
  private encodings?;
18
18
  simulcastCodecs: Map<VideoCodec, SimulcastTrackInfo>;
19
19
  private subscribedCodecs?;
20
+ private senderLock;
20
21
  /**
21
22
  *
22
23
  * @param mediaTrack
@@ -1 +1 @@
1
- {"version":3,"file":"LocalVideoTrack.d.ts","sourceRoot":"","sources":["../../../../src/room/track/LocalVideoTrack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAoC,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9E,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIjE,qBAAa,kBAAkB;IAC7B,KAAK,EAAE,UAAU,CAAC;IAElB,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB,SAAS,CAAC,EAAE,wBAAwB,EAAE,CAAC;gBAE3B,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB;CAIlE;AAID,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IAErD,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B,OAAO,CAAC,SAAS,CAAC,CAAgC;IAElD,OAAO,CAAC,SAAS,CAAC,CAA6B;IAG/C,eAAe,EAAE,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAA6C;IAEjG,OAAO,CAAC,gBAAgB,CAAC,CAAoB;IAE7C;;;;;OAKG;gBAED,UAAU,EAAE,gBAAgB,EAC5B,WAAW,CAAC,E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G,kBAAkB;IAchG,uBAAuB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY;IAgB/D;;;OAGG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAyC3E;;;OAGG;IACG,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,EAAE;IASxD,SAAS,CAAC,aAAa,sBAyBrB;cAEc,0BAA0B;CAO3C;AAqED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAW5D;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,wBAAwB,EAAE,GACrC,UAAU,EAAE,CA2Bd"}
@@ -221,7 +221,8 @@ export declare enum RoomEvent {
221
221
  */
222
222
  SignalConnected = "signalConnected",
223
223
  /**
224
- * Recording of a room has started/stopped.
224
+ * Recording of a room has started/stopped. Room.isRecording will be updated too.
225
+ * args: (isRecording: boolean)
225
226
  */
226
227
  RecordingStatusChanged = "recordingStatusChanged"
227
228
  }
@@ -17,6 +17,7 @@ export default class LocalVideoTrack extends LocalTrack {
17
17
  private encodings?;
18
18
  simulcastCodecs: Map<VideoCodec, SimulcastTrackInfo>;
19
19
  private subscribedCodecs?;
20
+ private senderLock;
20
21
  /**
21
22
  *
22
23
  * @param mediaTrack
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
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",
@@ -252,7 +252,8 @@ export enum RoomEvent {
252
252
  SignalConnected = 'signalConnected',
253
253
 
254
254
  /**
255
- * Recording of a room has started/stopped.
255
+ * Recording of a room has started/stopped. Room.isRecording will be updated too.
256
+ * args: (isRecording: boolean)
256
257
  */
257
258
  RecordingStatusChanged = 'recordingStatusChanged',
258
259
  }
@@ -957,7 +957,7 @@ export default class LocalParticipant extends Participant {
957
957
  }
958
958
  }
959
959
  } else if (update.subscribedQualities.length > 0) {
960
- pub.videoTrack?.setPublishingLayers(update.subscribedQualities);
960
+ await pub.videoTrack?.setPublishingLayers(update.subscribedQualities);
961
961
  }
962
962
  };
963
963
 
@@ -3,7 +3,7 @@ import log from '../../logger';
3
3
  import { VideoLayer, VideoQuality } from '../../proto/livekit_models';
4
4
  import type { SubscribedCodec, SubscribedQuality } from '../../proto/livekit_rtc';
5
5
  import { computeBitrate, monitorFrequency, VideoSenderStats } from '../stats';
6
- import { isFireFox, isMobile, isWeb } from '../utils';
6
+ import { isFireFox, isMobile, isWeb, Mutex } from '../utils';
7
7
  import LocalTrack from './LocalTrack';
8
8
  import type { VideoCaptureOptions, VideoCodec } from './options';
9
9
  import { Track } from './Track';
@@ -39,6 +39,12 @@ export default class LocalVideoTrack extends LocalTrack {
39
39
 
40
40
  private subscribedCodecs?: SubscribedCodec[];
41
41
 
42
+ // prevents concurrent manipulations to track sender
43
+ // if multiple get/setParameter are called concurrently, certain timing of events
44
+ // could lead to the browser throwing an exception in `setParameter`, due to
45
+ // a missing `getParameter` call.
46
+ private senderLock: Mutex;
47
+
42
48
  /**
43
49
  *
44
50
  * @param mediaTrack
@@ -51,6 +57,7 @@ export default class LocalVideoTrack extends LocalTrack {
51
57
  userProvidedTrack = true,
52
58
  ) {
53
59
  super(mediaTrack, Track.Kind.Video, constraints, userProvidedTrack);
60
+ this.senderLock = new Mutex();
54
61
  }
55
62
 
56
63
  get isSimulcast(): boolean {
@@ -257,6 +264,7 @@ export default class LocalVideoTrack extends LocalTrack {
257
264
  simulcastCodecInfo.sender,
258
265
  simulcastCodecInfo.encodings!,
259
266
  codec.qualities,
267
+ this.senderLock,
260
268
  );
261
269
  }
262
270
  }
@@ -274,7 +282,7 @@ export default class LocalVideoTrack extends LocalTrack {
274
282
  return;
275
283
  }
276
284
 
277
- await setPublishingLayersForSender(this.sender, this.encodings, qualities);
285
+ await setPublishingLayersForSender(this.sender, this.encodings, qualities, this.senderLock);
278
286
  }
279
287
 
280
288
  protected monitorSender = async () => {
@@ -317,58 +325,66 @@ async function setPublishingLayersForSender(
317
325
  sender: RTCRtpSender,
318
326
  senderEncodings: RTCRtpEncodingParameters[],
319
327
  qualities: SubscribedQuality[],
328
+ senderLock: Mutex,
320
329
  ) {
330
+ const unlock = await senderLock.lock();
321
331
  log.debug('setPublishingLayersForSender', { sender, qualities, senderEncodings });
322
- const params = sender.getParameters();
323
- const { encodings } = params;
324
- if (!encodings) {
325
- return;
326
- }
327
-
328
- if (encodings.length !== senderEncodings.length) {
329
- log.warn('cannot set publishing layers, encodings mismatch');
330
- return;
331
- }
332
-
333
- let hasChanged = false;
334
- encodings.forEach((encoding, idx) => {
335
- let rid = encoding.rid ?? '';
336
- if (rid === '') {
337
- rid = 'q';
332
+ try {
333
+ const params = sender.getParameters();
334
+ const { encodings } = params;
335
+ if (!encodings) {
336
+ return;
338
337
  }
339
- const quality = videoQualityForRid(rid);
340
- const subscribedQuality = qualities.find((q) => q.quality === quality);
341
- if (!subscribedQuality) {
338
+
339
+ if (encodings.length !== senderEncodings.length) {
340
+ log.warn('cannot set publishing layers, encodings mismatch');
342
341
  return;
343
342
  }
344
- if (encoding.active !== subscribedQuality.enabled) {
345
- hasChanged = true;
346
- encoding.active = subscribedQuality.enabled;
347
- log.debug(
348
- `setting layer ${subscribedQuality.quality} to ${encoding.active ? 'enabled' : 'disabled'}`,
349
- );
350
-
351
- // FireFox does not support setting encoding.active to false, so we
352
- // have a workaround of lowering its bitrate and resolution to the min.
353
- if (isFireFox()) {
354
- if (subscribedQuality.enabled) {
355
- encoding.scaleResolutionDownBy = senderEncodings[idx].scaleResolutionDownBy;
356
- encoding.maxBitrate = senderEncodings[idx].maxBitrate;
357
- /* @ts-ignore */
358
- encoding.maxFrameRate = senderEncodings[idx].maxFrameRate;
359
- } else {
360
- encoding.scaleResolutionDownBy = 4;
361
- encoding.maxBitrate = 10;
362
- /* @ts-ignore */
363
- encoding.maxFrameRate = 2;
343
+
344
+ let hasChanged = false;
345
+ encodings.forEach((encoding, idx) => {
346
+ let rid = encoding.rid ?? '';
347
+ if (rid === '') {
348
+ rid = 'q';
349
+ }
350
+ const quality = videoQualityForRid(rid);
351
+ const subscribedQuality = qualities.find((q) => q.quality === quality);
352
+ if (!subscribedQuality) {
353
+ return;
354
+ }
355
+ if (encoding.active !== subscribedQuality.enabled) {
356
+ hasChanged = true;
357
+ encoding.active = subscribedQuality.enabled;
358
+ log.debug(
359
+ `setting layer ${subscribedQuality.quality} to ${
360
+ encoding.active ? 'enabled' : 'disabled'
361
+ }`,
362
+ );
363
+
364
+ // FireFox does not support setting encoding.active to false, so we
365
+ // have a workaround of lowering its bitrate and resolution to the min.
366
+ if (isFireFox()) {
367
+ if (subscribedQuality.enabled) {
368
+ encoding.scaleResolutionDownBy = senderEncodings[idx].scaleResolutionDownBy;
369
+ encoding.maxBitrate = senderEncodings[idx].maxBitrate;
370
+ /* @ts-ignore */
371
+ encoding.maxFrameRate = senderEncodings[idx].maxFrameRate;
372
+ } else {
373
+ encoding.scaleResolutionDownBy = 4;
374
+ encoding.maxBitrate = 10;
375
+ /* @ts-ignore */
376
+ encoding.maxFrameRate = 2;
377
+ }
364
378
  }
365
379
  }
366
- }
367
- });
380
+ });
368
381
 
369
- if (hasChanged) {
370
- params.encodings = encodings;
371
- await sender.setParameters(params);
382
+ if (hasChanged) {
383
+ params.encodings = encodings;
384
+ await sender.setParameters(params);
385
+ }
386
+ } finally {
387
+ unlock();
372
388
  }
373
389
  }
374
390