livekit-client 2.1.5 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/README.md +2 -6
  2. package/dist/livekit-client.esm.mjs +175 -77
  3. package/dist/livekit-client.esm.mjs.map +1 -1
  4. package/dist/livekit-client.umd.js +1 -1
  5. package/dist/livekit-client.umd.js.map +1 -1
  6. package/dist/src/index.d.ts +2 -2
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/room/DeviceManager.d.ts.map +1 -1
  9. package/dist/src/room/RTCEngine.d.ts +2 -2
  10. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  11. package/dist/src/room/Room.d.ts +7 -2
  12. package/dist/src/room/Room.d.ts.map +1 -1
  13. package/dist/src/room/events.d.ts +18 -1
  14. package/dist/src/room/events.d.ts.map +1 -1
  15. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  16. package/dist/src/room/participant/Participant.d.ts +6 -3
  17. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  18. package/dist/src/room/participant/RemoteParticipant.d.ts +3 -3
  19. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  20. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  21. package/dist/src/room/track/LocalTrack.d.ts +1 -1
  22. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  23. package/dist/src/room/track/LocalVideoTrack.d.ts +1 -1
  24. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  25. package/dist/src/room/track/create.d.ts.map +1 -1
  26. package/dist/src/room/track/options.d.ts +9 -0
  27. package/dist/src/room/track/options.d.ts.map +1 -1
  28. package/dist/ts4.2/src/index.d.ts +2 -2
  29. package/dist/ts4.2/src/room/RTCEngine.d.ts +2 -2
  30. package/dist/ts4.2/src/room/Room.d.ts +7 -2
  31. package/dist/ts4.2/src/room/events.d.ts +18 -1
  32. package/dist/ts4.2/src/room/participant/Participant.d.ts +7 -3
  33. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +3 -3
  34. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -1
  35. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +1 -1
  36. package/dist/ts4.2/src/room/track/options.d.ts +9 -0
  37. package/package.json +9 -9
  38. package/src/index.ts +2 -1
  39. package/src/room/DeviceManager.test.ts +105 -0
  40. package/src/room/DeviceManager.ts +11 -6
  41. package/src/room/RTCEngine.ts +23 -6
  42. package/src/room/Room.ts +48 -11
  43. package/src/room/defaults.ts +1 -1
  44. package/src/room/events.ts +21 -1
  45. package/src/room/participant/LocalParticipant.ts +36 -25
  46. package/src/room/participant/Participant.ts +14 -1
  47. package/src/room/participant/RemoteParticipant.ts +17 -4
  48. package/src/room/participant/publishUtils.ts +4 -0
  49. package/src/room/track/LocalTrack.ts +14 -10
  50. package/src/room/track/LocalVideoTrack.ts +4 -1
  51. package/src/room/track/create.ts +37 -27
  52. package/src/room/track/options.ts +15 -0
package/README.md CHANGED
@@ -11,9 +11,7 @@
11
11
  # JavaScript/TypeScript client SDK for LiveKit
12
12
 
13
13
  <!--BEGIN_DESCRIPTION-->
14
-
15
14
  Use this SDK to add real-time video, audio and data features to your JavaScript/TypeScript app. By connecting to a self- or cloud-hosted <a href="https://livekit.io/">LiveKit</a> server, you can quickly build applications like interactive live streaming or video calls with just a few lines of code.
16
-
17
15
  <!--END_DESCRIPTION-->
18
16
 
19
17
  ## Docs
@@ -329,13 +327,11 @@ If you are targeting legacy browsers, but still want adaptiveStream functionalit
329
327
  Also when targeting legacy browsers, older than the ones specified in our browserslist target, make sure to transpile the library code to your desired target and include required polyfills with babel and/or corejs.
330
328
 
331
329
  <!--BEGIN_REPO_NAV-->
332
-
333
330
  <br/><table>
334
-
335
331
  <thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
336
332
  <tbody>
337
- <tr><td>Real-time SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <b>JavaScript</b> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
338
- <tr><td>Server APIs</td><td><a href="https://github.com/livekit/server-sdk-js">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/client-sdk-python">Python</a> · <a href="https://github.com/livekit/client-sdk-rust">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
333
+ <tr><td>Real-time SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <b>Browser</b> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <a href="https://github.com/livekit/client-sdk-react-native">React Native</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
334
+ <tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
339
335
  <tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
340
336
  <tr><td>Services</td><td><a href="https://github.com/livekit/livekit">Livekit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
341
337
  <tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/oss/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
@@ -1233,10 +1233,12 @@ class BinaryReader {
1233
1233
  return [fieldNo, wireType];
1234
1234
  }
