livekit-client 1.6.3 → 1.6.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.
Files changed (50) hide show
  1. package/dist/livekit-client.esm.mjs +418 -70
  2. package/dist/livekit-client.esm.mjs.map +1 -1
  3. package/dist/livekit-client.umd.js +1 -1
  4. package/dist/livekit-client.umd.js.map +1 -1
  5. package/dist/src/api/SignalClient.d.ts +13 -2
  6. package/dist/src/api/SignalClient.d.ts.map +1 -1
  7. package/dist/src/connectionHelper/ConnectionCheck.d.ts +2 -2
  8. package/dist/src/connectionHelper/ConnectionCheck.d.ts.map +1 -1
  9. package/dist/src/proto/livekit_models.d.ts +20 -3
  10. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  11. package/dist/src/proto/livekit_rtc.d.ts +2565 -464
  12. package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
  13. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  14. package/dist/src/room/Room.d.ts +1 -1
  15. package/dist/src/room/Room.d.ts.map +1 -1
  16. package/dist/src/room/errors.d.ts +3 -0
  17. package/dist/src/room/errors.d.ts.map +1 -1
  18. package/dist/src/room/participant/LocalParticipant.d.ts +1 -3
  19. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  20. package/dist/src/room/participant/Participant.d.ts +1 -1
  21. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  22. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  23. package/dist/src/room/track/create.d.ts.map +1 -1
  24. package/dist/src/room/track/options.d.ts +2 -2
  25. package/dist/src/room/track/options.d.ts.map +1 -1
  26. package/dist/src/test/mocks.d.ts +1 -1
  27. package/dist/ts4.2/src/api/SignalClient.d.ts +13 -2
  28. package/dist/ts4.2/src/connectionHelper/ConnectionCheck.d.ts +2 -2
  29. package/dist/ts4.2/src/proto/livekit_models.d.ts +24 -3
  30. package/dist/ts4.2/src/proto/livekit_rtc.d.ts +2775 -540
  31. package/dist/ts4.2/src/room/Room.d.ts +1 -1
  32. package/dist/ts4.2/src/room/errors.d.ts +3 -0
  33. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +1 -3
  34. package/dist/ts4.2/src/room/participant/Participant.d.ts +1 -1
  35. package/dist/ts4.2/src/room/track/options.d.ts +2 -2
  36. package/dist/ts4.2/src/test/mocks.d.ts +1 -1
  37. package/package.json +17 -17
  38. package/src/api/SignalClient.ts +46 -3
  39. package/src/connectionHelper/ConnectionCheck.ts +1 -1
  40. package/src/proto/google/protobuf/timestamp.ts +2 -2
  41. package/src/proto/livekit_models.ts +93 -9
  42. package/src/proto/livekit_rtc.ts +308 -6
  43. package/src/room/RTCEngine.ts +37 -16
  44. package/src/room/Room.ts +12 -11
  45. package/src/room/errors.ts +6 -0
  46. package/src/room/participant/LocalParticipant.ts +19 -20
  47. package/src/room/participant/Participant.ts +10 -2
  48. package/src/room/track/LocalAudioTrack.ts +5 -1
  49. package/src/room/track/create.ts +6 -1
  50. package/src/room/track/options.ts +2 -2
@@ -151,7 +151,9 @@ export interface SignalRequest {
151
151
  | { $case: "subscriptionPermission"; subscriptionPermission: SubscriptionPermission }
152
152
  | { $case: "syncState"; syncState: SyncState }
153
153
  | { $case: "simulate"; simulate: SimulateScenario }
154
- | { $case: "ping"; ping: number };
154
+ | { $case: "ping"; ping: number }
155
+ | { $case: "updateMetadata"; updateMetadata: UpdateParticipantMetadata }
156
+ | { $case: "pingReq"; pingReq: Ping };
155
157
  }
156
158
 
