@dtelecom/livekit-client 1.12.4 → 1.12.5

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 (159) hide show
  1. package/README.md +19 -11
  2. package/dist/livekit-client.e2ee.worker.js +1 -1
  3. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  4. package/dist/livekit-client.e2ee.worker.mjs +301 -389
  5. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  6. package/dist/livekit-client.esm.mjs +15291 -13060
  7. package/dist/livekit-client.esm.mjs.map +1 -1
  8. package/dist/livekit-client.umd.js +1 -1
  9. package/dist/livekit-client.umd.js.map +1 -1
  10. package/dist/src/api/SignalClient.d.ts +2 -2
  11. package/dist/src/api/SignalClient.d.ts.map +1 -1
  12. package/dist/src/connectionHelper/ConnectionCheck.d.ts +2 -3
  13. package/dist/src/connectionHelper/ConnectionCheck.d.ts.map +1 -1
  14. package/dist/src/connectionHelper/checks/Checker.d.ts +2 -3
  15. package/dist/src/connectionHelper/checks/Checker.d.ts.map +1 -1
  16. package/dist/src/connectionHelper/checks/webrtc.d.ts.map +1 -1
  17. package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
  18. package/dist/src/e2ee/E2eeManager.d.ts +2 -4
  19. package/dist/src/e2ee/E2eeManager.d.ts.map +1 -1
  20. package/dist/src/e2ee/KeyProvider.d.ts +2 -4
  21. package/dist/src/e2ee/KeyProvider.d.ts.map +1 -1
  22. package/dist/src/e2ee/constants.d.ts +0 -1
  23. package/dist/src/e2ee/constants.d.ts.map +1 -1
  24. package/dist/src/e2ee/types.d.ts +0 -1
  25. package/dist/src/e2ee/types.d.ts.map +1 -1
  26. package/dist/src/e2ee/worker/FrameCryptor.d.ts +2 -4
  27. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -1
  28. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +3 -14
  29. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -1
  30. package/dist/src/index.d.ts +1 -1
  31. package/dist/src/index.d.ts.map +1 -1
  32. package/dist/src/proto/google/protobuf/timestamp.d.ts +146 -0
  33. package/dist/src/proto/google/protobuf/timestamp.d.ts.map +1 -0
  34. package/dist/src/proto/livekit_models.d.ts +2399 -0
  35. package/dist/src/proto/livekit_models.d.ts.map +1 -0
  36. package/dist/src/proto/livekit_rtc.d.ts +14352 -0
  37. package/dist/src/proto/livekit_rtc.d.ts.map +1 -0
  38. package/dist/src/room/PCTransport.d.ts +1 -2
  39. package/dist/src/room/PCTransport.d.ts.map +1 -1
  40. package/dist/src/room/RTCEngine.d.ts +5 -9
  41. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  42. package/dist/src/room/RegionUrlProvider.d.ts +1 -4
  43. package/dist/src/room/RegionUrlProvider.d.ts.map +1 -1
  44. package/dist/src/room/Room.d.ts +11 -15
  45. package/dist/src/room/Room.d.ts.map +1 -1
  46. package/dist/src/room/participant/LocalParticipant.d.ts +2 -2
  47. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  48. package/dist/src/room/participant/Participant.d.ts +3 -5
  49. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  50. package/dist/src/room/participant/ParticipantTrackPermission.d.ts +1 -1
  51. package/dist/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -1
  52. package/dist/src/room/participant/RemoteParticipant.d.ts +3 -2
  53. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  54. package/dist/src/room/timers.d.ts +4 -5
  55. package/dist/src/room/timers.d.ts.map +1 -1
  56. package/dist/src/room/track/LocalTrackPublication.d.ts +1 -1
  57. package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
  58. package/dist/src/room/track/LocalVideoTrack.d.ts +2 -2
  59. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  60. package/dist/src/room/track/RemoteTrackPublication.d.ts +1 -1
  61. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  62. package/dist/src/room/track/Track.d.ts +4 -6
  63. package/dist/src/room/track/Track.d.ts.map +1 -1
  64. package/dist/src/room/track/TrackPublication.d.ts +5 -7
  65. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  66. package/dist/src/room/track/create.d.ts.map +1 -1
  67. package/dist/src/room/track/options.d.ts +0 -7
  68. package/dist/src/room/track/options.d.ts.map +1 -1
  69. package/dist/src/room/track/utils.d.ts +1 -5
  70. package/dist/src/room/track/utils.d.ts.map +1 -1
  71. package/dist/src/room/utils.d.ts +1 -3
  72. package/dist/src/room/utils.d.ts.map +1 -1
  73. package/dist/src/test/mocks.d.ts +4 -4
  74. package/dist/src/test/mocks.d.ts.map +1 -1
  75. package/dist/ts4.2/src/api/SignalClient.d.ts +2 -2
  76. package/dist/ts4.2/src/connectionHelper/ConnectionCheck.d.ts +2 -3
  77. package/dist/ts4.2/src/connectionHelper/checks/Checker.d.ts +2 -3
  78. package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +2 -4
  79. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +2 -4
  80. package/dist/ts4.2/src/e2ee/constants.d.ts +0 -1
  81. package/dist/ts4.2/src/e2ee/types.d.ts +0 -1
  82. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +2 -4
  83. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +3 -14
  84. package/dist/ts4.2/src/index.d.ts +1 -1
  85. package/dist/ts4.2/src/proto/google/protobuf/timestamp.d.ts +150 -0
  86. package/dist/ts4.2/src/proto/livekit_models.d.ts +2659 -0
  87. package/dist/ts4.2/src/proto/livekit_rtc.d.ts +15764 -0
  88. package/dist/ts4.2/src/room/PCTransport.d.ts +1 -2
  89. package/dist/ts4.2/src/room/RTCEngine.d.ts +5 -9
  90. package/dist/ts4.2/src/room/RegionUrlProvider.d.ts +1 -4
  91. package/dist/ts4.2/src/room/Room.d.ts +11 -15
  92. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +2 -2
  93. package/dist/ts4.2/src/room/participant/Participant.d.ts +3 -5
  94. package/dist/ts4.2/src/room/participant/ParticipantTrackPermission.d.ts +1 -1
  95. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +3 -2
  96. package/dist/ts4.2/src/room/timers.d.ts +4 -5
  97. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +1 -1
  98. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +2 -2
  99. package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +1 -1
  100. package/dist/ts4.2/src/room/track/Track.d.ts +4 -6
  101. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +5 -7
  102. package/dist/ts4.2/src/room/track/options.d.ts +0 -7
  103. package/dist/ts4.2/src/room/track/utils.d.ts +1 -5
  104. package/dist/ts4.2/src/room/utils.d.ts +1 -3
  105. package/dist/ts4.2/src/test/mocks.d.ts +4 -4
  106. package/package.json +11 -11
  107. package/src/api/SignalClient.ts +101 -104
  108. package/src/connectionHelper/ConnectionCheck.ts +2 -3
  109. package/src/connectionHelper/checks/Checker.ts +3 -3
  110. package/src/connectionHelper/checks/webrtc.ts +2 -66
  111. package/src/connectionHelper/checks/websocket.ts +0 -4
  112. package/src/e2ee/E2eeManager.ts +3 -4
  113. package/src/e2ee/KeyProvider.ts +2 -3
  114. package/src/e2ee/constants.ts +0 -4
  115. package/src/e2ee/types.ts +0 -1
  116. package/src/e2ee/worker/FrameCryptor.test.ts +3 -1
  117. package/src/e2ee/worker/FrameCryptor.ts +5 -5
  118. package/src/e2ee/worker/ParticipantKeyHandler.ts +6 -37
  119. package/src/e2ee/worker/e2ee.worker.ts +1 -1
  120. package/src/index.ts +1 -1
  121. package/src/proto/google/protobuf/timestamp.ts +230 -0
  122. package/src/proto/livekit_models.ts +4006 -0
  123. package/src/proto/livekit_rtc.ts +4672 -0
  124. package/src/room/PCTransport.ts +1 -1
  125. package/src/room/RTCEngine.ts +18 -24
  126. package/src/room/RegionUrlProvider.ts +2 -11
  127. package/src/room/Room.test.ts +0 -1
  128. package/src/room/Room.ts +79 -158
  129. package/src/room/participant/LocalParticipant.ts +59 -43
  130. package/src/room/participant/Participant.ts +4 -6
  131. package/src/room/participant/ParticipantTrackPermission.ts +3 -3
  132. package/src/room/participant/RemoteParticipant.ts +6 -5
  133. package/src/room/participant/publishUtils.test.ts +0 -1
  134. package/src/room/track/LocalTrackPublication.ts +1 -1
  135. package/src/room/track/LocalVideoTrack.test.ts +1 -2
  136. package/src/room/track/LocalVideoTrack.ts +22 -22
  137. package/src/room/track/RemoteTrackPublication.ts +7 -12
  138. package/src/room/track/RemoteVideoTrack.test.ts +4 -5
  139. package/src/room/track/Track.ts +6 -9
  140. package/src/room/track/TrackPublication.ts +5 -7
  141. package/src/room/track/create.ts +17 -9
  142. package/src/room/track/facingMode.test.ts +0 -1
  143. package/src/room/track/options.ts +0 -6
  144. package/src/room/track/utils.test.ts +0 -1
  145. package/src/room/track/utils.ts +2 -44
  146. package/src/room/utils.ts +4 -20
  147. package/src/test/mocks.ts +5 -7
  148. package/src/utils/AsyncQueue.test.ts +0 -1
  149. package/src/utils/browserParser.test.ts +3 -33
  150. package/src/utils/browserParser.ts +1 -1
  151. package/dist/src/proto/livekit_models_pb.d.ts +0 -1264
  152. package/dist/src/proto/livekit_models_pb.d.ts.map +0 -1
  153. package/dist/src/proto/livekit_rtc_pb.d.ts +0 -1373
  154. package/dist/src/proto/livekit_rtc_pb.d.ts.map +0 -1
  155. package/dist/ts4.2/src/proto/livekit_models_pb.d.ts +0 -1264
  156. package/dist/ts4.2/src/proto/livekit_rtc_pb.d.ts +0 -1373
  157. package/src/proto/livekit_models_pb.ts +0 -2096
  158. package/src/proto/livekit_rtc_pb.ts +0 -2332
  159. package/src/room/utils.test.ts +0 -16
