@afterrealism/dendri-client 2.4.0 → 2.5.0
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/README.md +8 -17
- package/dist/{chunk-MBMSG4EC.js → chunk-3CE674DE.js} +72 -15
- package/dist/chunk-3CE674DE.js.map +1 -0
- package/dist/dendri.browser.global.js +70 -13
- package/dist/dendri.browser.global.js.map +1 -1
- package/dist/dendri.cjs +70 -13
- package/dist/dendri.cjs.map +1 -1
- package/dist/dendri.d.cts +13 -4
- package/dist/dendri.d.ts +13 -4
- package/dist/dendri.js +2 -2
- package/dist/dendri.min.global.js +7 -7
- package/dist/dendri.min.global.js.map +1 -1
- package/dist/serializer.msgpack.d.cts +14 -0
- package/dist/serializer.msgpack.d.ts +14 -0
- package/dist/{store-DVE0ih44.d.cts → store-C3Nwl62R.d.cts} +14 -0
- package/dist/{store-DVE0ih44.d.ts → store-C3Nwl62R.d.ts} +14 -0
- package/dist/store.cjs +70 -13
- package/dist/store.cjs.map +1 -1
- package/dist/store.d.cts +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/store.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-MBMSG4EC.js.map +0 -1
package/dist/dendri.cjs
CHANGED
|
@@ -3533,7 +3533,7 @@ var Logger = class {
|
|
|
3533
3533
|
var logger_default = new Logger();
|
|
3534
3534
|
|
|
3535
3535
|
// src/api.ts
|
|
3536
|
-
var version = "2.
|
|
3536
|
+
var version = "2.5.0";
|
|
3537
3537
|
var API = class _API {
|
|
3538
3538
|
constructor(_options) {
|
|
3539
3539
|
this._options = _options;
|
|
@@ -3546,6 +3546,7 @@ var API = class _API {
|
|
|
3546
3546
|
const url = new URL(`${protocol}://${host}:${port}${path}${key}/${method}`);
|
|
3547
3547
|
url.searchParams.set("ts", `${Date.now()}${Math.random()}`);
|
|
3548
3548
|
url.searchParams.set("version", version);
|
|
3549
|
+
if (this._options.apiKey) url.searchParams.set("api_key", this._options.apiKey);
|
|
3549
3550
|
const controller = new AbortController();
|
|
3550
3551
|
const timeoutId = setTimeout(() => controller.abort(), _API.FETCH_TIMEOUT);
|
|
3551
3552
|
return fetch(url.href, {
|
|
@@ -3574,11 +3575,12 @@ var API = class _API {
|
|
|
3574
3575
|
async getTurnCredentials() {
|
|
3575
3576
|
const protocol = this._options.secure ? "https" : "http";
|
|
3576
3577
|
const { host, port, path, key } = this._options;
|
|
3577
|
-
const url = `${protocol}://${host}:${port}${path}${key}/turn-credentials
|
|
3578
|
+
const url = new URL(`${protocol}://${host}:${port}${path}${key}/turn-credentials`);
|
|
3579
|
+
if (this._options.apiKey) url.searchParams.set("api_key", this._options.apiKey);
|
|
3578
3580
|
try {
|
|
3579
3581
|
const controller = new AbortController();
|
|
3580
3582
|
const timeoutId = setTimeout(() => controller.abort(), _API.FETCH_TIMEOUT);
|
|
3581
|
-
const response = await fetch(url, {
|
|
3583
|
+
const response = await fetch(url.href, {
|
|
3582
3584
|
referrerPolicy: this._options.referrerPolicy,
|
|
3583
3585
|
signal: controller.signal
|
|
3584
3586
|
}).finally(() => clearTimeout(timeoutId));
|
|
@@ -5405,17 +5407,29 @@ var PollingTransport = class _PollingTransport extends SignalingTransport {
|
|
|
5405
5407
|
_heartbeatTimer;
|
|
5406
5408
|
_lastSeq = 0;
|
|
5407
5409
|
_baseUrl;
|
|
5410
|
+
_key;
|
|
5411
|
+
_jwt;
|
|
5412
|
+
_apiKey;
|
|
5408
5413
|
_pingInterval;
|
|
5409
5414
|
_abortController;
|
|
5410
5415
|
/** Backoff schedule base delays in milliseconds. */
|
|
5411
5416
|
static BACKOFF_SCHEDULE = [0, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
5412
5417
|
/** Random jitter range in milliseconds (applied as +/-). */
|
|
5413
5418
|
static BACKOFF_JITTER = 500;
|
|
5414
|
-
constructor(secure, host, port, path,
|
|
5419
|
+
constructor(secure, host, port, path, key, pingInterval = 5e3, jwt, apiKey) {
|
|
5415
5420
|
super();
|
|
5416
5421
|
const protocol = secure ? "https://" : "http://";
|
|
5417
5422
|
this._baseUrl = `${protocol + host}:${port}${path}`;
|
|
5418
5423
|
this._pingInterval = pingInterval;
|
|
5424
|
+
this._key = key;
|
|
5425
|
+
this._jwt = jwt;
|
|
5426
|
+
this._apiKey = apiKey;
|
|
5427
|
+
}
|
|
5428
|
+
/** Append the shared auth params (key, jwt, api_key) so every HTTP call authenticates like the WS transport. */
|
|
5429
|
+
_applyAuthParams(params) {
|
|
5430
|
+
params.set("key", this._key);
|
|
5431
|
+
if (this._jwt) params.set("jwt", this._jwt);
|
|
5432
|
+
if (this._apiKey) params.set("api_key", this._apiKey);
|
|
5419
5433
|
}
|
|
5420
5434
|
get reconnectAttempt() {
|
|
5421
5435
|
return this._reconnectAttempt;
|
|
@@ -5443,6 +5457,7 @@ var PollingTransport = class _PollingTransport extends SignalingTransport {
|
|
|
5443
5457
|
id: this._id,
|
|
5444
5458
|
token: this._token
|
|
5445
5459
|
});
|
|
5460
|
+
this._applyAuthParams(params);
|
|
5446
5461
|
if (this._lastSeq > 0) params.set("last_seq", String(this._lastSeq));
|
|
5447
5462
|
const response = await fetch(`${this._baseUrl}http/poll?${params}`, {
|
|
5448
5463
|
signal: this._abortController.signal
|
|
@@ -5481,6 +5496,7 @@ var PollingTransport = class _PollingTransport extends SignalingTransport {
|
|
|
5481
5496
|
id: this._id,
|
|
5482
5497
|
token: this._token
|
|
5483
5498
|
});
|
|
5499
|
+
this._applyAuthParams(params);
|
|
5484
5500
|
try {
|
|
5485
5501
|
await fetch(`${this._baseUrl}http/send?${params}`, {
|
|
5486
5502
|
method: "POST",
|
|
@@ -5545,13 +5561,16 @@ var PollingTransport = class _PollingTransport extends SignalingTransport {
|
|
|
5545
5561
|
};
|
|
5546
5562
|
|
|
5547
5563
|
// src/socket.ts
|
|
5548
|
-
var version2 = "2.
|
|
5564
|
+
var version2 = "2.5.0";
|
|
5549
5565
|
var Socket = class _Socket extends SignalingTransport {
|
|
5550
|
-
constructor(secure, host, port, path, key, pingInterval = 5e3, jwt) {
|
|
5566
|
+
constructor(secure, host, port, path, key, pingInterval = 5e3, jwt, apiKey) {
|
|
5551
5567
|
super();
|
|
5552
5568
|
this.pingInterval = pingInterval;
|
|
5553
5569
|
const wsProtocol = secure ? "wss://" : "ws://";
|
|
5554
5570
|
this._baseUrl = `${wsProtocol + host}:${port}${path}dendri?key=${key}`;
|
|
5571
|
+
if (apiKey) {
|
|
5572
|
+
this._baseUrl += `&api_key=${encodeURIComponent(apiKey)}`;
|
|
5573
|
+
}
|
|
5555
5574
|
this._jwt = jwt;
|
|
5556
5575
|
}
|
|
5557
5576
|
pingInterval;
|
|
@@ -5857,18 +5876,28 @@ var SSETransport = class _SSETransport extends SignalingTransport {
|
|
|
5857
5876
|
_heartbeatTimer;
|
|
5858
5877
|
_lastSeq = 0;
|
|
5859
5878
|
_baseUrl;
|
|
5879
|
+
_key;
|
|
5860
5880
|
_jwt;
|
|
5881
|
+
_apiKey;
|
|
5861
5882
|
_pingInterval;
|
|
5862
5883
|
/** Backoff schedule base delays in milliseconds. */
|
|
5863
5884
|
static BACKOFF_SCHEDULE = [0, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
5864
5885
|
/** Random jitter range in milliseconds (applied as +/-). */
|
|
5865
5886
|
static BACKOFF_JITTER = 500;
|
|
5866
|
-
constructor(secure, host, port, path,
|
|
5887
|
+
constructor(secure, host, port, path, key, pingInterval = 5e3, jwt, apiKey) {
|
|
5867
5888
|
super();
|
|
5868
5889
|
const protocol = secure ? "https://" : "http://";
|
|
5869
5890
|
this._baseUrl = `${protocol + host}:${port}${path}`;
|
|
5870
5891
|
this._pingInterval = pingInterval;
|
|
5892
|
+
this._key = key;
|
|
5871
5893
|
this._jwt = jwt;
|
|
5894
|
+
this._apiKey = apiKey;
|
|
5895
|
+
}
|
|
5896
|
+
/** Append the shared auth params (key, jwt, api_key) so every HTTP call authenticates like the WS transport. */
|
|
5897
|
+
_applyAuthParams(params) {
|
|
5898
|
+
params.set("key", this._key);
|
|
5899
|
+
if (this._jwt) params.set("jwt", this._jwt);
|
|
5900
|
+
if (this._apiKey) params.set("api_key", this._apiKey);
|
|
5872
5901
|
}
|
|
5873
5902
|
get reconnectAttempt() {
|
|
5874
5903
|
return this._reconnectAttempt;
|
|
@@ -5886,10 +5915,9 @@ var SSETransport = class _SSETransport extends SignalingTransport {
|
|
|
5886
5915
|
if (this._disconnected) return;
|
|
5887
5916
|
const params = new URLSearchParams({
|
|
5888
5917
|
id: this._id,
|
|
5889
|
-
token: this._token
|
|
5890
|
-
key: "dendri"
|
|
5918
|
+
token: this._token
|
|
5891
5919
|
});
|
|
5892
|
-
|
|
5920
|
+
this._applyAuthParams(params);
|
|
5893
5921
|
if (this._lastSeq > 0) params.set("last_seq", String(this._lastSeq));
|
|
5894
5922
|
const url = `${this._baseUrl}http/sse?${params}`;
|
|
5895
5923
|
try {
|
|
@@ -5963,6 +5991,7 @@ var SSETransport = class _SSETransport extends SignalingTransport {
|
|
|
5963
5991
|
id: this._id,
|
|
5964
5992
|
token: this._token
|
|
5965
5993
|
});
|
|
5994
|
+
this._applyAuthParams(params);
|
|
5966
5995
|
try {
|
|
5967
5996
|
await fetch(`${this._baseUrl}http/send?${params}`, {
|
|
5968
5997
|
method: "POST",
|
|
@@ -6035,6 +6064,28 @@ var SSETransport = class _SSETransport extends SignalingTransport {
|
|
|
6035
6064
|
};
|
|
6036
6065
|
|
|
6037
6066
|
// src/dendri.ts
|
|
6067
|
+
function parseServerUrl(url) {
|
|
6068
|
+
let parsed;
|
|
6069
|
+
try {
|
|
6070
|
+
parsed = new URL(url);
|
|
6071
|
+
} catch {
|
|
6072
|
+
throw new Error(
|
|
6073
|
+
`Invalid Dendri "url" option: "${url}". Expected a full URL like "wss://signal.example.com".`
|
|
6074
|
+
);
|
|
6075
|
+
}
|
|
6076
|
+
const secure = parsed.protocol === "wss:" || parsed.protocol === "https:";
|
|
6077
|
+
if (!secure && parsed.protocol !== "ws:" && parsed.protocol !== "http:") {
|
|
6078
|
+
throw new Error(
|
|
6079
|
+
`Invalid Dendri "url" protocol: "${parsed.protocol}". Use wss://, ws://, https://, or http://.`
|
|
6080
|
+
);
|
|
6081
|
+
}
|
|
6082
|
+
return {
|
|
6083
|
+
host: parsed.hostname,
|
|
6084
|
+
port: parsed.port ? Number(parsed.port) : secure ? 443 : 80,
|
|
6085
|
+
secure,
|
|
6086
|
+
path: parsed.pathname || "/"
|
|
6087
|
+
};
|
|
6088
|
+
}
|
|
6038
6089
|
var Dendri = class _Dendri extends EventEmitterWithError {
|
|
6039
6090
|
static DEFAULT_KEY = "dendri";
|
|
6040
6091
|
_serializers = {
|
|
@@ -6125,6 +6176,9 @@ var Dendri = class _Dendri extends EventEmitterWithError {
|
|
|
6125
6176
|
} else if (id) {
|
|
6126
6177
|
userId = id.toString();
|
|
6127
6178
|
}
|
|
6179
|
+
if (providedOptions?.url) {
|
|
6180
|
+
providedOptions = { ...parseServerUrl(providedOptions.url), ...providedOptions };
|
|
6181
|
+
}
|
|
6128
6182
|
const normalizedOptions = {
|
|
6129
6183
|
debug: 0,
|
|
6130
6184
|
// 1: Errors, 2: Warnings, 3: All logs
|
|
@@ -6243,7 +6297,8 @@ var Dendri = class _Dendri extends EventEmitterWithError {
|
|
|
6243
6297
|
this._options.path,
|
|
6244
6298
|
this._options.key,
|
|
6245
6299
|
this._options.pingInterval,
|
|
6246
|
-
this._options.jwt
|
|
6300
|
+
this._options.jwt,
|
|
6301
|
+
this._options.apiKey
|
|
6247
6302
|
) : transport === "polling" ? new PollingTransport(
|
|
6248
6303
|
this._options.secure ?? false,
|
|
6249
6304
|
this._options.host,
|
|
@@ -6251,7 +6306,8 @@ var Dendri = class _Dendri extends EventEmitterWithError {
|
|
|
6251
6306
|
this._options.path,
|
|
6252
6307
|
this._options.key,
|
|
6253
6308
|
this._options.pingInterval,
|
|
6254
|
-
this._options.jwt
|
|
6309
|
+
this._options.jwt,
|
|
6310
|
+
this._options.apiKey
|
|
6255
6311
|
) : new Socket(
|
|
6256
6312
|
this._options.secure ?? false,
|
|
6257
6313
|
this._options.host,
|
|
@@ -6259,7 +6315,8 @@ var Dendri = class _Dendri extends EventEmitterWithError {
|
|
|
6259
6315
|
this._options.path,
|
|
6260
6316
|
this._options.key,
|
|
6261
6317
|
this._options.pingInterval,
|
|
6262
|
-
this._options.jwt
|
|
6318
|
+
this._options.jwt,
|
|
6319
|
+
this._options.apiKey
|
|
6263
6320
|
);
|
|
6264
6321
|
socket.on("message" /* Message */, (data) => {
|
|
6265
6322
|
this._handleMessage(data);
|