livekit-client 2.13.8 → 2.15.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 (64) hide show
  1. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  2. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  3. package/dist/livekit-client.esm.mjs +276 -117
  4. package/dist/livekit-client.esm.mjs.map +1 -1
  5. package/dist/livekit-client.umd.js +1 -1
  6. package/dist/livekit-client.umd.js.map +1 -1
  7. package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
  8. package/dist/src/room/PCTransport.d.ts +1 -0
  9. package/dist/src/room/PCTransport.d.ts.map +1 -1
  10. package/dist/src/room/Room.d.ts.map +1 -1
  11. package/dist/src/room/events.d.ts +18 -0
  12. package/dist/src/room/events.d.ts.map +1 -1
  13. package/dist/src/room/participant/LocalParticipant.d.ts +1 -0
  14. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  15. package/dist/src/room/participant/Participant.d.ts +3 -0
  16. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  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/LocalTrackPublication.d.ts +1 -0
  20. package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
  21. package/dist/src/room/track/LocalVideoTrack.d.ts +7 -0
  22. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  23. package/dist/src/room/track/RemoteTrackPublication.d.ts +12 -3
  24. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  25. package/dist/src/room/track/Track.d.ts +1 -0
  26. package/dist/src/room/track/Track.d.ts.map +1 -1
  27. package/dist/src/room/track/TrackPublication.d.ts +1 -0
  28. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  29. package/dist/src/room/track/options.d.ts +5 -1
  30. package/dist/src/room/track/options.d.ts.map +1 -1
  31. package/dist/src/room/track/utils.d.ts +3 -1
  32. package/dist/src/room/track/utils.d.ts.map +1 -1
  33. package/dist/src/room/utils.d.ts +2 -1
  34. package/dist/src/room/utils.d.ts.map +1 -1
  35. package/dist/ts4.2/src/room/PCTransport.d.ts +1 -0
  36. package/dist/ts4.2/src/room/events.d.ts +18 -0
  37. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +1 -0
  38. package/dist/ts4.2/src/room/participant/Participant.d.ts +3 -0
  39. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +1 -0
  40. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +7 -0
  41. package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +12 -3
  42. package/dist/ts4.2/src/room/track/Track.d.ts +1 -0
  43. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +1 -0
  44. package/dist/ts4.2/src/room/track/options.d.ts +6 -1
  45. package/dist/ts4.2/src/room/track/utils.d.ts +3 -1
  46. package/dist/ts4.2/src/room/utils.d.ts +2 -1
  47. package/package.json +11 -11
  48. package/src/e2ee/E2eeManager.ts +3 -2
  49. package/src/room/PCTransport.ts +88 -77
  50. package/src/room/Room.ts +2 -0
  51. package/src/room/events.ts +21 -0
  52. package/src/room/participant/LocalParticipant.ts +14 -2
  53. package/src/room/participant/Participant.ts +3 -0
  54. package/src/room/participant/RemoteParticipant.ts +1 -0
  55. package/src/room/participant/publishUtils.ts +3 -2
  56. package/src/room/track/LocalTrackPublication.ts +9 -1
  57. package/src/room/track/LocalVideoTrack.ts +68 -1
  58. package/src/room/track/RemoteTrackPublication.ts +91 -32
  59. package/src/room/track/Track.ts +1 -0
  60. package/src/room/track/TrackPublication.ts +1 -0
  61. package/src/room/track/create.ts +2 -2
  62. package/src/room/track/options.ts +6 -1
  63. package/src/room/track/utils.ts +12 -1
  64. package/src/room/utils.ts +37 -3
