livekit-client 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. package/README.md +3 -2
  2. package/dist/livekit-client.esm.mjs +13470 -13341
  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/api/SignalClient.d.ts +11 -10
  7. package/dist/src/api/SignalClient.d.ts.map +1 -1
  8. package/dist/src/connectionHelper/ConnectionCheck.d.ts +1 -1
  9. package/dist/src/connectionHelper/ConnectionCheck.d.ts.map +1 -1
  10. package/dist/src/connectionHelper/checks/Checker.d.ts +1 -1
  11. package/dist/src/connectionHelper/checks/Checker.d.ts.map +1 -1
  12. package/dist/src/index.d.ts +5 -7
  13. package/dist/src/index.d.ts.map +1 -1
  14. package/dist/src/proto/livekit_models.d.ts +5 -0
  15. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  16. package/dist/src/proto/livekit_rtc.d.ts +32 -0
  17. package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
  18. package/dist/src/room/RTCEngine.d.ts +5 -3
  19. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  20. package/dist/src/room/Room.d.ts +19 -15
  21. package/dist/src/room/Room.d.ts.map +1 -1
  22. package/dist/src/room/events.d.ts +15 -0
  23. package/dist/src/room/events.d.ts.map +1 -1
  24. package/dist/src/room/participant/LocalParticipant.d.ts +14 -2
  25. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  26. package/dist/src/room/participant/Participant.d.ts +4 -2
  27. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  28. package/dist/src/room/participant/RemoteParticipant.d.ts +2 -2
  29. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  30. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  31. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  32. package/dist/src/room/track/LocalTrack.d.ts +1 -1
  33. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  34. package/dist/src/room/track/LocalTrackPublication.d.ts +1 -1
  35. package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
  36. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  37. package/dist/src/room/track/RemoteAudioTrack.d.ts +1 -1
  38. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  39. package/dist/src/room/track/create.d.ts.map +1 -1
  40. package/dist/src/room/types.d.ts +1 -0
  41. package/dist/src/room/types.d.ts.map +1 -1
  42. package/dist/ts4.2/src/api/SignalClient.d.ts +14 -10
  43. package/dist/ts4.2/src/connectionHelper/ConnectionCheck.d.ts +1 -1
  44. package/dist/ts4.2/src/connectionHelper/checks/Checker.d.ts +1 -1
  45. package/dist/ts4.2/src/index.d.ts +6 -7
  46. package/dist/ts4.2/src/proto/livekit_models.d.ts +5 -0
  47. package/dist/ts4.2/src/proto/livekit_rtc.d.ts +32 -0
  48. package/dist/ts4.2/src/room/RTCEngine.d.ts +5 -3
  49. package/dist/ts4.2/src/room/Room.d.ts +19 -15
  50. package/dist/ts4.2/src/room/events.d.ts +15 -0
  51. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +14 -2
  52. package/dist/ts4.2/src/room/participant/Participant.d.ts +4 -2
  53. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +2 -2
  54. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -1
  55. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +1 -1
  56. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +1 -1
  57. package/dist/ts4.2/src/room/types.d.ts +1 -0
  58. package/package.json +4 -3
  59. package/src/api/SignalClient.ts +38 -26
  60. package/src/connectionHelper/ConnectionCheck.ts +1 -2
  61. package/src/connectionHelper/checks/Checker.ts +1 -1
  62. package/src/connectionHelper/checks/reconnect.ts +1 -1
  63. package/src/index.ts +8 -10
  64. package/src/proto/livekit_models.ts +15 -0
  65. package/src/room/RTCEngine.ts +32 -11
  66. package/src/room/RegionUrlProvider.ts +1 -1
  67. package/src/room/Room.ts +102 -70
  68. package/src/room/events.ts +17 -0
  69. package/src/room/participant/LocalParticipant.ts +30 -7
  70. package/src/room/participant/Participant.ts +27 -3
  71. package/src/room/participant/RemoteParticipant.ts +6 -3
  72. package/src/room/participant/publishUtils.test.ts +1 -1
  73. package/src/room/participant/publishUtils.ts +1 -1
  74. package/src/room/track/LocalAudioTrack.ts +1 -1
  75. package/src/room/track/LocalTrack.ts +2 -2
  76. package/src/room/track/LocalTrackPublication.ts +1 -1
  77. package/src/room/track/LocalVideoTrack.ts +3 -3
  78. package/src/room/track/RemoteAudioTrack.ts +1 -1
  79. package/src/room/track/RemoteVideoTrack.test.ts +1 -1
  80. package/src/room/track/RemoteVideoTrack.ts +3 -3
  81. package/src/room/track/create.ts +2 -2
  82. package/src/room/types.ts +11 -0
