livekit-client 2.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/README.md +8 -0
  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 +4 -4
  5. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  6. package/dist/livekit-client.esm.mjs +122 -39
  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/proto/livekit_models_pb.d.ts +9 -1
  11. package/dist/src/proto/livekit_models_pb.d.ts.map +1 -1
  12. package/dist/src/proto/livekit_rtc_pb.d.ts +38 -0
  13. package/dist/src/proto/livekit_rtc_pb.d.ts.map +1 -1
  14. package/dist/src/room/PCTransport.d.ts +1 -2
  15. package/dist/src/room/PCTransport.d.ts.map +1 -1
  16. package/dist/src/room/PCTransportManager.d.ts.map +1 -1
  17. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  18. package/dist/src/room/Room.d.ts.map +1 -1
  19. package/dist/src/room/events.d.ts +8 -1
  20. package/dist/src/room/events.d.ts.map +1 -1
  21. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  22. package/dist/src/room/track/LocalAudioTrack.d.ts +8 -7
  23. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  24. package/dist/src/room/track/LocalTrack.d.ts +10 -9
  25. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  26. package/dist/src/room/track/LocalTrackPublication.d.ts +2 -2
  27. package/dist/src/room/track/LocalVideoTrack.d.ts +3 -3
  28. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  29. package/dist/src/room/track/RemoteAudioTrack.d.ts +2 -1
  30. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  31. package/dist/src/room/track/RemoteTrack.d.ts +2 -2
  32. package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
  33. package/dist/src/room/track/RemoteVideoTrack.d.ts +2 -1
  34. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  35. package/dist/src/room/track/Track.d.ts +3 -3
  36. package/dist/src/room/track/Track.d.ts.map +1 -1
  37. package/dist/src/room/track/processor/types.d.ts +4 -0
  38. package/dist/src/room/track/processor/types.d.ts.map +1 -1
  39. package/dist/ts4.2/src/proto/livekit_models_pb.d.ts +9 -1
  40. package/dist/ts4.2/src/proto/livekit_rtc_pb.d.ts +38 -0
  41. package/dist/ts4.2/src/room/PCTransport.d.ts +1 -2
  42. package/dist/ts4.2/src/room/events.d.ts +8 -1
  43. package/dist/ts4.2/src/room/track/LocalAudioTrack.d.ts +8 -7
  44. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +10 -9
  45. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +2 -2
  46. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +3 -3
  47. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +2 -1
  48. package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +2 -2
  49. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +2 -1
  50. package/dist/ts4.2/src/room/track/Track.d.ts +3 -3
  51. package/dist/ts4.2/src/room/track/processor/types.d.ts +4 -0
  52. package/package.json +2 -2
  53. package/src/api/SignalClient.ts +1 -1
  54. package/src/e2ee/worker/e2ee.worker.ts +8 -4
  55. package/src/proto/livekit_models_pb.ts +12 -0
  56. package/src/proto/livekit_rtc_pb.ts +53 -0
  57. package/src/room/PCTransport.ts +3 -13
  58. package/src/room/PCTransportManager.ts +1 -2
  59. package/src/room/RTCEngine.ts +5 -0
  60. package/src/room/Room.ts +3 -0
  61. package/src/room/events.ts +8 -1
  62. package/src/room/participant/LocalParticipant.ts +0 -1
  63. package/src/room/track/LocalAudioTrack.ts +8 -11
  64. package/src/room/track/LocalTrack.ts +36 -23
  65. package/src/room/track/LocalVideoTrack.ts +3 -3
  66. package/src/room/track/RemoteAudioTrack.ts +1 -1
  67. package/src/room/track/RemoteTrack.ts +4 -2
  68. package/src/room/track/RemoteVideoTrack.ts +1 -1
  69. package/src/room/track/Track.ts +5 -3
  70. package/src/room/track/processor/types.ts +4 -0
@@ -3874,6 +3874,14 @@ var DisconnectReason;
3874
3874
  * @generated from enum value: JOIN_FAILURE = 7;
3875
3875
  */