@@ -21,6 +21,8 @@ export default class LocalVideoTrack extends LocalTrack<Track.Kind.Video> {
21
21
  private subscribedCodecs?;
22
22
  private senderLock;
23
23
  private degradationPreference;
24
+ private isCpuConstrained;
25
+ private optimizeForPerformance;
24
26
  get sender(): RTCRtpSender | undefined;
25
27
  set sender(sender: RTCRtpSender | undefined);
26
28
  /**
@@ -56,6 +58,11 @@ export default class LocalVideoTrack extends LocalTrack<Track.Kind.Video> {
56
58
  * Sets layers that should be publishing
57
59
  */
58
60
  setPublishingLayers(isSvc: boolean, qualities: SubscribedQuality[]): Promise<void>;
61
+ /**
62
+ * Designed for lower powered devices, reduces video publishing quality and disables simulcast.
63
+ * @experimental
64
+ */
65
+ prioritizePerformance(): Promise<void>;
59
66
  protected monitorSender: () => Promise<void>;
60
67
  protected handleAppVisibilityChanged(): Promise<void>;
61
68
  }
@@ -8,9 +8,11 @@ export default class RemoteTrackPublication extends TrackPublication {
8
8
  /** @internal */
9
9
  protected allowed: boolean;
10
10
  protected subscribed?: boolean;
11
- protected disabled: boolean;
12
- protected currentVideoQuality?: VideoQuality;
13
- protected videoDimensions?: Track.Dimensions;
11
+ protected requestedDisabled: boolean | undefined;
12
+ protected visible: boolean;
13
+ protected videoDimensionsAdaptiveStream?: Track.Dimensions;
14
+ protected requestedVideoDimensions?: Track.Dimensions;
15
+ protected requestedMaxQuality?: VideoQuality;
14
16
  protected fps?: number;
15
17
  protected subscriptionError?: SubscriptionError;
16
18
  constructor(kind: Track.Kind, ti: TrackInfo, autoSubscribe: boolean | undefined, loggerOptions?: LoggerOptions);
@@ -43,6 +45,13 @@ export default class RemoteTrackPublication extends TrackPublication {
43
45
  * optimize for uninterrupted video
44
46
  */
45
47
  setVideoQuality(quality: VideoQuality): void;
48
+ /**
49
+ * Explicitly set the video dimensions for this track.
50
+ *
51
+ * This will take precedence over adaptive stream dimensions.
52
+ *
53
+ * @param dimensions The video dimensions to set.
54
+ */
46
55
  setVideoDimensions(dimensions: Track.Dimensions): void;
47
56
  setVideoFPS(fps: number): void;
48
57
  get videoQuality(): VideoQuality | undefined;
@@ -146,6 +146,7 @@ export type TrackEventCallbacks = {
146
146
  rtpTimestamp: number;
147
147
  }) => void;
148
148
  preConnectBufferFlushed: (buffer: Uint8Array[]) => void;
149
+ cpuConstrained: () => void;
149
150
  };
150
151
  export {};
151
152
  //# sourceMappingURL=Track.d.ts.map
@@ -75,6 +75,7 @@ export type PublicationEventCallbacks = {
75
75
  subscriptionFailed: (error: SubscriptionError) => void;
76
76
  transcriptionReceived: (transcription: TranscriptionSegment[]) => void;
77
77
  timeSyncUpdate: (timestamp: number) => void;
78
+ cpuConstrained: (track: LocalVideoTrack) => void;
78
79
  };
79
80
  export {};
80
81
  //# sourceMappingURL=TrackPublication.d.ts.map
@@ -149,6 +149,10 @@ export interface VideoCaptureOptions {
149
149
  * IDs which are acceptable and/or required.
150
150
  */
151
151
  deviceId?: ConstrainDOMString;
152
+ /**
153
+ * A ConstrainDouble specifying the frame rate or range of frame rates which are acceptable and/or required.
154
+ */
155
+ frameRate?: ConstrainDouble;
152
156
  /**
153
157
  * a facing or an array of facings which are acceptable and/or required.
154
158
  */
@@ -295,7 +299,8 @@ export declare const videoCodecs: readonly [
295
299
  "vp8",
296
300
  "h264",
297
301
  "vp9",
298
- "av1"
302
+ "av1",
303
+ "h265"
299
304
  ];
300
305
  export type VideoCodec = (typeof videoCodecs)[number];
301
306
  export type BackupVideoCodec = (typeof backupCodecs)[number];
@@ -1,4 +1,4 @@
1
- import { TrackPublishedResponse, TrackSource } from '@livekit/protocol';
1
+ import { TrackInfo, TrackPublishedResponse, TrackSource, VideoQuality } from '@livekit/protocol';
2
2
  import type { AudioProcessorOptions, TrackProcessor, VideoProcessorOptions } from '../..';
3
3
  import { Track } from './Track';
4
4
  import type { TrackPublication } from './TrackPublication';
@@ -42,4 +42,6 @@ export declare function extractProcessorsFromOptions(options: CreateLocalTracksO
42
42
  };
43
43
  };