157
159
  export interface SignalResponse {
@@ -173,7 +175,8 @@ export interface SignalResponse {
173
175
  | { $case: "refreshToken"; refreshToken: string }
174
176
  | { $case: "trackUnpublished"; trackUnpublished: TrackUnpublishedResponse }
175
177
  | { $case: "pong"; pong: number }
176
- | { $case: "reconnect"; reconnect: ReconnectResponse };
178
+ | { $case: "reconnect"; reconnect: ReconnectResponse }
179
+ | { $case: "pongResp"; pongResp: Pong };
177
180
  }
178
181
 
179
182
  export interface SimulcastCodec {
@@ -240,6 +243,9 @@ export interface JoinResponse {
240
243
  export interface ReconnectResponse {
241
244
  iceServers: ICEServer[];
242
245
  clientConfiguration?: ClientConfiguration;
246
+ room?: Room;
247
+ participant?: ParticipantInfo;
248
+ otherParticipants: ParticipantInfo[];
243
249
  }
244
250
 
245
251
  export interface TrackPublishedResponse {
@@ -278,6 +284,16 @@ export interface UpdateTrackSettings {
278
284
  /** for video, height to receive */
279
285
  height: number;
280
286
  fps: number;
287
+ /**
288
+ * subscription priority. 1 being the highest (0 is unset)
289
+ * when unset, server sill assign priority based on the order of subscription
290
+ * server will use priority in the following ways:
291
+ * 1. when subscribed tracks exceed per-participant subscription limit, server will
292
+ * pause the lowest priority tracks
293
+ * 2. when the network is congested, server will assign available bandwidth to
294
+ * higher priority tracks first. lowest priority tracks can be paused
295
+ */
296
+ priority: number;
281
297
  }
282
298
 
283
299
  export interface LeaveRequest {
@@ -295,6 +311,10 @@ export interface UpdateVideoLayers {
295
311
  layers: VideoLayer[];
296
312
  }
297
313
 
314
+ export interface UpdateParticipantMetadata {
315
+ metadata: string;
316
+ }
317
+
298
318
  export interface ICEServer {
299
319
  urls: string[];
300
320
  username: string;
@@ -389,6 +409,18 @@ export interface SimulateScenario {
389
409
  | { $case: "switchCandidateProtocol"; switchCandidateProtocol: CandidateProtocol };
390
410
  }
391
411
 
412
+ export interface Ping {
413
+ timestamp: number;
414
+ /** rtt in milliseconds calculated by client */
415
+ rtt: number;
416
+ }
417
+
418
+ export interface Pong {
419
+ /** timestamp field of last received ping request */
420
+ lastPingTimestamp: number;
421
+ timestamp: number;
422
+ }
423
+
392
424
  function createBaseSignalRequest(): SignalRequest {
393
425
  return { message: undefined };
394
426
  }
@@ -434,6 +466,12 @@ export const SignalRequest = {
434
466
  if (message.message?.$case === "ping") {
435
467
  writer.uint32(112).int64(message.message.ping);
436
468
  }
469
+ if (message.message?.$case === "updateMetadata") {
470
+ UpdateParticipantMetadata.encode(message.message.updateMetadata, writer.uint32(122).fork()).ldelim();
471
+ }
472
+ if (message.message?.$case === "pingReq") {
473
+ Ping.encode(message.message.pingReq, writer.uint32(130).fork()).ldelim();
474
+ }
437
475
  return writer;
438
476
  },
439
477
 
@@ -489,6 +527,15 @@ export const SignalRequest = {
489
527
  case 14:
490
528
  message.message = { $case: "ping", ping: longToNumber(reader.int64() as Long) };
491
529
  break;
530
+ case 15:
531
+ message.message = {
532
+ $case: "updateMetadata",
533
+ updateMetadata: UpdateParticipantMetadata.decode(reader, reader.uint32()),
534
+ };
535
+ break;
536
+ case 16:
537
+ message.message = { $case: "pingReq", pingReq: Ping.decode(reader, reader.uint32()) };
538
+ break;
492
539
  default:
493
540
  reader.skipType(tag & 7);
494
541
  break;
@@ -528,6 +575,10 @@ export const SignalRequest = {
528
575
  ? { $case: "simulate", simulate: SimulateScenario.fromJSON(object.simulate) }
529
576
  : isSet(object.ping)
530
577
  ? { $case: "ping", ping: Number(object.ping) }
578
+ : isSet(object.updateMetadata)
579
+ ? { $case: "updateMetadata", updateMetadata: UpdateParticipantMetadata.fromJSON(object.updateMetadata) }
580
+ : isSet(object.pingReq)
581
+ ? { $case: "pingReq", pingReq: Ping.fromJSON(object.pingReq) }
531
582
  : undefined,
532
583
  };
533
584
  },
@@ -564,6 +615,11 @@ export const SignalRequest = {
564
615
  message.message?.$case === "simulate" &&
565
616
  (obj.simulate = message.message?.simulate ? SimulateScenario.toJSON(message.message?.simulate) : undefined);
566
617
  message.message?.$case === "ping" && (obj.ping = Math.round(message.message?.ping));
618
+ message.message?.$case === "updateMetadata" && (obj.updateMetadata = message.message?.updateMetadata
619
+ ? UpdateParticipantMetadata.toJSON(message.message?.updateMetadata)
620
+ : undefined);
621
+ message.message?.$case === "pingReq" &&
622
+ (obj.pingReq = message.message?.pingReq ? Ping.toJSON(message.message?.pingReq) : undefined);
567
623
  return obj;
568
624
  },
569
625
 
@@ -650,6 +706,21 @@ export const SignalRequest = {
650
706
  if (object.message?.$case === "ping" && object.message?.ping !== undefined && object.message?.ping !== null) {
651
707
  message.message = { $case: "ping", ping: object.message.ping };
652
708
  }
709
+ if (
710
+ object.message?.$case === "updateMetadata" &&
711
+ object.message?.updateMetadata !== undefined &&
712
+ object.message?.updateMetadata !== null
713
+ ) {
714
+ message.message = {
715
+ $case: "updateMetadata",
716
+ updateMetadata: UpdateParticipantMetadata.fromPartial(object.message.updateMetadata),
717
+ };
718
+ }
719
+ if (
720
+ object.message?.$case === "pingReq" && object.message?.pingReq !== undefined && object.message?.pingReq !== null
721
+ ) {
722
+ message.message = { $case: "pingReq", pingReq: Ping.fromPartial(object.message.pingReq) };
723
+ }
653
724
  return message;
654
725
  },
655
726
  };
@@ -715,6 +786,9 @@ export const SignalResponse = {
715
786
  if (message.message?.$case === "reconnect") {
716
787
  ReconnectResponse.encode(message.message.reconnect, writer.uint32(154).fork()).ldelim();
717
788
  }
789
+ if (message.message?.$case === "pongResp") {
790
+ Pong.encode(message.message.pongResp, writer.uint32(162).fork()).ldelim();
791
+ }
718
792
  return writer;
719
793
  },
720
794
 
@@ -800,6 +874,9 @@ export const SignalResponse = {
800
874
  case 19:
801
875
  message.message = { $case: "reconnect", reconnect: ReconnectResponse.decode(reader, reader.uint32()) };
802
876
  break;
877
+ case 20:
878
+ message.message = { $case: "pongResp", pongResp: Pong.decode(reader, reader.uint32()) };
879
+ break;
803
880
  default:
804
881
  reader.skipType(tag & 7);
805
882
  break;
@@ -852,6 +929,8 @@ export const SignalResponse = {
852
929
  ? { $case: "pong", pong: Number(object.pong) }
853
930
  : isSet(object.reconnect)
854
931
  ? { $case: "reconnect", reconnect: ReconnectResponse.fromJSON(object.reconnect) }
932
+ : isSet(object.pongResp)
933
+ ? { $case: "pongResp", pongResp: Pong.fromJSON(object.pongResp) }
855
934
  : undefined,
856
935
  };
857
936
  },
@@ -901,6 +980,8 @@ export const SignalResponse = {
901
980
  message.message?.$case === "pong" && (obj.pong = Math.round(message.message?.pong));
902
981
  message.message?.$case === "reconnect" &&
903
982
  (obj.reconnect = message.message?.reconnect ? ReconnectResponse.toJSON(message.message?.reconnect) : undefined);
983
+ message.message?.$case === "pongResp" &&
984
+ (obj.pongResp = message.message?.pongResp ? Pong.toJSON(message.message?.pongResp) : undefined);
904
985
  return obj;
905
986
  },
906
987
 
@@ -1025,6 +1106,13 @@ export const SignalResponse = {
1025
1106
  ) {
1026
1107
  message.message = { $case: "reconnect", reconnect: ReconnectResponse.fromPartial(object.message.reconnect) };
1027
1108
  }
1109
+ if (
1110
+ object.message?.$case === "pongResp" &&
1111
+ object.message?.pongResp !== undefined &&
1112
+ object.message?.pongResp !== null
1113
+ ) {
1114
+ message.message = { $case: "pongResp", pongResp: Pong.fromPartial(object.message.pongResp) };
1115
+ }
1028
1116
  return message;
1029
1117
  },
1030
1118
  };
@@ -1587,7 +1675,13 @@ export const JoinResponse = {
1587
1675
  };
1588
1676
 
1589
1677
  function createBaseReconnectResponse(): ReconnectResponse {
1590
- return { iceServers: [], clientConfiguration: undefined };
1678
+ return {
1679
+ iceServers: [],
1680
+ clientConfiguration: undefined,
1681
+ room: undefined,
1682
+ participant: undefined,
1683
+ otherParticipants: [],
1684
+ };
1591
1685
  }
1592
1686
 
1593
1687
  export const ReconnectResponse = {
@@ -1598,6 +1692,15 @@ export const ReconnectResponse = {
1598
1692
  if (message.clientConfiguration !== undefined) {
1599
1693
  ClientConfiguration.encode(message.clientConfiguration, writer.uint32(18).fork()).ldelim();
1600
1694
  }
1695
+ if (message.room !== undefined) {
1696
+ Room.encode(message.room, writer.uint32(26).fork()).ldelim();
1697
+ }
1698
+ if (message.participant !== undefined) {
1699
+ ParticipantInfo.encode(message.participant, writer.uint32(34).fork()).ldelim();
1700
+ }
1701
+ for (const v of message.otherParticipants) {
1702
+ ParticipantInfo.encode(v!, writer.uint32(42).fork()).ldelim();
1703
+ }
1601
1704
  return writer;
1602
1705
  },
1603
1706
 
@@ -1614,6 +1717,15 @@ export const ReconnectResponse = {
1614
1717
  case 2:
1615
1718
  message.clientConfiguration = ClientConfiguration.decode(reader, reader.uint32());
1616
1719
  break;
1720
+ case 3:
1721
+ message.room = Room.decode(reader, reader.uint32());
1722
+ break;
1723
+ case 4:
1724
+ message.participant = ParticipantInfo.decode(reader, reader.uint32());
1725
+ break;
1726
+ case 5:
1727
+ message.otherParticipants.push(ParticipantInfo.decode(reader, reader.uint32()));
1728
+ break;
1617
1729
  default:
1618
1730
  reader.skipType(tag & 7);
1619
1731
  break;
@@ -1628,6 +1740,11 @@ export const ReconnectResponse = {
1628
1740
  clientConfiguration: isSet(object.clientConfiguration)
1629
1741
  ? ClientConfiguration.fromJSON(object.clientConfiguration)
1630
1742
  : undefined,
1743
+ room: isSet(object.room) ? Room.fromJSON(object.room) : undefined,
1744
+ participant: isSet(object.participant) ? ParticipantInfo.fromJSON(object.participant) : undefined,
1745
+ otherParticipants: Array.isArray(object?.otherParticipants)
1746
+ ? object.otherParticipants.map((e: any) => ParticipantInfo.fromJSON(e))
1747
+ : [],
1631
1748
  };
1632
1749
  },
1633
1750
 
@@ -1641,6 +1758,14 @@ export const ReconnectResponse = {
1641
1758
  message.clientConfiguration !== undefined && (obj.clientConfiguration = message.clientConfiguration
1642
1759
  ? ClientConfiguration.toJSON(message.clientConfiguration)
1643
1760
  : undefined);
1761
+ message.room !== undefined && (obj.room = message.room ? Room.toJSON(message.room) : undefined);
1762
+ message.participant !== undefined &&
1763
+ (obj.participant = message.participant ? ParticipantInfo.toJSON(message.participant) : undefined);
1764
+ if (message.otherParticipants) {
1765
+ obj.otherParticipants = message.otherParticipants.map((e) => e ? ParticipantInfo.toJSON(e) : undefined);
1766
+ } else {
1767
+ obj.otherParticipants = [];
1768
+ }
1644
1769
  return obj;
1645
1770
  },
1646
1771
 
@@ -1650,6 +1775,11 @@ export const ReconnectResponse = {
1650
1775
  message.clientConfiguration = (object.clientConfiguration !== undefined && object.clientConfiguration !== null)
1651
1776
  ? ClientConfiguration.fromPartial(object.clientConfiguration)
1652
1777
  : undefined;
1778
+ message.room = (object.room !== undefined && object.room !== null) ? Room.fromPartial(object.room) : undefined;
1779
+ message.participant = (object.participant !== undefined && object.participant !== null)
1780
+ ? ParticipantInfo.fromPartial(object.participant)
1781
+ : undefined;
1782
+ message.otherParticipants = object.otherParticipants?.map((e) => ParticipantInfo.fromPartial(e)) || [];
1653
1783
  return message;
1654
1784
  },
1655
1785
  };
@@ -1949,7 +2079,7 @@ export const UpdateSubscription = {
1949
2079
  };
1950
2080
 
1951
2081
  function createBaseUpdateTrackSettings(): UpdateTrackSettings {
1952
- return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0, fps: 0 };
2082
+ return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0, fps: 0, priority: 0 };
1953
2083
  }
1954
2084
 
1955
2085
  export const UpdateTrackSettings = {
@@ -1972,6 +2102,9 @@ export const UpdateTrackSettings = {
1972
2102
  if (message.fps !== 0) {
1973
2103
  writer.uint32(56).uint32(message.fps);
1974
2104
  }
2105
+ if (message.priority !== 0) {
2106
+ writer.uint32(64).uint32(message.priority);
2107
+ }
1975
2108
  return writer;
1976
2109
  },
1977
2110
 
@@ -2000,6 +2133,9 @@ export const UpdateTrackSettings = {
2000
2133
  case 7:
2001
2134
  message.fps = reader.uint32();
2002
2135
  break;
2136
+ case 8:
2137
+ message.priority = reader.uint32();
2138
+ break;
2003
2139
  default:
2004
2140
  reader.skipType(tag & 7);
2005
2141
  break;
@@ -2016,6 +2152,7 @@ export const UpdateTrackSettings = {
2016
2152
  width: isSet(object.width) ? Number(object.width) : 0,
2017
2153
  height: isSet(object.height) ? Number(object.height) : 0,
2018
2154
  fps: isSet(object.fps) ? Number(object.fps) : 0,
2155
+ priority: isSet(object.priority) ? Number(object.priority) : 0,
2019
2156
  };
2020
2157
  },
2021
2158
 
@@ -2031,6 +2168,7 @@ export const UpdateTrackSettings = {
2031
2168
  message.width !== undefined && (obj.width = Math.round(message.width));
2032
2169
  message.height !== undefined && (obj.height = Math.round(message.height));
2033
2170
  message.fps !== undefined && (obj.fps = Math.round(message.fps));
2171
+ message.priority !== undefined && (obj.priority = Math.round(message.priority));
2034
2172
  return obj;
2035
2173
  },
2036
2174
 
@@ -2042,6 +2180,7 @@ export const UpdateTrackSettings = {
2042
2180
  message.width = object.width ?? 0;
2043
2181
  message.height = object.height ?? 0;
2044
2182
  message.fps = object.fps ?? 0;
2183
+ message.priority = object.priority ?? 0;
2045
2184
  return message;
2046
2185
  },
2047
2186
  };
@@ -2166,6 +2305,53 @@ export const UpdateVideoLayers = {
2166
2305
  },
2167
2306
  };