@@ -2,9 +2,9 @@ import type { TrackInfo } from '../../proto/livekit_models';
2
2
  import type LocalAudioTrack from './LocalAudioTrack';
3
3
  import type LocalTrack from './LocalTrack';
4
4
  import type LocalVideoTrack from './LocalVideoTrack';
5
- import type { TrackPublishOptions } from './options';
6
5
  import type { Track } from './Track';
7
6
  import { TrackPublication } from './TrackPublication';
7
+ import type { TrackPublishOptions } from './options';
8
8
  export default class LocalTrackPublication extends TrackPublication {
9
9
  track?: LocalTrack;
10
10
  options?: TrackPublishOptions;
@@ -1,6 +1,6 @@
1
1
  import { AudioReceiverStats } from '../stats';
2
- import type { AudioOutputOptions } from './options';
3
2
  import RemoteTrack from './RemoteTrack';
3
+ import type { AudioOutputOptions } from './options';
4
4
  export default class RemoteAudioTrack extends RemoteTrack {
5
5
  private prevStats?;
6
6
  private elementVolume;
@@ -22,4 +22,5 @@ export type LiveKitReactNativeInfo = {
22
22
  platform: 'ios' | 'android' | 'windows' | 'macos' | 'web' | 'native';
23
23
  devicePixelRatio: number;
24
24
  };
25
+ export type SimulationScenario = 'signal-reconnect' | 'speaker' | 'node-failure' | 'server-leave' | 'migration' | 'resume-reconnect' | 'force-tcp' | 'force-tls' | 'full-reconnect';
25
26
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-client",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "JavaScript/TypeScript client SDK for LiveKit",
5
5
  "main": "./dist/livekit-client.umd.js",
6
6
  "unpkg": "./dist/livekit-client.umd.js",
@@ -53,13 +53,14 @@
53
53
  "devDependencies": {
54
54
  "@babel/core": "7.21.4",
55
55
  "@babel/preset-env": "7.21.4",
56
- "@changesets/changelog-github": "0.4.8",
57
56
  "@changesets/cli": "2.26.1",
57
+ "@livekit/changesets-changelog-github": "^0.0.4",
58
58
  "@rollup/plugin-babel": "6.0.3",
59
59
  "@rollup/plugin-commonjs": "24.1.0",
60
60
  "@rollup/plugin-json": "6.0.0",
61
61
  "@rollup/plugin-node-resolve": "15.0.2",
62
62
  "@rollup/plugin-terser": "^0.4.0",
63
+ "@trivago/prettier-plugin-sort-imports": "^4.1.1",
63
64
  "@types/jest": "29.5.0",
64
65
  "@types/sdp-transform": "2.4.6",
65
66
  "@types/ua-parser-js": "0.7.36",
@@ -73,7 +74,7 @@
73
74
  "eslint-plugin-import": "2.27.5",
74
75
  "gh-pages": "5.0.0",
75
76
  "jest": "29.5.0",
76
- "prettier": "2.8.7",
77
+ "prettier": "^2.8.8",
77
78
  "rollup": "3.20.2",
78
79
  "rollup-plugin-delete": "^2.0.0",
79
80
  "rollup-plugin-filesize": "10.0.0",
@@ -33,7 +33,7 @@ import {
33
33
  } from '../proto/livekit_rtc';
34
34
  import { ConnectionError, ConnectionErrorReason } from '../room/errors';
35
35
  import CriticalTimers from '../room/timers';
36
- import { getClientInfo, isReactNative, Mutex, sleep } from '../room/utils';
36
+ import { Mutex, getClientInfo, isReactNative, sleep } from '../room/utils';
37
37
 
38
38
  // internal options
39
39
  interface ConnectOpts {
@@ -374,7 +374,7 @@ export class SignalClient {
374
374
  // answer a server-initiated offer
375
375
  sendAnswer(answer: RTCSessionDescriptionInit) {
376
376
  log.debug('sending answer');
377
- this.sendRequest({
377
+ return this.sendRequest({
378
378
  $case: 'answer',
379
379
  answer: toProtoSessionDescription(answer),
380
380
  });
@@ -382,7 +382,7 @@ export class SignalClient {
382
382
 
383
383
  sendIceCandidate(candidate: RTCIceCandidateInit, target: SignalTarget) {
384
384
  log.trace('sending ice candidate', candidate);
385
- this.sendRequest({
385
+ return this.sendRequest({
386
386
  $case: 'trickle',
387
387
  trickle: {
388
388
  candidateInit: JSON.stringify(candidate),
@@ -392,7 +392,7 @@ export class SignalClient {
392
392
  }
393
393
 
394
394
  sendMuteTrack(trackSid: string, muted: boolean) {
395
- this.sendRequest({
395
+ return this.sendRequest({
396
396
  $case: 'mute',
397
397
  mute: {
398
398
  sid: trackSid,
@@ -401,13 +401,23 @@ export class SignalClient {
401
401
  });
402
402
  }
403
403
 
404
- sendAddTrack(req: AddTrackRequest): void {
405
- this.sendRequest({
404
+ sendAddTrack(req: AddTrackRequest) {
405
+ return this.sendRequest({
406
406
  $case: 'addTrack',
407
407
  addTrack: AddTrackRequest.fromPartial(req),
408
408
  });
409
409
  }
410
410
 
411
+ sendUpdateLocalMetadata(metadata: string, name: string) {
412
+ return this.sendRequest({
413
+ $case: 'updateMetadata',
414
+ updateMetadata: {
415
+ metadata,
416
+ name,
417
+ },
418
+ });
419
+ }
420
+
411
421
  sendUpdateTrackSettings(settings: UpdateTrackSettings) {
412
422
  this.sendRequest({
413
423
  $case: 'trackSetting',
@@ -416,21 +426,21 @@ export class SignalClient {
416
426
  }
417
427
 
418
428
  sendUpdateSubscription(sub: UpdateSubscription) {
419
- this.sendRequest({
429
+ return this.sendRequest({
420
430
  $case: 'subscription',
421
431
  subscription: sub,
422
432
  });
423
433
  }
424
434
 
425
435
  sendSyncState(sync: SyncState) {
426
- this.sendRequest({
436
+ return this.sendRequest({
427
437
  $case: 'syncState',
428
438
  syncState: sync,
429
439
  });
430
440
  }
431
441
 
432
442
  sendUpdateVideoLayers(trackSid: string, layers: VideoLayer[]) {
433
- this.sendRequest({
443
+ return this.sendRequest({
434
444
  $case: 'updateLayers',
435
445
  updateLayers: {
436
446
  trackSid,
@@ -440,7 +450,7 @@ export class SignalClient {
440
450
  }
441
451
 
442
452
  sendUpdateSubscriptionPermissions(allParticipants: boolean, trackPermissions: TrackPermission[]) {
443
- this.sendRequest({
453
+ return this.sendRequest({
444
454
  $case: 'subscriptionPermission',
445
455
  subscriptionPermission: {
446
456
  allParticipants,
@@ -450,7 +460,7 @@ export class SignalClient {
450
460
  }
451
461
 
452
462
  sendSimulateScenario(scenario: SimulateScenario) {
453
- this.sendRequest({
463
+ return this.sendRequest({
454
464
  $case: 'simulate',
455
465
  simulate: scenario,
456
466
  });
@@ -458,21 +468,23 @@ export class SignalClient {
458
468
 
459
469
  sendPing() {
460
470
  /** send both of ping and pingReq for compatibility to old and new server */
461
- this.sendRequest({
462
- $case: 'ping',
463
- ping: Date.now(),
464
- });
465
- this.sendRequest({
466
- $case: 'pingReq',
467
- pingReq: {
468
- timestamp: Date.now(),
469
- rtt: this.rtt,
470
- },
471
- });
472
- }
473
-
474
- async sendLeave() {
475
- await this.sendRequest({
471
+ return Promise.all([
472
+ this.sendRequest({
473
+ $case: 'ping',
474
+ ping: Date.now(),
475
+ }),
476
+ this.sendRequest({
477
+ $case: 'pingReq',
478
+ pingReq: {
479
+ timestamp: Date.now(),
480
+ rtt: this.rtt,
481
+ },
482
+ }),
483
+ ]);
484
+ }
485
+
486
+ sendLeave() {
487
+ return this.sendRequest({
476
488
  $case: 'leave',
477
489
  leave: {
478
490
  canReconnect: false,
@@ -1,7 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import type TypedEmitter from 'typed-emitter';
3
-
4
- import { Checker, CheckInfo, CheckStatus, InstantiableCheck } from './checks/Checker';
3
+ import { CheckInfo, CheckStatus, Checker, InstantiableCheck } from './checks/Checker';
5
4
  import { PublishAudioCheck } from './checks/publishAudio';
6
5
  import { PublishVideoCheck } from './checks/publishVideo';
7
6
  import { ReconnectCheck } from './checks/reconnect';
@@ -1,8 +1,8 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import type TypedEmitter from 'typed-emitter';
3
3
  import type { RoomConnectOptions, RoomOptions } from '../../options';
4
- import Room, { ConnectionState } from '../../room/Room';
5
4
  import type RTCEngine from '../../room/RTCEngine';
5
+ import Room, { ConnectionState } from '../../room/Room';
6
6
 
7
7
  type LogMessage = {
8
8
  level: 'info' | 'warning' | 'error';
@@ -1,5 +1,5 @@
1
- import { RoomEvent } from '../../room/events';
2
1
  import { ConnectionState } from '../../room/Room';
2
+ import { RoomEvent } from '../../room/events';
3
3
  import { Checker } from './Checker';
4
4
 
5
5
  export class ReconnectCheck extends Checker {
package/src/index.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { LogLevel, setLogExtension, setLogLevel } from './logger';
2
2
  import { DataPacket_Kind, DisconnectReason, VideoQuality } from './proto/livekit_models';
3
3
  import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
4
+ import Room, { ConnectionState, RoomState } from './room/Room';
4
5
  import LocalParticipant from './room/participant/LocalParticipant';
5
6
  import Participant, { ConnectionQuality } from './room/participant/Participant';
6
7
  import type { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
7
8
  import RemoteParticipant from './room/participant/RemoteParticipant';
8
- import Room, { ConnectionState, RoomState } from './room/Room';
9
+ import CriticalTimers from './room/timers';
9
10
  import LocalAudioTrack from './room/track/LocalAudioTrack';
10
11
  import LocalTrack from './room/track/LocalTrack';
11
12
  import LocalTrackPublication from './room/track/LocalTrackPublication';
@@ -13,27 +14,24 @@ import LocalVideoTrack from './room/track/LocalVideoTrack';
13
14
  import RemoteAudioTrack from './room/track/RemoteAudioTrack';
14
15
  import RemoteTrack from './room/track/RemoteTrack';
15
16
  import RemoteTrackPublication from './room/track/RemoteTrackPublication';
16
- import RemoteVideoTrack from './room/track/RemoteVideoTrack';
17
- import type { ElementInfo } from './room/track/RemoteVideoTrack';
17
+ import RemoteVideoTrack, { type ElementInfo } from './room/track/RemoteVideoTrack';
18
18
  import { TrackPublication } from './room/track/TrackPublication';
19
- import CriticalTimers from './room/timers';
19
+ import type { LiveKitReactNativeInfo } from './room/types';
20
20
  import {
21
+ type AudioAnalyserOptions,
22
+ createAudioAnalyser,
21
23
  getEmptyAudioStreamTrack,
22
24
  getEmptyVideoStreamTrack,
23
25
  isBrowserSupported,
24
- supportsAdaptiveStream,
25
26
  supportsAV1,
27
+ supportsAdaptiveStream,
26
28
  supportsDynacast,
27
- createAudioAnalyser,
28
29
  } from './room/utils';
29
30
 
30
- import type { AudioAnalyserOptions } from './room/utils';
31
- import type { LiveKitReactNativeInfo } from './room/types';
32
-
33
31
  export * from './options';
34
32
  export * from './room/errors';
35
33
  export * from './room/events';
36
- export type { DataPublishOptions } from './room/types';
34
+ export type { DataPublishOptions, SimulationScenario } from './room/types';
37
35
  export * from './room/track/create';
38
36
  export * from './room/track/options';
39
37
  export * from './room/track/Track';
@@ -438,6 +438,7 @@ export interface Room {
438
438
  enabledCodecs: Codec[];
439
439
  metadata: string;
440
440
  numParticipants: number;
441
+ numPublishers: number;
441
442
  activeRecording: boolean;
442
443
  }
443
444
 
@@ -904,6 +905,7 @@ function createBaseRoom(): Room {
904
905
  enabledCodecs: [],
905
906
  metadata: "",
906
907
  numParticipants: 0,
908
+ numPublishers: 0,
907
909
  activeRecording: false,
908
910
  };
909
911
  }
@@ -937,6 +939,9 @@ export const Room = {
937
939
  if (message.numParticipants !== 0) {
938
940
  writer.uint32(72).uint32(message.numParticipants);
939
941
  }
942
+ if (message.numPublishers !== 0) {
943
+ writer.uint32(88).uint32(message.numPublishers);
944
+ }
940
945
  if (message.activeRecording === true) {
941
946
  writer.uint32(80).bool(message.activeRecording);
942
947
  }
@@ -1013,6 +1018,13 @@ export const Room = {
1013
1018
 
1014
1019
  message.numParticipants = reader.uint32();
1015
1020
  continue;
1021
+ case 11:
1022
+ if (tag != 88) {
1023
+ break;
1024
+ }
1025
+
1026
+ message.numPublishers = reader.uint32();
1027
+ continue;
1016
1028
  case 10:
1017
1029
  if (tag != 80) {
1018
1030
  break;
@@ -1042,6 +1054,7 @@ export const Room = {
1042
1054
  : [],
1043
1055
  metadata: isSet(object.metadata) ? String(object.metadata) : "",
1044
1056
  numParticipants: isSet(object.numParticipants) ? Number(object.numParticipants) : 0,
1057
+ numPublishers: isSet(object.numPublishers) ? Number(object.numPublishers) : 0,
1045
1058
  activeRecording: isSet(object.activeRecording) ? Boolean(object.activeRecording) : false,
1046
1059
  };
1047
1060
  },
@@ -1061,6 +1074,7 @@ export const Room = {
1061
1074
  }
1062
1075
  message.metadata !== undefined && (obj.metadata = message.metadata);
1063
1076
  message.numParticipants !== undefined && (obj.numParticipants = Math.round(message.numParticipants));
1077
+ message.numPublishers !== undefined && (obj.numPublishers = Math.round(message.numPublishers));
1064
1078
  message.activeRecording !== undefined && (obj.activeRecording = message.activeRecording);
1065
1079
  return obj;
1066
1080
  },
@@ -1080,6 +1094,7 @@ export const Room = {
1080
1094
  message.enabledCodecs = object.enabledCodecs?.map((e) => Codec.fromPartial(e)) || [];
1081
1095
  message.metadata = object.metadata ?? "";
1082
1096
  message.numParticipants = object.numParticipants ?? 0;
1097
+ message.numPublishers = object.numPublishers ?? 0;
1083
1098
  message.activeRecording = object.activeRecording ?? false;
1084
1099
  return message;
1085
1100
  },
@@ -22,6 +22,9 @@ import {
22
22
  SignalTarget,
23
23
  TrackPublishedResponse,
24
24
  } from '../proto/livekit_rtc';
25
+ import PCTransport, { PCEvents } from './PCTransport';
26
+ import type { ReconnectContext, ReconnectPolicy } from './ReconnectPolicy';
27
+ import { RegionUrlProvider } from './RegionUrlProvider';
25
28
  import { roomConnectOptionDefaults } from './defaults';
26
29
  import {
27
30
  ConnectionError,
@@ -31,24 +34,21 @@ import {
31
34
  UnexpectedConnectionState,
32
35
  } from './errors';
33
36
  import { EngineEvent } from './events';
34
- import PCTransport, { PCEvents } from './PCTransport';
35
- import type { ReconnectContext, ReconnectPolicy } from './ReconnectPolicy';
36
37
  import CriticalTimers from './timers';
37
38
  import type LocalTrack from './track/LocalTrack';
38
39
  import type LocalVideoTrack from './track/LocalVideoTrack';
39
40
  import type { SimulcastTrackInfo } from './track/LocalVideoTrack';
40
- import type { TrackPublishOptions, VideoCodec } from './track/options';
41
41
  import { Track } from './track/Track';
42
+ import type { TrackPublishOptions, VideoCodec } from './track/options';
42
43
  import {
44
+ Mutex,
43
45
  isCloud,
44
46
  isWeb,
45
- Mutex,
46
47
  sleep,
47
48
  supportsAddTrack,
48
49
  supportsSetCodecPreferences,
49
50
  supportsTransceiver,
50
51
  } from './utils';
51
- import { RegionUrlProvider } from './RegionUrlProvider';
52
52
 
53
53
  const lossyDataChannel = '_lossy';
54
54
  const reliableDataChannel = '_reliable';
@@ -75,6 +75,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
75
75
 
76
76
  peerConnectionTimeout: number = roomConnectOptionDefaults.peerConnectionTimeout;
77
77
 
78
+ fullReconnectOnNext: boolean = false;
79
+
78
80
  get isClosed() {
79
81
  return this._isClosed;
80
82
  }
@@ -118,8 +120,6 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
118
120
 
119
121
  private reconnectStart: number = 0;
120
122
 
121
- private fullReconnectOnNext: boolean = false;
122
-
123
123
  private clientConfiguration?: ClientConfiguration;
124
124
 
125
125
  private attemptingReconnect: boolean = false;
@@ -879,11 +879,13 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
879
879
  throw new Error('simulated failure');
880
880
  }
881
881
 
882
- await this.waitForPCReconnected();
883
882
  this.client.setReconnected();
883
+ this.emit(EngineEvent.SignalRestarted, joinResponse);
884
+
885
+ await this.waitForPCReconnected();
884
886
  this.regionUrlProvider?.resetAttempts();
885
887
  // reconnect success
886
- this.emit(EngineEvent.Restarted, joinResponse);
888
+ this.emit(EngineEvent.Restarted);
887
889
  } catch (error) {
888
890
  const nextRegionUrl = await this.regionUrlProvider?.getNextBestRegionUrl();
889
891
  if (nextRegionUrl) {
@@ -992,7 +994,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
992
994
  });
993
995
  }
994
996
 
995
- async waitForPCReconnected() {
997
+ private async waitForPCReconnected() {
996
998
  const startTime = Date.now();
997
999
  let now = startTime;
998
1000
  this.pcState = PCState.Reconnecting;
@@ -1022,6 +1024,24 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
1022
1024
  throw new ConnectionError('could not establish PC connection');
1023
1025
  }
1024
1026
 
1027
+ waitForRestarted = () => {
1028
+ return new Promise<void>((resolve, reject) => {
1029
+ if (this.pcState === PCState.Connected) {
1030
+ resolve();
1031
+ }
1032
+ const onRestarted = () => {
1033
+ this.off(EngineEvent.Disconnected, onDisconnected);
1034
+ resolve();
1035
+ };
1036
+ const onDisconnected = () => {
1037
+ this.off(EngineEvent.Restarted, onRestarted);
1038
+ reject();
1039
+ };
1040
+ this.once(EngineEvent.Restarted, onRestarted);
1041
+ this.once(EngineEvent.Disconnected, onDisconnected);
1042
+ });
1043
+ };
1044
+
1025
1045
  /* @internal */
1026
1046
  async sendDataPacket(packet: DataPacket, kind: DataPacket_Kind) {
1027
1047
  const msg = DataPacket.encode(packet).finish();
@@ -1246,8 +1266,9 @@ export type EngineEventCallbacks = {
1246
1266
  resuming: () => void;
1247
1267
  resumed: () => void;
1248
1268
  restarting: () => void;
1249
- restarted: (joinResp: JoinResponse) => void;
1269
+ restarted: () => void;
1250
1270
  signalResumed: () => void;
1271
+ signalRestarted: (joinResp: JoinResponse) => void;
1251
1272
  closing: () => void;
1252
1273
  mediaTrackAdded: (
1253
1274
  track: MediaStreamTrack,
@@ -1,6 +1,6 @@
1
+ import log from '../logger';
1
2
  import type { RegionInfo, RegionSettings } from '../proto/livekit_rtc';
2
3
  import { ConnectionError, ConnectionErrorReason } from './errors';
3
- import log from '../logger';
4
4
  import { isCloud } from './utils';
5
5
 
6
6
  export class RegionUrlProvider {