@dtelecom/livekit-client 1.12.21 → 1.12.23

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.
@@ -3647,8 +3647,12 @@ Reader$1.prototype.bytes = function read_bytes() {
3647
3647
  if (Array.isArray(this.buf))
3648
3648
  // plain array
3649
3649
  return this.buf.slice(start, end);
3650
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
3651
- ? new this.buf.constructor(0) : this._slice.call(this.buf, start, end);
3650
+ if (start === end) {
3651
+ // fix for IE 10/Win8 and others' subarray returning array of size 1
3652
+ var nativeBuffer = util$2.Buffer;
3653
+ return nativeBuffer ? nativeBuffer.alloc(0) : new this.buf.constructor(0);
3654
+ }
3655
+ return this._slice.call(this.buf, start, end);
3652
3656
  };
3653
3657
 
3654
3658
  /**
@@ -14198,7 +14202,7 @@ function getMatch(exp, ua) {
14198
14202
  return match && match.length >= id && match[id] || '';
14199
14203
  }
14200
14204
 
14201
- var version$1 = "1.12.21";
14205
+ var version$1 = "1.12.23";
14202
14206
 
14203
14207
  const version = version$1;
14204
14208
  const protocolVersion = 9;
@@ -15724,8 +15728,18 @@ class SignalClient {
15724
15728
  const clientInfo = getClientInfo();
15725
15729
  const params = createConnectionParams(token, clientInfo, opts);
15726
15730
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
15731
+ const cleanup = () => {
15732
+ clearTimeout(wsTimeout);
15733
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
15734
+ };
15735
+ const wsTimeout = setTimeout(() => {
15736
+ livekitLogger.debug('websocket connection timeout');
15737
+ cleanup();
15738
+ reject(new ConnectionError(opts.reconnect ? 'signal reconnect timed out' : 'signal connection timed out', 1 /* ConnectionErrorReason.ServerUnreachable */));
15739
+ }, opts.websocketTimeout || 3000);
15727
15740
  const abortHandler = () => __awaiter(this, void 0, void 0, function* () {
15728
15741
  this.close();
15742
+ cleanup();
15729
15743
  reject(new ConnectionError('room connection has been cancelled (signal)'));
15730
15744
  });
15731
15745
  if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
@@ -15750,8 +15764,9 @@ class SignalClient {
15750
15764
  }
15751
15765
  } catch (e) {
15752
15766
  reject(new ConnectionError('server was not reachable', 1 /* ConnectionErrorReason.ServerUnreachable */));
15767
+ } finally {
15768
+ cleanup();
15753
15769
  }
15754
-
15755
15770
  return;
15756
15771
  }
15757
15772
  // other errors, handle
