livekit-client 1.11.4 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. package/README.md +1 -3
  2. package/dist/livekit-client.e2ee.worker.js +2 -0
  3. package/dist/livekit-client.e2ee.worker.js.map +1 -0
  4. package/dist/livekit-client.e2ee.worker.mjs +1525 -0
  5. package/dist/livekit-client.e2ee.worker.mjs.map +1 -0
  6. package/dist/livekit-client.esm.mjs +4749 -4055
  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 +4 -1
  11. package/dist/src/api/SignalClient.d.ts.map +1 -1
  12. package/dist/src/connectionHelper/checks/turn.d.ts.map +1 -1
  13. package/dist/src/connectionHelper/checks/websocket.d.ts.map +1 -1
  14. package/dist/src/e2ee/E2eeManager.d.ts +45 -0
  15. package/dist/src/e2ee/E2eeManager.d.ts.map +1 -0
  16. package/dist/src/e2ee/KeyProvider.d.ts +42 -0
  17. package/dist/src/e2ee/KeyProvider.d.ts.map +1 -0
  18. package/dist/src/e2ee/constants.d.ts +14 -0
  19. package/dist/src/e2ee/constants.d.ts.map +1 -0
  20. package/dist/src/e2ee/errors.d.ts +11 -0
  21. package/dist/src/e2ee/errors.d.ts.map +1 -0
  22. package/dist/src/e2ee/index.d.ts +4 -0
  23. package/dist/src/e2ee/index.d.ts.map +1 -0
  24. package/dist/src/e2ee/types.d.ts +129 -0
  25. package/dist/src/e2ee/types.d.ts.map +1 -0
  26. package/dist/src/e2ee/utils.d.ts +24 -0
  27. package/dist/src/e2ee/utils.d.ts.map +1 -0
  28. package/dist/src/e2ee/worker/FrameCryptor.d.ts +175 -0
  29. package/dist/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
  30. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
  31. package/dist/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
  32. package/dist/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  33. package/dist/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
  34. package/dist/src/index.d.ts +1 -0
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/logger.d.ts +4 -1
  37. package/dist/src/logger.d.ts.map +1 -1
  38. package/dist/src/options.d.ts +5 -0
  39. package/dist/src/options.d.ts.map +1 -1
  40. package/dist/src/proto/livekit_models.d.ts +2 -2
  41. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  42. package/dist/src/room/PCTransport.d.ts +3 -1
  43. package/dist/src/room/PCTransport.d.ts.map +1 -1
  44. package/dist/src/room/RTCEngine.d.ts +17 -3
  45. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  46. package/dist/src/room/Room.d.ts +10 -0
  47. package/dist/src/room/Room.d.ts.map +1 -1
  48. package/dist/src/room/events.d.ts +14 -2
  49. package/dist/src/room/events.d.ts.map +1 -1
  50. package/dist/src/room/participant/LocalParticipant.d.ts +7 -2
  51. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  52. package/dist/src/room/participant/Participant.d.ts +1 -0
  53. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  54. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  55. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  56. package/dist/src/room/track/TrackPublication.d.ts +3 -0
  57. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  58. package/dist/src/room/track/options.d.ts +2 -2
  59. package/dist/src/room/track/options.d.ts.map +1 -1
  60. package/dist/src/room/track/utils.d.ts +9 -0
  61. package/dist/src/room/track/utils.d.ts.map +1 -1
  62. package/dist/src/room/utils.d.ts +2 -0
  63. package/dist/src/room/utils.d.ts.map +1 -1
  64. package/dist/src/test/MockMediaStreamTrack.d.ts.map +1 -1
  65. package/dist/ts4.2/src/api/SignalClient.d.ts +4 -1
  66. package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +45 -0
  67. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +42 -0
  68. package/dist/ts4.2/src/e2ee/constants.d.ts +14 -0
  69. package/dist/ts4.2/src/e2ee/errors.d.ts +11 -0
  70. package/dist/ts4.2/src/e2ee/index.d.ts +4 -0
  71. package/dist/ts4.2/src/e2ee/types.d.ts +129 -0
  72. package/dist/ts4.2/src/e2ee/utils.d.ts +24 -0
  73. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +175 -0
  74. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
  75. package/dist/ts4.2/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  76. package/dist/ts4.2/src/index.d.ts +1 -0
  77. package/dist/ts4.2/src/logger.d.ts +4 -1
  78. package/dist/ts4.2/src/options.d.ts +5 -0
  79. package/dist/ts4.2/src/proto/livekit_models.d.ts +2 -2
  80. package/dist/ts4.2/src/room/PCTransport.d.ts +3 -1
  81. package/dist/ts4.2/src/room/RTCEngine.d.ts +17 -3
  82. package/dist/ts4.2/src/room/Room.d.ts +10 -0
  83. package/dist/ts4.2/src/room/events.d.ts +14 -2
  84. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +7 -2
  85. package/dist/ts4.2/src/room/participant/Participant.d.ts +1 -0
  86. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +3 -0
  87. package/dist/ts4.2/src/room/track/options.d.ts +6 -6
  88. package/dist/ts4.2/src/room/track/utils.d.ts +9 -0
  89. package/dist/ts4.2/src/room/utils.d.ts +2 -0
  90. package/package.json +17 -7
  91. package/src/api/SignalClient.ts +28 -9
  92. package/src/connectionHelper/checks/turn.ts +1 -0
  93. package/src/connectionHelper/checks/websocket.ts +1 -0
  94. package/src/e2ee/E2eeManager.ts +374 -0
  95. package/src/e2ee/KeyProvider.ts +77 -0
  96. package/src/e2ee/constants.ts +40 -0
  97. package/src/e2ee/errors.ts +16 -0
  98. package/src/e2ee/index.ts +3 -0
  99. package/src/e2ee/types.ts +160 -0
  100. package/src/e2ee/utils.ts +127 -0
  101. package/src/e2ee/worker/FrameCryptor.test.ts +21 -0
  102. package/src/e2ee/worker/FrameCryptor.ts +614 -0
  103. package/src/e2ee/worker/ParticipantKeyHandler.ts +129 -0
  104. package/src/e2ee/worker/e2ee.worker.ts +217 -0
  105. package/src/e2ee/worker/tsconfig.json +6 -0
  106. package/src/index.ts +1 -0
  107. package/src/logger.ts +10 -2
  108. package/src/options.ts +6 -0
  109. package/src/proto/livekit_models.ts +12 -12
  110. package/src/room/PCTransport.ts +39 -9
  111. package/src/room/RTCEngine.ts +127 -34
  112. package/src/room/Room.ts +77 -22
  113. package/src/room/defaults.ts +1 -1
  114. package/src/room/events.ts +14 -0
  115. package/src/room/participant/LocalParticipant.ts +52 -8
  116. package/src/room/participant/Participant.ts +4 -0
  117. package/src/room/track/LocalTrack.ts +5 -4
  118. package/src/room/track/RemoteVideoTrack.ts +2 -2
  119. package/src/room/track/TrackPublication.ts +9 -1
  120. package/src/room/track/options.ts +3 -2
  121. package/src/room/track/utils.ts +27 -0
  122. package/src/room/utils.ts +5 -0
  123. package/src/room/worker.d.ts +4 -0
  124. package/src/test/MockMediaStreamTrack.ts +1 -0
