livekit-client 1.11.3 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) 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 +1462 -660
  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 +2 -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 -1
  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 +9 -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/LocalAudioTrack.d.ts.map +1 -1
  55. package/dist/src/room/track/LocalTrack.d.ts +3 -2
  56. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  57. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  58. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  59. package/dist/src/room/track/TrackPublication.d.ts +3 -0
  60. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  61. package/dist/src/room/track/facingMode.d.ts +41 -0
  62. package/dist/src/room/track/facingMode.d.ts.map +1 -0
  63. package/dist/src/room/track/options.d.ts +2 -2
  64. package/dist/src/room/track/options.d.ts.map +1 -1
  65. package/dist/src/room/track/utils.d.ts +5 -35
  66. package/dist/src/room/track/utils.d.ts.map +1 -1
  67. package/dist/src/room/utils.d.ts +2 -0
  68. package/dist/src/room/utils.d.ts.map +1 -1
  69. package/dist/src/test/MockMediaStreamTrack.d.ts.map +1 -1
  70. package/dist/ts4.2/src/api/SignalClient.d.ts +4 -1
  71. package/dist/ts4.2/src/e2ee/E2eeManager.d.ts +45 -0
  72. package/dist/ts4.2/src/e2ee/KeyProvider.d.ts +42 -0
  73. package/dist/ts4.2/src/e2ee/constants.d.ts +14 -0
  74. package/dist/ts4.2/src/e2ee/errors.d.ts +11 -0
  75. package/dist/ts4.2/src/e2ee/index.d.ts +4 -0
  76. package/dist/ts4.2/src/e2ee/types.d.ts +129 -0
  77. package/dist/ts4.2/src/e2ee/utils.d.ts +24 -0
  78. package/dist/ts4.2/src/e2ee/worker/FrameCryptor.d.ts +175 -0
  79. package/dist/ts4.2/src/e2ee/worker/ParticipantKeyHandler.d.ts +46 -0
  80. package/dist/ts4.2/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  81. package/dist/ts4.2/src/index.d.ts +2 -0
  82. package/dist/ts4.2/src/logger.d.ts +4 -1
  83. package/dist/ts4.2/src/options.d.ts +5 -0
  84. package/dist/ts4.2/src/proto/livekit_models.d.ts +2 -2
  85. package/dist/ts4.2/src/room/PCTransport.d.ts +3 -1
  86. package/dist/ts4.2/src/room/RTCEngine.d.ts +17 -3
  87. package/dist/ts4.2/src/room/Room.d.ts +10 -1
  88. package/dist/ts4.2/src/room/events.d.ts +14 -2
  89. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +9 -2
  90. package/dist/ts4.2/src/room/participant/Participant.d.ts +1 -0
  91. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +3 -2
  92. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +3 -0
  93. package/dist/ts4.2/src/room/track/facingMode.d.ts +41 -0
  94. package/dist/ts4.2/src/room/track/options.d.ts +6 -6
  95. package/dist/ts4.2/src/room/track/utils.d.ts +5 -35
  96. package/dist/ts4.2/src/room/utils.d.ts +2 -0
  97. package/package.json +17 -7
  98. package/src/api/SignalClient.ts +28 -9
  99. package/src/connectionHelper/checks/turn.ts +1 -0
  100. package/src/connectionHelper/checks/websocket.ts +1 -0
  101. package/src/e2ee/E2eeManager.ts +374 -0
  102. package/src/e2ee/KeyProvider.ts +77 -0
  103. package/src/e2ee/constants.ts +40 -0
  104. package/src/e2ee/errors.ts +16 -0
  105. package/src/e2ee/index.ts +3 -0
  106. package/src/e2ee/types.ts +160 -0
  107. package/src/e2ee/utils.ts +127 -0
  108. package/src/e2ee/worker/FrameCryptor.test.ts +21 -0
  109. package/src/e2ee/worker/FrameCryptor.ts +614 -0
  110. package/src/e2ee/worker/ParticipantKeyHandler.ts +129 -0
  111. package/src/e2ee/worker/e2ee.worker.ts +217 -0
  112. package/src/e2ee/worker/tsconfig.json +6 -0
  113. package/src/index.ts +2 -0
  114. package/src/logger.ts +10 -2
  115. package/src/options.ts +6 -0
  116. package/src/proto/livekit_models.ts +12 -12
  117. package/src/room/PCTransport.ts +39 -9
  118. package/src/room/RTCEngine.ts +127 -34
  119. package/src/room/Room.ts +83 -30
  120. package/src/room/defaults.ts +1 -1
  121. package/src/room/events.ts +14 -0
  122. package/src/room/participant/LocalParticipant.ts +82 -10
  123. package/src/room/participant/Participant.ts +4 -0
  124. package/src/room/track/LocalAudioTrack.ts +11 -4
  125. package/src/room/track/LocalTrack.ts +50 -43
  126. package/src/room/track/LocalVideoTrack.ts +5 -3
  127. package/src/room/track/RemoteVideoTrack.ts +2 -2
  128. package/src/room/track/TrackPublication.ts +9 -1
  129. package/src/room/track/facingMode.test.ts +30 -0
  130. package/src/room/track/facingMode.ts +103 -0
  131. package/src/room/track/options.ts +3 -2
  132. package/src/room/track/utils.test.ts +1 -30
  133. package/src/room/track/utils.ts +16 -91
  134. package/src/room/utils.ts +5 -0
  135. package/src/room/worker.d.ts +4 -0
  136. package/src/test/MockMediaStreamTrack.ts +1 -0