44
44
  export declare function getTrackSourceFromProto(source: TrackSource): Track.Source;
45
+ export declare function areDimensionsSmaller(a: Track.Dimensions, b: Track.Dimensions): boolean;
46
+ export declare function layerDimensionsFor(trackInfo: TrackInfo, quality: VideoQuality): Track.Dimensions | undefined;
45
47
  //# sourceMappingURL=utils.d.ts.map
@@ -27,6 +27,7 @@ export declare function supportsAdaptiveStream(): boolean;
27
27
  export declare function supportsDynacast(): boolean;
28
28
  export declare function supportsAV1(): boolean;
29
29
  export declare function supportsVP9(): boolean;
30
+ export declare function supportsH265(): boolean;
30
31
  export declare function isSVCCodec(codec?: string): boolean;
31
32
  export declare function supportsSetSinkId(elm?: HTMLMediaElement): boolean;
32
33
  export declare function isBrowserSupported(): boolean;
@@ -34,7 +35,7 @@ export declare function isFireFox(): boolean;
34
35
  export declare function isChromiumBased(): boolean;
35
36
  export declare function isSafari(): boolean;
36
37
  export declare function isSafariBased(): boolean;
37
- export declare function isSafari17(): boolean;
38
+ export declare function isSafari17Based(): boolean;
38
39
  export declare function isSafariSvcApi(browser?: BrowserDetails): boolean;
39
40
  export declare function isMobile(): boolean;
40
41
  export declare function isE2EESimulcastSupported(): boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "2.13.8",
3
+ "version": "2.15.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",
@@ -37,7 +37,7 @@
37
37
  "license": "Apache-2.0",
38
38
  "dependencies": {
39
39
  "@livekit/mutex": "1.1.1",
40
- "@livekit/protocol": "1.39.2",
40
+ "@livekit/protocol": "1.39.3",
41
41
  "events": "^3.3.0",
42
42
  "loglevel": "^1.9.2",
43
43
  "sdp-transform": "^2.15.0",
@@ -50,13 +50,13 @@
50
50
  "@types/dom-mediacapture-record": "^1"
51
51
  },
52
52
  "devDependencies": {
53
- "@babel/core": "7.27.4",
54
- "@babel/preset-env": "7.27.2",
53
+ "@babel/core": "7.28.0",
54
+ "@babel/preset-env": "7.28.0",
55
55
  "@bufbuild/protoc-gen-es": "^1.10.0",
56
- "@changesets/cli": "2.29.4",
56
+ "@changesets/cli": "2.29.5",
57
57
  "@livekit/changesets-changelog-github": "^0.0.4",
58
58
  "@rollup/plugin-babel": "6.0.4",
59
- "@rollup/plugin-commonjs": "28.0.5",
59
+ "@rollup/plugin-commonjs": "28.0.6",
60
60
  "@rollup/plugin-json": "6.1.0",
61
61
  "@rollup/plugin-node-resolve": "16.0.1",
62
62
  "@rollup/plugin-terser": "^0.4.4",
@@ -73,20 +73,20 @@
73
73
  "eslint-config-airbnb-typescript": "18.0.0",
74
74
  "eslint-config-prettier": "10.1.5",
75
75
  "eslint-plugin-ecmascript-compat": "^3.2.1",
76
- "eslint-plugin-import": "2.31.0",
76
+ "eslint-plugin-import": "2.32.0",
77
77
  "gh-pages": "6.3.0",
78
78
  "happy-dom": "^17.2.0",
79
79
  "jsdom": "^26.1.0",
80
80
  "prettier": "^3.4.2",
81
- "rollup": "4.43.0",
81
+ "rollup": "4.44.1",
82
82
  "rollup-plugin-delete": "^2.1.0",
83
83
  "rollup-plugin-typescript2": "0.36.0",
84
84
  "size-limit": "^11.2.0",
85
- "typedoc": "0.28.5",
85
+ "typedoc": "0.28.7",
86
86
  "typedoc-plugin-no-inherit": "1.6.1",
87
87
  "typescript": "5.8.3",
88
- "vite": "5.4.19",
89
- "vitest": "^1.6.0"
88
+ "vite": "7.0.0",
89
+ "vitest": "^3.0.0"
90
90
  },