@@ -6,17 +6,15 @@ import {
6
6
  Encryption_Type,
7
7
  ParticipantInfo,
8
8
  ParticipantPermission,
9
- UserPacket,
10
- } from '../../proto/livekit_models_pb';
9
+ } from '../../proto/livekit_models';
11
10
  import {
12
11
  AddTrackRequest,
13
12
  DataChannelInfo,
14
13
  SignalTarget,
15
- SimulcastCodec,
16
14
  SubscribedQualityUpdate,
17
15
  TrackPublishedResponse,
18
16
  TrackUnpublishedResponse,
19
- } from '../../proto/livekit_rtc_pb';
17
+ } from '../../proto/livekit_rtc';
20
18
  import type RTCEngine from '../RTCEngine';
21
19
  import { DeviceUnsupportedError, TrackInvalidError, UnexpectedConnectionState } from '../errors';
22
20
  import { EngineEvent, ParticipantEvent, TrackEvent } from '../events';
@@ -34,11 +32,7 @@ import type {
34
32
  VideoCaptureOptions,
35
33
  } from '../track/options';
36
34
  import { ScreenSharePresets, VideoPresets, isBackupCodec, isCodecEqual } from '../track/options';
37
- import {
38
- constraintsForOptions,
39
- mergeDefaultOptions,
40
- screenCaptureToDisplayMediaStreamOptions,
41
- } from '../track/utils';
35
+ import { constraintsForOptions, mergeDefaultOptions } from '../track/utils';
42
36
  import type { DataPublishOptions } from '../types';