2168
2307
 
2308
+ function createBaseUpdateParticipantMetadata(): UpdateParticipantMetadata {
2309
+ return { metadata: "" };
2310
+ }
2311
+
2312
+ export const UpdateParticipantMetadata = {
2313
+ encode(message: UpdateParticipantMetadata, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
2314
+ if (message.metadata !== "") {
2315
+ writer.uint32(10).string(message.metadata);
2316
+ }
2317
+ return writer;
2318
+ },
2319
+
2320
+ decode(input: _m0.Reader | Uint8Array, length?: number): UpdateParticipantMetadata {
2321
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
2322
+ let end = length === undefined ? reader.len : reader.pos + length;
2323
+ const message = createBaseUpdateParticipantMetadata();
2324
+ while (reader.pos < end) {
2325
+ const tag = reader.uint32();
2326
+ switch (tag >>> 3) {
2327
+ case 1:
2328
+ message.metadata = reader.string();
2329
+ break;
2330
+ default:
2331
+ reader.skipType(tag & 7);
2332
+ break;
2333
+ }
2334
+ }
2335
+ return message;
2336
+ },
2337
+
2338
+ fromJSON(object: any): UpdateParticipantMetadata {
2339
+ return { metadata: isSet(object.metadata) ? String(object.metadata) : "" };
2340
+ },
2341
+
2342
+ toJSON(message: UpdateParticipantMetadata): unknown {
2343
+ const obj: any = {};
2344
+ message.metadata !== undefined && (obj.metadata = message.metadata);
2345
+ return obj;
2346
+ },
2347
+
2348
+ fromPartial<I extends Exact<DeepPartial<UpdateParticipantMetadata>, I>>(object: I): UpdateParticipantMetadata {
2349
+ const message = createBaseUpdateParticipantMetadata();
2350
+ message.metadata = object.metadata ?? "";
2351
+ return message;
2352
+ },
2353
+ };
2354
+
2169
2355
  function createBaseICEServer(): ICEServer {
2170
2356
  return { urls: [], username: "", credential: "" };
2171
2357
  }
