livekit-client 2.13.4 → 2.13.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2966,7 +2966,17 @@ function makeUtilCommon() {
2966
2966
  }
2967
2967
  switch (m.kind) {
2968
2968
  case "message":
2969
- return m.T.equals(va, vb);
2969
+ let a = va;
2970
+ let b = vb;
2971
+ if (m.T.fieldWrapper) {
2972
+ if (a !== undefined && !isMessage(a)) {
2973
+ a = m.T.fieldWrapper.wrapField(a);
2974
+ }
2975
+ if (b !== undefined && !isMessage(b)) {
2976
+ b = m.T.fieldWrapper.wrapField(b);
2977
+ }
2978
+ }
2979
+ return m.T.equals(a, b);
2970
2980
  case "enum":
2971
2981
  return scalarEquals(ScalarType.INT32, va, vb);
2972
2982
  case "scalar":
@@ -3887,6 +3897,9 @@ const DisconnectReason = /* @__PURE__ */proto3.makeEnum("livekit.DisconnectReaso
3887
3897
  }, {
3888
3898
  no: 14,
3889
3899
  name: "CONNECTION_TIMEOUT"
3900
+ }, {
3901
+ no: 15,
3902
+ name: "MEDIA_FAILURE"
3890
3903
  }]);
3891
3904
  const ReconnectReason = /* @__PURE__ */proto3.makeEnum("livekit.ReconnectReason", [{
3892
3905
  no: 0,
@@ -4491,6 +4504,18 @@ const DataPacket = /* @__PURE__ */proto3.makeMessageType("livekit.DataPacket", (
4491
4504
  kind: "message",
4492
4505
  T: DataStream_Trailer,
4493
4506
  oneof: "value"
4507
+ }, {
4508
+ no: 16,
4509
+ name: "sequence",
4510
+ kind: "scalar",
4511
+ T: 13
4512
+ /* ScalarType.UINT32 */
4513
+ }, {
4514
+ no: 17,
4515
+ name: "participant_sid",
4516
+ kind: "scalar",
4517
+ T: 9
4518
+ /* ScalarType.STRING */
4494
4519
  }]);
4495
4520
  const DataPacket_Kind = /* @__PURE__ */proto3.makeEnum("livekit.DataPacket.Kind", [{
4496
4521
  no: 0,
@@ -5676,6 +5701,17 @@ const ReconnectResponse = /* @__PURE__ */proto3.makeMessageType("livekit.Reconne
5676
5701
  name: "client_configuration",
5677
5702
  kind: "message",
5678
5703
  T: ClientConfiguration
5704
+ }, {
5705
+ no: 3,
5706
+ name: "server_info",
5707
+ kind: "message",
5708
+ T: ServerInfo
5709
+ }, {
5710
+ no: 4,
5711
+ name: "last_message_seq",
5712
+ kind: "scalar",
5713
+ T: 13
5714
+ /* ScalarType.UINT32 */
5679
5715
  }]);
5680
5716
  const TrackPublishedResponse = /* @__PURE__ */proto3.makeMessageType("livekit.TrackPublishedResponse", () => [{
5681
5717
  no: 1,
@@ -6122,6 +6158,25 @@ const SyncState = /* @__PURE__ */proto3.makeMessageType("livekit.SyncState", ()
6122
6158
  kind: "scalar",
6123
6159
  T: 9,
6124
6160
  repeated: true
6161
+ }, {
6162
+ no: 7,
6163
+ name: "datachannel_receive_states",
6164
+ kind: "message",
6165
+ T: DataChannelReceiveState,
6166
+ repeated: true
6167
+ }]);
6168
+ const DataChannelReceiveState = /* @__PURE__ */proto3.makeMessageType("livekit.DataChannelReceiveState", () => [{
6169
+ no: 1,
6170
+ name: "publisher_sid",
6171
+ kind: "scalar",
6172
+ T: 9
6173
+ /* ScalarType.STRING */
6174
+ }, {
6175
+ no: 2,
6176
+ name: "last_seq",
6177
+ kind: "scalar",
6178
+ T: 13
6179
+ /* ScalarType.UINT32 */
6125
6180
  }]);
6126
6181
  const DataChannelInfo = /* @__PURE__ */proto3.makeMessageType("livekit.DataChannelInfo", () => [{
6127
6182
  no: 1,
@@ -11270,7 +11325,7 @@ function getOSVersion(ua) {
11270
11325
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
11271
11326
  }
11272
11327
 
11273
- var version$1 = "2.13.4";
11328
+ var version$1 = "2.13.5";
11274
11329
 
11275
11330
  const version = version$1;
11276
11331
  const protocolVersion = 16;
@@ -13189,7 +13244,10 @@ class SignalClient {
13189
13244
  sid,
13190
13245
  reconnectReason: reason
13191
13246
  }));
13192
- return res;
13247
+ if (res instanceof ReconnectResponse) {
13248
+ return res;
13249
+ }
13250
+ return;
13193
13251
  });
13194
13252
  }
13195
13253
  connect(url, token, opts, abortSignal) {
@@ -13787,6 +13845,135 @@ function createConnectionParams(token, info, opts) {
13787
13845
  return params;
13788
13846
  }
13789
13847
 
13848
+ class DataPacketBuffer {
13849
+ constructor() {
13850
+ this.buffer = [];
13851
+ this._totalSize = 0;
13852
+ }
13853
+ push(item) {
13854
+ this.buffer.push(item);
13855
+ this._totalSize += item.data.byteLength;
13856
+ }
13857
+ pop() {
13858
+ const item = this.buffer.shift();
13859
+ if (item) {
13860
+ this._totalSize -= item.data.byteLength;
13861
+ }
13862
+ return item;
13863
+ }
13864
+ getAll() {
13865
+ return this.buffer.slice();
13866
+ }
13867
+ popToSequence(sequence) {
13868
+ while (this.buffer.length > 0) {
13869
+ const first = this.buffer[0];
13870
+ if (first.sequence <= sequence) {
13871
+ this.pop();
13872
+ } else {
13873
+ break;
13874
+ }
13875
+ }
13876
+ }
13877
+ alignBufferedAmount(bufferedAmount) {
13878
+ while (this.buffer.length > 0) {
13879
+ const first = this.buffer[0];
13880
+ if (this._totalSize - first.data.byteLength <= bufferedAmount) {
13881
+ break;
13882
+ }
13883
+ this.pop();
13884
+ }
13885
+ }
13886
+ get length() {
13887
+ return this.buffer.length;
13888
+ }
13889
+ }
13890
+
13891
+ class TTLMap {
13892
+ /**
13893
+ * @param ttl ttl of the key (ms)
13894
+ */
13895
+ constructor(ttl) {
13896
+ this._map = new Map();
13897
+ this._lastCleanup = 0;
13898
+ this.ttl = ttl;
13899
+ }
13900
+ set(key, value) {
13901
+ const now = Date.now();
13902
+ if (now - this._lastCleanup > this.ttl / 2) {
13903
+ this.cleanup();
13904
+ }
13905
+ const expiresAt = now + this.ttl;
13906
+ this._map.set(key, {
13907
+ value,
13908
+ expiresAt
13909
+ });
13910
+ return this;
13911
+ }
13912
+ get(key) {
13913
+ const entry = this._map.get(key);
13914
+ if (!entry) return undefined;
13915
+ if (entry.expiresAt < Date.now()) {
13916
+ this._map.delete(key);
13917
+ return undefined;
13918
+ }
13919
+ return entry.value;
13920
+ }
13921
+ has(key) {
13922
+ const entry = this._map.get(key);
13923
+ if (!entry) return false;
13924
+ if (entry.expiresAt < Date.now()) {
13925
+ this._map.delete(key);
13926
+ return false;
13927
+ }
13928
+ return true;
13929
+ }
13930
+ delete(key) {
13931
+ return this._map.delete(key);
13932
+ }
13933
+ clear() {
13934
+ this._map.clear();
13935
+ }
13936
+ cleanup() {
13937
+ const now = Date.now();
13938
+ for (const [key, entry] of this._map.entries()) {
13939
+ if (entry.expiresAt < now) {
13940
+ this._map.delete(key);
13941
+ }
13942
+ }
13943
+ this._lastCleanup = now;
13944
+ }
13945
+ get size() {
13946
+ this.cleanup();
13947
+ return this._map.size;
13948
+ }
13949
+ forEach(callback) {
13950
+ this.cleanup();
13951
+ for (const [key, entry] of this._map.entries()) {
13952
+ if (entry.expiresAt >= Date.now()) {
13953
+ callback(entry.value, key, this.asValueMap());
13954
+ }
13955
+ }
13956
+ }
13957
+ map(callback) {
13958
+ this.cleanup();
13959
+ const result = [];
13960
+ const valueMap = this.asValueMap();
13961
+ for (const [key, value] of valueMap.entries()) {
13962
+ result.push(callback(value, key, valueMap));
13963
+ }
13964
+ return result;
13965
+ }
13966
+ asValueMap() {
13967
+ const result = new Map();
13968
+ for (const [key, entry] of this._map.entries()) {
13969
+ if (entry.expiresAt >= Date.now()) {
13970
+ result.set(key, entry.value);
13971
+ }
13972
+ }
13973
+ return result;
13974
+ }
13975
+ }
13976
+
13790
13977
  var lib = {};
13791
13978
 
13792
13979
  var parser = {};
@@ -17366,6 +17553,7 @@ const lossyDataChannel = '_lossy';
17366
17553
  const reliableDataChannel = '_reliable';
17367
17554
  const minReconnectWait = 2 * 1000;
17368
17555
  const leaveReconnect = 'leave-reconnect';
17556
+ const reliabeReceiveStateTTL = 30000;
17369
17557
  var PCState;
17370
17558
  (function (PCState) {
17371
17559
  PCState[PCState["New"] = 0] = "New";
@@ -17402,6 +17590,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17402
17590
  this.maxJoinAttempts = 1;
17403
17591
  this.shouldFailNext = false;
17404
17592
  this.log = livekitLogger;
17593
+ this.reliableDataSequence = 1;
17594
+ this.reliableMessageBuffer = new DataPacketBuffer();
17595
+ this.reliableReceivedState = new TTLMap(reliabeReceiveStateTTL);
17405
17596
  this.handleDataChannel = _a => __awaiter(this, [_a], void 0, function (_ref) {
17406
17597
  var _this = this;
17407
17598
  let {
@@ -17440,6 +17631,14 @@ class RTCEngine extends eventsExports.EventEmitter {
17440
17631
  return;
17441
17632
  }
17442
17633
  const dp = DataPacket.fromBinary(new Uint8Array(buffer));
17634
+ if (dp.sequence > 0 && dp.participantSid !== '') {
17635
+ const lastSeq = this.reliableReceivedState.get(dp.participantSid);
17636
+ if (lastSeq && dp.sequence <= lastSeq) {
17637
+ // ignore duplicate or out-of-order packets in reliable channel
17638
+ return;
17639
+ }
17640
+ this.reliableReceivedState.set(dp.participantSid, dp.sequence);
17641
+ }
17443
17642
  if (((_a = dp.value) === null || _a === void 0 ? void 0 : _a.case) === 'speaker') {
17444
17643
  // dispatch speaker updates
17445
17644
  this.emit(EngineEvent.ActiveSpeakersUpdate, dp.value.value.speakers);
@@ -17540,6 +17739,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17540
17739
  this.isBufferStatusLow = kind => {
17541
17740
  const dc = this.dataChannelForKind(kind);
17542
17741
  if (dc) {
17742
+ if (kind === DataPacket_Kind.RELIABLE) {
17743
+ this.reliableMessageBuffer.alignBufferedAmount(dc.bufferedAmount);
17744
+ }
17543
17745
  return dc.bufferedAmount <= dc.bufferedAmountLowThreshold;
17544
17746
  }
17545
17747
  };
@@ -17661,6 +17863,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17661
17863
  this.lossyDCSub = undefined;
17662
17864
  this.reliableDC = undefined;
17663
17865
  this.reliableDCSub = undefined;
17866
+ this.reliableMessageBuffer = new DataPacketBuffer();
17867
+ this.reliableDataSequence = 1;
17868
+ this.reliableReceivedState.clear();
17664
17869
  });
17665
17870
  }
17666
17871
  cleanupClient() {
@@ -18185,6 +18390,9 @@ class RTCEngine extends eventsExports.EventEmitter {
18185
18390
  if (res) {
18186
18391
  const rtcConfig = this.makeRTCConfiguration(res);
18187
18392
  this.pcManager.updateConfiguration(rtcConfig);
18393
+ if (this.latestJoinResponse) {
18394
+ this.latestJoinResponse.serverInfo = res.serverInfo;
18395
+ }
18188
18396
  } else {
18189
18397
  this.log.warn('Did not receive reconnect response', this.logContext);
18190
18398
  }
@@ -18204,6 +18412,9 @@ class RTCEngine extends eventsExports.EventEmitter {
18204
18412
  if (((_a = this.reliableDC) === null || _a === void 0 ? void 0 : _a.readyState) === 'open' && this.reliableDC.id === null) {
18205
18413
  this.createDataChannels();
18206
18414
  }
18415
+ if (res === null || res === void 0 ? void 0 : res.lastMessageSeq) {
18416
+ this.resendReliableMessagesForResume(res.lastMessageSeq);
18417
+ }
18207
18418
  // resume success
18208
18419
  this.emit(EngineEvent.Resumed);
18209
18420
  });
@@ -18276,16 +18487,42 @@ class RTCEngine extends eventsExports.EventEmitter {
18276
18487
  /* @internal */
18277
18488
  sendDataPacket(packet, kind) {
18278
18489
  return __awaiter(this, void 0, void 0, function* () {
18279
- const msg = packet.toBinary();
18280
18490
  // make sure we do have a data connection
18281
18491
  yield this.ensurePublisherConnected(kind);
18492
+ if (kind === DataPacket_Kind.RELIABLE) {
18493
+ packet.sequence = this.reliableDataSequence;
18494
+ this.reliableDataSequence += 1;
18495
+ }
18496
+ const msg = packet.toBinary();
18282
18497
  const dc = this.dataChannelForKind(kind);
18283
18498
  if (dc) {
18499
+ if (kind === DataPacket_Kind.RELIABLE) {
18500
+ this.reliableMessageBuffer.push({
18501
+ data: msg,
18502
+ sequence: packet.sequence
18503
+ });
18504
+ }
18505
+ if (this.attemptingReconnect) {
18506
+ return;
18507
+ }
18284
18508
  dc.send(msg);
18285
18509
  }
18286
18510
  this.updateAndEmitDCBufferStatus(kind);
18287
18511
  });
18288
18512
  }
18513
+ resendReliableMessagesForResume(lastMessageSeq) {
18514
+ return __awaiter(this, void 0, void 0, function* () {
18515
+ yield this.ensurePublisherConnected(DataPacket_Kind.RELIABLE);
18516
+ const dc = this.dataChannelForKind(DataPacket_Kind.RELIABLE);
18517
+ if (dc) {
18518
+ this.reliableMessageBuffer.popToSequence(lastMessageSeq);
18519
+ this.reliableMessageBuffer.getAll().forEach(msg => {
18520
+ dc.send(msg.data);
18521
+ });
18522
+ }
18523
+ this.updateAndEmitDCBufferStatus(DataPacket_Kind.RELIABLE);
18524
+ });
18525
+ }
18289
18526
  waitForBufferStatusLow(kind) {
18290
18527
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18291
18528
  if (this.isBufferStatusLow(kind)) {
@@ -18477,7 +18714,13 @@ class RTCEngine extends eventsExports.EventEmitter {
18477
18714
  }),
18478
18715
  publishTracks: getTrackPublicationInfo(localTracks),
18479
18716
  dataChannels: this.dataChannelsInfo(),
18480
- trackSidsDisabled
18717
+ trackSidsDisabled,
18718
+ datachannelReceiveStates: this.reliableReceivedState.map((seq, sid) => {
18719
+ return new DataChannelReceiveState({
18720
+ publisherSid: sid,
18721
+ lastSeq: seq
18722
+ });
18723
+ })
18481
18724
  }));
18482
18725
  }
18483
18726
  /* @internal */
@@ -23588,7 +23831,7 @@ class Room extends eventsExports.EventEmitter {
23588
23831
  this.remoteParticipants.forEach((participant, identity) => {
23589
23832
  this.handleParticipantDisconnected(identity, participant);
23590
23833
  });
23591
- this.emit(RoomEvent.Moved, roomMoved.room.name, roomMoved.token);
23834
+ this.emit(RoomEvent.Moved, roomMoved.room.name);
23592
23835
  if (roomMoved.participant) {
23593
23836
  this.handleParticipantUpdates([roomMoved.participant, ...roomMoved.otherParticipants]);
23594
23837
  } else {