3876
3876
  DisconnectReason[DisconnectReason["JOIN_FAILURE"] = 7] = "JOIN_FAILURE";
3877
+ /**
3878
+ * @generated from enum value: MIGRATION = 8;
3879
+ */
3880
+ DisconnectReason[DisconnectReason["MIGRATION"] = 8] = "MIGRATION";
3881
+ /**
3882
+ * @generated from enum value: SIGNAL_CLOSE = 9;
3883
+ */
3884
+ DisconnectReason[DisconnectReason["SIGNAL_CLOSE"] = 9] = "SIGNAL_CLOSE";
3877
3885
  })(DisconnectReason || (DisconnectReason = {}));
3878
3886
  // Retrieve enum metadata with: proto3.getEnumType(DisconnectReason)
3879
3887
  proto3.util.setEnumType(DisconnectReason, "livekit.DisconnectReason", [{
@@ -3900,6 +3908,12 @@ proto3.util.setEnumType(DisconnectReason, "livekit.DisconnectReason", [{
3900
3908
  }, {
3901
3909
  no: 7,
3902
3910
  name: "JOIN_FAILURE"
3911
+ }, {
3912
+ no: 8,
3913
+ name: "MIGRATION"
3914
+ }, {
3915
+ no: 9,
3916
+ name: "SIGNAL_CLOSE"
3903
3917
  }]);
3904
3918
  /**
3905
3919
  * @generated from enum livekit.ReconnectReason
@@ -10108,7 +10122,14 @@ var RoomEvent;
10108
10122
  RoomEvent["Reconnected"] = "reconnected";
10109
10123
  /**
10110
10124
  * When disconnected from room. This fires when room.disconnect() is called or
10111
- * when an unrecoverable connection issue had occured
10125
+ * when an unrecoverable connection issue had occured.
10126
+ *
10127
+ * DisconnectReason can be used to determine why the participant was disconnected. Notable reasons are
10128
+ * - DUPLICATE_IDENTITY: another client with the same identity has joined the room
10129
+ * - PARTICIPANT_REMOVED: participant was removed by RemoveParticipant API
10130
+ * - ROOM_DELETED: the room has ended via DeleteRoom API
10131
+ *
10132
+ * args: ([[DisconnectReason]])
10112
10133
  */
10113
10134
  RoomEvent["Disconnected"] = "disconnected";
10114
10135
  /**
@@ -10682,7 +10703,7 @@ function getMatch(exp, ua) {
10682
10703
  return match && match.length >= id && match[id] || '';
10683
10704
  }
10684
10705
 
10685
- var version$1 = "2.0.0";
10706
+ var version$1 = "2.0.2";
10686
10707
 
10687
10708
  const version = version$1;
10688
10709
  const protocolVersion = 12;
@@ -11943,6 +11964,7 @@ class LeaveRequest extends Message {
11943
11964
  /**
11944
11965
  * sent when server initiates the disconnect due to server-restart
11945
11966
  * indicates clients should attempt full-reconnect sequence
11967
+ * NOTE: `can_reconnect` obsoleted by `action` starting in protocol version 13
11946
11968
  *
11947
11969
  * @generated from field: bool can_reconnect = 1;
11948
11970
  */
@@ -11951,6 +11973,10 @@ class LeaveRequest extends Message {
11951
11973
  * @generated from field: livekit.DisconnectReason reason = 2;
11952
11974
  */
11953
11975
  this.reason = DisconnectReason.UNKNOWN_REASON;
11976
+ /**
11977
+ * @generated from field: livekit.LeaveRequest.Action action = 3;
11978
+ */
11979
+ this.action = LeaveRequest_Action.DISCONNECT;
11954
11980
  proto3.util.initPartial(data, this);
11955
11981
  }
11956
11982
  static fromBinary(bytes, options) {
@@ -11978,6 +12004,53 @@ LeaveRequest.fields = proto3.util.newFieldList(() => [{
11978
12004
  name: "reason",
11979
12005
  kind: "enum",
11980
12006
  T: proto3.getEnumType(DisconnectReason)
12007
+ }, {
12008
+ no: 3,
12009
+ name: "action",
12010
+ kind: "enum",
12011
+ T: proto3.getEnumType(LeaveRequest_Action)
12012
+ }, {
12013
+ no: 4,
12014
+ name: "regions",
12015
+ kind: "message",
12016
+ T: RegionSettings
12017
+ }]);
12018
+ /**
12019
+ * indicates action clients should take on receiving this message
12020
+ *
12021
+ * @generated from enum livekit.LeaveRequest.Action
12022
+ */
12023
+ var LeaveRequest_Action;
12024
+ (function (LeaveRequest_Action) {
12025
+ /**
12026
+ * should disconnect
12027
+ *
12028
+ * @generated from enum value: DISCONNECT = 0;
12029
+ */
12030
+ LeaveRequest_Action[LeaveRequest_Action["DISCONNECT"] = 0] = "DISCONNECT";
12031
+ /**
12032
+ * should attempt a resume with `reconnect=1` in join URL
12033
+ *
12034
+ * @generated from enum value: RESUME = 1;
12035
+ */
12036
+ LeaveRequest_Action[LeaveRequest_Action["RESUME"] = 1] = "RESUME";
12037
+ /**
12038
+ * should attempt a reconnect, i. e. no `reconnect=1`
12039
+ *
12040
+ * @generated from enum value: RECONNECT = 2;
12041
+ */
12042
+ LeaveRequest_Action[LeaveRequest_Action["RECONNECT"] = 2] = "RECONNECT";
12043
+ })(LeaveRequest_Action || (LeaveRequest_Action = {}));
12044
+ // Retrieve enum metadata with: proto3.getEnumType(LeaveRequest_Action)
12045
+ proto3.util.setEnumType(LeaveRequest_Action, "livekit.LeaveRequest.Action", [{
12046
+ no: 0,
12047
+ name: "DISCONNECT"
12048
+ }, {
12049
+ no: 1,
12050
+ name: "RESUME"
12051
+ }, {
12052
+ no: 2,
12053
+ name: "RECONNECT"
11981
12054
  }]);
11982
12055
  /**
11983
12056
  * message to indicate published video track dimensions are changing
@@ -12660,6 +12733,10 @@ class SyncState extends Message {
12660
12733
  * @generated from field: repeated livekit.DataChannelInfo data_channels = 4;
12661
12734
  */
12662
12735
  this.dataChannels = [];
12736
+ /**
12737
+ * @generated from field: repeated string track_sids_disabled = 6;
12738
+ */
12739
+ this.trackSidsDisabled = [];
12663
12740
  proto3.util.initPartial(data, this);
12664
12741
  }
12665
12742
  static fromBinary(bytes, options) {
@@ -12704,6 +12781,12 @@ SyncState.fields = proto3.util.newFieldList(() => [{
12704
12781
  name: "offer",
12705
12782
  kind: "message",
12706
12783
  T: SessionDescription
12784
+ }, {
12785
+ no: 6,
12786
+ name: "track_sids_disabled",
12787
+ kind: "scalar",
12788
+ T: 9 /* ScalarType.STRING */,
12789
+ repeated: true
12707
12790
  }]);
12708
12791
  /**
12709
12792
  * @generated from message livekit.DataChannelInfo
@@ -13731,10 +13814,6 @@ function isFireFox() {
13731
13814
  var _a;
13732
13815
  return ((_a = getBrowser()) === null || _a === void 0 ? void 0 : _a.name) === 'Firefox';
13733
13816
  }
13734
- function isChromiumBased() {
13735
- var _a;
13736
- return ((_a = getBrowser()) === null || _a === void 0 ? void 0 : _a.name) === 'Chrome';
13737
- }
13738
13817
  function isSafari() {
13739
13818
  var _a;
13740
13819
  return ((_a = getBrowser()) === null || _a === void 0 ? void 0 : _a.name) === 'Safari';
@@ -14191,20 +14270,27 @@ class LocalTrack extends Track {
14191
14270
  this._constraints = newTrack.getConstraints();
14192
14271
  }
14193
14272
  let processedTrack;
14194
- if (this.processor && newTrack && this.processorElement) {
14195
- this.log.debug('restarting processor', this.logContext);
14196
- if (this.kind === 'unknown') {
14197
- throw TypeError('cannot set processor on track of unknown kind');
14273
+ if (this.processor && newTrack) {
14274
+ const unlock = yield this.processorLock.lock();
14275
+ try {
14276
+ this.log.debug('restarting processor', this.logContext);
14277
+ if (this.kind === 'unknown') {
14278
+ throw TypeError('cannot set processor on track of unknown kind');
14279
+ }
14280
+ if (this.processorElement) {
14281
+ attachToElement(newTrack, this.processorElement);
14282
+ // ensure the processorElement itself stays muted
14283
+ this.processorElement.muted = true;
14284
+ }
14285
+ yield this.processor.restart({
14286
+ track: newTrack,
14287
+ kind: this.kind,
14288
+ element: this.processorElement
14289
+ });
14290
+ processedTrack = this.processor.processedTrack;
14291
+ } finally {
14292
+ unlock();
14198
14293
  }
14199
- attachToElement(newTrack, this.processorElement);
14200
- // ensure the processorElement itself stays muted
14201
- this.processorElement.muted = true;
14202
- yield this.processor.restart({
14203
- track: newTrack,
14204
- kind: this.kind,
14205
- element: this.processorElement
14206
- });
14207
- processedTrack = this.processor.processedTrack;
14208
14294
  }
14209
14295
  if (this.sender) {
14210
14296
  yield this.sender.replaceTrack(processedTrack !== null && processedTrack !== void 0 ? processedTrack : newTrack);
@@ -14469,7 +14555,8 @@ class LocalTrack extends Track {
14469
14555
  const processorOptions = {
14470
14556
  kind: this.kind,
14471
14557
  track: this._mediaStreamTrack,
14472
- element: this.processorElement
14558
+ element: this.processorElement,
14559
+ audioContext: this.audioContext
14473
14560
  };
14474
14561
  yield processor.init(processorOptions);
14475
14562
  this.processor = processor;
@@ -15044,7 +15131,9 @@ class SignalClient {
15044
15131
  let resp;
15045
15132
  if (typeof ev.data === 'string') {
15046
15133
  const json = JSON.parse(ev.data);
15047
- resp = SignalResponse.fromJson(json);
15134
+ resp = SignalResponse.fromJson(json, {
15135
+ ignoreUnknownFields: true
15136
+ });
15048
15137
  } else if (ev.data instanceof ArrayBuffer) {
15049
15138
  resp = SignalResponse.fromBinary(new Uint8Array(ev.data));
15050
15139
  } else {
@@ -16218,8 +16307,7 @@ class PCTransport extends eventsExports.EventEmitter {
16218
16307
  return this._pc;
16219
16308
  }
16220
16309
  constructor(config) {
16221
- let mediaConstraints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16222
- let loggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16310
+ let loggerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16223
16311
  var _a;
16224
16312
  super();
16225
16313
  this.log = livekitLogger;
@@ -16263,13 +16351,10 @@ class PCTransport extends eventsExports.EventEmitter {
16263
16351
  this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.PCTransport);
16264
16352
  this.loggerOptions = loggerOptions;
16265
16353
  this.config = config;
16266
- this.mediaConstraints = mediaConstraints;
16267
16354
  this._pc = this.createPC();
16268
16355
  }
16269
16356
  createPC() {
16270
- const pc = isChromiumBased() ?
16271
- // @ts-expect-error chrome allows additional media constraints to be passed into the RTCPeerConnection constructor
16272
- new RTCPeerConnection(this.config, this.mediaConstraints) : new RTCPeerConnection(this.config);
16357
+ const pc = new RTCPeerConnection(this.config);
16273
16358
  pc.onicecandidate = ev => {
16274
16359
  var _a;
16275
16360
  if (!ev.candidate) return;
@@ -16812,12 +16897,7 @@ class PCTransportManager {
16812
16897
  this.loggerOptions = loggerOptions;
16813
16898
  this.isPublisherConnectionRequired = !subscriberPrimary;
16814
16899
  this.isSubscriberConnectionRequired = subscriberPrimary;
16815
- const googConstraints = {
16816
- optional: [{
16817
- googDscp: true
16818
- }]
16819
- };
16820
- this.publisher = new PCTransport(rtcConfig, googConstraints, loggerOptions);
16900
+ this.publisher = new PCTransport(rtcConfig, loggerOptions);
16821
16901
  this.subscriber = new PCTransport(rtcConfig, loggerOptions);
16822
16902
  this.publisher.onConnectionStateChange = this.updateState;
16823
16903
  this.subscriber.onConnectionStateChange = this.updateState;
@@ -18056,10 +18136,14 @@ class RTCEngine extends eventsExports.EventEmitter {
18056
18136
  */
18057
18137
  const autoSubscribe = (_b = (_a = this.signalOpts) === null || _a === void 0 ? void 0 : _a.autoSubscribe) !== null && _b !== void 0 ? _b : true;
18058
18138
  const trackSids = new Array();
18139
+ const trackSidsDisabled = new Array();
18059
18140
  remoteTracks.forEach(track => {
18060
18141
  if (track.isDesired !== autoSubscribe) {
18061
18142
  trackSids.push(track.trackSid);
18062
18143
  }
18144
+ if (!track.isEnabled) {
18145
+ trackSidsDisabled.push(track.trackSid);
18146
+ }
18063
18147
  });
18064
18148
  this.client.sendSyncState(new SyncState({
18065
18149
  answer: previousAnswer ? toProtoSessionDescription({
@@ -18076,7 +18160,8 @@ class RTCEngine extends eventsExports.EventEmitter {
18076
18160
  participantTracks: []
18077
18161
  }),
18078
18162
  publishTracks: getTrackPublicationInfo(localTracks),
18079
- dataChannels: this.dataChannelsInfo()
18163
+ dataChannels: this.dataChannelsInfo(),
18164
+ trackSidsDisabled
18080
18165
  }));
18081
18166
  }
18082
18167
  /* @internal */
@@ -18345,9 +18430,6 @@ class LocalAudioTrack extends LocalTrack {
18345
18430
  if (this.processor) {
18346
18431
  yield this.stopProcessor();
18347
18432
  }
18348
- if (this.kind === 'unknown') {
18349
- throw TypeError('cannot set processor on track of unknown kind');
18350
- }
18351
18433
  const processorOptions = {
18352
18434
  kind: this.kind,
18353
18435
  track: this._mediaStreamTrack,
@@ -22402,7 +22484,8 @@ class Room extends eventsExports.EventEmitter {
22402
22484
  this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
22403
22485
  };
22404
22486
  this.onLocalTrackPublished = pub => __awaiter(this, void 0, void 0, function* () {
22405
- var _r;
22487
+ var _r, _s, _t, _u;
22488
+ (_t = (_s = (_r = pub.track) === null || _r === void 0 ? void 0 : _r.getProcessor()) === null || _s === void 0 ? void 0 : _s.onPublish) === null || _t === void 0 ? void 0 : _t.call(_s, this);
22406
22489
  this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
22407
22490
  if (pub.track instanceof LocalAudioTrack) {
22408
22491
  const trackIsSilent = yield pub.track.checkForSilence();
@@ -22410,7 +22493,7 @@ class Room extends eventsExports.EventEmitter {
22410
22493
  this.emit(RoomEvent.LocalAudioSilenceDetected, pub);
22411
22494
  }
22412
22495
  }
22413
- const deviceId = yield (_r = pub.track) === null || _r === void 0 ? void 0 : _r.getDeviceId();
22496
+ const deviceId = yield (_u = pub.track) === null || _u === void 0 ? void 0 : _u.getDeviceId();
22414
22497
  const deviceKind = sourceToKind(pub.source);
22415
22498
  if (deviceKind && deviceId && deviceId !== this.localParticipant.activeDeviceMap.get(deviceKind)) {
22416
22499
  this.localParticipant.activeDeviceMap.set(deviceKind, deviceId);