@@ -3293,10 +3479,126 @@ export const SimulateScenario = {
3293
3479
  },
3294
3480
  };
3295
3481
 
3482
+ function createBasePing(): Ping {
3483
+ return { timestamp: 0, rtt: 0 };
3484
+ }
3485
+
3486
+ export const Ping = {
3487
+ encode(message: Ping, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
3488
+ if (message.timestamp !== 0) {
3489
+ writer.uint32(8).int64(message.timestamp);
3490
+ }
3491
+ if (message.rtt !== 0) {
3492
+ writer.uint32(16).int64(message.rtt);
3493
+ }
3494
+ return writer;
3495
+ },
3496
+
3497
+ decode(input: _m0.Reader | Uint8Array, length?: number): Ping {
3498
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
3499
+ let end = length === undefined ? reader.len : reader.pos + length;
3500
+ const message = createBasePing();
3501
+ while (reader.pos < end) {
3502
+ const tag = reader.uint32();
3503
+ switch (tag >>> 3) {
3504
+ case 1:
3505
+ message.timestamp = longToNumber(reader.int64() as Long);
3506
+ break;
3507
+ case 2:
3508
+ message.rtt = longToNumber(reader.int64() as Long);
3509
+ break;
3510
+ default:
3511
+ reader.skipType(tag & 7);
3512
+ break;
3513
+ }
3514
+ }
3515
+ return message;
3516
+ },
3517
+
3518
+ fromJSON(object: any): Ping {
3519
+ return {
3520
+ timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0,
3521
+ rtt: isSet(object.rtt) ? Number(object.rtt) : 0,
3522
+ };
3523
+ },
3524
+
3525
+ toJSON(message: Ping): unknown {
3526
+ const obj: any = {};
3527
+ message.timestamp !== undefined && (obj.timestamp = Math.round(message.timestamp));
3528
+ message.rtt !== undefined && (obj.rtt = Math.round(message.rtt));
3529
+ return obj;
3530
+ },
3531
+
3532
+ fromPartial<I extends Exact<DeepPartial<Ping>, I>>(object: I): Ping {
3533
+ const message = createBasePing();
3534
+ message.timestamp = object.timestamp ?? 0;
3535
+ message.rtt = object.rtt ?? 0;
3536
+ return message;
3537
+ },
3538
+ };
3539
+
3540
+ function createBasePong(): Pong {
3541
+ return { lastPingTimestamp: 0, timestamp: 0 };
3542
+ }
3543
+
3544
+ export const Pong = {
3545
+ encode(message: Pong, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
3546
+ if (message.lastPingTimestamp !== 0) {
3547
+ writer.uint32(8).int64(message.lastPingTimestamp);
3548
+ }
3549
+ if (message.timestamp !== 0) {
3550
+ writer.uint32(16).int64(message.timestamp);
3551
+ }
3552
+ return writer;
3553
+ },
3554
+
3555
+ decode(input: _m0.Reader | Uint8Array, length?: number): Pong {
3556
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
3557
+ let end = length === undefined ? reader.len : reader.pos + length;
3558
+ const message = createBasePong();
3559
+ while (reader.pos < end) {
3560
+ const tag = reader.uint32();
3561
+ switch (tag >>> 3) {
3562
+ case 1:
3563
+ message.lastPingTimestamp = longToNumber(reader.int64() as Long);
3564
+ break;
3565
+ case 2:
3566
+ message.timestamp = longToNumber(reader.int64() as Long);
3567
+ break;
3568
+ default:
3569
+ reader.skipType(tag & 7);
3570
+ break;
3571
+ }
3572
+ }
3573
+ return message;
3574
+ },
3575
+
3576
+ fromJSON(object: any): Pong {
3577
+ return {
3578
+ lastPingTimestamp: isSet(object.lastPingTimestamp) ? Number(object.lastPingTimestamp) : 0,
3579
+ timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0,
3580
+ };
3581
+ },
3582
+
3583
+ toJSON(message: Pong): unknown {
3584
+ const obj: any = {};
3585
+ message.lastPingTimestamp !== undefined && (obj.lastPingTimestamp = Math.round(message.lastPingTimestamp));
3586
+ message.timestamp !== undefined && (obj.timestamp = Math.round(message.timestamp));
3587
+ return obj;
3588
+ },
3589
+
3590
+ fromPartial<I extends Exact<DeepPartial<Pong>, I>>(object: I): Pong {
3591
+ const message = createBasePong();
3592
+ message.lastPingTimestamp = object.lastPingTimestamp ?? 0;
3593
+ message.timestamp = object.timestamp ?? 0;
3594
+ return message;
3595
+ },
3596
+ };
3597
+
3296
3598
  declare var self: any | undefined;