@@ -1,6 +1,5 @@
1
1
  import { sleep } from '../utils';
2
- import log from './../../logger';
3
- import LocalTrack from './LocalTrack';
2
+ import { Track } from './Track';
4
3
  import type { AudioCaptureOptions, CreateLocalTracksOptions, VideoCaptureOptions } from './options';
5
4
  import type { AudioTrack } from './types';
6
5
 
@@ -115,102 +114,28 @@ export function getNewAudioContext(): AudioContext | void {
115
114
  }
116
115
  }
117
116
 
118
- type FacingMode = NonNullable<VideoCaptureOptions['facingMode']>;
119
- type FacingModeFromLocalTrackOptions = {
120
- /**
121
- * If no facing mode can be determined, this value will be used.
122
- * @defaultValue 'user'
123
- */
124
- defaultFacingMode?: FacingMode;
125
- };
126
- type FacingModeFromLocalTrackReturnValue = {
127
- /**
128
- * The (probable) facingMode of the track.
129
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode | MDN docs on facingMode}
130
- */
131
- facingMode: FacingMode;
132
- /**
133
- * The confidence that the returned facingMode is correct.
134
- */
135
- confidence: 'high' | 'medium' | 'low';
136
- };
137
-
138
117
  /**
139
- * Try to analyze the local track to determine the facing mode of a track.
140
- *
141
- * @remarks
142
- * There is no property supported by all browsers to detect whether a video track originated from a user- or environment-facing camera device.
143
- * For this reason, we use the `facingMode` property when available, but will fall back on a string-based analysis of the device label to determine the facing mode.
144
- * If both methods fail, the default facing mode will be used.
145
- *
146
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode | MDN docs on facingMode}
147
- * @experimental
118
+ * @internal
148
119
  */
149
- export function facingModeFromLocalTrack(
150
- localTrack: LocalTrack | MediaStreamTrack,
151
- options: FacingModeFromLocalTrackOptions = {},
152
- ): FacingModeFromLocalTrackReturnValue {
153
- const track = localTrack instanceof LocalTrack ? localTrack.mediaStreamTrack : localTrack;
154
- const trackSettings = track.getSettings();
155
- let result: FacingModeFromLocalTrackReturnValue = {
156
- facingMode: options.defaultFacingMode ?? 'user',
157
- confidence: 'low',
158
- };
159
-
160
- // 1. Try to get facingMode from track settings.
161
- if ('facingMode' in trackSettings) {
162
- const rawFacingMode = trackSettings.facingMode;
163
- log.debug('rawFacingMode', { rawFacingMode });
164
- if (rawFacingMode && typeof rawFacingMode === 'string' && isFacingModeValue(rawFacingMode)) {
165
- result = { facingMode: rawFacingMode, confidence: 'high' };
166
- }
167
- }
168
-
169
- // 2. If we don't have a high confidence we try to get the facing mode from the device label.
170
- if (['low', 'medium'].includes(result.confidence)) {
171
- log.debug(`Try to get facing mode from device label: (${track.label})`);
172
- const labelAnalysisResult = facingModeFromDeviceLabel(track.label);
173
- if (labelAnalysisResult !== undefined) {
174
- result = labelAnalysisResult;
175
- }
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;
176
127
  }
177
-
178
- return result;
179
128
  }
180
129
 
181
- const knownDeviceLabels = new Map<string, FacingModeFromLocalTrackReturnValue>([
182
- ['obs virtual camera', { facingMode: 'environment', confidence: 'medium' }],
183
- ]);
184
- const knownDeviceLabelSections = new Map<string, FacingModeFromLocalTrackReturnValue>([
185
- ['iphone', { facingMode: 'environment', confidence: 'medium' }],
186
- ['ipad', { facingMode: 'environment', confidence: 'medium' }],
187
- ]);
188
130
  /**
189
- * Attempt to analyze the device label to determine the facing mode.
190
- *
191
- * @experimental
131
+ * @internal
192
132
  */
193
- export function facingModeFromDeviceLabel(
194
- deviceLabel: string,
195
- ): FacingModeFromLocalTrackReturnValue | undefined {
196
- const label = deviceLabel.trim().toLowerCase();
197
- // Empty string is a valid device label but we can't infer anything from it.
198
- if (label === '') {
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 {
199
139
  return undefined;
200
140
  }
201
-
202
- // Can we match against widely known device labels.
203
- if (knownDeviceLabels.has(label)) {
204
- return knownDeviceLabels.get(label);
205
- }
206
-
207
- // Can we match against sections of the device label.
208
- return Array.from(knownDeviceLabelSections.entries()).find(([section]) =>
209
- label.includes(section),
210
- )?.[1];
211
- }
212
-
213
- function isFacingModeValue(item: string): item is FacingMode {
214
- const allowedValues: FacingMode[] = ['user', 'environment', 'left', 'right'];
215
- return item === undefined || allowedValues.includes(item as FacingMode);
216
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