43
37
  import { Future, isFireFox, isSVCCodec, isSafari, isWeb, supportsAV1, supportsVP9 } from '../utils';
44
38
  import Participant from './Participant';
@@ -317,9 +311,6 @@ export default class LocalParticipant extends Participant {
317
311
  // revisit if we want to return an array of tracks instead for v2
318
312
  [track] = publishedTracks;
319
313
  } catch (e) {
320
- localTracks?.forEach((tr) => {
321
- tr.stop();
322
- });
323
314
  if (e instanceof Error && !(e instanceof TrackInvalidError)) {
324
315
  this.emit(ParticipantEvent.MediaDevicesError, e);
325
316
  }
@@ -442,12 +433,36 @@ export default class LocalParticipant extends Participant {
442
433
  options.resolution = ScreenSharePresets.h1080fps15.resolution;
443
434
  }
444
435
 
436
+ let videoConstraints: MediaTrackConstraints | boolean = true;
437
+ if (options.resolution) {
438
+ if (isSafari()) {
439
+ videoConstraints = {
440
+ width: { max: options.resolution.width },
441
+ height: { max: options.resolution.height },
442
+ frameRate: options.resolution.frameRate,
443
+ };
444
+ } else {
445
+ videoConstraints = {
446
+ width: { ideal: options.resolution.width },
447
+ height: { ideal: options.resolution.height },
448
+ frameRate: options.resolution.frameRate,
449
+ };
450
+ }
451
+ }
452
+
445
453
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
446
454
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
447
455
  }
448
456
 
449
- const constraints = screenCaptureToDisplayMediaStreamOptions(options);
450
- const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia(constraints);
457
+ const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
458
+ audio: options.audio ?? false,
459
+ video: videoConstraints,
460
+ // @ts-expect-error support for experimental display media features
461
+ controller: options.controller,
462
+ selfBrowserSurface: options.selfBrowserSurface,
463
+ surfaceSwitching: options.surfaceSwitching,
464
+ systemAudio: options.systemAudio,
465
+ });
451
466
 
452
467
  const tracks = stream.getVideoTracks();