91
91
  "scripts": {
92
92
  "build": "rollup --config --bundleConfigAsCjs && rollup --config rollup.config.worker.js --bundleConfigAsCjs && pnpm downlevel-dts",
@@ -221,8 +221,9 @@ export class E2EEManager
221
221
  this.room.localParticipant.identity,
222
222
  );
223
223
  });
224
- room.localParticipant.on(ParticipantEvent.LocalTrackPublished, async (publication) => {
225
- this.setupE2EESender(publication.track!, publication.track!.sender!);
224
+
225
+ room.localParticipant.on(ParticipantEvent.LocalSenderCreated, async (sender, track) => {
226
+ this.setupE2EESender(track, sender);
226
227
  });
227
228
 
228
229
  keyProvider
@@ -1,3 +1,4 @@
1
+ import { Mutex } from '@livekit/mutex';
1
2
  import { EventEmitter } from 'events';
2
3
  import type { MediaDescription, SessionDescription } from 'sdp-transform';
3
4
  import { parse, write } from 'sdp-transform';
@@ -52,6 +53,8 @@ export default class PCTransport extends EventEmitter {
52
53
 
53
54
  private latestOfferId: number = 0;
54
55
 
56
+ private offerLock: Mutex;
57
+
55
58
  pendingCandidates: RTCIceCandidateInit[] = [];
56
59
 
57
60
  restartingIce: boolean = false;
@@ -86,6 +89,7 @@ export default class PCTransport extends EventEmitter {
86
89
  this.loggerOptions = loggerOptions;
87
90
  this.config = config;
88
91
  this._pc = this.createPC();
92
+ this.offerLock = new Mutex();
89
93
  }
90
94
 
91
95
  private createPC() {
@@ -251,101 +255,108 @@ export default class PCTransport extends EventEmitter {
251
255
  }, debounceInterval);
252
256
 
253
257
  async createAndSendOffer(options?: RTCOfferOptions) {
254
- // increase the offer id at the start to ensure the offer is always > 0 so that we can use 0 as a default value for legacy behavior
255
- const offerId = this.latestOfferId + 1;
256
- this.latestOfferId = offerId;
257
- if (this.onOffer === undefined) {
258
- return;
259
- }
258
+ const unlock = await this.offerLock.lock();
260
259
 
261
- if (options?.iceRestart) {
262
- this.log.debug('restarting ICE', this.logContext);
263
- this.restartingIce = true;
264
- }
260
+ try {
261
+ // increase the offer id at the start to ensure the offer is always > 0 so that we can use 0 as a default value for legacy behavior
262
+ const offerId = this.latestOfferId + 1;
263
+ this.latestOfferId = offerId;
265
264
 
266
- if (this._pc && this._pc.signalingState === 'have-local-offer') {
267
- // we're waiting for the peer to accept our offer, so we'll just wait
268
- // the only exception to this is when ICE restart is needed
269
- const currentSD = this._pc.remoteDescription;
270
- if (options?.iceRestart && currentSD) {
271
- // TODO: handle when ICE restart is needed but we don't have a remote description
272
- // the best thing to do is to recreate the peerconnection
273
- await this._pc.setRemoteDescription(currentSD);
274
- } else {
275
- this.renegotiate = true;
265
+ if (this.onOffer === undefined) {
276
266
  return;
277
267
  }
278
- } else if (!this._pc || this._pc.signalingState === 'closed') {
279
- this.log.warn('could not createOffer with closed peer connection', this.logContext);
280
- return;
281
- }
282
268
 
283
- // actually negotiate
284
- this.log.debug('starting to negotiate', this.logContext);
285
- const offer = await this.pc.createOffer(options);
286
- this.log.debug('original offer', { sdp: offer.sdp, ...this.logContext });
269
+ if (options?.iceRestart) {
270
+ this.log.debug('restarting ICE', this.logContext);
271
+ this.restartingIce = true;
272
+ }
287
273
 
288
- const sdpParsed = parse(offer.sdp ?? '');
289
- sdpParsed.media.forEach((media) => {
290
- ensureIPAddrMatchVersion(media);
291
- if (media.type === 'audio') {
292
- ensureAudioNackAndStereo(media, [], []);
293
- } else if (media.type === 'video') {
294
- this.trackBitrates.some((trackbr): boolean => {
295
- if (!media.msid || !trackbr.cid || !media.msid.includes(trackbr.cid)) {
296
- return false;
297
- }
274
+ if (this._pc && this._pc.signalingState === 'have-local-offer') {
275
+ // we're waiting for the peer to accept our offer, so we'll just wait
276
+ // the only exception to this is when ICE restart is needed
277
+ const currentSD = this._pc.remoteDescription;
278
+ if (options?.iceRestart && currentSD) {
279
+ // TODO: handle when ICE restart is needed but we don't have a remote description
280
+ // the best thing to do is to recreate the peerconnection
281
+ await this._pc.setRemoteDescription(currentSD);
282
+ } else {
283
+ this.renegotiate = true;
284
+ return;
285
+ }
286
+ } else if (!this._pc || this._pc.signalingState === 'closed') {
287
+ this.log.warn('could not createOffer with closed peer connection', this.logContext);
288
+ return;
289
+ }
298
290
 
299
- let codecPayload = 0;
300
- media.rtp.some((rtp): boolean => {
301
- if (rtp.codec.toUpperCase() === trackbr.codec.toUpperCase()) {
302
- codecPayload = rtp.payload;
303
- return true;
291
+ // actually negotiate
292
+ this.log.debug('starting to negotiate', this.logContext);
293
+ const offer = await this.pc.createOffer(options);
294
+ this.log.debug('original offer', { sdp: offer.sdp, ...this.logContext });
295
+
296
+ const sdpParsed = parse(offer.sdp ?? '');
297
+ sdpParsed.media.forEach((media) => {
298
+ ensureIPAddrMatchVersion(media);
299
+ if (media.type === 'audio') {
300
+ ensureAudioNackAndStereo(media, [], []);
301
+ } else if (media.type === 'video') {
302
+ this.trackBitrates.some((trackbr): boolean => {
303
+ if (!media.msid || !trackbr.cid || !media.msid.includes(trackbr.cid)) {
304
+ return false;
304
305
  }
305
- return false;
306
- });
307
306
 
308
- if (codecPayload === 0) {
309
- return true;
310
- }
307
+ let codecPayload = 0;
308
+ media.rtp.some((rtp): boolean => {
309
+ if (rtp.codec.toUpperCase() === trackbr.codec.toUpperCase()) {
310
+ codecPayload = rtp.payload;
311
+ return true;
312
+ }
313
+ return false;
314
+ });
311
315
 
312
- if (isSVCCodec(trackbr.codec)) {
313
- this.ensureVideoDDExtensionForSVC(media, sdpParsed);
314
- }
316
+ if (codecPayload === 0) {
317
+ return true;
318
+ }
315
319
 
316
- // TODO: av1 slow starting issue already fixed in chrome 124, clean this after some versions
317
- // mung sdp for av1 bitrate setting that can't apply by sendEncoding
318
- if (trackbr.codec !== 'av1') {
319
- return true;
320
- }
320
+ if (isSVCCodec(trackbr.codec)) {
321
+ this.ensureVideoDDExtensionForSVC(media, sdpParsed);
322
+ }
323
+
324
+ // TODO: av1 slow starting issue already fixed in chrome 124, clean this after some versions
325
+ // mung sdp for av1 bitrate setting that can't apply by sendEncoding
326
+ if (trackbr.codec !== 'av1') {
327
+ return true;
328
+ }
321
329
 
322
- const startBitrate = Math.round(trackbr.maxbr * startBitrateForSVC);
330
+ const startBitrate = Math.round(trackbr.maxbr * startBitrateForSVC);
323
331
 
324
- for (const fmtp of media.fmtp) {
325
- if (fmtp.payload === codecPayload) {
326
- // if another track's fmtp already is set, we cannot override the bitrate
327
- // this has the unfortunate consequence of being forced to use the
328
- // initial track's bitrate for all tracks
329
- if (!fmtp.config.includes('x-google-start-bitrate')) {
330
- fmtp.config += `;x-google-start-bitrate=${startBitrate}`;
332
+ for (const fmtp of media.fmtp) {
333
+ if (fmtp.payload === codecPayload) {
334
+ // if another track's fmtp already is set, we cannot override the bitrate
335
+ // this has the unfortunate consequence of being forced to use the
336
+ // initial track's bitrate for all tracks
337
+ if (!fmtp.config.includes('x-google-start-bitrate')) {
338
+ fmtp.config += `;x-google-start-bitrate=${startBitrate}`;
339
+ }
340
+ break;
331
341
  }
332
- break;
333
342
  }
334
- }
335
- return true;
343
+ return true;
344
+ });
345
+ }
346
+ });
347
+ if (this.latestOfferId > offerId) {
348
+ this.log.warn('latestOfferId mismatch', {
349
+ ...this.logContext,
350
+ latestOfferId: this.latestOfferId,
351
+ offerId,
336
352
  });
353
+ return;
337
354
  }
338
- });
339
- if (this.latestOfferId > offerId) {
340
- this.log.warn('latestOfferId mismatch', {
341
- ...this.logContext,
342
- latestOfferId: this.latestOfferId,
343
- offerId,
344
- });
345
- return;
355
+ await this.setMungedSDP(offer, write(sdpParsed));
356
+ this.onOffer(offer, this.latestOfferId);
357
+ } finally {
358
+ unlock();
346
359
  }
347
- await this.setMungedSDP(offer, write(sdpParsed));
348
- this.onOffer(offer, this.latestOfferId);
349
360
  }
350
361
 
351
362
  async createAndSetAnswer(): Promise<RTCSessionDescriptionInit> {
package/src/room/Room.ts CHANGED
@@ -1337,6 +1337,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
1337
1337
  this.options.videoCaptureDefaults!.deviceId = prevDeviceId;
1338
1338
  throw e;
1339
1339
  }
1340
+ const isMuted = tracks.some((t) => t.track?.isMuted ?? false);
1341
+ if (success && isMuted) shouldTriggerImmediateDeviceChange = true;
1340
1342
  } else if (kind === 'audiooutput') {
1341
1343
  shouldTriggerImmediateDeviceChange = true;
1342
1344
  if (
@@ -429,6 +429,21 @@ export enum ParticipantEvent {
429
429
  */
430
430
  LocalTrackUnpublished = 'localTrackUnpublished',
431
431
 
432
+ /**
433
+ * A local track has been constrained by cpu.
434
+ * This event is useful to know when to reduce the capture resolution of the track.
435
+ *
436
+ * This event is emitted on the local participant.
437
+ *
438
+ * args: ([[LocalVideoTrack]], [[LocalTrackPublication]])
439
+ */
440
+ LocalTrackCpuConstrained = 'localTrackCpuConstrained',
441
+
442
+ /**
443
+ * @internal
444
+ */
445
+ LocalSenderCreated = 'localSenderCreated',
446
+
432
447
  /**
433
448
  * Participant metadata is a simple way for app-specific state to be pushed to
434
449
  * all users.
@@ -515,6 +530,11 @@ export enum ParticipantEvent {
515
530
  */
516
531
  TrackSubscriptionStatusChanged = 'trackSubscriptionStatusChanged',
517
532
 
533
+ /**
534
+ * a local track has been constrained by cpu
535
+ */
536
+ TrackCpuConstrained = 'trackCpuConstrained',
537
+
518
538
  // fired only on LocalParticipant
519
539
  /** @internal */
520
540
  MediaDevicesError = 'mediaDevicesError',
@@ -599,6 +619,7 @@ export enum TrackEvent {
599
619
  Ended = 'ended',
600
620
  Subscribed = 'subscribed',
601
621
  Unsubscribed = 'unsubscribed',
622
+ CpuConstrained = 'cpuConstrained',
602
623
  /** @internal */
603
624
  UpdateSettings = 'updateSettings',
604
625
  /** @internal */
@@ -93,7 +93,7 @@ import {
93
93
  isLocalTrack,
94
94
  isLocalVideoTrack,
95
95
  isSVCCodec,
96
- isSafari17,
96
+ isSafari17Based,
97
97
  isVideoTrack,
98
98
  isWeb,
99
99
  numberToBigInt,
@@ -708,7 +708,7 @@ export default class LocalParticipant extends Participant {
708
708
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
709
709
  }
710
710
 
711
- if (options.resolution === undefined && !isSafari17()) {
711
+ if (options.resolution === undefined && !isSafari17Based()) {
712
712
  // we need to constrain the dimensions, otherwise it could lead to low bitrate
713
713
  // due to encoding a huge video. Encoding such large surfaces is really expensive
714
714
  // unfortunately Safari 17 has a but and cannot be constrained by default
@@ -1169,6 +1169,7 @@ export default class LocalParticipant extends Participant {
1169
1169
  }
1170
1170
 
1171
1171
  track.sender = await this.engine.createSender(track, opts, encodings);
1172
+ this.emit(ParticipantEvent.LocalSenderCreated, track.sender, track);
1172
1173
 
1173
1174
  if (isLocalVideoTrack(track)) {
1174
1175
  opts.degradationPreference ??= getDefaultDegradationPreference(track);
@@ -1271,6 +1272,9 @@ export default class LocalParticipant extends Participant {
1271
1272
  loggerName: this.roomOptions.loggerName,
1272
1273
  loggerContextCb: () => this.logContext,
1273
1274
  });
1275
+ publication.on(TrackEvent.CpuConstrained, (constrainedTrack) =>
1276
+ this.onTrackCpuConstrained(constrainedTrack, publication),
1277
+ );
1274
1278
  // save options for when it needs to be republished again
1275
1279
  publication.options = opts;
1276
1280
  track.sid = ti.sid;
@@ -2329,6 +2333,14 @@ export default class LocalParticipant extends Participant {
2329
2333
  this.engine.client.sendUpdateLocalAudioTrack(pub.trackSid, pub.getTrackFeatures());
2330
2334
  };
2331
2335
 
2336
+ private onTrackCpuConstrained = (track: LocalVideoTrack, publication: LocalTrackPublication) => {
2337
+ this.log.debug('track cpu constrained', {
2338
+ ...this.logContext,
2339
+ ...getLogContextFromTrack(publication),
2340
+ });
2341
+ this.emit(ParticipantEvent.LocalTrackCpuConstrained, track, publication);
2342
+ };
2343
+
2332
2344
  private handleSubscribedQualityUpdate = async (update: SubscribedQualityUpdate) => {
2333
2345
  if (!this.roomOptions?.dynacast) {
2334
2346
  return;
@@ -13,6 +13,7 @@ import type TypedEmitter from 'typed-emitter';
13
13
  import log, { LoggerNames, type StructuredLogger, getLogger } from '../../logger';
14
14
  import { ParticipantEvent, TrackEvent } from '../events';
15
15
  import type LocalTrackPublication from '../track/LocalTrackPublication';
16
+ import type LocalVideoTrack from '../track/LocalVideoTrack';
16
17
  import type RemoteTrack from '../track/RemoteTrack';
17
18
  import type RemoteTrackPublication from '../track/RemoteTrackPublication';
18
19
  import { Track } from '../track/Track';
@@ -403,6 +404,8 @@ export type ParticipantEventCallbacks = {
403
404
  trackUnmuted: (publication: TrackPublication) => void;
404
405
  localTrackPublished: (publication: LocalTrackPublication) => void;
405
406
  localTrackUnpublished: (publication: LocalTrackPublication) => void;
407
+ localTrackCpuConstrained: (track: LocalVideoTrack, publication: LocalTrackPublication) => void;
408
+ localSenderCreated: (sender: RTCRtpSender, track: Track) => void;
406
409
  participantMetadataChanged: (prevMetadata: string | undefined, participant?: any) => void;
407
410
  participantNameChanged: (name: string) => void;
408
411
  dataReceived: (payload: Uint8Array, kind: DataPacket_Kind) => void;
@@ -86,6 +86,7 @@ export default class RemoteParticipant extends Participant {
86
86
  this.log.debug('send update settings', {
87
87
  ...this.logContext,
88
88
  ...getLogContextFromTrack(publication),
89
+ settings,
89
90
  });
90
91
  this.signalClient.sendUpdateTrackSettings(settings);
91
92
  });
@@ -18,7 +18,7 @@ import {
18
18
  isFireFox,
19
19
  isReactNative,
20
20
  isSVCCodec,
21
- isSafari,
21
+ isSafariBased,
22
22
  isSafariSvcApi,
23
23
  unwrapConstraint,
24
24
  } from '../utils';
@@ -151,7 +151,7 @@ export function computeVideoEncodings(
151
151
  // Announced here: https://groups.google.com/g/discuss-webrtc/c/-QQ3pxrl-fw?pli=1
152
152
  const browser = getBrowser();
153
153
  if (
154
- isSafari() ||
154
+ isSafariBased() ||
155
155
  // Even tho RN runs M114, it does not produce SVC layers when a single encoding
156
156
  // is provided. So we'll use the legacy SVC specification for now.
157
157
  // TODO: when we upstream libwebrtc, this will need additional verification
@@ -302,6 +302,7 @@ export function determineAppropriateEncoding(
302
302
  if (codec) {
303
303
  switch (codec) {
304
304
  case 'av1':
305
+ case 'h265':
305
306
  encoding = { ...encoding };
306
307
  encoding.maxBitrate = encoding.maxBitrate * 0.7;
307
308
  break;
@@ -1,7 +1,7 @@
1
1
  import { AudioTrackFeature, TrackInfo } from '@livekit/protocol';
2
2
  import { TrackEvent } from '../events';
3
3
  import type { LoggerOptions } from '../types';
4
- import { isAudioTrack } from '../utils';
4
+ import { isAudioTrack, isVideoTrack } from '../utils';
5
5
  import LocalAudioTrack from './LocalAudioTrack';
6
6
  import type LocalTrack from './LocalTrack';
7
7
  import type LocalVideoTrack from './LocalVideoTrack';
@@ -28,12 +28,14 @@ export default class LocalTrackPublication extends TrackPublication {
28
28
  setTrack(track?: Track) {
29
29
  if (this.track) {
30
30
  this.track.off(TrackEvent.Ended, this.handleTrackEnded);
31
+ this.track.off(TrackEvent.CpuConstrained, this.handleCpuConstrained);
31
32
  }
32
33
 
33
34
  super.setTrack(track);
34
35
 
35
36
  if (track) {
36
37
  track.on(TrackEvent.Ended, this.handleTrackEnded);
38
+ track.on(TrackEvent.CpuConstrained, this.handleCpuConstrained);
37
39
  }
38
40
  }
39
41
 
@@ -116,4 +118,10 @@ export default class LocalTrackPublication extends TrackPublication {
116
118
  handleTrackEnded = () => {
117
119
  this.emit(TrackEvent.Ended);
118
120
  };
121
+
122
+ private handleCpuConstrained = () => {
123
+ if (this.track && isVideoTrack(this.track)) {
124
+ this.emit(TrackEvent.CpuConstrained, this.track);
125
+ }
126
+ };
119
127
  }