@stream-io/video-client 0.0.1-alpha.124 → 0.0.1-alpha.126
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/CHANGELOG.md +13 -0
- package/dist/index.browser.es.js +54 -33
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +54 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +54 -33
- package/dist/index.es.js.map +1 -1
- package/dist/src/rtc/flows/__tests__/latency.test.d.ts +1 -0
- package/dist/src/rtc/flows/latency.d.ts +20 -3
- package/package.json +1 -1
- package/src/rtc/flows/__tests__/latency.test.ts +46 -0
- package/src/rtc/flows/join.ts +2 -11
- package/src/rtc/flows/latency.ts +78 -30
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.1-alpha.126](https://github.com/GetStream/stream-video-js/compare/client0.0.1-alpha.125...client0.0.1-alpha.126) (2023-05-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **latency:** breadth-first time-boxed latency measurement ([#467](https://github.com/GetStream/stream-video-js/issues/467)) ([6d66003](https://github.com/GetStream/stream-video-js/commit/6d660032064667586902a9b410ee6dabfcc6b7ba))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.1-alpha.125](https://github.com/GetStream/stream-video-js/compare/client0.0.1-alpha.124...client0.0.1-alpha.125) (2023-05-08)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
## [0.0.1-alpha.124](https://github.com/GetStream/stream-video-js/compare/client0.0.1-alpha.123...client0.0.1-alpha.124) (2023-05-05)
|
|
6
19
|
|
|
7
20
|
|
package/dist/index.browser.es.js
CHANGED
|
@@ -7093,39 +7093,64 @@ const registerRingingCallEventHandlers = (call) => {
|
|
|
7093
7093
|
const toSeconds = (ms) => ms / 1000;
|
|
7094
7094
|
/**
|
|
7095
7095
|
* Measures the latency of the current client to the given endpoint.
|
|
7096
|
-
* Uses HTML Image tag in order to avoid CORS issues.
|
|
7097
7096
|
*
|
|
7098
7097
|
* @param endpoint the endpoint.
|
|
7099
|
-
* @param rounds the number of measuring rounds to perform.
|
|
7100
7098
|
* @param timeoutAfterMs the request cancellation period.
|
|
7101
7099
|
*/
|
|
7102
|
-
const measureResourceLoadLatencyTo = (endpoint,
|
|
7103
|
-
const
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
.
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
const
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
console.debug(`failed to measure latency to ${endpoint}`, e);
|
|
7123
|
-
measurements.push(-1); // indicate error in measurement
|
|
7124
|
-
}
|
|
7100
|
+
const measureResourceLoadLatencyTo = (endpoint, timeoutAfterMs = 1000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7101
|
+
const start = Date.now();
|
|
7102
|
+
const controller = new AbortController();
|
|
7103
|
+
const abortTimeout = setTimeout(() => {
|
|
7104
|
+
controller.abort();
|
|
7105
|
+
}, timeoutAfterMs);
|
|
7106
|
+
try {
|
|
7107
|
+
const src = new URL(endpoint);
|
|
7108
|
+
src.searchParams.set('r', `js_${Math.random() * 10000000}`);
|
|
7109
|
+
yield fetch(src.toString(), {
|
|
7110
|
+
signal: controller.signal,
|
|
7111
|
+
});
|
|
7112
|
+
const latency = Date.now() - start;
|
|
7113
|
+
return toSeconds(latency);
|
|
7114
|
+
}
|
|
7115
|
+
catch (e) {
|
|
7116
|
+
console.debug(`failed to measure latency to ${endpoint}`, e);
|
|
7117
|
+
return -1; // indicate error in measurement
|
|
7118
|
+
}
|
|
7119
|
+
finally {
|
|
7125
7120
|
// clear timeout in case fetch completes before timeout
|
|
7126
7121
|
clearTimeout(abortTimeout);
|
|
7127
|
-
}
|
|
7128
|
-
|
|
7122
|
+
}
|
|
7123
|
+
});
|
|
7124
|
+
/**
|
|
7125
|
+
* Measures the latency of the current client to the given edges.
|
|
7126
|
+
*
|
|
7127
|
+
* All measurements run in parallel,
|
|
7128
|
+
* and the whole process is limited by the given timeout.
|
|
7129
|
+
*
|
|
7130
|
+
* @param edges the edges to measure latency to.
|
|
7131
|
+
* @param attempts the number of attempts to measure latency.
|
|
7132
|
+
* @param attemptTimeoutAfterMs the request cancellation period per measurement.
|
|
7133
|
+
* @param measureTimeoutAfterMs the hard-limit for the whole measure process.
|
|
7134
|
+
*/
|
|
7135
|
+
const measureLatencyToEdges = (edges, { attempts = 3, attemptTimeoutAfterMs = 1000, measureTimeoutAfterMs = 1200, } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7136
|
+
const latencyByEdge = {};
|
|
7137
|
+
const measurements = [];
|
|
7138
|
+
const start = Date.now();
|
|
7139
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
7140
|
+
for (const edge of edges) {
|
|
7141
|
+
measurements.push(measureResourceLoadLatencyTo(edge.latency_url, attemptTimeoutAfterMs).then((latency) => {
|
|
7142
|
+
var _a;
|
|
7143
|
+
var _b;
|
|
7144
|
+
((_a = latencyByEdge[_b = edge.name]) !== null && _a !== void 0 ? _a : (latencyByEdge[_b] = [])).push(latency);
|
|
7145
|
+
}));
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
yield Promise.race([
|
|
7149
|
+
Promise.all(measurements),
|
|
7150
|
+
new Promise((resolve) => setTimeout(resolve, measureTimeoutAfterMs)),
|
|
7151
|
+
]);
|
|
7152
|
+
console.log(`finished measuring latency to ${edges.length} edges in ${Date.now() - start}ms.`);
|
|
7153
|
+
return latencyByEdge;
|
|
7129
7154
|
});
|
|
7130
7155
|
|
|
7131
7156
|
const getCascadingModeParams = () => {
|
|
@@ -7167,12 +7192,8 @@ const join = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0, f
|
|
|
7167
7192
|
};
|
|
7168
7193
|
});
|
|
7169
7194
|
const getCallEdgeServer = (httpClient, type, id, edges) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7170
|
-
const latencyByEdge = {};
|
|
7171
|
-
yield Promise.all(edges.map((edge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7172
|
-
latencyByEdge[edge.name] = yield measureResourceLoadLatencyTo(edge.latency_url);
|
|
7173
|
-
})));
|
|
7174
7195
|
const data = {
|
|
7175
|
-
latency_measurements:
|
|
7196
|
+
latency_measurements: yield measureLatencyToEdges(edges),
|
|
7176
7197
|
};
|
|
7177
7198
|
// FIXME OL: remove this once cascading is enabled by default
|
|
7178
7199
|
const cascadingModeParams = getCascadingModeParams();
|
|
@@ -10250,7 +10271,7 @@ class StreamClient {
|
|
|
10250
10271
|
}
|
|
10251
10272
|
getUserAgent() {
|
|
10252
10273
|
return (this.userAgent ||
|
|
10253
|
-
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.1-alpha.
|
|
10274
|
+
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.1-alpha.125"}`);
|
|
10254
10275
|
}
|
|
10255
10276
|
setUserAgent(userAgent) {
|
|
10256
10277
|
this.userAgent = userAgent;
|