453
468
  if (tracks.length === 0) {
@@ -570,7 +585,7 @@ export default class LocalParticipant extends Participant {
570
585
  if (opts.source) {
571
586
  track.source = opts.source;
572
587
  }
573
- const publishPromise = this.publish(track, opts, isStereo);
588
+ const publishPromise = this.publish(track, opts, options, isStereo);
574
589
  this.pendingPublishPromises.set(track, publishPromise);
575
590
  try {
576
591
  const publication = await publishPromise;
@@ -582,7 +597,12 @@ export default class LocalParticipant extends Participant {
582
597
  }
583
598
  }
584
599
 
585
- private async publish(track: LocalTrack, opts: TrackPublishOptions, isStereo: boolean) {
600
+ private async publish(
601
+ track: LocalTrack,
602
+ opts: TrackPublishOptions,
603
+ options: TrackPublishOptions | undefined,
604
+ isStereo: boolean,
605
+ ) {
586
606
  const existingTrackOfSource = Array.from(this.tracks.values()).find(
587
607
  (publishedTrack) => track instanceof LocalTrack && publishedTrack.source === track.source,
588
608
  );
@@ -626,10 +646,10 @@ export default class LocalParticipant extends Participant {
626
646
  track.on(TrackEvent.UpstreamResumed, this.onTrackUpstreamResumed);
627
647
 
628
648
  // create track publication from track
629
- const req = new AddTrackRequest({
649
+ const req = AddTrackRequest.fromPartial({
630
650
  // get local track id for use during publishing
631
651
  cid: track.mediaStreamTrack.id,
632
- name: opts.name,
652
+ name: options?.name,
633
653
  type: Track.kindToProto(track.kind),
634
654
  muted: track.isMuted,
635
655
  source: Track.sourceToProto(track.source),
@@ -678,26 +698,26 @@ export default class LocalParticipant extends Participant {
678
698
  simEncodings = computeTrackBackupEncodings(track, opts.backupCodec.codec, simOpts);
679
699
 
680
700
  req.simulcastCodecs = [
681
- new SimulcastCodec({
701
+ {
682
702
  codec: opts.videoCodec,
683
703
  cid: track.mediaStreamTrack.id,
684
704
  enableSimulcastLayers: true,
685
- }),
686
- new SimulcastCodec({
705
+ },
706
+ {
687
707
  codec: opts.backupCodec.codec,
688
708
  cid: '',
689
709
  enableSimulcastLayers: true,
690
- }),
710
+ },
691
711
  ];
692
712
  } else if (opts.videoCodec) {
693
713
  // pass codec info to sfu so it can prefer codec for the client which don't support
694
714
  // setCodecPreferences
695
715
  req.simulcastCodecs = [
696
- new SimulcastCodec({
716
+ {
697
717
  codec: opts.videoCodec,
698
718
  cid: track.mediaStreamTrack.id,
699
719
  enableSimulcastLayers: opts.simulcast ?? false,
700
- }),
720
+ },
701
721
  ];
702
722
  }
703
723
  }
@@ -859,7 +879,7 @@ export default class LocalParticipant extends Participant {
859
879
  return;
860
880
  }
861
881
  const simulcastTrack = track.addSimulcastTrack(videoCodec, encodings);
862
- const req = new AddTrackRequest({
882
+ const req = AddTrackRequest.fromPartial({
863
883
  cid: simulcastTrack.mediaStreamTrack.id,
864
884
  type: Track.kindToProto(track.kind),
865
885
  muted: track.isMuted,
@@ -1079,18 +1099,18 @@ export default class LocalParticipant extends Participant {
1079
1099
  });
1080
1100
  }
1081
1101
 
1082
- const packet = new DataPacket({
1102
+ const packet: DataPacket = {
1083
1103
  kind,
1084
1104
  value: {
1085
- case: 'user',
1086
- value: new UserPacket({
1105
+ $case: 'user',
1106
+ user: {
1087
1107
  participantSid: this.sid,
1088
1108
  payload: data,
1089
1109
  destinationSids: destinationSids,
1090
1110
  topic,
1091
- }),
1111
+ },
1092
1112
  },
1093
- });
1113
+ };
1094
1114
 
1095
1115
  await this.engine.sendDataPacket(packet, kind);
1096
1116
  }
@@ -1313,12 +1333,10 @@ export default class LocalParticipant extends Participant {
1313
1333
  const infos: TrackPublishedResponse[] = [];
1314
1334
  this.tracks.forEach((track: LocalTrackPublication) => {
1315
1335
  if (track.track !== undefined) {
1316
- infos.push(
1317
- new TrackPublishedResponse({
1318
- cid: track.track.mediaStreamID,
1319
- track: track.trackInfo,
1320
- }),
1321
- );
1336
+ infos.push({
1337
+ cid: track.track.mediaStreamID,
1338
+ track: track.trackInfo,
1339
+ });
1322
1340
  }
1323
1341
  });
1324
1342
  return infos;
@@ -1329,13 +1347,11 @@ export default class LocalParticipant extends Participant {
1329
1347
  const infos: DataChannelInfo[] = [];
1330
1348
  const getInfo = (dc: RTCDataChannel | undefined, target: SignalTarget) => {
1331
1349
  if (dc?.id !== undefined && dc.id !== null) {
1332
- infos.push(
1333
- new DataChannelInfo({
1334
- label: dc.label,
1335
- id: dc.id,
1336
- target,
1337
- }),
1338
- );
1350
+ infos.push({
1351
+ label: dc.label,
1352
+ id: dc.id,
1353
+ target,
1354
+ });
1339
1355
  }
1340
1356
  };
1341
1357
  getInfo(this.engine.dataChannelForKind(DataPacket_Kind.LOSSY), SignalTarget.PUBLISHER);
@@ -1,5 +1,4 @@
1
- import { EventEmitter } from 'events';
2
- import type TypedEmitter from 'typed-emitter';
1
+ import EventEmitter from 'eventemitter3';
3
2
  import log from '../../logger';
4
3
  import {
5
4
  DataPacket_Kind,
@@ -7,7 +6,7 @@ import {
7
6
  ParticipantPermission,
8
7
  ConnectionQuality as ProtoQuality,
9
8
  SubscriptionError,
10
- } from '../../proto/livekit_models_pb';
9
+ } from '../../proto/livekit_models';
11
10
  import { ParticipantEvent, TrackEvent } from '../events';
12
11
  import type LocalTrackPublication from '../track/LocalTrackPublication';
13
12
  import type RemoteTrack from '../track/RemoteTrack';
@@ -35,7 +34,7 @@ function qualityFromProto(q: ProtoQuality): ConnectionQuality {
35
34
  }
36
35
  }
37
36
 
38
- export default class Participant extends (EventEmitter as new () => TypedEmitter<ParticipantEventCallbacks>) {
37
+ export default class Participant extends EventEmitter<ParticipantEventCallbacks> {
39
38
  protected participantInfo?: ParticipantInfo;
40
39
 
41
40
  audioTracks: Map<string, TrackPublication>;
@@ -76,7 +75,6 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
76
75
  /** @internal */
77
76
  constructor(sid: string, identity: string, name?: string, metadata?: string) {
78
77
  super();
79
- this.setMaxListeners(100);
80
78
  this.sid = sid;
81
79
  this.identity = identity;
82
80
  this.name = name;
@@ -143,7 +141,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
143
141
  /** when participant joined the room */
144
142
  get joinedAt(): Date | undefined {
145
143
  if (this.participantInfo) {
146
- return new Date(Number.parseInt(this.participantInfo.joinedAt.toString()) * 1000);
144
+ return new Date(this.participantInfo.joinedAt * 1000);
147
145
  }
148
146
  return new Date();
149
147
  }
@@ -1,4 +1,4 @@
1
- import { TrackPermission } from '../../proto/livekit_rtc_pb';
1
+ import type { TrackPermission } from '../../proto/livekit_rtc';
2
2
 
3
3
  export interface ParticipantTrackPermission {
4
4
  /**
@@ -33,10 +33,10 @@ export function trackPermissionToProto(perms: ParticipantTrackPermission): Track
33
33
  'Invalid track permission, must provide at least one of participantIdentity and participantSid',
34
34
  );
35
35
  }
36
- return new TrackPermission({
36
+ return {
37
37
  participantIdentity: perms.participantIdentity ?? '',
38
38
  participantSid: perms.participantSid ?? '',
39
39
  allTracks: perms.allowAll ?? false,
40
40
  trackSids: perms.allowedTrackSids || [],
41
- });
41
+ };
42
42
  }
@@ -1,7 +1,8 @@
1
+ import type EventEmitter from 'eventemitter3';
1
2
  import type { SignalClient } from '../../api/SignalClient';
2
3
  import log from '../../logger';
3
- import type { ParticipantInfo, SubscriptionError } from '../../proto/livekit_models_pb';
4
- import type { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc_pb';
4
+ import type { ParticipantInfo, SubscriptionError } from '../../proto/livekit_models';
5
+ import type { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc';
5
6
  import { ParticipantEvent, TrackEvent } from '../events';
6
7
  import RemoteAudioTrack from '../track/RemoteAudioTrack';
7
8
  import type RemoteTrack from '../track/RemoteTrack';
@@ -349,9 +350,9 @@ export default class RemoteParticipant extends Participant {
349
350
  }
350
351
 
351
352
  /** @internal */
352
- emit<E extends keyof ParticipantEventCallbacks>(
353
- event: E,
354
- ...args: Parameters<ParticipantEventCallbacks[E]>
353
+ emit<T extends EventEmitter.EventNames<ParticipantEventCallbacks>>(
354
+ event: T,
355
+ ...args: EventEmitter.EventArgs<ParticipantEventCallbacks, T>
355
356
  ): boolean {
356
357
  log.trace('participant event', { participant: this.sid, event, args });
357
358
  return super.emit(event, ...args);
@@ -1,4 +1,3 @@
1
- import { describe, expect, it } from 'vitest';
2
1
  import { ScreenSharePresets, VideoPreset, VideoPresets, VideoPresets43 } from '../track/options';
3
2
  import {
4
3
  computeDefaultScreenShareSimulcastPresets,
@@ -1,4 +1,4 @@
1
- import type { TrackInfo } from '../../proto/livekit_models_pb';
1
+ import type { TrackInfo } from '../../proto/livekit_models';
2
2
  import { TrackEvent } from '../events';
3
3
  import type LocalAudioTrack from './LocalAudioTrack';
4
4
  import type LocalTrack from './LocalTrack';
@@ -1,5 +1,4 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { VideoQuality } from '../../proto/livekit_models_pb';
1
+ import { VideoQuality } from '../../proto/livekit_models';
3
2
  import { videoLayersFromEncodings } from './LocalVideoTrack';
4
3
 
5
4
  describe('videoLayersFromEncodings', () => {
@@ -1,7 +1,8 @@
1
1
  import type { SignalClient } from '../../api/SignalClient';
2
2
  import log from '../../logger';
3
- import { VideoLayer, VideoQuality } from '../../proto/livekit_models_pb';
4
- import { SubscribedCodec, SubscribedQuality } from '../../proto/livekit_rtc_pb';
3
+ import { VideoLayer, VideoQuality } from '../../proto/livekit_models';
4
+ import type { SubscribedCodec, SubscribedQuality } from '../../proto/livekit_rtc';
5
+ import { ScalabilityMode } from '../participant/publishUtils';
5
6
  import { computeBitrate, monitorFrequency } from '../stats';
6
7
  import type { VideoSenderStats } from '../stats';
7
8
  import { Mutex, isFireFox, isMobile, isWeb, unwrapConstraint } from '../utils';
@@ -172,12 +173,10 @@ export default class LocalVideoTrack extends LocalTrack {
172
173
  setPublishingQuality(maxQuality: VideoQuality) {
173
174
  const qualities: SubscribedQuality[] = [];
174
175
  for (let q = VideoQuality.LOW; q <= VideoQuality.HIGH; q += 1) {
175
- qualities.push(
176
- new SubscribedQuality({
177
- quality: q,
178
- enabled: q <= maxQuality,
179
- }),
180
- );
176
+ qualities.push({
177
+ quality: q,
178
+ enabled: q <= maxQuality,
179
+ });
181
180
  }
182
181
  log.debug(`setting publishing quality. max quality ${maxQuality}`);
183
182
  this.setPublishingLayers(qualities);
@@ -457,7 +456,7 @@ export function videoQualityForRid(rid: string): VideoQuality {
457
456
  case 'q':
458
457
  return VideoQuality.LOW;
459
458
  default:
460
- return VideoQuality.HIGH;
459
+ return VideoQuality.UNRECOGNIZED;
461
460
  }
462
461
  }
463
462
 
@@ -470,13 +469,13 @@ export function videoLayersFromEncodings(
470
469
  // default to a single layer, HQ
471
470
  if (!encodings) {
472
471
  return [
473
- new VideoLayer({
472
+ {
474
473
  quality: VideoQuality.HIGH,
475
474
  width,
476
475
  height,
477
476
  bitrate: 0,
478
477
  ssrc: 0,
479
- }),
478
+ },
480
479
  ];
481
480
  }
482
481
 
@@ -486,15 +485,13 @@ export function videoLayersFromEncodings(
486
485
  const sm = new ScalabilityMode(encodings[0].scalabilityMode);
487
486
  const layers = [];
488
487
  for (let i = 0; i < sm.spatial; i += 1) {
489
- layers.push(
490
- new VideoLayer({
491
- quality: VideoQuality.HIGH - i,
492
- width: width / 2 ** i,
493
- height: height / 2 ** i,
494
- bitrate: encodings[0].maxBitrate ? encodings[0].maxBitrate / 3 ** i : 0,
495
- ssrc: 0,
496
- }),
497
- );
488
+ layers.push({
489
+ quality: VideoQuality.HIGH - i,
490
+ width: width / 2 ** i,
491
+ height: height / 2 ** i,
492
+ bitrate: encodings[0].maxBitrate ? encodings[0].maxBitrate / 3 ** i : 0,
493
+ ssrc: 0,
494
+ });
498
495
  }
499
496
  return layers;
500
497
  }
@@ -502,12 +499,15 @@ export function videoLayersFromEncodings(
502
499
  return encodings.map((encoding) => {
503
500
  const scale = encoding.scaleResolutionDownBy ?? 1;
504
501
  let quality = videoQualityForRid(encoding.rid ?? '');
505
- return new VideoLayer({
502
+ if (quality === VideoQuality.UNRECOGNIZED && encodings.length === 1) {
503
+ quality = VideoQuality.HIGH;
504
+ }
505
+ return {
506
506
  quality,
507
507
  width: width / scale,
508
508
  height: height / scale,
509
509
  bitrate: encoding.maxBitrate ?? 0,
510
510
  ssrc: 0,
511
- });
511
+ };
512
512
  });
513
513
  }
@@ -1,11 +1,6 @@
1
1
  import log from '../../logger';
2
- import {
3
- ParticipantTracks,
4
- SubscriptionError,
5
- TrackInfo,
6
- VideoQuality,
7
- } from '../../proto/livekit_models_pb';
8
- import { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc_pb';
2
+ import { SubscriptionError, TrackInfo, VideoQuality } from '../../proto/livekit_models';
3
+ import { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc';
9
4
  import { TrackEvent } from '../events';
10
5
  import type RemoteTrack from './RemoteTrack';
11
6
  import RemoteVideoTrack from './RemoteVideoTrack';
@@ -51,18 +46,18 @@ export default class RemoteTrackPublication extends TrackPublication {
51
46
  this.allowed = true;
52
47
  }
53
48
 
54
- const sub = new UpdateSubscription({
49
+ const sub: UpdateSubscription = {
55
50
  trackSids: [this.trackSid],
56
51
  subscribe: this.subscribed,
57
52
  participantTracks: [
58
- new ParticipantTracks({
53
+ {
59
54
  // sending an empty participant id since TrackPublication doesn't keep it
60
55
  // this is filled in by the participant that receives this message
61
56
  participantSid: '',
62
57
  trackSids: [this.trackSid],
63
- }),
58
+ },
64
59
  ],
65
- });
60
+ };
66
61
  this.emit(TrackEvent.UpdateSubscription, sub);
67
62
  this.emitSubscriptionUpdateIfChanged(prevStatus);
68
63
  this.emitPermissionUpdateIfChanged(prevPermission);
@@ -291,7 +286,7 @@ export default class RemoteTrackPublication extends TrackPublication {
291
286
 
292
287
  /* @internal */
293
288
  emitTrackUpdate() {
294
- const settings: UpdateTrackSettings = new UpdateTrackSettings({
289
+ const settings: UpdateTrackSettings = UpdateTrackSettings.fromPartial({
295
290
  trackSids: [this.trackSid],
296
291
  disabled: this.disabled,
297
292
  fps: this.fps,
@@ -1,10 +1,9 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
1
  import MockMediaStreamTrack from '../../test/MockMediaStreamTrack';
3
2
  import { TrackEvent } from '../events';
4
3
  import RemoteVideoTrack, { ElementInfo } from './RemoteVideoTrack';
5
4
  import type { Track } from './Track';
6
5
 
7
- vi.useFakeTimers();
6
+ jest.useFakeTimers();
8
7
 
9
8
  describe('RemoteVideoTrack', () => {
10
9
  let track: RemoteVideoTrack;
@@ -74,7 +73,7 @@ describe('RemoteVideoTrack', () => {
74
73
  elementInfo.setDimensions(100, 100);
75
74
 
76
75
  track.observeElementInfo(elementInfo);
77
- vi.runAllTimers();
76
+ jest.runAllTimers();
78
77
 
79
78
  expect(events).toHaveLength(1);
80
79
  expect(events[0].width).toBe(100);
@@ -86,10 +85,10 @@ describe('RemoteVideoTrack', () => {
86
85
  elementInfo.setDimensions(100, 100);
87
86
 
88
87
  track.observeElementInfo(elementInfo);
89
- vi.runAllTimers();
88
+ jest.runAllTimers();
90
89
 
91
90
  elementInfo.setDimensions(200, 200);
92
- vi.runAllTimers();
91
+ jest.runAllTimers();
93
92
 
94
93
  expect(events).toHaveLength(2);
95
94
  expect(events[1].width).toBe(200);
@@ -1,9 +1,8 @@
1
- import { EventEmitter } from 'events';
2
- import type TypedEventEmitter from 'typed-emitter';
1
+ import EventEmitter from 'eventemitter3';
3
2
  import type { SignalClient } from '../../api/SignalClient';
4
3
  import log from '../../logger';
5
- import { TrackSource, TrackType } from '../../proto/livekit_models_pb';
6
- import { StreamState as ProtoStreamState } from '../../proto/livekit_rtc_pb';
4
+ import { TrackSource, TrackType } from '../../proto/livekit_models';
5
+ import { StreamState as ProtoStreamState } from '../../proto/livekit_rtc';
7
6
  import { TrackEvent } from '../events';
8
7
  import { isFireFox, isSafari, isWeb } from '../utils';
9
8
 
@@ -13,7 +12,7 @@ const BACKGROUND_REACTION_DELAY = 5000;
13
12
  // Safari tracks which audio elements have been "blessed" by the user.
14
13
  const recycledElements: Array<HTMLAudioElement> = [];
15
14
 
16
- export abstract class Track extends (EventEmitter as new () => TypedEventEmitter<TrackEventCallbacks>) {
15
+ export abstract class Track extends EventEmitter<TrackEventCallbacks> {
17
16
  kind: Track.Kind;
18
17
 
19
18
  attachedElements: HTMLMediaElement[] = [];
@@ -52,7 +51,6 @@ export abstract class Track extends (EventEmitter as new () => TypedEventEmitter
52
51
 
53
52
  protected constructor(mediaTrack: MediaStreamTrack, kind: Track.Kind) {
54
53
  super();
55
- this.setMaxListeners(100);
56
54
  this.kind = kind;
57
55
  this._mediaStreamTrack = mediaTrack;
58
56
  this._mediaStreamID = mediaTrack.id;
@@ -370,8 +368,7 @@ export namespace Track {
370
368
  case Kind.Video:
371
369
  return TrackType.VIDEO;
372
370
  default:
373
- // FIXME this was UNRECOGNIZED before
374
- return TrackType.DATA;
371
+ return TrackType.UNRECOGNIZED;
375
372
  }
376
373
  }
377
374
 
@@ -399,7 +396,7 @@ export namespace Track {
399
396
  case Source.ScreenShareAudio:
400
397
  return TrackSource.SCREEN_SHARE_AUDIO;
401
398
  default:
402
- return TrackSource.UNKNOWN;
399
+ return TrackSource.UNRECOGNIZED;
403
400
  }
404
401
  }
405
402
 
@@ -1,9 +1,8 @@
1
- import { EventEmitter } from 'events';
2
- import type TypedEventEmitter from 'typed-emitter';
1
+ import EventEmitter from 'eventemitter3';
3
2
  import log from '../../logger';
4
- import { Encryption_Type } from '../../proto/livekit_models_pb';
5
- import type { SubscriptionError, TrackInfo } from '../../proto/livekit_models_pb';
6
- import type { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc_pb';
3
+ import { Encryption_Type } from '../../proto/livekit_models';
4
+ import type { SubscriptionError, TrackInfo } from '../../proto/livekit_models';
5
+ import type { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc';
7
6
  import { TrackEvent } from '../events';
8
7
  import LocalAudioTrack from './LocalAudioTrack';
9
8
  import LocalVideoTrack from './LocalVideoTrack';
@@ -12,7 +11,7 @@ import type RemoteTrack from './RemoteTrack';
12
11
  import RemoteVideoTrack from './RemoteVideoTrack';
13
12
  import { Track } from './Track';
14
13
 
15
- export class TrackPublication extends (EventEmitter as new () => TypedEventEmitter<PublicationEventCallbacks>) {
14
+ export class TrackPublication extends EventEmitter<PublicationEventCallbacks> {
16
15
  kind: Track.Kind;
17
16
 
18
17
  trackName: string;
@@ -41,7 +40,6 @@ export class TrackPublication extends (EventEmitter as new () => TypedEventEmitt
41
40
 
42
41
  constructor(kind: Track.Kind, id: string, name: string) {
43
42
  super();
44
- this.setMaxListeners(100);
45
43
  this.kind = kind;
46
44
  this.trackSid = id;
47
45
  this.trackName = name;
@@ -6,18 +6,14 @@ import LocalAudioTrack from './LocalAudioTrack';
6
6
  import type LocalTrack from './LocalTrack';
7
7
  import LocalVideoTrack from './LocalVideoTrack';
8
8
  import { Track } from './Track';
9
- import { ScreenSharePresets } from './options';
9
+ import { VideoPresets } from './options';
10
10
  import type {
11
11
  AudioCaptureOptions,
12
12
  CreateLocalTracksOptions,
13
13
  ScreenShareCaptureOptions,
14
14
  VideoCaptureOptions,
15
15
  } from './options';
16
- import {
17
- constraintsForOptions,
18
- mergeDefaultOptions,
19
- screenCaptureToDisplayMediaStreamOptions,
20
- } from './utils';
16
+ import { constraintsForOptions, mergeDefaultOptions } from './utils';
21
17
 
22
18
  /**
23
19
  * Creates a local video and audio track at the same time. When acquiring both
@@ -117,15 +113,27 @@ export async function createLocalScreenTracks(
117
113
  options = {};
118
114
  }
119
115
  if (options.resolution === undefined) {
120
- options.resolution = ScreenSharePresets.h1080fps15.resolution;
116
+ options.resolution = VideoPresets.h1080.resolution;
117
+ }
118
+
119
+ let videoConstraints: MediaTrackConstraints | boolean = true;
120
+ if (options.resolution) {
121
+ videoConstraints = {
122
+ width: options.resolution.width,
123
+ height: options.resolution.height,
124
+ };
121
125
  }
122
126
 
123
127
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
124
128
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
125
129
  }
126
130
 
127
- const constraints = screenCaptureToDisplayMediaStreamOptions(options);
128
- const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia(constraints);
131
+ // typescript definition is missing getDisplayMedia: https://github.com/microsoft/TypeScript/issues/33232
132
+ // @ts-ignore
133
+ const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
134
+ audio: options.audio ?? false,
135
+ video: videoConstraints,
136
+ });
129
137
 
130
138
  const tracks = stream.getVideoTracks();
131
139
  if (tracks.length === 0) {
@@ -1,4 +1,3 @@
1
- import { describe, expect, test } from 'vitest';
2
1
  import { facingModeFromDeviceLabel } from './facingMode';
3
2
 
4
3
  describe('Test facingMode detection', () => {
@@ -147,12 +147,6 @@ export interface ScreenShareCaptureOptions {
147
147
  */
148
148
  audio?: boolean | AudioCaptureOptions;
149
149
 
150
- /**
151
- * only allows for 'true' and chrome allows for additional options to be passed in
152
- * https://developer.chrome.com/docs/web-platform/screen-sharing-controls/#displaySurface
153
- */
154
- video?: true | { displaySurface?: 'window' | 'browser' | 'monitor' };
155
-
156
150
  /** capture resolution, defaults to full HD */
157
151
  resolution?: VideoResolution;
158
152
 
@@ -1,4 +1,3 @@
1
- import { describe, expect, it } from 'vitest';
2
1
  import { AudioCaptureOptions, VideoCaptureOptions, VideoPresets } from './options';
3
2
  import { constraintsForOptions, mergeDefaultOptions } from './utils';
4
3