livekit-client 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/README.md +4 -4
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  4. package/dist/livekit-client.esm.mjs +109 -34
  5. package/dist/livekit-client.esm.mjs.map +1 -1
  6. package/dist/livekit-client.umd.js +1 -1
  7. package/dist/livekit-client.umd.js.map +1 -1
  8. package/dist/src/api/SignalClient.d.ts +3 -2
  9. package/dist/src/api/SignalClient.d.ts.map +1 -1
  10. package/dist/src/connectionHelper/checks/publishAudio.d.ts.map +1 -1
  11. package/dist/src/connectionHelper/checks/publishVideo.d.ts.map +1 -1
  12. package/dist/src/room/PCTransport.d.ts +1 -1
  13. package/dist/src/room/PCTransport.d.ts.map +1 -1
  14. package/dist/src/room/RTCEngine.d.ts +4 -3
  15. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  16. package/dist/src/room/Room.d.ts.map +1 -1
  17. package/dist/src/room/errors.d.ts +4 -3
  18. package/dist/src/room/errors.d.ts.map +1 -1
  19. package/dist/src/room/events.d.ts +2 -1
  20. package/dist/src/room/events.d.ts.map +1 -1
  21. package/dist/src/room/participant/LocalParticipant.d.ts +1 -1
  22. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  23. package/dist/src/room/participant/RemoteParticipant.d.ts +1 -1
  24. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  25. package/dist/src/room/track/RemoteAudioTrack.d.ts +1 -1
  26. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  27. package/dist/src/room/track/RemoteTrack.d.ts +12 -2
  28. package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
  29. package/dist/src/room/track/RemoteVideoTrack.d.ts +1 -1
  30. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  31. package/dist/src/version.d.ts +1 -1
  32. package/dist/ts4.2/src/api/SignalClient.d.ts +3 -2
  33. package/dist/ts4.2/src/room/PCTransport.d.ts +1 -1
  34. package/dist/ts4.2/src/room/RTCEngine.d.ts +4 -3
  35. package/dist/ts4.2/src/room/errors.d.ts +4 -3
  36. package/dist/ts4.2/src/room/events.d.ts +2 -1
  37. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +1 -1
  38. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +1 -1
  39. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +1 -1
  40. package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +12 -2
  41. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +1 -1
  42. package/dist/ts4.2/src/version.d.ts +1 -1
  43. package/package.json +10 -10
  44. package/src/api/SignalClient.ts +12 -6
  45. package/src/connectionHelper/checks/publishAudio.ts +4 -1
  46. package/src/connectionHelper/checks/publishVideo.ts +6 -3
  47. package/src/room/PCTransport.ts +1 -0
  48. package/src/room/RTCEngine.ts +10 -4
  49. package/src/room/Room.ts +15 -5
  50. package/src/room/errors.ts +7 -3
  51. package/src/room/events.ts +2 -1
  52. package/src/room/participant/LocalParticipant.ts +13 -8
  53. package/src/room/participant/RemoteParticipant.ts +1 -1
  54. package/src/room/track/RemoteAudioTrack.ts +1 -1
  55. package/src/room/track/RemoteTrack.ts +38 -2
  56. package/src/room/track/RemoteVideoTrack.ts +2 -2
  57. package/src/version.ts +1 -1
@@ -3527,6 +3527,9 @@ const DisconnectReason = /*@__PURE__*/proto3.makeEnum("livekit.DisconnectReason"
3527
3527
  }, {
3528
3528
  no: 9,
3529
3529
  name: "SIGNAL_CLOSE"
3530
+ }, {
3531
+ no: 10,
3532
+ name: "ROOM_CLOSED"
3530
3533
  }]);
3531
3534
 
3532
3535
  /**
@@ -3791,6 +3794,11 @@ const ParticipantInfo = /*@__PURE__*/proto3.makeMessageType("livekit.Participant
3791
3794
  kind: "scalar",
3792
3795
  T: 9 /* ScalarType.STRING */
3793
3796
  }
3797
+ }, {
3798
+ no: 16,
3799
+ name: "disconnect_reason",
3800
+ kind: "enum",
3801
+ T: proto3.getEnumType(DisconnectReason)
3794
3802
  }]);
3795
3803
 
3796
3804
  /**
@@ -4742,9 +4750,15 @@ const SignalResponse = /*@__PURE__*/proto3.makeMessageType("livekit.SignalRespon
4742
4750
  oneof: "message"
4743
4751
  }, {
4744
4752
  no: 22,
4745
- name: "error_response",
4753
+ name: "request_response",
4746
4754
  kind: "message",
4747
- T: ErrorResponse,
4755
+ T: RequestResponse,
4756
+ oneof: "message"
4757
+ }, {
4758
+ no: 23,
4759
+ name: "track_subscribed",
4760
+ kind: "message",
4761
+ T: TrackSubscribed,
4748
4762
  oneof: "message"
4749
4763
  }]);
