@dtelecom/livekit-client 1.12.15 → 1.12.17
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.
- package/dist/livekit-client.esm.mjs +89 -14
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts +1 -0
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/options.d.ts +2 -0
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/room/FallbackUrlProvider.d.ts +9 -0
- package/dist/src/room/FallbackUrlProvider.d.ts.map +1 -0
- package/dist/src/room/RTCEngine.d.ts +2 -0
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +1 -0
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +3 -1
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/ts4.2/src/api/SignalClient.d.ts +1 -0
- package/dist/ts4.2/src/options.d.ts +2 -0
- package/dist/ts4.2/src/room/FallbackUrlProvider.d.ts +9 -0
- package/dist/ts4.2/src/room/RTCEngine.d.ts +2 -0
- package/dist/ts4.2/src/room/Room.d.ts +1 -0
- package/dist/ts4.2/src/room/utils.d.ts +3 -1
- package/package.json +1 -1
- package/src/api/SignalClient.ts +1 -0
- package/src/options.ts +3 -0
- package/src/room/FallbackUrlProvider.ts +36 -0
- package/src/room/RTCEngine.ts +21 -2
- package/src/room/Room.ts +43 -8
- package/src/room/utils.ts +14 -1
|
@@ -14198,7 +14198,7 @@ function getMatch(exp, ua) {
|
|
|
14198
14198
|
return match && match.length >= id && match[id] || '';
|
|
14199
14199
|
}
|
|
14200
14200
|
|
|
14201
|
-
var version$1 = "1.12.
|
|
14201
|
+
var version$1 = "1.12.17";
|
|
14202
14202
|
|
|
14203
14203
|
const version = version$1;
|
|
14204
14204
|
const protocolVersion = 9;
|
|
@@ -15572,6 +15572,16 @@ function unwrapConstraint(constraint) {
|
|
|
15572
15572
|
}
|
|
15573
15573
|
throw Error('could not unwrap constraint');
|
|
15574
15574
|
}
|
|
15575
|
+
function getDisconnectReasonFromConnectionError(e) {
|
|
15576
|
+
switch (e.reason) {
|
|
15577
|
+
case 3 /* ConnectionErrorReason.Cancelled */:
|
|
15578
|
+
return DisconnectReason.CLIENT_INITIATED;
|
|
15579
|
+
case 1 /* ConnectionErrorReason.ServerUnreachable */:
|
|
15580
|
+
return DisconnectReason.JOIN_FAILURE;
|
|
15581
|
+
default:
|
|
15582
|
+
return DisconnectReason.UNKNOWN_REASON;
|
|
15583
|
+
}
|
|
15584
|
+
}
|
|
15575
15585
|
|
|
15576
15586
|
var QueueTaskStatus;
|
|
15577
15587
|
(function (QueueTaskStatus) {
|
|
@@ -19239,6 +19249,34 @@ function videoLayersFromEncodings(width, height, encodings, svc) {
|
|
|
19239
19249
|
});
|
|
19240
19250
|
}
|
|
19241
19251
|
|
|
19252
|
+
class FallbackUrlProvider {
|
|
19253
|
+
constructor(fallbackUrls) {
|
|
19254
|
+
this.attemptedUrls = [];
|
|
19255
|
+
this.fallbackUrls = fallbackUrls;
|
|
19256
|
+
}
|
|
19257
|
+
isAvailable() {
|
|
19258
|
+
return this.fallbackUrls && this.fallbackUrls.length > 0;
|
|
19259
|
+
}
|
|
19260
|
+
getNextUrl() {
|
|
19261
|
+
var _a;
|
|
19262
|
+
if (!this.isAvailable()) {
|
|
19263
|
+
throw Error('no fallback urls proviced');
|
|
19264
|
+
}
|
|
19265
|
+
const urlsLeft = (_a = this.fallbackUrls) === null || _a === void 0 ? void 0 : _a.filter(url => !this.attemptedUrls.find(attempted => attempted === url));
|
|
19266
|
+
if (urlsLeft && urlsLeft.length > 0) {
|
|
19267
|
+
const nextUrl = urlsLeft[0];
|
|
19268
|
+
this.attemptedUrls.push(nextUrl);
|
|
19269
|
+
livekitLogger.debug("next url: ".concat(nextUrl));
|
|
19270
|
+
return nextUrl;
|
|
19271
|
+
} else {
|
|
19272
|
+
return null;
|
|
19273
|
+
}
|
|
19274
|
+
}
|
|
19275
|
+
resetAttempts() {
|
|
19276
|
+
this.attemptedUrls = [];
|
|
19277
|
+
}
|
|
19278
|
+
}
|
|
19279
|
+
|
|
19242
19280
|
const lossyDataChannel = '_lossy';
|
|
19243
19281
|
const reliableDataChannel = '_reliable';
|
|
19244
19282
|
const minReconnectWait = 2 * 1000;
|
|
@@ -19373,6 +19411,9 @@ class RTCEngine extends EventEmitter {
|
|
|
19373
19411
|
if (this.url && this.token && isCloud(new URL(this.url))) {
|
|
19374
19412
|
this.regionUrlProvider = new RegionUrlProvider(this.url, this.token);
|
|
19375
19413
|
}
|
|
19414
|
+
if (this.fallbackUrls) {
|
|
19415
|
+
this.fallbackUrlProvider = new FallbackUrlProvider(this.fallbackUrls);
|
|
19416
|
+
}
|
|
19376
19417
|
this.reconnectTimeout = CriticalTimers.setTimeout(() => this.attemptReconnect(disconnectReason), delay);
|
|
19377
19418
|
};
|
|
19378
19419
|
this.waitForRestarted = () => {
|
|
@@ -19433,6 +19474,8 @@ class RTCEngine extends EventEmitter {
|
|
|
19433
19474
|
this.url = url;
|
|
19434
19475
|
this.token = token;
|
|
19435
19476
|
this.signalOpts = opts;
|
|
19477
|
+
this.maxJoinAttempts = opts.maxRetries;
|
|
19478
|
+
this.fallbackUrls = opts.fallbackUrs;
|
|
19436
19479
|
try {
|
|
19437
19480
|
this.joinAttempts += 1;
|
|
19438
19481
|
const joinResponse = yield this.client.join(url, token, opts, abortSignal);
|
|
@@ -19919,7 +19962,7 @@ class RTCEngine extends EventEmitter {
|
|
|
19919
19962
|
});
|
|
19920
19963
|
// unrecoverable
|
|
19921
19964
|
recoverable = false;
|
|
19922
|
-
} else if (!(e instanceof SignalReconnectError)) {
|
|
19965
|
+
} else if (e instanceof SignalReconnectError && e.message === 'server was not reachable' || !(e instanceof SignalReconnectError)) {
|
|
19923
19966
|
// cannot resume
|
|
19924
19967
|
this.fullReconnectOnNext = true;
|
|
19925
19968
|
}
|
|
@@ -19947,7 +19990,7 @@ class RTCEngine extends EventEmitter {
|
|
|
19947
19990
|
return null;
|
|
19948
19991
|
}
|
|
19949
19992
|
restartConnection(regionUrl) {
|
|
19950
|
-
var _a, _b, _c;
|
|
19993
|
+
var _a, _b, _c, _d, _e;
|
|
19951
19994
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19952
19995
|
try {
|
|
19953
19996
|
if (!this.url || !this.token) {
|
|
@@ -19983,16 +20026,21 @@ class RTCEngine extends EventEmitter {
|
|
|
19983
20026
|
this.emit(EngineEvent.SignalRestarted, joinResponse);
|
|
19984
20027
|
yield this.waitForPCReconnected();
|
|
19985
20028
|
(_a = this.regionUrlProvider) === null || _a === void 0 ? void 0 : _a.resetAttempts();
|
|
20029
|
+
(_b = this.fallbackUrlProvider) === null || _b === void 0 ? void 0 : _b.resetAttempts();
|
|
19986
20030
|
// reconnect success
|
|
19987
20031
|
this.emit(EngineEvent.Restarted);
|
|
19988
20032
|
} catch (error) {
|
|
19989
|
-
|
|
20033
|
+
let nextRegionUrl = yield (_c = this.regionUrlProvider) === null || _c === void 0 ? void 0 : _c.getNextBestRegionUrl();
|
|
20034
|
+
if (this.fallbackUrlProvider && !nextRegionUrl) {
|
|
20035
|
+
nextRegionUrl = this.fallbackUrlProvider.getNextUrl();
|
|
20036
|
+
}
|
|
19990
20037
|
if (nextRegionUrl) {
|
|
19991
20038
|
yield this.restartConnection(nextRegionUrl);
|
|
19992
20039
|
return;
|
|
19993
20040
|
} else {
|
|
19994
20041
|
// no more regions to try (or we're not on cloud)
|
|
19995
|
-
(
|
|
20042
|
+
(_d = this.regionUrlProvider) === null || _d === void 0 ? void 0 : _d.resetAttempts();
|
|
20043
|
+
(_e = this.fallbackUrlProvider) === null || _e === void 0 ? void 0 : _e.resetAttempts();
|
|
19996
20044
|
throw error;
|
|
19997
20045
|
}
|
|
19998
20046
|
}
|
|
@@ -22892,6 +22940,9 @@ class Room extends EventEmitter {
|
|
|
22892
22940
|
}
|
|
22893
22941
|
this.setAndEmitConnectionState(ConnectionState.Connecting);
|
|
22894
22942
|
const urlProvider = new RegionUrlProvider(url, token);
|
|
22943
|
+
if (opts === null || opts === void 0 ? void 0 : opts.fallbackUrls) {
|
|
22944
|
+
this.fallbackUrlProvider = new FallbackUrlProvider(opts.fallbackUrls);
|
|
22945
|
+
}
|
|
22895
22946
|
const connectFn = (resolve, reject, regionUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
22896
22947
|
var _b;
|
|
22897
22948
|
if (this.abortController) {
|
|
@@ -22905,12 +22956,17 @@ class Room extends EventEmitter {
|
|
|
22905
22956
|
this.abortController = undefined;
|
|
22906
22957
|
resolve();
|
|
22907
22958
|
} catch (e) {
|
|
22908
|
-
if (isCloud(new URL(url)) && e instanceof ConnectionError && e.reason !== 3 /* ConnectionErrorReason.Cancelled */) {
|
|
22959
|
+
if ((isCloud(new URL(url)) || this.fallbackUrlProvider) && e instanceof ConnectionError && e.reason !== 3 /* ConnectionErrorReason.Cancelled */) {
|
|
22909
22960
|
let nextUrl = null;
|
|
22910
22961
|
try {
|
|
22911
|
-
|
|
22962
|
+
if (this.fallbackUrlProvider) {
|
|
22963
|
+
nextUrl = this.fallbackUrlProvider.getNextUrl();
|
|
22964
|
+
} else {
|
|
22965
|
+
nextUrl = yield urlProvider.getNextBestRegionUrl((_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal);
|
|
22966
|
+
}
|
|
22912
22967
|
} catch (error) {
|
|
22913
22968
|
if (error instanceof ConnectionError && (error.status === 401 || error.reason === 3 /* ConnectionErrorReason.Cancelled */)) {
|
|
22969
|
+
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
|
|
22914
22970
|
reject(error);
|
|
22915
22971
|
return;
|
|
22916
22972
|
}
|
|
@@ -22919,9 +22975,15 @@ class Room extends EventEmitter {
|
|
|
22919
22975
|
livekitLogger.debug('initial connection failed, retrying with another region');
|
|
22920
22976
|
yield connectFn(resolve, reject, nextUrl);
|
|
22921
22977
|
} else {
|
|
22978
|
+
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, getDisconnectReasonFromConnectionError(e));
|
|
22922
22979
|
reject(e);
|
|
22923
22980
|
}
|
|
22924
22981
|
} else {
|
|
22982
|
+
let disconnectReason = DisconnectReason.UNKNOWN_REASON;
|
|
22983
|
+
if (e instanceof ConnectionError) {
|
|
22984
|
+
disconnectReason = getDisconnectReasonFromConnectionError(e);
|
|
22985
|
+
}
|
|
22986
|
+
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, disconnectReason);
|
|
22925
22987
|
reject(e);
|
|
22926
22988
|
}
|
|
22927
22989
|
}
|
|
@@ -22937,7 +22999,8 @@ class Room extends EventEmitter {
|
|
|
22937
22999
|
publishOnly: connectOptions.publishOnly,
|
|
22938
23000
|
adaptiveStream: typeof roomOptions.adaptiveStream === 'object' ? true : roomOptions.adaptiveStream,
|
|
22939
23001
|
maxRetries: connectOptions.maxRetries,
|
|
22940
|
-
e2eeEnabled: !!this.e2eeManager
|
|
23002
|
+
e2eeEnabled: !!this.e2eeManager,
|
|
23003
|
+
fallbackUrs: connectOptions.fallbackUrls
|
|
22941
23004
|
}, abortController.signal);
|
|
22942
23005
|
let serverInfo = joinResponse.serverInfo;
|
|
22943
23006
|
if (!serverInfo) {
|
|
@@ -22995,8 +23058,8 @@ class Room extends EventEmitter {
|
|
|
22995
23058
|
this.setupLocalParticipantEvents();
|
|
22996
23059
|
this.emit(RoomEvent.SignalConnected);
|
|
22997
23060
|
} catch (err) {
|
|
23061
|
+
yield this.engine.close();
|
|
22998
23062
|
this.recreateEngine();
|
|
22999
|
-
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
|
|
23000
23063
|
const resultingError = new ConnectionError("could not establish signal connection");
|
|
23001
23064
|
if (err instanceof Error) {
|
|
23002
23065
|
resultingError.message = "".concat(resultingError.message, ": ").concat(err.message);
|
|
@@ -23011,15 +23074,15 @@ class Room extends EventEmitter {
|
|
|
23011
23074
|
throw resultingError;
|
|
23012
23075
|
}
|
|
23013
23076
|
if (abortController.signal.aborted) {
|
|
23077
|
+
yield this.engine.close();
|
|
23014
23078
|
this.recreateEngine();
|
|
23015
|
-
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
|
|
23016
23079
|
throw new ConnectionError("Connection attempt aborted");
|
|
23017
23080
|
}
|
|
23018
23081
|
try {
|
|
23019
23082
|
yield this.engine.waitForPCInitialConnection(this.connOptions.peerConnectionTimeout, abortController);
|
|
23020
23083
|
} catch (e) {
|
|
23084
|
+
yield this.engine.close();
|
|
23021
23085
|
this.recreateEngine();
|
|
23022
|
-
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
|
|
23023
23086
|
throw e;
|
|
23024
23087
|
}
|
|
23025
23088
|
// also hook unload event
|
|
@@ -23536,10 +23599,22 @@ class Room extends EventEmitter {
|
|
|
23536
23599
|
* @experimental
|
|
23537
23600
|
*/
|
|
23538
23601
|
prepareConnection(url) {
|
|
23602
|
+
var _a;
|
|
23539
23603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23604
|
+
if ((_a = this.connOptions) === null || _a === void 0 ? void 0 : _a.fallbackUrls) {
|
|
23605
|
+
this.fallbackUrlProvider = new FallbackUrlProvider(this.connOptions.fallbackUrls);
|
|
23606
|
+
const nextUrl = this.fallbackUrlProvider.getNextUrl();
|
|
23607
|
+
if (nextUrl && this.state === ConnectionState.Disconnected) {
|
|
23608
|
+
yield fetch("http".concat(nextUrl.substring(2)), {
|
|
23609
|
+
method: 'HEAD'
|
|
23610
|
+
});
|
|
23611
|
+
livekitLogger.debug("prepared connection to ".concat(nextUrl));
|
|
23612
|
+
}
|
|
23613
|
+
} else {
|
|
23614
|
+
yield fetch("http".concat(url.substring(2)), {
|
|
23615
|
+
method: 'HEAD'
|
|
23616
|
+
});
|
|
23617
|
+
}
|
|
23543
23618
|
});
|
|
23544
23619
|
}
|
|
23545
23620
|
/**
|