moqtail 0.12.1 → 0.13.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 +7 -7
- package/dist/client-BzncAN14.mjs +4359 -0
- package/dist/client-DahXR3l4.cjs +4496 -0
- package/dist/client.cjs +25 -8242
- package/dist/client.d.cts +1333 -1470
- package/dist/client.d.mts +1706 -0
- package/dist/client.mjs +2 -0
- package/dist/index-C8pNnaj0.d.cts +2814 -0
- package/dist/index-C8pNnaj0.d.mts +2814 -0
- package/dist/index.cjs +284 -8963
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/logger-ByDB8lYF.mjs +56 -0
- package/dist/logger-c2NoQqtx.cjs +85 -0
- package/dist/{logger-C6QS408Z.d.cts → logger-dEoueCj7.d.cts} +13 -12
- package/dist/{logger-C6QS408Z.d.ts → logger-dEoueCj7.d.mts} +13 -12
- package/dist/model.cjs +6173 -4871
- package/dist/model.d.cts +2 -442
- package/dist/model.d.mts +2 -0
- package/dist/model.mjs +6115 -0
- package/dist/util.cjs +123 -142
- package/dist/util.d.cts +29 -24
- package/dist/{util.d.ts → util.d.mts} +29 -24
- package/dist/util.mjs +121 -0
- package/package.json +19 -18
- package/dist/client.d.ts +0 -1843
- package/dist/client.js +0 -8221
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -8813
- package/dist/model.d.ts +0 -442
- package/dist/model.js +0 -4939
- package/dist/setup_parameter-BgNrJRDS.d.cts +0 -2758
- package/dist/setup_parameter-BgNrJRDS.d.ts +0 -2758
- package/dist/util.js +0 -139
package/dist/util.cjs
CHANGED
|
@@ -1,147 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_logger = require("./logger-c2NoQqtx.cjs");
|
|
3
|
+
//#region src/util/telemetry.ts
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2025 The MOQtail Authors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
4
19
|
var NetworkTelemetry = class {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
events = [];
|
|
21
|
+
windowMs;
|
|
22
|
+
constructor(windowMs = 1e3) {
|
|
23
|
+
this.windowMs = windowMs;
|
|
24
|
+
}
|
|
25
|
+
push({ latency, size }) {
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
this.events.push({
|
|
28
|
+
timestamp: now,
|
|
29
|
+
latency,
|
|
30
|
+
size
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
clean() {
|
|
34
|
+
const cutoff = Date.now() - this.windowMs;
|
|
35
|
+
while (this.events.length && this.events[0] && this.events[0].timestamp < cutoff) this.events.shift();
|
|
36
|
+
}
|
|
37
|
+
get throughput() {
|
|
38
|
+
this.clean();
|
|
39
|
+
return this.events.reduce((sum, e) => sum + e.size, 0) / (this.windowMs / 1e3);
|
|
40
|
+
}
|
|
41
|
+
get latency() {
|
|
42
|
+
this.clean();
|
|
43
|
+
if (!this.events.length) return 0;
|
|
44
|
+
return this.events.reduce((sum, e) => sum + e.latency, 0) / this.events.length;
|
|
45
|
+
}
|
|
30
46
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/util/clock_normalizer.ts
|
|
49
|
+
/**
|
|
50
|
+
* Copyright 2025 The MOQtail Authors
|
|
51
|
+
*
|
|
52
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
53
|
+
* you may not use this file except in compliance with the License.
|
|
54
|
+
* You may obtain a copy of the License at
|
|
55
|
+
*
|
|
56
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
57
|
+
*
|
|
58
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
const DEFAULT_SAMPLE_SIZE = 5;
|
|
65
|
+
const DEFAULT_TIME_SERVER = "https://time.akamai.com/?ms";
|
|
66
|
+
var ClockNormalizer = class ClockNormalizer {
|
|
67
|
+
offset;
|
|
68
|
+
timeServerUrl;
|
|
69
|
+
numSamples;
|
|
70
|
+
constructor(timeServerUrl, offset, numSamples) {
|
|
71
|
+
this.timeServerUrl = timeServerUrl;
|
|
72
|
+
this.offset = offset;
|
|
73
|
+
this.numSamples = numSamples;
|
|
74
|
+
}
|
|
75
|
+
static async create(timeServerUrl, numberOfSamples) {
|
|
76
|
+
const url = timeServerUrl ? timeServerUrl : DEFAULT_TIME_SERVER;
|
|
77
|
+
const numSamples = numberOfSamples ? numberOfSamples : DEFAULT_SAMPLE_SIZE;
|
|
78
|
+
const offset = await ClockNormalizer.calculateSkew(url, numSamples);
|
|
79
|
+
return new ClockNormalizer(url, offset, numSamples);
|
|
80
|
+
}
|
|
81
|
+
getSkew() {
|
|
82
|
+
return this.offset;
|
|
83
|
+
}
|
|
84
|
+
now() {
|
|
85
|
+
return Date.now() - this.offset;
|
|
86
|
+
}
|
|
87
|
+
async recalibrate() {
|
|
88
|
+
this.offset = await ClockNormalizer.calculateSkew(this.timeServerUrl, this.numSamples);
|
|
89
|
+
return this.offset;
|
|
90
|
+
}
|
|
91
|
+
static async calculateSkew(timeServerUrl, numSamples) {
|
|
92
|
+
const samples = [];
|
|
93
|
+
for (let i = 0; i < numSamples; i++) {
|
|
94
|
+
const sample = await ClockNormalizer.takeSingleSample(timeServerUrl);
|
|
95
|
+
if (sample !== null) samples.push(sample);
|
|
96
|
+
if (i < numSamples - 1) await new Promise((resolve) => setTimeout(resolve, 20));
|
|
97
|
+
}
|
|
98
|
+
if (samples.length === 0) throw new Error("Failed to get any valid samples");
|
|
99
|
+
const offsets = samples.map((s) => s.offset);
|
|
100
|
+
const average = offsets.reduce((sum, offset) => sum + offset, 0) / offsets.length;
|
|
101
|
+
return Math.round(average);
|
|
102
|
+
}
|
|
103
|
+
static async takeSingleSample(timeServerUrl) {
|
|
104
|
+
const url = `${timeServerUrl}${timeServerUrl.includes("?") ? "&" : "?"}_=${Date.now()}`;
|
|
105
|
+
const t0 = performance.now();
|
|
106
|
+
const localTimeBeforeRequest = Date.now();
|
|
107
|
+
const serverTimeText = await (await fetch(url, { cache: "no-store" })).text();
|
|
108
|
+
const t1 = performance.now();
|
|
109
|
+
const localTimeAfterRequest = Date.now();
|
|
110
|
+
const serverTime = parseFloat(serverTimeText);
|
|
111
|
+
if (isNaN(serverTime)) return null;
|
|
112
|
+
const serverTimeMs = serverTime * 1e3;
|
|
113
|
+
const rtt = t1 - t0;
|
|
114
|
+
const oneWayDelay = rtt / 2;
|
|
115
|
+
return {
|
|
116
|
+
offset: (localTimeBeforeRequest + localTimeAfterRequest) / 2 - oneWayDelay - serverTimeMs,
|
|
117
|
+
rtt
|
|
118
|
+
};
|
|
119
|
+
}
|
|
99
120
|
};
|
|
100
|
-
|
|
101
|
-
// src/util/logger.ts
|
|
102
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
103
|
-
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
104
|
-
LogLevel2[LogLevel2["LOG"] = 1] = "LOG";
|
|
105
|
-
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
106
|
-
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
107
|
-
LogLevel2[LogLevel2["NONE"] = 4] = "NONE";
|
|
108
|
-
return LogLevel2;
|
|
109
|
-
})(LogLevel || {});
|
|
110
|
-
var _config = {
|
|
111
|
-
level: 2 /* WARN */,
|
|
112
|
-
enabledModules: null
|
|
113
|
-
};
|
|
114
|
-
function setLogLevel(level) {
|
|
115
|
-
_config.level = level;
|
|
116
|
-
}
|
|
117
|
-
function setLogEnabledModules(modules) {
|
|
118
|
-
_config.enabledModules = modules;
|
|
119
|
-
}
|
|
120
|
-
var Logger = class {
|
|
121
|
-
isEnabled(module, level) {
|
|
122
|
-
if (level < _config.level) return false;
|
|
123
|
-
if (_config.enabledModules !== null && !_config.enabledModules.includes(module)) return false;
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
debug(module, ...args) {
|
|
127
|
-
if (this.isEnabled(module, 0 /* DEBUG */)) console.debug(`[MOQtail][${module}]`, ...args);
|
|
128
|
-
}
|
|
129
|
-
log(module, ...args) {
|
|
130
|
-
if (this.isEnabled(module, 1 /* LOG */)) console.log(`[MOQtail][${module}]`, ...args);
|
|
131
|
-
}
|
|
132
|
-
warn(module, ...args) {
|
|
133
|
-
if (this.isEnabled(module, 2 /* WARN */)) console.warn(`[MOQtail][${module}]`, ...args);
|
|
134
|
-
}
|
|
135
|
-
error(module, ...args) {
|
|
136
|
-
if (this.isEnabled(module, 3 /* ERROR */)) console.error(`[MOQtail][${module}]`, ...args);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
var logger = new Logger();
|
|
140
|
-
|
|
121
|
+
//#endregion
|
|
141
122
|
exports.ClockNormalizer = ClockNormalizer;
|
|
142
|
-
exports.LogLevel = LogLevel;
|
|
143
|
-
exports.Logger = Logger;
|
|
123
|
+
exports.LogLevel = require_logger.LogLevel;
|
|
124
|
+
exports.Logger = require_logger.Logger;
|
|
144
125
|
exports.NetworkTelemetry = NetworkTelemetry;
|
|
145
|
-
exports.logger = logger;
|
|
146
|
-
exports.setLogEnabledModules = setLogEnabledModules;
|
|
147
|
-
exports.setLogLevel = setLogLevel;
|
|
126
|
+
exports.logger = require_logger.logger;
|
|
127
|
+
exports.setLogEnabledModules = require_logger.setLogEnabledModules;
|
|
128
|
+
exports.setLogLevel = require_logger.setLogLevel;
|
package/dist/util.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as setLogLevel, i as setLogEnabledModules, n as Logger, r as logger, t as LogLevel } from "./logger-dEoueCj7.cjs";
|
|
2
2
|
|
|
3
|
+
//#region src/util/telemetry.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Copyright 2025 The MOQtail Authors
|
|
5
6
|
*
|
|
@@ -16,18 +17,22 @@ export { L as LogLevel, a as Logger, l as logger, s as setLogEnabledModules, b a
|
|
|
16
17
|
* limitations under the License.
|
|
17
18
|
*/
|
|
18
19
|
declare class NetworkTelemetry {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
private events;
|
|
21
|
+
private windowMs;
|
|
22
|
+
constructor(windowMs?: number);
|
|
23
|
+
push({
|
|
24
|
+
latency,
|
|
25
|
+
size
|
|
26
|
+
}: {
|
|
27
|
+
latency: number;
|
|
28
|
+
size: number;
|
|
29
|
+
}): void;
|
|
30
|
+
private clean;
|
|
31
|
+
get throughput(): number;
|
|
32
|
+
get latency(): number;
|
|
29
33
|
}
|
|
30
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/util/clock_normalizer.d.ts
|
|
31
36
|
/**
|
|
32
37
|
* Copyright 2025 The MOQtail Authors
|
|
33
38
|
*
|
|
@@ -44,16 +49,16 @@ declare class NetworkTelemetry {
|
|
|
44
49
|
* limitations under the License.
|
|
45
50
|
*/
|
|
46
51
|
declare class ClockNormalizer {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
private offset;
|
|
53
|
+
private timeServerUrl;
|
|
54
|
+
private numSamples;
|
|
55
|
+
private constructor();
|
|
56
|
+
static create(timeServerUrl?: string, numberOfSamples?: number): Promise<ClockNormalizer>;
|
|
57
|
+
getSkew(): number;
|
|
58
|
+
now(): number;
|
|
59
|
+
recalibrate(): Promise<number>;
|
|
60
|
+
private static calculateSkew;
|
|
61
|
+
private static takeSingleSample;
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
export { ClockNormalizer, NetworkTelemetry };
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ClockNormalizer, LogLevel, Logger, NetworkTelemetry, logger, setLogEnabledModules, setLogLevel };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as setLogLevel, i as setLogEnabledModules, n as Logger, r as logger, t as LogLevel } from "./logger-dEoueCj7.mjs";
|
|
2
2
|
|
|
3
|
+
//#region src/util/telemetry.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Copyright 2025 The MOQtail Authors
|
|
5
6
|
*
|
|
@@ -16,18 +17,22 @@ export { L as LogLevel, a as Logger, l as logger, s as setLogEnabledModules, b a
|
|
|
16
17
|
* limitations under the License.
|
|
17
18
|
*/
|
|
18
19
|
declare class NetworkTelemetry {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
private events;
|
|
21
|
+
private windowMs;
|
|
22
|
+
constructor(windowMs?: number);
|
|
23
|
+
push({
|
|
24
|
+
latency,
|
|
25
|
+
size
|
|
26
|
+
}: {
|
|
27
|
+
latency: number;
|
|
28
|
+
size: number;
|
|
29
|
+
}): void;
|
|
30
|
+
private clean;
|
|
31
|
+
get throughput(): number;
|
|
32
|
+
get latency(): number;
|
|
29
33
|
}
|
|
30
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/util/clock_normalizer.d.ts
|
|
31
36
|
/**
|
|
32
37
|
* Copyright 2025 The MOQtail Authors
|
|
33
38
|
*
|
|
@@ -44,16 +49,16 @@ declare class NetworkTelemetry {
|
|
|
44
49
|
* limitations under the License.
|
|
45
50
|
*/
|
|
46
51
|
declare class ClockNormalizer {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
private offset;
|
|
53
|
+
private timeServerUrl;
|
|
54
|
+
private numSamples;
|
|
55
|
+
private constructor();
|
|
56
|
+
static create(timeServerUrl?: string, numberOfSamples?: number): Promise<ClockNormalizer>;
|
|
57
|
+
getSkew(): number;
|
|
58
|
+
now(): number;
|
|
59
|
+
recalibrate(): Promise<number>;
|
|
60
|
+
private static calculateSkew;
|
|
61
|
+
private static takeSingleSample;
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
export { ClockNormalizer, NetworkTelemetry };
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ClockNormalizer, LogLevel, Logger, NetworkTelemetry, logger, setLogEnabledModules, setLogLevel };
|
package/dist/util.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { a as setLogLevel, i as setLogEnabledModules, n as Logger, r as logger, t as LogLevel } from "./logger-ByDB8lYF.mjs";
|
|
2
|
+
//#region src/util/telemetry.ts
|
|
3
|
+
/**
|
|
4
|
+
* Copyright 2025 The MOQtail Authors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
var NetworkTelemetry = class {
|
|
19
|
+
events = [];
|
|
20
|
+
windowMs;
|
|
21
|
+
constructor(windowMs = 1e3) {
|
|
22
|
+
this.windowMs = windowMs;
|
|
23
|
+
}
|
|
24
|
+
push({ latency, size }) {
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
this.events.push({
|
|
27
|
+
timestamp: now,
|
|
28
|
+
latency,
|
|
29
|
+
size
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
clean() {
|
|
33
|
+
const cutoff = Date.now() - this.windowMs;
|
|
34
|
+
while (this.events.length && this.events[0] && this.events[0].timestamp < cutoff) this.events.shift();
|
|
35
|
+
}
|
|
36
|
+
get throughput() {
|
|
37
|
+
this.clean();
|
|
38
|
+
return this.events.reduce((sum, e) => sum + e.size, 0) / (this.windowMs / 1e3);
|
|
39
|
+
}
|
|
40
|
+
get latency() {
|
|
41
|
+
this.clean();
|
|
42
|
+
if (!this.events.length) return 0;
|
|
43
|
+
return this.events.reduce((sum, e) => sum + e.latency, 0) / this.events.length;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/util/clock_normalizer.ts
|
|
48
|
+
/**
|
|
49
|
+
* Copyright 2025 The MOQtail Authors
|
|
50
|
+
*
|
|
51
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
52
|
+
* you may not use this file except in compliance with the License.
|
|
53
|
+
* You may obtain a copy of the License at
|
|
54
|
+
*
|
|
55
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
56
|
+
*
|
|
57
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
58
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
59
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
60
|
+
* See the License for the specific language governing permissions and
|
|
61
|
+
* limitations under the License.
|
|
62
|
+
*/
|
|
63
|
+
const DEFAULT_SAMPLE_SIZE = 5;
|
|
64
|
+
const DEFAULT_TIME_SERVER = "https://time.akamai.com/?ms";
|
|
65
|
+
var ClockNormalizer = class ClockNormalizer {
|
|
66
|
+
offset;
|
|
67
|
+
timeServerUrl;
|
|
68
|
+
numSamples;
|
|
69
|
+
constructor(timeServerUrl, offset, numSamples) {
|
|
70
|
+
this.timeServerUrl = timeServerUrl;
|
|
71
|
+
this.offset = offset;
|
|
72
|
+
this.numSamples = numSamples;
|
|
73
|
+
}
|
|
74
|
+
static async create(timeServerUrl, numberOfSamples) {
|
|
75
|
+
const url = timeServerUrl ? timeServerUrl : DEFAULT_TIME_SERVER;
|
|
76
|
+
const numSamples = numberOfSamples ? numberOfSamples : DEFAULT_SAMPLE_SIZE;
|
|
77
|
+
const offset = await ClockNormalizer.calculateSkew(url, numSamples);
|
|
78
|
+
return new ClockNormalizer(url, offset, numSamples);
|
|
79
|
+
}
|
|
80
|
+
getSkew() {
|
|
81
|
+
return this.offset;
|
|
82
|
+
}
|
|
83
|
+
now() {
|
|
84
|
+
return Date.now() - this.offset;
|
|
85
|
+
}
|
|
86
|
+
async recalibrate() {
|
|
87
|
+
this.offset = await ClockNormalizer.calculateSkew(this.timeServerUrl, this.numSamples);
|
|
88
|
+
return this.offset;
|
|
89
|
+
}
|
|
90
|
+
static async calculateSkew(timeServerUrl, numSamples) {
|
|
91
|
+
const samples = [];
|
|
92
|
+
for (let i = 0; i < numSamples; i++) {
|
|
93
|
+
const sample = await ClockNormalizer.takeSingleSample(timeServerUrl);
|
|
94
|
+
if (sample !== null) samples.push(sample);
|
|
95
|
+
if (i < numSamples - 1) await new Promise((resolve) => setTimeout(resolve, 20));
|
|
96
|
+
}
|
|
97
|
+
if (samples.length === 0) throw new Error("Failed to get any valid samples");
|
|
98
|
+
const offsets = samples.map((s) => s.offset);
|
|
99
|
+
const average = offsets.reduce((sum, offset) => sum + offset, 0) / offsets.length;
|
|
100
|
+
return Math.round(average);
|
|
101
|
+
}
|
|
102
|
+
static async takeSingleSample(timeServerUrl) {
|
|
103
|
+
const url = `${timeServerUrl}${timeServerUrl.includes("?") ? "&" : "?"}_=${Date.now()}`;
|
|
104
|
+
const t0 = performance.now();
|
|
105
|
+
const localTimeBeforeRequest = Date.now();
|
|
106
|
+
const serverTimeText = await (await fetch(url, { cache: "no-store" })).text();
|
|
107
|
+
const t1 = performance.now();
|
|
108
|
+
const localTimeAfterRequest = Date.now();
|
|
109
|
+
const serverTime = parseFloat(serverTimeText);
|
|
110
|
+
if (isNaN(serverTime)) return null;
|
|
111
|
+
const serverTimeMs = serverTime * 1e3;
|
|
112
|
+
const rtt = t1 - t0;
|
|
113
|
+
const oneWayDelay = rtt / 2;
|
|
114
|
+
return {
|
|
115
|
+
offset: (localTimeBeforeRequest + localTimeAfterRequest) / 2 - oneWayDelay - serverTimeMs,
|
|
116
|
+
rtt
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { ClockNormalizer, LogLevel, Logger, NetworkTelemetry, logger, setLogEnabledModules, setLogLevel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moqtail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Media Over QUIC Transport client implementation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"main": "dist/index.cjs",
|
|
33
|
-
"module": "dist/index.
|
|
34
|
-
"types": "dist/index.d.
|
|
33
|
+
"module": "dist/index.mjs",
|
|
34
|
+
"types": "dist/index.d.mts",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
37
|
"import": {
|
|
38
|
-
"types": "./dist/index.d.
|
|
39
|
-
"default": "./dist/index.
|
|
38
|
+
"types": "./dist/index.d.mts",
|
|
39
|
+
"default": "./dist/index.mjs"
|
|
40
40
|
},
|
|
41
41
|
"require": {
|
|
42
42
|
"types": "./dist/index.d.cts",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"./client": {
|
|
47
47
|
"import": {
|
|
48
|
-
"types": "./dist/client.d.
|
|
49
|
-
"default": "./dist/client.
|
|
48
|
+
"types": "./dist/client.d.mts",
|
|
49
|
+
"default": "./dist/client.mjs"
|
|
50
50
|
},
|
|
51
51
|
"require": {
|
|
52
52
|
"types": "./dist/client.d.cts",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"./model": {
|
|
57
57
|
"import": {
|
|
58
|
-
"types": "./dist/model.d.
|
|
59
|
-
"default": "./dist/model.
|
|
58
|
+
"types": "./dist/model.d.mts",
|
|
59
|
+
"default": "./dist/model.mjs"
|
|
60
60
|
},
|
|
61
61
|
"require": {
|
|
62
62
|
"types": "./dist/model.d.cts",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
},
|
|
66
66
|
"./util": {
|
|
67
67
|
"import": {
|
|
68
|
-
"types": "./dist/util.d.
|
|
69
|
-
"default": "./dist/util.
|
|
68
|
+
"types": "./dist/util.d.mts",
|
|
69
|
+
"default": "./dist/util.mjs"
|
|
70
70
|
},
|
|
71
71
|
"require": {
|
|
72
72
|
"types": "./dist/util.d.cts",
|
|
@@ -75,20 +75,21 @@
|
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
|
-
"
|
|
78
|
+
"prepare": "npm run transpile",
|
|
79
|
+
"transpile": "tsdown",
|
|
80
|
+
"build": "tsc --noEmit && npm run transpile && api-extractor run",
|
|
79
81
|
"test": "vitest",
|
|
80
82
|
"format": "prettier --check .",
|
|
81
83
|
"test:run": "vitest run",
|
|
82
|
-
"clean": "rimraf dist",
|
|
83
84
|
"docs": "typedoc"
|
|
84
85
|
},
|
|
85
86
|
"devDependencies": {
|
|
86
|
-
"@microsoft/api-extractor": "^7.
|
|
87
|
+
"@microsoft/api-extractor": "^7.58.9",
|
|
87
88
|
"@tsconfig/strictest": "^2.0.8",
|
|
88
89
|
"tslib": "^2.8.1",
|
|
89
|
-
"
|
|
90
|
-
"typedoc": "^0.28.
|
|
91
|
-
"typescript": "^
|
|
92
|
-
"vitest": "^
|
|
90
|
+
"tsdown": "^0.22.3",
|
|
91
|
+
"typedoc": "^0.28.20",
|
|
92
|
+
"typescript": "^6.0.3",
|
|
93
|
+
"vitest": "^5.0.3"
|
|
93
94
|
}
|
|
94
95
|
}
|