1235
1235
  /**
1236
- * Skip one element on the wire and return the skipped data.
1237
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
1236
+ * Skip one element and return the skipped data.
1237
+ *
1238
+ * When skipping StartGroup, provide the tags field number to check for
1239
+ * matching field number in the EndGroup tag.
1238
1240
  */
1239
- skip(wireType) {
1241
+ skip(wireType, fieldNo) {
1240
1242
  let start = this.pos;
1241
1243
  switch (wireType) {
1242
1244
  case WireType.Varint:
@@ -1258,10 +1260,15 @@ class BinaryReader {
1258
1260
  this.pos += len;
1259
1261
  break;
1260
1262
  case WireType.StartGroup:
1261
- // TODO check for matching field numbers in StartGroup / EndGroup tags
1262
- let t;
1263
- while ((t = this.tag()[1]) !== WireType.EndGroup) {
1264
- this.skip(t);
1263
+ for (;;) {
1264
+ const [fn, wt] = this.tag();
1265
+ if (wt === WireType.EndGroup) {
1266
+ if (fieldNo !== undefined && fn !== fieldNo) {
1267
+ throw new Error("invalid end group tag");
1268
+ }
1269
+ break;
1270
+ }
1271
+ this.skip(wt, fn);
1265
1272
  }
1266
1273
  break;
1267
1274
  default:
@@ -1651,7 +1658,7 @@ function setExtension(message, extension, value, options) {
1651
1658
  const reader = readOpt.readerFactory(writer.finish());
1652
1659
  while (reader.pos < reader.len) {
1653
1660
  const [no, wireType] = reader.tag();
1654
- const data = reader.skip(wireType);
1661
+ const data = reader.skip(wireType, no);
1655
1662
  message.getType().runtime.bin.onUnknownField(message, no, wireType, data);
1656
1663
  }
1657
1664
  }
@@ -2459,12 +2466,12 @@ function makeBinaryFormat() {
2459
2466
  let fieldNo, wireType;
2460
2467
  while (reader.pos < end) {
2461
2468
  [fieldNo, wireType] = reader.tag();
2462
- if (wireType == WireType.EndGroup) {
2469
+ if (delimitedMessageEncoding === true && wireType == WireType.EndGroup) {
2463
2470
  break;
2464
2471
  }
2465
2472
  const field = type.fields.find(fieldNo);
2466
2473
  if (!field) {
2467
- const data = reader.skip(wireType);
2474
+ const data = reader.skip(wireType, fieldNo);
2468
2475
  if (options.readUnknownFields) {
2469
2476
  this.onUnknownField(message, fieldNo, wireType, data);
2470
2477
  }
@@ -2825,7 +2832,7 @@ function makeUtilCommon() {
2825
2832
  const localName = member.localName,
2826
2833
  t = target,
2827
2834
  s = source;
2828
- if (s[localName] === undefined) {
2835
+ if (s[localName] == null) {
2829
2836
  // TODO if source is a Message instance, we should use isFieldSet() here to support future field presence
2830
2837
  continue;
2831
2838
  }
@@ -9884,6 +9891,12 @@ var RoomEvent;
9884
9891
  * to reconnect.
9885
9892
  */
9886
9893
  RoomEvent["Reconnecting"] = "reconnecting";
9894
+ /**
9895
+ * When the signal connection to the server has been interrupted. This isn't noticeable to users most of the time.
9896
+ * It will resolve with a `RoomEvent.Reconnected` once the signal connection has been re-established.
9897
+ * If media fails additionally it an additional `RoomEvent.Reconnecting` will be emitted.
9898
+ */
9899
+ RoomEvent["SignalReconnecting"] = "signalReconnecting";
9887
9900
  /**
9888
9901
  * Fires when a reconnection has been successful.
9889
9902
  */
@@ -10040,6 +10053,12 @@ var RoomEvent;
10040
10053
  * args: (payload: Uint8Array, participant: [[Participant]], kind: [[DataPacket_Kind]], topic?: string)
10041
10054
  */
10042
10055
  RoomEvent["DataReceived"] = "dataReceived";
10056
+ /**
10057
+ * SIP DTMF tones received from another participant.
10058
+ *
10059
+ * args: (participant: [[Participant]], dtmf: [[DataPacket_Kind]])
10060
+ */
10061
+ RoomEvent["SipDTMFReceived"] = "sipDTMFReceived";
10043
10062
  /**
10044
10063
  * Transcription received from a participant's track.
10045
10064
  * @beta
@@ -10226,6 +10245,12 @@ var ParticipantEvent;
10226
10245
  * args: (payload: Uint8Array, kind: [[DataPacket_Kind]])
10227
10246
  */
10228
10247
  ParticipantEvent["DataReceived"] = "dataReceived";
10248
+ /**
10249
+ * SIP DTMF tones received from this participant as sender.
10250
+ *
10251
+ * args: (dtmf: [[DataPacket_Kind]])
10252
+ */
10253
+ ParticipantEvent["SipDTMFReceived"] = "sipDTMFReceived";
10229
10254
  /**
10230
10255
  * Transcription received from this participant as data source.
10231
10256
  * @beta
@@ -10300,7 +10325,6 @@ var EngineEvent;
10300
10325
  EngineEvent["MediaTrackAdded"] = "mediaTrackAdded";
10301
10326
  EngineEvent["ActiveSpeakersUpdate"] = "activeSpeakersUpdate";
10302
10327
  EngineEvent["DataPacketReceived"] = "dataPacketReceived";
10303
- EngineEvent["TranscriptionReceived"] = "transcriptionReceived";
10304
10328
  EngineEvent["RTPVideoMapUpdate"] = "rtpVideoMapUpdate";
10305
10329
  EngineEvent["DCBufferStatusChanged"] = "dcBufferStatusChanged";
10306
10330
  EngineEvent["ParticipantUpdate"] = "participantUpdate";
@@ -10505,7 +10529,7 @@ function getOSVersion(ua) {
10505
10529
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
10506
10530
  }
10507
10531
 
10508
- var version$1 = "2.1.5";
10532
+ var version$1 = "2.3.0";
10509
10533
 
10510
10534
  const version = version$1;
10511
10535
  const protocolVersion = 13;
@@ -11699,16 +11723,16 @@ class DeviceManager {
11699
11723
  // resolve actual device id if it's 'default': Chrome returns it when no
11700
11724
  // device has been chosen
11701
11725
  const devices = yield this.getDevices(kind);
11702
- // `default` devices will have the same groupId as the entry with the actual device id so we store the counts for each group id
11703
- const groupIdCounts = new Map(devices.map(d => [d.groupId, 0]));
11704
- devices.forEach(d => {
11705
- var _a;
11706
- return groupIdCounts.set(d.groupId, ((_a = groupIdCounts.get(d.groupId)) !== null && _a !== void 0 ? _a : 0) + 1);
11707
- });
11708
- const device = devices.find(d => {
11709
- var _a;
11710
- return (groupId === d.groupId || ((_a = groupIdCounts.get(d.groupId)) !== null && _a !== void 0 ? _a : 0) > 1) && d.deviceId !== defaultId;
11711
- });
11726
+ const defaultDevice = devices.find(d => d.deviceId === defaultId);
11727
+ if (!defaultDevice) {
11728
+ livekitLogger.warn('could not reliably determine default device');
11729
+ return undefined;
11730
+ }
11731
+ const device = devices.find(d => d.deviceId !== defaultId && d.groupId === (groupId !== null && groupId !== void 0 ? groupId : defaultDevice.groupId));
11732
+ if (!device) {
11733
+ livekitLogger.warn('could not reliably determine default device');
11734
+ return undefined;
11735
+ }
11712
11736
  return device === null || device === void 0 ? void 0 : device.deviceId;
11713
11737
  });
11714
11738
  }
@@ -12083,7 +12107,7 @@ class LocalTrack extends Track {
12083
12107
  this._isUpstreamPaused = false;
12084
12108
  this.emit(TrackEvent.UpstreamResumed, this);
12085
12109
  // this operation is noop if mediastreamtrack is already being sent
12086
- yield this.sender.replaceTrack(this._mediaStreamTrack);
12110
+ yield this.sender.replaceTrack(this.mediaStreamTrack);
12087
12111
  } finally {
12088
12112
  unlock();
12089
12113
  }
@@ -12120,30 +12144,32 @@ class LocalTrack extends Track {
12120
12144
  var _this2 = this;
12121
12145
  let showProcessedStreamLocally = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
12122
12146
  return function* () {
12123
- var _a, _b;
12147
+ var _a;
12124
12148
  const unlock = yield _this2.processorLock.lock();
12125
12149
  try {
12126
12150
  _this2.log.debug('setting up processor', _this2.logContext);
12127
- _this2.processorElement = (_a = _this2.processorElement) !== null && _a !== void 0 ? _a : document.createElement(_this2.kind);
12151
+ const processorElement = document.createElement(_this2.kind);
12128
12152
  const processorOptions = {
12129
12153
  kind: _this2.kind,
12130
12154
  track: _this2._mediaStreamTrack,
12131
- element: _this2.processorElement,
12155
+ element: processorElement,
12132
12156
  audioContext: _this2.audioContext
12133
12157
  };
12134
12158
  yield processor.init(processorOptions);
12159
+ _this2.log.debug('processor initialized', _this2.logContext);
12135
12160
  if (_this2.processor) {
12136
12161
  yield _this2.stopProcessor();
12137
12162
  }
12138
12163
  if (_this2.kind === 'unknown') {
12139
12164
  throw TypeError('cannot set processor on track of unknown kind');
12140
12165
  }
12141
- attachToElement(_this2._mediaStreamTrack, _this2.processorElement);
12142
- _this2.processorElement.muted = true;
12143
- _this2.processorElement.play().catch(error => _this2.log.error('failed to play processor element', Object.assign(Object.assign({}, _this2.logContext), {
12166
+ attachToElement(_this2._mediaStreamTrack, processorElement);
12167
+ processorElement.muted = true;
12168
+ processorElement.play().catch(error => _this2.log.error('failed to play processor element', Object.assign(Object.assign({}, _this2.logContext), {
12144
12169
  error
12145
12170
  })));
12146
12171
  _this2.processor = processor;
12172
+ _this2.processorElement = processorElement;
12147
12173
  if (_this2.processor.processedTrack) {
12148
12174
  for (const el of _this2.attachedElements) {
12149
12175
  if (el !== _this2.processorElement && showProcessedStreamLocally) {
@@ -12151,7 +12177,7 @@ class LocalTrack extends Track {
12151
12177
  attachToElement(_this2.processor.processedTrack, el);
12152
12178
  }
12153
12179
  }
12154
- yield (_b = _this2.sender) === null || _b === void 0 ? void 0 : _b.replaceTrack(_this2.processor.processedTrack);
12180
+ yield (_a = _this2.sender) === null || _a === void 0 ? void 0 : _a.replaceTrack(_this2.processor.processedTrack);
12155
12181
  }
12156
12182
  _this2.emit(TrackEvent.TrackProcessorUpdate, _this2.processor);
12157
12183
  } finally {
@@ -12171,20 +12197,26 @@ class LocalTrack extends Track {
12171
12197
  * @returns
12172
12198
  */
12173
12199
  stopProcessor() {
12174
- return __awaiter(this, void 0, void 0, function* () {
12175
- var _a, _b;
12176
- if (!this.processor) return;
12177
- this.log.debug('stopping processor', this.logContext);
12178
- (_a = this.processor.processedTrack) === null || _a === void 0 ? void 0 : _a.stop();
12179
- yield this.processor.destroy();
12180
- this.processor = undefined;
12181
- (_b = this.processorElement) === null || _b === void 0 ? void 0 : _b.remove();
12182
- this.processorElement = undefined;
12183
- // apply original track constraints in case the processor changed them
12184
- yield this._mediaStreamTrack.applyConstraints(this._constraints);
12185
- // force re-setting of the mediaStreamTrack on the sender
12186
- yield this.setMediaStreamTrack(this._mediaStreamTrack, true);
12187
- this.emit(TrackEvent.TrackProcessorUpdate);
12200
+ return __awaiter(this, arguments, void 0, function () {
12201
+ var _this3 = this;
12202
+ let keepElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
12203
+ return function* () {
12204
+ var _a, _b;
12205
+ if (!_this3.processor) return;
12206
+ _this3.log.debug('stopping processor', _this3.logContext);
12207
+ (_a = _this3.processor.processedTrack) === null || _a === void 0 ? void 0 : _a.stop();
12208
+ yield _this3.processor.destroy();
12209
+ _this3.processor = undefined;
12210
+ if (!keepElement) {
12211
+ (_b = _this3.processorElement) === null || _b === void 0 ? void 0 : _b.remove();
12212
+ _this3.processorElement = undefined;
12213
+ }
12214
+ // apply original track constraints in case the processor changed them
12215
+ yield _this3._mediaStreamTrack.applyConstraints(_this3._constraints);
12216
+ // force re-setting of the mediaStreamTrack on the sender
12217
+ yield _this3.setMediaStreamTrack(_this3._mediaStreamTrack, true);
12218
+ _this3.emit(TrackEvent.TrackProcessorUpdate);
12219
+ }();
12188
12220
  });
12189
12221
  }
12190
12222
  }
@@ -14441,7 +14473,7 @@ const roomOptionDefaults = {
14441
14473
  stopLocalTrackOnUnpublish: true,
14442
14474
  reconnectPolicy: new DefaultReconnectPolicy(),
14443
14475
  disconnectOnPageLeave: true,
14444
- webAudioMix: true
14476
+ webAudioMix: false
14445
14477
  };
14446
14478
  const roomConnectOptionDefaults = {
14447
14479
  autoSubscribe: true,
@@ -15060,7 +15092,11 @@ function computeVideoEncodings(isScreenShare, width, height, options) {
15060
15092
  // before M113.
15061
15093
  // Announced here: https://groups.google.com/g/discuss-webrtc/c/-QQ3pxrl-fw?pli=1
15062
15094
  const browser = getBrowser();
15063
- if (isSafari() || (browser === null || browser === void 0 ? void 0 : browser.name) === 'Chrome' && compareVersions(browser === null || browser === void 0 ? void 0 : browser.version, '113') < 0) {
15095
+ if (isSafari() ||
15096
+ // Even tho RN runs M114, it does not produce SVC layers when a single encoding
15097
+ // is provided. So we'll use the legacy SVC specification for now.
15098
+ // TODO: when we upstream libwebrtc, this will need additional verification
15099
+ isReactNative() || (browser === null || browser === void 0 ? void 0 : browser.name) === 'Chrome' && compareVersions(browser === null || browser === void 0 ? void 0 : browser.version, '113') < 0) {
15064
15100
  const bitratesRatio = sm.suffix == 'h' ? 2 : 3;
15065
15101
  for (let i = 0; i < sm.spatial; i += 1) {
15066
15102
  // in legacy SVC, scaleResolutionDownBy cannot be set
@@ -15983,7 +16019,7 @@ class RTCEngine extends eventsExports.EventEmitter {
15983
16019
  }();
15984
16020
  });
15985
16021
  this.handleDataMessage = message => __awaiter(this, void 0, void 0, function* () {
15986
- var _c, _d, _e;
16022
+ var _c, _d;
15987
16023
  // make sure to respect incoming data message order by processing message events one after the other
15988
16024
  const unlock = yield this.dataProcessLock.lock();
15989
16025
  try {
@@ -16003,10 +16039,12 @@ class RTCEngine extends eventsExports.EventEmitter {
16003
16039
  if (((_c = dp.value) === null || _c === void 0 ? void 0 : _c.case) === 'speaker') {
16004
16040
  // dispatch speaker updates
16005
16041
  this.emit(EngineEvent.ActiveSpeakersUpdate, dp.value.value.speakers);
16006
- } else if (((_d = dp.value) === null || _d === void 0 ? void 0 : _d.case) === 'user') {
16007
- this.emit(EngineEvent.DataPacketReceived, dp.value.value, dp.kind);
16008
- } else if (((_e = dp.value) === null || _e === void 0 ? void 0 : _e.case) === 'transcription') {
16009
- this.emit(EngineEvent.TranscriptionReceived, dp.value.value);
16042
+ } else {
16043
+ if (((_d = dp.value) === null || _d === void 0 ? void 0 : _d.case) === 'user') {
16044
+ // compatibility
16045
+ applyUserDataCompat(dp, dp.value.value);
16046
+ }
16047
+ this.emit(EngineEvent.DataPacketReceived, dp);
16010
16048
  }
16011
16049
  } finally {
16012
16050
  unlock();
@@ -17017,6 +17055,14 @@ class SignalReconnectError extends Error {}
17017
17055
  function supportOptionalDatachannel(protocol) {
17018
17056
  return protocol !== undefined && protocol > 13;
17019
17057
  }
17058
+ function applyUserDataCompat(newObj, oldObj) {
17059
+ const participantIdentity = newObj.participantIdentity ? newObj.participantIdentity : oldObj.participantIdentity;
17060
+ newObj.participantIdentity = participantIdentity;
17061
+ oldObj.participantIdentity = participantIdentity;
17062
+ const destinationIdentities = newObj.destinationIdentities.length !== 0 ? newObj.destinationIdentities : oldObj.destinationIdentities;
17063
+ newObj.destinationIdentities = destinationIdentities;
17064
+ oldObj.destinationIdentities = destinationIdentities;
17065
+ }
17020
17066
 
17021
17067
  class RegionUrlProvider {
17022
17068
  constructor(url, token) {
@@ -17921,11 +17967,15 @@ class Participant extends eventsExports.EventEmitter {
17921
17967
  return this.trackPublications.size > 0 && Array.from(this.trackPublications.values()).every(tr => tr.isEncrypted);
17922
17968
  }
17923
17969
  get isAgent() {
17924
- var _a, _b;
17925
- return (_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.agent) !== null && _b !== void 0 ? _b : false;
17970
+ var _a;
17971
+ return ((_a = this.permissions) === null || _a === void 0 ? void 0 : _a.agent) || this.kind === ParticipantInfo_Kind.AGENT;
17972
+ }
17973
+ get kind() {
17974
+ return this._kind;
17926
17975
  }
17927
17976
  /** @internal */
17928
17977
  constructor(sid, identity, name, metadata, loggerOptions) {
17978
+ let kind = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ParticipantInfo_Kind.STANDARD;
17929
17979
  var _a;
17930
17980
  super();
17931
17981
  /** audio level between 0-1.0, 1 being loudest, 0 being softest */
@@ -17944,6 +17994,7 @@ class Participant extends eventsExports.EventEmitter {
17944
17994
  this.audioTrackPublications = new Map();
17945
17995
  this.videoTrackPublications = new Map();
17946
17996
  this.trackPublications = new Map();
17997
+ this._kind = kind;
17947
17998
  }
17948
17999
  getTrackPublications() {
17949
18000
  return Array.from(this.trackPublications.values());
@@ -18498,8 +18549,8 @@ class LocalParticipant extends Participant {
18498
18549
  createTracks(options) {
18499
18550
  return __awaiter(this, void 0, void 0, function* () {
18500
18551
  var _a, _b;
18501
- const opts = mergeDefaultOptions(options, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.audioCaptureDefaults, (_b = this.roomOptions) === null || _b === void 0 ? void 0 : _b.videoCaptureDefaults);
18502
- const constraints = constraintsForOptions(opts);
18552
+ const mergedOptions = mergeDefaultOptions(options, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.audioCaptureDefaults, (_b = this.roomOptions) === null || _b === void 0 ? void 0 : _b.videoCaptureDefaults);
18553
+ const constraints = constraintsForOptions(mergedOptions);
18503
18554
  let stream;
18504
18555
  try {
18505
18556
  stream = yield navigator.mediaDevices.getUserMedia(constraints);
@@ -18521,9 +18572,12 @@ class LocalParticipant extends Participant {
18521
18572
  if (constraints.video) {
18522
18573
  this.cameraError = undefined;
18523
18574
  }
18524
- return stream.getTracks().map(mediaStreamTrack => {
18575
+ return Promise.all(stream.getTracks().map(mediaStreamTrack => __awaiter(this, void 0, void 0, function* () {
18525
18576
  const isAudio = mediaStreamTrack.kind === 'audio';
18526
- isAudio ? options.audio : options.video;
18577
+ let trackOptions = isAudio ? mergedOptions.audio : mergedOptions.video;
18578
+ if (typeof trackOptions === 'boolean' || !trackOptions) {
18579
+ trackOptions = {};
18580
+ }
18527
18581
  let trackConstraints;
18528
18582
  const conOrBool = isAudio ? constraints.audio : constraints.video;
18529
18583
  if (typeof conOrBool !== 'boolean') {
@@ -18537,10 +18591,18 @@ class LocalParticipant extends Participant {
18537
18591
  track.source = Track.Source.Camera;
18538
18592
  } else if (track.kind === Track.Kind.Audio) {
18539
18593
  track.source = Track.Source.Microphone;
18594
+ track.setAudioContext(this.audioContext);
18540
18595
  }
18541
18596
  track.mediaStream = stream;
18597
+ if (trackOptions.processor) {
18598
+ if (track instanceof LocalAudioTrack) {
18599
+ yield track.setProcessor(trackOptions.processor);
18600
+ } else {
18601
+ yield track.setProcessor(trackOptions.processor);
18602
+ }
18603
+ }
18542
18604
  return track;
18543
- });
18605
+ })));
18544
18606
  });
18545
18607
  }
18546
18608
  /**
@@ -19430,8 +19492,8 @@ class RemoteTrackPublication extends TrackPublication {
19430
19492
 
19431
19493
  class RemoteParticipant extends Participant {
19432
19494
  /** @internal */
19433
- static fromParticipantInfo(signalClient, pi) {
19434
- return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata);
19495
+ static fromParticipantInfo(signalClient, pi, loggerOptions) {
19496
+ return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata, loggerOptions, pi.kind);
19435
19497
  }
19436
19498
  get logContext() {
19437
19499
  return Object.assign(Object.assign({}, super.logContext), {
@@ -19441,7 +19503,8 @@ class RemoteParticipant extends Participant {
19441
19503
  }
19442
19504
  /** @internal */
19443
19505
  constructor(signalClient, sid, identity, name, metadata, loggerOptions) {
19444
- super(sid, identity || '', name, metadata, loggerOptions);
19506
+ let kind = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : ParticipantInfo_Kind.STANDARD;
19507
+ super(sid, identity || '', name, metadata, loggerOptions, kind);
19445
19508
  this.signalClient = signalClient;
19446
19509
  this.trackPublications = new Map();
19447
19510
  this.audioTrackPublications = new Map();
@@ -19698,8 +19761,9 @@ var ConnectionState;
19698
19761
  ConnectionState["Connecting"] = "connecting";
19699
19762
  ConnectionState["Connected"] = "connected";
19700
19763
  ConnectionState["Reconnecting"] = "reconnecting";
19764
+ ConnectionState["SignalReconnecting"] = "signalReconnecting";
19701
19765
  })(ConnectionState || (ConnectionState = {}));
19702
- const connectionReconcileFrequency = 2 * 1000;
19766
+ const connectionReconcileFrequency = 4 * 1000;
19703
19767
  /**
19704
19768
  * In LiveKit, a room is the logical grouping for a list of participants.
19705
19769
  * Participants in a room can publish tracks, and subscribe to others' tracks.
@@ -20241,17 +20305,31 @@ class Room extends eventsExports.EventEmitter {
20241
20305
  }
20242
20306
  pub.setSubscriptionError(update.err);
20243
20307
  };
20244
- this.handleDataPacket = (userPacket, kind) => {
20308
+ this.handleDataPacket = packet => {
20245
20309
  // find the participant
20246
- const participant = this.remoteParticipants.get(userPacket.participantIdentity);
20310
+ const participant = this.remoteParticipants.get(packet.participantIdentity);
20311
+ if (packet.value.case === 'user') {
20312
+ this.handleUserPacket(participant, packet.value.value, packet.kind);
20313
+ } else if (packet.value.case === 'transcription') {
20314
+ this.handleTranscription(participant, packet.value.value);
20315
+ } else if (packet.value.case === 'sipDtmf') {
20316
+ this.handleSipDtmf(participant, packet.value.value);
20317
+ }
20318
+ };
20319
+ this.handleUserPacket = (participant, userPacket, kind) => {
20247
20320
  this.emit(RoomEvent.DataReceived, userPacket.payload, participant, kind, userPacket.topic);
20248
20321
  // also emit on the participant
20249
20322
  participant === null || participant === void 0 ? void 0 : participant.emit(ParticipantEvent.DataReceived, userPacket.payload, kind);
20250
20323
  };
20324
+ this.handleSipDtmf = (participant, dtmf) => {
20325
+ this.emit(RoomEvent.SipDTMFReceived, dtmf, participant);
20326
+ // also emit on the participant
20327
+ participant === null || participant === void 0 ? void 0 : participant.emit(ParticipantEvent.SipDTMFReceived, dtmf);
20328
+ };
20251
20329
  this.bufferedSegments = new Map();
20252
- this.handleTranscription = transcription => {
20330
+ this.handleTranscription = (remoteParticipant, transcription) => {
20253
20331
  // find the participant
20254
- const participant = transcription.participantIdentity === this.localParticipant.identity ? this.localParticipant : this.remoteParticipants.get(transcription.participantIdentity);
20332
+ const participant = transcription.participantIdentity === this.localParticipant.identity ? this.localParticipant : remoteParticipant;
20255
20333
  const publication = participant === null || participant === void 0 ? void 0 : participant.trackPublications.get(transcription.trackId);
20256
20334
  const segments = extractTranscriptionSegments(transcription);
20257
20335
  publication === null || publication === void 0 ? void 0 : publication.emit(TrackEvent.TranscriptionReceived, segments);
@@ -20483,16 +20561,22 @@ class Room extends eventsExports.EventEmitter {
20483
20561
  this.onTrackAdded(mediaTrack, stream, receiver);
20484
20562
  }).on(EngineEvent.Disconnected, reason => {
20485
20563
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, reason);
20486
- }).on(EngineEvent.ActiveSpeakersUpdate, this.handleActiveSpeakersUpdate).on(EngineEvent.DataPacketReceived, this.handleDataPacket).on(EngineEvent.TranscriptionReceived, this.handleTranscription).on(EngineEvent.Resuming, () => {
20564
+ }).on(EngineEvent.ActiveSpeakersUpdate, this.handleActiveSpeakersUpdate).on(EngineEvent.DataPacketReceived, this.handleDataPacket).on(EngineEvent.Resuming, () => {
20487
20565
  this.clearConnectionReconcile();
20488
20566
  this.isResuming = true;
20489
20567
  this.log.info('Resuming signal connection', this.logContext);
20568
+ if (this.setAndEmitConnectionState(ConnectionState.SignalReconnecting)) {
20569
+ this.emit(RoomEvent.SignalReconnecting);
20570
+ }
20490
20571
  }).on(EngineEvent.Resumed, () => {
20491
20572
  this.registerConnectionReconcile();
20492
20573
  this.isResuming = false;
20493
20574
  this.log.info('Resumed signal connection', this.logContext);
20494
20575
  this.updateSubscriptions();
20495
20576
  this.emitBufferedEvents();
20577
+ if (this.setAndEmitConnectionState(ConnectionState.Connected)) {
20578
+ this.emit(RoomEvent.Reconnected);
20579
+ }
20496
20580
  }).on(EngineEvent.SignalResumed, () => {
20497
20581
  this.bufferedEvents = [];
20498
20582
  if (this.state === ConnectionState.Reconnecting || this.isResuming) {
@@ -20780,11 +20864,12 @@ class Room extends eventsExports.EventEmitter {
20780
20864
  if (_this3.options.webAudioMix) {
20781
20865
  // @ts-expect-error setSinkId is not yet in the typescript type of AudioContext
20782
20866
  (_c = _this3.audioContext) === null || _c === void 0 ? void 0 : _c.setSinkId(deviceId);
20783
- } else {
20784
- yield Promise.all(Array.from(_this3.remoteParticipants.values()).map(p => p.setAudioOutput({
20785
- deviceId
20786
- })));
20787
20867
  }
20868
+ // also set audio output on all audio elements, even if webAudioMix is enabled in order to workaround echo cancellation not working on chrome with non-default output devices
20869
+ // see https://issues.chromium.org/issues/40252911#comment7
20870
+ yield Promise.all(Array.from(_this3.remoteParticipants.values()).map(p => p.setAudioOutput({
20871
+ deviceId
20872
+ })));
20788
20873
  } catch (e) {
20789
20874
  _this3.options.audioOutput.deviceId = prevDeviceId;
20790
20875
  throw e;
@@ -20962,7 +21047,10 @@ class Room extends eventsExports.EventEmitter {
20962
21047
  var _a;
20963
21048
  let participant;
20964
21049
  if (info) {
20965
- participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info);
21050
+ participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info, {
21051
+ loggerContextCb: () => this.logContext,
21052
+ loggerName: this.options.loggerName
21053
+ });
20966
21054
  } else {
20967
21055
  participant = new RemoteParticipant(this.engine.client, '', identity, undefined, undefined, {
20968
21056
  loggerContextCb: () => this.logContext,
@@ -21415,9 +21503,12 @@ function createLocalTracks(options) {
21415
21503
  mediaPromise.catch(() => DeviceManager.userMediaPromiseMap.delete('videoinput'));
21416
21504
  }
21417
21505
  const stream = yield mediaPromise;
21418
- return stream.getTracks().map(mediaStreamTrack => {
21506
+ return Promise.all(stream.getTracks().map(mediaStreamTrack => __awaiter(this, void 0, void 0, function* () {
21419
21507
  const isAudio = mediaStreamTrack.kind === 'audio';
21420
- isAudio ? options.audio : options.video;
21508
+ let trackOptions = isAudio ? options.audio : options.video;
21509
+ if (typeof trackOptions === 'boolean' || !trackOptions) {
21510
+ trackOptions = {};
21511
+ }
21421
21512
  let trackConstraints;
21422
21513
  const conOrBool = isAudio ? constraints.audio : constraints.video;
21423
21514
  if (typeof conOrBool !== 'boolean') {
@@ -21439,8 +21530,15 @@ function createLocalTracks(options) {
21439
21530
  track.source = Track.Source.Microphone;
21440
21531
  }
21441
21532
  track.mediaStream = stream;
21533
+ if (trackOptions.processor) {
21534
+ if (track instanceof LocalAudioTrack) {
21535
+ yield track.setProcessor(trackOptions.processor);
21536
+ } else if (track instanceof LocalVideoTrack) {
21537
+ yield track.setProcessor(trackOptions.processor);
21538
+ }
21539
+ }
21442
21540
  return track;
21443
- });
21541
+ })));
21444
21542
  });
21445
21543
  }
21446
21544
  /**
@@ -21906,5 +22004,5 @@ function isFacingModeValue(item) {
21906
22004
  return item === undefined || allowedValues.includes(item);
21907
22005
  }
21908
22006
 
21909
- export { AudioPresets, BaseKeyProvider, CheckStatus, Checker, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, LoggerNames, MediaDeviceFailure, Mutex, NegotiationError, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, ScreenSharePresets, SubscriptionError, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getBrowser, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, getLogger, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
22007
+ export { AudioPresets, BaseKeyProvider, CheckStatus, Checker, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, LoggerNames, MediaDeviceFailure, Mutex, NegotiationError, Participant, ParticipantEvent, ParticipantInfo_Kind as ParticipantKind, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, ScreenSharePresets, SubscriptionError, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getBrowser, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, getLogger, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
21910
22008
  //# sourceMappingURL=livekit-client.esm.mjs.map