@@ -56,9 +56,10 @@ export default abstract class LocalTrack extends Track {
56
56
  this.muteLock = new Mutex();
57
57
  this.pauseUpstreamLock = new Mutex();
58
58
  this.processorLock = new Mutex();
59
+ this.setMediaStreamTrack(mediaTrack, true);
60
+
59
61
  // added to satisfy TS compiler, constraints are synced with MediaStreamTrack
60
62
  this._constraints = mediaTrack.getConstraints();
61
- this.setMediaStreamTrack(mediaTrack);
62
63
  if (constraints) {
63
64
  this._constraints = constraints;
64
65
  }
@@ -97,8 +98,8 @@ export default abstract class LocalTrack extends Track {
97
98
  return this.processor?.processedTrack ?? this._mediaStreamTrack;
98
99
  }
99
100
 
100
- private async setMediaStreamTrack(newTrack: MediaStreamTrack) {
101
- if (newTrack === this._mediaStreamTrack) {
101
+ private async setMediaStreamTrack(newTrack: MediaStreamTrack, force?: boolean) {
102
+ if (newTrack === this._mediaStreamTrack && !force) {
102
103
  return;
103
104
  }
104
105
  if (this._mediaStreamTrack) {
@@ -109,7 +110,7 @@ export default abstract class LocalTrack extends Track {
109
110
  this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
110
111
  this._mediaStreamTrack.removeEventListener('mute', this.pauseUpstream);
111
112
  this._mediaStreamTrack.removeEventListener('unmute', this.resumeUpstream);
112
- if (!this.providedByUser) {
113
+ if (!this.providedByUser && this._mediaStreamTrack !== newTrack) {
113
114
  this._mediaStreamTrack.stop();
114
115
  }
115
116
  }
@@ -123,6 +123,7 @@ export default class RemoteVideoTrack extends RemoteTrack {
123
123
  }
124
124
  this.elementInfos = this.elementInfos.filter((info) => info !== elementInfo);
125
125
  this.updateVisibility();
126
+ this.debouncedHandleResize();
126
127
  }
127
128
 
128
129
  detach(): HTMLMediaElement[];
@@ -195,9 +196,8 @@ export default class RemoteVideoTrack extends RemoteTrack {
195
196
  private stopObservingElement(element: HTMLMediaElement) {
196
197
  const stopElementInfos = this.elementInfos.filter((info) => info.element === element);
197
198
  for (const info of stopElementInfos) {
198
- info.stopObserving();
199
+ this.stopObservingElementInfo(info);
199
200
  }
200
- this.elementInfos = this.elementInfos.filter((info) => info.element !== element);
201
201
  }
202
202
 
203
203
  protected async handleAppVisibilityChanged() {
@@ -1,5 +1,6 @@
1
1
  import EventEmitter from 'eventemitter3';
2
2
  import log from '../../logger';
3
+ import { Encryption_Type } from '../../proto/livekit_models';
3
4
  import type { SubscriptionError, TrackInfo } from '../../proto/livekit_models';
4
5
  import type { UpdateSubscription, UpdateTrackSettings } from '../../proto/livekit_rtc';
5
6
  import { TrackEvent } from '../events';
@@ -35,6 +36,8 @@ export class TrackPublication extends EventEmitter<PublicationEventCallbacks> {
35
36
 
36
37
  protected metadataMuted: boolean = false;
37
38
 
39
+ protected encryption: Encryption_Type = Encryption_Type.NONE;
40
+
38
41
  constructor(kind: Track.Kind, id: string, name: string) {
39
42
  super();
40
43
  this.kind = kind;
@@ -71,6 +74,10 @@ export class TrackPublication extends EventEmitter<PublicationEventCallbacks> {
71
74
  return this.track !== undefined;
72
75
  }
73
76
 
77
+ get isEncrypted(): boolean {
78
+ return this.encryption !== Encryption_Type.NONE;
79
+ }
80
+
74
81
  /**
75
82
  * an [AudioTrack] if this publication holds an audio track
76
83
  */
@@ -110,8 +117,9 @@ export class TrackPublication extends EventEmitter<PublicationEventCallbacks> {
110
117
  };
111
118
  this.simulcasted = info.simulcast;
112
119
  }
120
+ this.encryption = info.encryption;
113
121
  this.trackInfo = info;
114
- log.trace('update publication info', { info });
122
+ log.debug('update publication info', { info });
115
123
  }
116
124
  }
117
125
 
@@ -272,10 +272,11 @@ export interface AudioPreset {
272
272
  priority?: RTCPriorityType;
273
273
  }
274
274
 
275
- const codecs = ['vp8', 'h264', 'vp9', 'av1'] as const;
276
275
  const backupCodecs = ['vp8', 'h264'] as const;
277
276
 
278
- export type VideoCodec = (typeof codecs)[number];
277
+ export const videoCodecs = ['vp8', 'h264', 'vp9', 'av1'] as const;
278
+
279
+ export type VideoCodec = (typeof videoCodecs)[number];
279
280
 
280
281
  export type BackupVideoCodec = (typeof backupCodecs)[number];
281
282
 
@@ -1,4 +1,5 @@
1
1
  import { sleep } from '../utils';
2
+ import { Track } from './Track';
2
3
  import type { AudioCaptureOptions, CreateLocalTracksOptions, VideoCaptureOptions } from './options';
3
4
  import type { AudioTrack } from './types';
4
5
 
@@ -112,3 +113,29 @@ export function getNewAudioContext(): AudioContext | void {
112
113
  return new AudioContext({ latencyHint: 'interactive' });
113
114
  }
114
115
  }
116
+
117
+ /**
118
+ * @internal
119
+ */
120
+ export function kindToSource(kind: MediaDeviceKind) {
121
+ if (kind === 'audioinput') {
122
+ return Track.Source.Microphone;
123
+ } else if (kind === 'videoinput') {
124
+ return Track.Source.Camera;
125
+ } else {
126
+ return Track.Source.Unknown;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * @internal
132
+ */
133
+ export function sourceToKind(source: Track.Source): MediaDeviceKind | undefined {
134
+ if (source === Track.Source.Microphone) {
135
+ return 'audioinput';
136
+ } else if (source === Track.Source.Camera) {
137
+ return 'videoinput';
138
+ } else {
139
+ return undefined;
140
+ }
141
+ }
package/src/room/utils.ts CHANGED
@@ -4,6 +4,7 @@ import type { DetectableBrowser } from '../utils/browserParser';
4
4
  import { protocolVersion, version } from '../version';
5
5
  import type LocalAudioTrack from './track/LocalAudioTrack';
6
6
  import type RemoteAudioTrack from './track/RemoteAudioTrack';
7
+ import { VideoCodec, videoCodecs } from './track/options';
7
8
  import { getNewAudioContext } from './track/utils';
8
9
  import type { LiveKitReactNativeInfo } from './types';
9
10
 
@@ -456,6 +457,10 @@ export class Mutex {
456
457
  }
457
458
  }
458
459
 
460
+ export function isVideoCodec(maybeCodec: string): maybeCodec is VideoCodec {
461
+ return videoCodecs.includes(maybeCodec as VideoCodec);
462
+ }
463
+
459
464
  export function unwrapConstraint(constraint: ConstrainDOMString): string {
460
465
  if (typeof constraint === 'string') {
461
466
  return constraint;
@@ -0,0 +1,4 @@
1
+ declare module 'web-worker:*' {
2
+ const WorkerFactory: new () => Worker;
3
+ export default WorkerFactory;
4
+ }
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ // @ts-ignore
2
3
  export default class MockMediaStreamTrack implements MediaStreamTrack {
3
4
  contentHint: string = '';
4
5