4750
4764
 
@@ -4858,6 +4872,11 @@ const TrickleRequest = /*@__PURE__*/proto3.makeMessageType("livekit.TrickleReque
4858
4872
  name: "target",
4859
4873
  kind: "enum",
4860
4874
  T: proto3.getEnumType(SignalTarget)
4875
+ }, {
4876
+ no: 3,
4877
+ name: "final",
4878
+ kind: "scalar",
4879
+ T: 8 /* ScalarType.BOOL */
4861
4880
  }]);
4862
4881
 
4863
4882
  /**
@@ -5615,9 +5634,9 @@ const SubscriptionResponse = /*@__PURE__*/proto3.makeMessageType("livekit.Subscr
5615
5634
  }]);
5616
5635
 
5617
5636
  /**
5618
- * @generated from message livekit.ErrorResponse
5637
+ * @generated from message livekit.RequestResponse
5619
5638
  */
5620
- const ErrorResponse = /*@__PURE__*/proto3.makeMessageType("livekit.ErrorResponse", () => [{
5639
+ const RequestResponse = /*@__PURE__*/proto3.makeMessageType("livekit.RequestResponse", () => [{
5621
5640
  no: 1,
5622
5641
  name: "request_id",
5623
5642
  kind: "scalar",
@@ -5626,7 +5645,7 @@ const ErrorResponse = /*@__PURE__*/proto3.makeMessageType("livekit.ErrorResponse
5626
5645
  no: 2,
5627
5646
  name: "reason",
5628
5647
  kind: "enum",
5629
- T: proto3.getEnumType(ErrorResponse_Reason)
5648
+ T: proto3.getEnumType(RequestResponse_Reason)
5630
5649
  }, {
5631
5650
  no: 3,
5632
5651
  name: "message",
@@ -5635,11 +5654,11 @@ const ErrorResponse = /*@__PURE__*/proto3.makeMessageType("livekit.ErrorResponse
5635
5654
  }]);
5636
5655
 
5637
5656
  /**
5638
- * @generated from enum livekit.ErrorResponse.Reason
5657
+ * @generated from enum livekit.RequestResponse.Reason
5639
5658
  */
5640
- const ErrorResponse_Reason = /*@__PURE__*/proto3.makeEnum("livekit.ErrorResponse.Reason", [{
5659
+ const RequestResponse_Reason = /*@__PURE__*/proto3.makeEnum("livekit.RequestResponse.Reason", [{
5641
5660
  no: 0,
5642
- name: "UNKNOWN"
5661
+ name: "OK"
5643
5662
  }, {
5644
5663
  no: 1,
5645
5664
  name: "NOT_FOUND"
@@ -5648,7 +5667,17 @@ const ErrorResponse_Reason = /*@__PURE__*/proto3.makeEnum("livekit.ErrorResponse
5648
5667
  name: "NOT_ALLOWED"
5649
5668
  }, {
5650
5669
  no: 3,
5651
- name: "INVALID_ARGUMENT"
5670
+ name: "LIMIT_EXCEEDED"
5671
+ }]);
5672
+
5673
+ /**
5674
+ * @generated from message livekit.TrackSubscribed
5675
+ */
5676
+ const TrackSubscribed = /*@__PURE__*/proto3.makeMessageType("livekit.TrackSubscribed", () => [{
5677
+ no: 1,
5678
+ name: "track_sid",
5679
+ kind: "scalar",
5680
+ T: 9 /* ScalarType.STRING */
5652
5681
  }]);
5653
5682
 
5654
5683
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -9818,8 +9847,7 @@ class PublishDataError extends LivekitError {
9818
9847
  }
9819
9848
  }
9820
9849
  class SignalRequestError extends LivekitError {
9821
- constructor(message) {
9822
- let reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ErrorResponse_Reason.UNKNOWN;
9850
+ constructor(message, reason) {
9823
9851
  super(15, message);
9824
9852
  this.reason = reason;
9825
9853
  }
@@ -10346,8 +10374,9 @@ var EngineEvent;
10346
10374
  EngineEvent["RemoteMute"] = "remoteMute";
10347
10375
  EngineEvent["SubscribedQualityUpdate"] = "subscribedQualityUpdate";
10348
10376
  EngineEvent["LocalTrackUnpublished"] = "localTrackUnpublished";
10377
+ EngineEvent["LocalTrackSubscribed"] = "localTrackSubscribed";
10349
10378
  EngineEvent["Offline"] = "offline";
10350
- EngineEvent["SignalRequestError"] = "signalRequestError";
10379
+ EngineEvent["SignalRequestResponse"] = "signalRequestResponse";
10351
10380
  })(EngineEvent || (EngineEvent = {}));
10352
10381
  var TrackEvent;
10353
10382
  (function (TrackEvent) {
@@ -10539,10 +10568,10 @@ function getOSVersion(ua) {
10539
10568
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
10540
10569
  }
10541
10570
 
10542
- var version$1 = "2.4.1";
10571
+ var version$1 = "2.5.0";
10543
10572
 
10544
10573
  const version = version$1;
10545
- const protocolVersion = 13;
10574
+ const protocolVersion = 15;
10546
10575
 
10547
10576
  /**
10548
10577
  * Timers that can be overridden with platform specific implementations
@@ -12863,6 +12892,7 @@ class SignalClient {
12863
12892
  return function* () {
12864
12893
  const unlock = yield _this.closingLock.lock();
12865
12894
  try {
12895
+ _this.clearPingInterval();
12866
12896
  if (updateState) {
12867
12897
  _this.state = SignalConnectionState.DISCONNECTING;
12868
12898
  }
@@ -12891,7 +12921,6 @@ class SignalClient {
12891
12921
  if (updateState) {
12892
12922
  _this.state = SignalConnectionState.DISCONNECTED;
12893
12923
  }
12894
- _this.clearPingInterval();
12895
12924
  unlock();
12896
12925
  }
12897
12926
  }();
@@ -13158,9 +13187,13 @@ class SignalClient {
13158
13187
  this.rtt = Date.now() - Number.parseInt(msg.value.lastPingTimestamp.toString());
13159
13188
  this.resetPingTimeout();
13160
13189
  pingHandled = true;
13161
- } else if (msg.case === 'errorResponse') {
13162
- if (this.onErrorResponse) {
13163
- this.onErrorResponse(msg.value);
13190
+ } else if (msg.case === 'requestResponse') {
13191
+ if (this.onRequestResponse) {
13192
+ this.onRequestResponse(msg.value);
13193
+ }
13194
+ } else if (msg.case === 'trackSubscribed') {
13195
+ if (this.onLocalTrackSubscribed) {
13196
+ this.onLocalTrackSubscribed(msg.value.trackSid);
13164
13197
  }
13165
13198
  } else {
13166
13199
  this.log.debug('unsupported message', Object.assign(Object.assign({}, this.logContext), {
@@ -14195,6 +14228,9 @@ class PCTransport extends eventsExports.EventEmitter {
14195
14228
  // actually negotiate
14196
14229
  this.log.debug('starting to negotiate', this.logContext);
14197
14230
  const offer = yield this.pc.createOffer(options);
14231
+ this.log.debug('original offer', Object.assign({
14232
+ sdp: offer.sdp
14233
+ }, this.logContext));
14198
14234
  const sdpParsed = parse((_a = offer.sdp) !== null && _a !== void 0 ? _a : '');
14199
14235
  sdpParsed.media.forEach(media => {
14200
14236
  if (media.type === 'audio') {
@@ -16211,7 +16247,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16211
16247
  this.client.onSubscriptionPermissionUpdate = update => this.emit(EngineEvent.SubscriptionPermissionUpdate, update);
16212
16248
  this.client.onSpeakersChanged = update => this.emit(EngineEvent.SpeakersChanged, update);
16213
16249
  this.client.onStreamStateUpdate = update => this.emit(EngineEvent.StreamStateChanged, update);
16214
- this.client.onErrorResponse = error => this.emit(EngineEvent.SignalRequestError, error);
16250
+ this.client.onRequestResponse = response => this.emit(EngineEvent.SignalRequestResponse, response);
16215
16251
  }
16216
16252
  /** @internal */
16217
16253
  get logContext() {
@@ -16477,6 +16513,9 @@ class RTCEngine extends eventsExports.EventEmitter {
16477
16513
  this.client.onLocalTrackUnpublished = response => {
16478
16514
  this.emit(EngineEvent.LocalTrackUnpublished, response);
16479
16515
  };
16516
+ this.client.onLocalTrackSubscribed = trackSid => {
16517
+ this.emit(EngineEvent.LocalTrackSubscribed, trackSid);
16518
+ };
16480
16519
  this.client.onTokenRefresh = token => {
16481
16520
  this.token = token;
16482
16521
  };
@@ -17198,6 +17237,9 @@ class RemoteTrack extends Track {
17198
17237
  const onRemoveTrack = event => {
17199
17238
  if (event.track === this._mediaStreamTrack) {
17200
17239
  stream.removeEventListener('removetrack', onRemoveTrack);
17240
+ if (this.receiver && 'playoutDelayHint' in this.receiver) {
17241
+ this.receiver.playoutDelayHint = undefined;
17242
+ }
17201
17243
  this.receiver = undefined;
17202
17244
  this._currentBitrate = 0;
17203
17245
  this.emit(TrackEvent.Ended, this);
@@ -17231,6 +17273,37 @@ class RemoteTrack extends Track {
17231
17273
  return statsReport;
17232
17274
  });
17233
17275
  }
17276
+ /**
17277
+ * Allows to set a playout delay (in seconds) for this track.
17278
+ * A higher value allows for more buffering of the track in the browser
17279
+ * and will result in a delay of media being played back of `delayInSeconds`
17280
+ */
17281
+ setPlayoutDelay(delayInSeconds) {
17282
+ if (this.receiver) {
17283
+ if ('playoutDelayHint' in this.receiver) {
17284
+ this.receiver.playoutDelayHint = delayInSeconds;
17285
+ } else {
17286
+ this.log.warn('Playout delay not supported in this browser');
17287
+ }
17288
+ } else {
17289
+ this.log.warn('Cannot set playout delay, track already ended');
17290
+ }
17291
+ }
17292
+ /**
17293
+ * Returns the current playout delay (in seconds) of this track.
17294
+ */
17295
+ getPlayoutDelay() {
17296
+ if (this.receiver) {
17297
+ if ('playoutDelayHint' in this.receiver) {
17298
+ return this.receiver.playoutDelayHint;
17299
+ } else {
17300
+ this.log.warn('Playout delay not supported in this browser');
17301
+ }
17302
+ } else {
17303
+ this.log.warn('Cannot get playout delay, track already ended');
17304
+ }
17305
+ return 0;
17306
+ }
17234
17307
  /* @internal */
17235
17308
  startMonitor() {
17236
17309
  if (!this.monitorInterval) {
@@ -18261,15 +18334,17 @@ class LocalParticipant extends Participant {
18261
18334
  this.reconnectFuture = undefined;
18262
18335
  }
18263
18336
  };
18264
- this.handleSignalRequestError = error => {
18337
+ this.handleSignalRequestResponse = response => {
18265
18338
  const {
18266
18339
  requestId,
18267
18340
  reason,
18268
18341
  message
18269
- } = error;
18270
- const failedRequest = this.pendingSignalRequests.get(requestId);
18271
- if (failedRequest) {
18272
- failedRequest.reject(new SignalRequestError(message, reason));
18342
+ } = response;
18343
+ const targetRequest = this.pendingSignalRequests.get(requestId);
18344
+ if (targetRequest) {
18345
+ if (reason !== RequestResponse_Reason.OK) {
18346
+ targetRequest.reject(new SignalRequestError(message, reason));
18347
+ }
18273
18348
  this.pendingSignalRequests.delete(requestId);
18274
18349
  }
18275
18350
  };
@@ -18453,7 +18528,7 @@ class LocalParticipant extends Participant {
18453
18528
  pub.unmute();
18454
18529
  }
18455
18530
  });
18456
- this.engine.on(EngineEvent.Connected, this.handleReconnected).on(EngineEvent.SignalRestarted, this.handleReconnected).on(EngineEvent.SignalResumed, this.handleReconnected).on(EngineEvent.Restarting, this.handleReconnecting).on(EngineEvent.Resuming, this.handleReconnecting).on(EngineEvent.LocalTrackUnpublished, this.handleLocalTrackUnpublished).on(EngineEvent.SubscribedQualityUpdate, this.handleSubscribedQualityUpdate).on(EngineEvent.Disconnected, this.handleDisconnected).on(EngineEvent.SignalRequestError, this.handleSignalRequestError);
18531
+ this.engine.on(EngineEvent.Connected, this.handleReconnected).on(EngineEvent.SignalRestarted, this.handleReconnected).on(EngineEvent.SignalResumed, this.handleReconnected).on(EngineEvent.Restarting, this.handleReconnecting).on(EngineEvent.Resuming, this.handleReconnecting).on(EngineEvent.LocalTrackUnpublished, this.handleLocalTrackUnpublished).on(EngineEvent.SubscribedQualityUpdate, this.handleSubscribedQualityUpdate).on(EngineEvent.Disconnected, this.handleDisconnected).on(EngineEvent.SignalRequestResponse, this.handleSignalRequestResponse);
18457
18532
  }
18458
18533
  /**
18459
18534
  * Sets and updates the metadata of the local participant.
@@ -18532,7 +18607,7 @@ class LocalParticipant extends Participant {
18532
18607
  }
18533
18608
  yield sleep(50);
18534
18609
  }
18535
- reject(new SignalRequestError('Request to update local metadata timed out'));
18610
+ reject(new SignalRequestError('Request to update local metadata timed out', 'TimeoutError'));
18536
18611
  } catch (e) {
18537
18612
  if (e instanceof Error) reject(e);
18538
18613
  }
@@ -19986,7 +20061,7 @@ class Room extends eventsExports.EventEmitter {
19986
20061
  });
19987
20062
  }
19988
20063
  const connectFn = (resolve, reject, regionUrl) => __awaiter(this, void 0, void 0, function* () {
19989
- var _a;
20064
+ var _a, _b;
19990
20065
  if (this.abortController) {
19991
20066
  this.abortController.abort();
19992
20067
  }
@@ -20011,7 +20086,7 @@ class Room extends eventsExports.EventEmitter {
20011
20086
  return;
20012
20087
  }
20013
20088
  }
20014
- if (nextUrl) {
20089
+ if (nextUrl && !((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.aborted)) {
20015
20090
  this.log.info("Initial connection failed with ConnectionError: ".concat(e.message, ". Retrying with another region: ").concat(nextUrl), this.logContext);
20016
20091
  this.recreateEngine();
20017
20092
  yield connectFn(resolve, reject, nextUrl);
@@ -21468,7 +21543,7 @@ class Room extends eventsExports.EventEmitter {
21468
21543
  sid: Math.floor(Math.random() * 10000).toString(),
21469
21544
  type: TrackType.AUDIO
21470
21545
  });
21471
- p.addSubscribedMediaTrack(dummyVideo, videoTrack.sid, new MediaStream([dummyVideo]));
21546
+ p.addSubscribedMediaTrack(dummyVideo, videoTrack.sid, new MediaStream([dummyVideo]), new RTCRtpReceiver());
21472
21547
  info.tracks = [...info.tracks, videoTrack];
21473
21548
  }
21474
21549
  if (participantOptions.audio) {
@@ -21478,7 +21553,7 @@ class Room extends eventsExports.EventEmitter {
21478
21553
  sid: Math.floor(Math.random() * 10000).toString(),
21479
21554
  type: TrackType.AUDIO
21480
21555
  });
21481
- p.addSubscribedMediaTrack(dummyTrack, audioTrack.sid, new MediaStream([dummyTrack]));
21556
+ p.addSubscribedMediaTrack(dummyTrack, audioTrack.sid, new MediaStream([dummyTrack]), new RTCRtpReceiver());
21482
21557
  info.tracks = [...info.tracks, audioTrack];
21483
21558
  }
21484
21559
  p.updateInfo(info);
@@ -21774,7 +21849,7 @@ class PublishAudioCheck extends Checker {
21774
21849
  }
21775
21850
  let numPackets = 0;
21776
21851
  stats.forEach(stat => {
21777
- if (stat.type === 'outbound-rtp' && stat.mediaType === 'audio') {
21852
+ if (stat.type === 'outbound-rtp' && (stat.kind === 'audio' || !stat.kind && stat.mediaType === 'audio')) {
21778
21853
  numPackets = stat.packetsSent;
21779
21854
  }
21780
21855
  });
@@ -21797,7 +21872,7 @@ class PublishVideoCheck extends Checker {
21797
21872
  const track = yield createLocalVideoTrack();
21798
21873
  room.localParticipant.publishTrack(track);
21799
21874
  // wait for a few seconds to publish
21800
- yield new Promise(resolve => setTimeout(resolve, 3000));
21875
+ yield new Promise(resolve => setTimeout(resolve, 5000));
21801
21876
  // verify RTC stats that it's publishing
21802
21877
  const stats = yield (_a = track.sender) === null || _a === void 0 ? void 0 : _a.getStats();
21803
21878
  if (!stats) {
@@ -21805,8 +21880,8 @@ class PublishVideoCheck extends Checker {
21805
21880
  }
21806
21881
  let numPackets = 0;
21807
21882
  stats.forEach(stat => {
21808
- if (stat.type === 'outbound-rtp' && stat.mediaType === 'video') {
21809
- numPackets = stat.packetsSent;
21883
+ if (stat.type === 'outbound-rtp' && (stat.kind === 'video' || !stat.kind && stat.mediaType === 'video')) {
21884
+ numPackets += stat.packetsSent;
21810
21885
  }
21811
21886
  });
21812
21887
  if (numPackets === 0) {