@@ -15775,7 +15790,7 @@ class SignalClient {
15775
15790
  // handle join message only
15776
15791
  if (((_a = resp.message) === null || _a === void 0 ? void 0 : _a.$case) === 'join') {
15777
15792
  this.isConnected = true;
15778
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
15793
+ cleanup();
15779
15794
  this.pingTimeoutDuration = resp.message.join.pingTimeout;
15780
15795
  this.pingIntervalDuration = resp.message.join.pingInterval;
15781
15796
  if (this.pingTimeoutDuration && this.pingTimeoutDuration > 0) {
@@ -15789,7 +15804,7 @@ class SignalClient {
15789
15804
  } else if (opts.reconnect) {
15790
15805
  // in reconnecting, any message received means signal reconnected
15791
15806
  this.isConnected = true;
15792
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
15807
+ cleanup();
15793
15808
  this.startPingInterval();
15794
15809
  if (((_b = resp.message) === null || _b === void 0 ? void 0 : _b.$case) === 'reconnect') {
15795
15810
  resolve((_c = resp.message) === null || _c === void 0 ? void 0 : _c.reconnect);
@@ -17171,6 +17186,34 @@ class E2EEManager extends EventEmitter {
17171
17186
  }
17172
17187
  }
17173
17188
 
17189
+ class FallbackUrlProvider {
17190
+ constructor(fallbackUrls) {
17191
+ this.attemptedUrls = [];
17192
+ this.fallbackUrls = fallbackUrls;
17193
+ }
17194
+ isAvailable() {
17195
+ return this.fallbackUrls && this.fallbackUrls.length > 0;
17196
+ }
17197
+ getNextUrl() {
17198
+ var _a;
17199
+ if (!this.isAvailable()) {
17200
+ throw Error('no fallback urls proviced');
17201
+ }
17202
+ const urlsLeft = (_a = this.fallbackUrls) === null || _a === void 0 ? void 0 : _a.filter(url => !this.attemptedUrls.find(attempted => attempted === url));
17203
+ if (urlsLeft && urlsLeft.length > 0) {
17204
+ const nextUrl = urlsLeft[0];
17205
+ this.attemptedUrls.push(nextUrl);
17206
+ livekitLogger.debug("next url: ".concat(nextUrl));
17207
+ return nextUrl;
17208
+ } else {
17209
+ return null;
17210
+ }
17211
+ }
17212
+ resetAttempts() {
17213
+ this.attemptedUrls = [];
17214
+ }
17215
+ }
17216
+
17174
17217
  var parser$1 = {};
17175
17218
 
17176
17219
  var grammar$2 = {exports: {}};
@@ -19274,38 +19317,11 @@ function videoLayersFromEncodings(width, height, encodings, svc) {
19274
19317
  });
19275
19318
  }
19276
19319
 
19277
- class FallbackUrlProvider {
19278
- constructor(fallbackUrls) {
19279
- this.attemptedUrls = [];
19280
- this.fallbackUrls = fallbackUrls;
19281
- }
19282
- isAvailable() {
19283
- return this.fallbackUrls && this.fallbackUrls.length > 0;
19284
- }
19285
- getNextUrl() {
19286
- var _a;
19287
- if (!this.isAvailable()) {
19288
- throw Error('no fallback urls proviced');
19289
- }
19290
- const urlsLeft = (_a = this.fallbackUrls) === null || _a === void 0 ? void 0 : _a.filter(url => !this.attemptedUrls.find(attempted => attempted === url));
19291
- if (urlsLeft && urlsLeft.length > 0) {
19292
- const nextUrl = urlsLeft[0];
19293
- this.attemptedUrls.push(nextUrl);
19294
- livekitLogger.debug("next url: ".concat(nextUrl));
19295
- return nextUrl;
19296
- } else {
19297
- return null;
19298
- }
19299
- }
19300
- resetAttempts() {
19301
- this.attemptedUrls = [];
19302
- }
19303
- }
19304
-
19305
19320
  const lossyDataChannel = '_lossy';
19306
19321
  const reliableDataChannel = '_reliable';
19307
19322
  const minReconnectWait = 2 * 1000;
19308
19323
  const leaveReconnect = 'leave-reconnect';
19324
+ const joinRetryDelayMs = 750;
19309
19325
  var PCState;
19310
19326
  (function (PCState) {
19311
19327
  PCState[PCState["New"] = 0] = "New";
@@ -19522,7 +19538,7 @@ class RTCEngine extends EventEmitter {
19522
19538
  if (e instanceof ConnectionError && navigator.onLine === true) {
19523
19539
  if (e.reason === 1 /* ConnectionErrorReason.ServerUnreachable */) {
19524
19540
  if (this.joinAttempts <= this.maxJoinAttempts) {
19525
- yield sleep(220 * this.joinAttempts);
19541
+ yield sleep(Math.min(joinRetryDelayMs * this.joinAttempts, 2000));
19526
19542
  livekitLogger.warn("Couldn't connect to server, attempt ".concat(this.joinAttempts, " of ").concat(this.maxJoinAttempts));
19527
19543
  return this.join(url, token, opts, abortSignal);
19528
19544
  }
@@ -23034,7 +23050,8 @@ class Room extends EventEmitter {
23034
23050
  adaptiveStream: typeof roomOptions.adaptiveStream === 'object' ? true : roomOptions.adaptiveStream,
23035
23051
  maxRetries: connectOptions.maxRetries,
23036
23052
  e2eeEnabled: !!this.e2eeManager,
23037
- fallbackUrs: connectOptions.fallbackUrls
23053
+ fallbackUrs: connectOptions.fallbackUrls,
23054
+ websocketTimeout: connectOptions.websocketTimeout
23038
23055
  }, abortController.signal);
23039
23056
  let serverInfo = joinResponse.serverInfo;
23040
23057
  if (!serverInfo) {
@@ -23121,12 +23138,14 @@ class Room extends EventEmitter {
23121
23138
  }
23122
23139
  // also hook unload event
23123
23140
  if (isWeb() && this.options.disconnectOnPageLeave) {
23124
- // capturing both 'pagehide' and 'beforeunload' to capture broadest set of browser behaviors
23141
+ // capture page leave across browser behaviors
23125
23142
  window.addEventListener('pagehide', this.onPageLeave);
23126
- window.addEventListener('beforeunload', this.onPageLeave);
23143
+ if (this.options.disconnectOnPageLeave !== 'pagehide') {
23144
+ window.addEventListener('beforeunload', this.onPageLeave);
23145
+ }
23127
23146
  }
23128
23147
  if (isWeb()) {
23129
- document.addEventListener('freeze', this.onPageLeave);
23148
+ window.addEventListener('freeze', this.onPageLeave);
23130
23149
  (_c = navigator.mediaDevices) === null || _c === void 0 ? void 0 : _c.addEventListener('devicechange', this.handleDeviceChange);
23131
23150
  }
23132
23151
  this.setAndEmitConnectionState(ConnectionState.Connected);