3297
3599
  declare var window: any | undefined;
3298
3600
  declare var global: any | undefined;
3299
- var globalThis: any = (() => {
3601
+ var tsProtoGlobalThis: any = (() => {
3300
3602
  if (typeof globalThis !== "undefined") {
3301
3603
  return globalThis;
3302
3604
  }
@@ -3326,7 +3628,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P
3326
3628
 
3327
3629
  function longToNumber(long: Long): number {
3328
3630
  if (long.gt(Number.MAX_SAFE_INTEGER)) {
3329
- throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
3631
+ throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
3330
3632
  }
3331
3633
  return long.toNumber();
3332
3634
  }
@@ -9,6 +9,7 @@ import {
9
9
  DataPacket,
10
10
  DataPacket_Kind,
11
11
  DisconnectReason,
12
+ ReconnectReason,
12
13
  SpeakerInfo,
13
14
  TrackInfo,
14
15
  UserPacket,
@@ -305,7 +306,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
305
306
 
306
307
  let primaryPC = this.publisher.pc;
307
308
  let secondaryPC = this.subscriber.pc;
308
- if (joinResponse.subscriberPrimary) {
309
+ let subscriberPrimary = joinResponse.subscriberPrimary;
310
+ if (subscriberPrimary) {
309
311
  primaryPC = this.subscriber.pc;
310
312
  secondaryPC = this.publisher.pc;
311
313
  // in subscriber primary mode, server side opens sub data channels.
@@ -330,7 +332,13 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
330
332
  if (this.pcState === PCState.Connected) {
331
333
  this.pcState = PCState.Disconnected;
332
334
 
333
- this.handleDisconnect('primary peerconnection');
335
+ this.handleDisconnect(
336
+ 'primary peerconnection',
337
+ false,
338
+ subscriberPrimary
339
+ ? ReconnectReason.REASON_SUBSCRIBER_FAILED
340
+ : ReconnectReason.REASON_PUBLISHER_FAILED,
341
+ );
334
342
  }
335
343
  }
336
344
  };
@@ -338,7 +346,13 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
338
346
  log.debug(`secondary PC state changed ${secondaryPC.connectionState}`);
339
347
  // also reconnect if secondary peerconnection fails
340
348
  if (secondaryPC.connectionState === 'failed') {
341
- this.handleDisconnect('secondary peerconnection');
349
+ this.handleDisconnect(
350
+ 'secondary peerconnection',
351
+ false,
352
+ subscriberPrimary
353
+ ? ReconnectReason.REASON_PUBLISHER_FAILED
354
+ : ReconnectReason.REASON_SUBSCRIBER_FAILED,
355
+ );
342
356
  }
343
357
  };
344
358
 
@@ -405,7 +419,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
405
419
  };
406
420
 
407
421
  this.client.onClose = () => {
408
- this.handleDisconnect('signal');
422
+ this.handleDisconnect('signal', false, ReconnectReason.REASON_SIGNAL_DISCONNECTED);
409
423
  };
410
424
 
411
425
  this.client.onLeave = (leave?: LeaveRequest) => {
@@ -676,19 +690,23 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
676
690
  // websocket reconnect behavior. if websocket is interrupted, and the PeerConnection
677
691
  // continues to work, we can reconnect to websocket to continue the session
678
692
  // after a number of retries, we'll close and give up permanently
679
- private handleDisconnect = (connection: string, signalEvents: boolean = false) => {
693
+ private handleDisconnect = (
694
+ connection: string,
695
+ signalEvents: boolean = false,
696
+ disconnectReason?: ReconnectReason,
697
+ ) => {
680
698
  if (this._isClosed) {
681
699
  return;
682
700
  }
683
701
 
684
- log.debug(`${connection} disconnected`);
702
+ log.warn(`${connection} disconnected`);
685
703
  if (this.reconnectAttempts === 0) {
686
704
  // only reset start time on the first try
687
705
  this.reconnectStart = Date.now();
688
706
  }
689
707
 
690
708
  const disconnect = (duration: number) => {
691
- log.info(
709
+ log.warn(
692
710
  `could not recover connection after ${this.reconnectAttempts} attempts, ${duration}ms. giving up`,
693
711
  );
694
712
  this.emit(EngineEvent.Disconnected);
@@ -713,12 +731,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
713
731
 
714
732
  this.clearReconnectTimeout();
715
733
  this.reconnectTimeout = CriticalTimers.setTimeout(
716
- () => this.attemptReconnect(signalEvents),
734
+ () => this.attemptReconnect(signalEvents, disconnectReason),
717
735
  delay,
718
736
  );
719
737
  };
720
738
 
721
- private async attemptReconnect(signalEvents: boolean = false) {
739
+ private async attemptReconnect(signalEvents: boolean = false, reason?: ReconnectReason) {
722
740
  if (this._isClosed) {
723
741
  return;
724
742
  }
@@ -740,7 +758,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
740
758
  if (this.fullReconnectOnNext) {
741
759
  await this.restartConnection(signalEvents);
742
760
  } else {
743
- await this.resumeConnection(signalEvents);
761
+ await this.resumeConnection(signalEvents, reason);
744
762
  }
745
763
  this.clearPendingReconnect();
746
764
  this.fullReconnectOnNext = false;
@@ -766,7 +784,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
766
784
  }
767
785
 
768
786
  if (recoverable) {
769
- this.handleDisconnect('reconnect', requireSignalEvents);
787
+ this.handleDisconnect('reconnect', requireSignalEvents, ReconnectReason.REASON_UNKOWN);
770
788
  } else {
771
789
  log.info(
772
790
  `could not recover connection after ${this.reconnectAttempts} attempts, ${
@@ -831,7 +849,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
831
849
  this.emit(EngineEvent.Restarted, joinResponse);
832
850
  }
833
851
 
834
- private async resumeConnection(emitResuming: boolean = false): Promise<void> {
852
+ private async resumeConnection(
853
+ emitResuming: boolean = false,
854
+ reason?: ReconnectReason,
855
+ ): Promise<void> {
835
856
  if (!this.url || !this.token) {
836
857
  // permanent failure, don't attempt reconnection
837
858
  throw new UnexpectedConnectionState('could not reconnect, url or token not saved');
@@ -847,7 +868,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
847
868
  }
848
869
 
849
870
  try {
850
- const res = await this.client.reconnect(this.url, this.token, this.participantSid);
871
+ const res = await this.client.reconnect(this.url, this.token, this.participantSid, reason);
851
872
  if (res) {
852
873
  const rtcConfig = this.makeRTCConfiguration(res);
853
874
  this.publisher.pc.setConfiguration(rtcConfig);
@@ -1001,7 +1022,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1001
1022
 
1002
1023
  const negotiationTimeout = setTimeout(() => {
1003
1024
  reject('negotiation timed out');
1004
- this.handleDisconnect('negotiation');
1025
+ this.handleDisconnect('negotiation', false, ReconnectReason.REASON_SIGNAL_DISCONNECTED);
1005
1026
  }, this.peerConnectionTimeout);
1006
1027
 
1007
1028
  const cleanup = () => {
@@ -1022,7 +1043,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1022
1043
  if (e instanceof NegotiationError) {
1023
1044
  this.fullReconnectOnNext = true;
1024
1045
  }
1025
- this.handleDisconnect('negotiation');
1046
+ this.handleDisconnect('negotiation', false, ReconnectReason.REASON_UNKOWN);
1026
1047
  });
1027
1048
  });
1028
1049
  }
@@ -1060,7 +1081,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1060
1081
  // in case the engine is currently reconnecting, attempt a reconnect immediately after the browser state has changed to 'onLine'
1061
1082
  if (this.client.isReconnecting) {
1062
1083
  this.clearReconnectTimeout();
1063
- this.attemptReconnect(true);
1084
+ this.attemptReconnect(true, ReconnectReason.REASON_SIGNAL_DISCONNECTED);
1064
1085
  }
1065
1086
  };
1066
1087