@webmusic/kernel 0.1.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/LICENSE +21 -0
- package/README.md +435 -0
- package/dist/audio-context.cjs +10 -0
- package/dist/audio-context.cjs.map +1 -0
- package/dist/audio-context.d.cts +13 -0
- package/dist/audio-context.d.ts +13 -0
- package/dist/audio-context.js +10 -0
- package/dist/audio-context.js.map +1 -0
- package/dist/build-receipt.json +7 -0
- package/dist/chunk-3INDOVUC.cjs +134 -0
- package/dist/chunk-3INDOVUC.cjs.map +1 -0
- package/dist/chunk-53YD73OY.js +162 -0
- package/dist/chunk-53YD73OY.js.map +1 -0
- package/dist/chunk-7ZTZZ5PN.cjs +25 -0
- package/dist/chunk-7ZTZZ5PN.cjs.map +1 -0
- package/dist/chunk-BR63OD53.cjs +1 -0
- package/dist/chunk-BR63OD53.cjs.map +1 -0
- package/dist/chunk-C3YWUZW3.cjs +57 -0
- package/dist/chunk-C3YWUZW3.cjs.map +1 -0
- package/dist/chunk-FJLY3RWZ.js +134 -0
- package/dist/chunk-FJLY3RWZ.js.map +1 -0
- package/dist/chunk-GO4N5T27.js +94 -0
- package/dist/chunk-GO4N5T27.js.map +1 -0
- package/dist/chunk-HOKRTYPV.js +199 -0
- package/dist/chunk-HOKRTYPV.js.map +1 -0
- package/dist/chunk-HY2YIL75.js +16 -0
- package/dist/chunk-HY2YIL75.js.map +1 -0
- package/dist/chunk-HZQX4J2J.cjs +199 -0
- package/dist/chunk-HZQX4J2J.cjs.map +1 -0
- package/dist/chunk-ILKEVUJ3.js +57 -0
- package/dist/chunk-ILKEVUJ3.js.map +1 -0
- package/dist/chunk-JNXB74G3.cjs +987 -0
- package/dist/chunk-JNXB74G3.cjs.map +1 -0
- package/dist/chunk-N6KU2HYA.js +25 -0
- package/dist/chunk-N6KU2HYA.js.map +1 -0
- package/dist/chunk-PXG64RU4.js +25 -0
- package/dist/chunk-PXG64RU4.js.map +1 -0
- package/dist/chunk-SM5YPDDI.cjs +162 -0
- package/dist/chunk-SM5YPDDI.cjs.map +1 -0
- package/dist/chunk-TEM2I2NN.js +1 -0
- package/dist/chunk-TEM2I2NN.js.map +1 -0
- package/dist/chunk-UMTPJ76S.cjs +94 -0
- package/dist/chunk-UMTPJ76S.cjs.map +1 -0
- package/dist/chunk-VVZX7DQ6.cjs +254 -0
- package/dist/chunk-VVZX7DQ6.cjs.map +1 -0
- package/dist/chunk-VY6WWZSW.cjs +16 -0
- package/dist/chunk-VY6WWZSW.cjs.map +1 -0
- package/dist/chunk-WNFGDB7B.js +254 -0
- package/dist/chunk-WNFGDB7B.js.map +1 -0
- package/dist/chunk-XBJBY4J5.js +987 -0
- package/dist/chunk-XBJBY4J5.js.map +1 -0
- package/dist/chunk-ZMU72HJS.cjs +25 -0
- package/dist/chunk-ZMU72HJS.cjs.map +1 -0
- package/dist/effect.cjs +2 -0
- package/dist/effect.cjs.map +1 -0
- package/dist/effect.d.cts +19 -0
- package/dist/effect.d.ts +19 -0
- package/dist/effect.js +2 -0
- package/dist/effect.js.map +1 -0
- package/dist/elements.cjs +24 -0
- package/dist/elements.cjs.map +1 -0
- package/dist/elements.d.cts +76 -0
- package/dist/elements.d.ts +76 -0
- package/dist/elements.js +24 -0
- package/dist/elements.js.map +1 -0
- package/dist/events.cjs +8 -0
- package/dist/events.cjs.map +1 -0
- package/dist/events.d.cts +36 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.js +8 -0
- package/dist/events.js.map +1 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/meter.cjs +12 -0
- package/dist/meter.cjs.map +1 -0
- package/dist/meter.d.cts +76 -0
- package/dist/meter.d.ts +76 -0
- package/dist/meter.js +12 -0
- package/dist/meter.js.map +1 -0
- package/dist/player.cjs +16 -0
- package/dist/player.cjs.map +1 -0
- package/dist/player.d.cts +49 -0
- package/dist/player.d.ts +49 -0
- package/dist/player.js +16 -0
- package/dist/player.js.map +1 -0
- package/dist/sync.cjs +12 -0
- package/dist/sync.cjs.map +1 -0
- package/dist/sync.d.cts +304 -0
- package/dist/sync.d.ts +304 -0
- package/dist/sync.js +12 -0
- package/dist/sync.js.map +1 -0
- package/dist/tick.cjs +10 -0
- package/dist/tick.cjs.map +1 -0
- package/dist/tick.d.cts +48 -0
- package/dist/tick.d.ts +48 -0
- package/dist/tick.js +10 -0
- package/dist/tick.js.map +1 -0
- package/dist/transport.cjs +8 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +114 -0
- package/dist/transport.d.ts +114 -0
- package/dist/transport.js +8 -0
- package/dist/transport.js.map +1 -0
- package/dist/worker.cjs +10 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +49 -0
- package/dist/worker.d.ts +49 -0
- package/dist/worker.js +10 -0
- package/dist/worker.js.map +1 -0
- package/package.json +164 -0
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_TIMER_DELAY_MS,
|
|
3
|
+
createTickSource
|
|
4
|
+
} from "./chunk-FJLY3RWZ.js";
|
|
5
|
+
import {
|
|
6
|
+
TransportClock
|
|
7
|
+
} from "./chunk-53YD73OY.js";
|
|
8
|
+
import {
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateMethod,
|
|
12
|
+
__privateSet,
|
|
13
|
+
__privateWrapper
|
|
14
|
+
} from "./chunk-PXG64RU4.js";
|
|
15
|
+
|
|
16
|
+
// src/sync.ts
|
|
17
|
+
var MAX_CONSECUTIVE_DRIFT_JOINS = 3;
|
|
18
|
+
var MIRROR_RATE_TOLERANCE = 0.02;
|
|
19
|
+
var _master, _followers, _now, _leadIn, _driftTolerance, _driftIntervalMs, _ticker, _tickOptions, _ticksPerDriftCheck, _tickCount, _loop, _wrapping, _generation, _revision, _pendingCommands, _observers, _lastSnapshot, _pendingTransitions, _commandActive, _queuedCommands, _intent, _disposed, _onOperationError, _TransportGroup_instances, dispatch_fn, publish_fn, setLoop_fn, play_fn, pause_fn, stop_fn, seek_fn, setRate_fn, wrapLocal_fn, localPosition_fn, joinFollowers_fn, applyFollowerRate_fn, resetDriftConvergence_fn, onTick_fn, reconcileMasterStop_fn, handleMasterStopped_fn, checkLoop_fn, wrap_fn, startDriftMonitor_fn, stopDriftMonitor_fn, needsMonitor_fn, isCurrent_fn, reportOperationError_fn, settleMasterStopped_fn, settleFailedResume_fn, assertActive_fn, observeReconciliation_fn, queueJoin_fn, enqueueCommand_fn, finishCommand_fn, readSettledMasterPosition_fn, reconcileStaleSeek_fn, reapplySynchronousIntent_fn, applyPause_fn, applyStop_fn, rollbackFailedPlay_fn;
|
|
20
|
+
var TransportGroup = class {
|
|
21
|
+
constructor(master, now, options = {}) {
|
|
22
|
+
__privateAdd(this, _TransportGroup_instances);
|
|
23
|
+
__privateAdd(this, _master);
|
|
24
|
+
__privateAdd(this, _followers, []);
|
|
25
|
+
__privateAdd(this, _now);
|
|
26
|
+
__privateAdd(this, _leadIn);
|
|
27
|
+
__privateAdd(this, _driftTolerance);
|
|
28
|
+
__privateAdd(this, _driftIntervalMs);
|
|
29
|
+
__privateAdd(this, _ticker, null);
|
|
30
|
+
__privateAdd(this, _tickOptions);
|
|
31
|
+
__privateAdd(this, _ticksPerDriftCheck);
|
|
32
|
+
__privateAdd(this, _tickCount, 0);
|
|
33
|
+
__privateAdd(this, _loop, null);
|
|
34
|
+
__privateAdd(this, _wrapping, false);
|
|
35
|
+
__privateAdd(this, _generation, 0);
|
|
36
|
+
__privateAdd(this, _revision, 0);
|
|
37
|
+
__privateAdd(this, _pendingCommands, /* @__PURE__ */ new Set());
|
|
38
|
+
__privateAdd(this, _observers, /* @__PURE__ */ new Set());
|
|
39
|
+
__privateAdd(this, _lastSnapshot);
|
|
40
|
+
__privateAdd(this, _pendingTransitions, 0);
|
|
41
|
+
/** Serializes transport commands so late async settlements cannot reorder state. */
|
|
42
|
+
__privateAdd(this, _commandActive, false);
|
|
43
|
+
__privateAdd(this, _queuedCommands, []);
|
|
44
|
+
__privateAdd(this, _intent, "paused");
|
|
45
|
+
__privateAdd(this, _disposed, false);
|
|
46
|
+
__privateAdd(this, _onOperationError);
|
|
47
|
+
__privateSet(this, _master, master);
|
|
48
|
+
__privateSet(this, _now, now);
|
|
49
|
+
__privateSet(this, _leadIn, options.leadInSeconds ?? 0.06);
|
|
50
|
+
__privateSet(this, _driftTolerance, options.driftToleranceSeconds ?? 0.03);
|
|
51
|
+
__privateSet(this, _driftIntervalMs, options.driftCheckIntervalMs ?? 250);
|
|
52
|
+
__privateSet(this, _onOperationError, options.onOperationError);
|
|
53
|
+
__privateSet(this, _tickOptions, { intervalMs: 25, ...options.tick });
|
|
54
|
+
assertFiniteNonNegative("leadInSeconds", __privateGet(this, _leadIn));
|
|
55
|
+
assertFiniteNonNegative("driftToleranceSeconds", __privateGet(this, _driftTolerance));
|
|
56
|
+
assertFiniteNonNegative("driftCheckIntervalMs", __privateGet(this, _driftIntervalMs));
|
|
57
|
+
const tickInterval = __privateGet(this, _tickOptions).intervalMs ?? 25;
|
|
58
|
+
if (!Number.isSafeInteger(tickInterval) || tickInterval < 1 || tickInterval > MAX_TIMER_DELAY_MS) {
|
|
59
|
+
throw new RangeError(
|
|
60
|
+
`tick.intervalMs must be a positive safe integer no greater than ${MAX_TIMER_DELAY_MS}.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
__privateSet(this, _ticksPerDriftCheck, Math.max(1, Math.round(__privateGet(this, _driftIntervalMs) / (__privateGet(this, _tickOptions).intervalMs ?? 25))));
|
|
64
|
+
if (options.loop) {
|
|
65
|
+
assertValidLoop(options.loop);
|
|
66
|
+
__privateSet(this, _loop, { ...options.loop });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The group timeline: a read-through to the master's own clock. */
|
|
70
|
+
get clock() {
|
|
71
|
+
return __privateGet(this, _master).clock;
|
|
72
|
+
}
|
|
73
|
+
/** Current position on the master axis. */
|
|
74
|
+
get position() {
|
|
75
|
+
return __privateGet(this, _master).position;
|
|
76
|
+
}
|
|
77
|
+
/** Read one coherent state on the master's stable position axis. */
|
|
78
|
+
get snapshot() {
|
|
79
|
+
if (__privateGet(this, _disposed) && __privateGet(this, _lastSnapshot)) {
|
|
80
|
+
return Object.freeze({ ...__privateGet(this, _lastSnapshot), revision: __privateGet(this, _revision), pending: false, disposed: true });
|
|
81
|
+
}
|
|
82
|
+
const referenceTime = __privateGet(this, _now).call(this);
|
|
83
|
+
const clock = this.clock;
|
|
84
|
+
const loop = this.loop;
|
|
85
|
+
const snapshot = Object.freeze({
|
|
86
|
+
revision: __privateGet(this, _revision),
|
|
87
|
+
referenceTime,
|
|
88
|
+
position: clock.positionAt(referenceTime),
|
|
89
|
+
rate: clock.rate,
|
|
90
|
+
paused: clock.paused,
|
|
91
|
+
holding: clock.holding && clock.state.originTime > referenceTime,
|
|
92
|
+
loop: loop ? Object.freeze(loop) : null,
|
|
93
|
+
pending: __privateGet(this, _pendingCommands).size > 0 || __privateGet(this, _pendingTransitions) > 0,
|
|
94
|
+
disposed: __privateGet(this, _disposed)
|
|
95
|
+
});
|
|
96
|
+
__privateSet(this, _lastSnapshot, snapshot);
|
|
97
|
+
return snapshot;
|
|
98
|
+
}
|
|
99
|
+
/** Register before synchronously delivering the initial snapshot. Observer
|
|
100
|
+
* failures are contained. Unsubscribe never stops borrowed playback. */
|
|
101
|
+
subscribe(listener) {
|
|
102
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
103
|
+
__privateGet(this, _observers).add(listener);
|
|
104
|
+
try {
|
|
105
|
+
listener({ type: "snapshot", snapshot: this.snapshot });
|
|
106
|
+
} catch {
|
|
107
|
+
__privateGet(this, _observers).delete(listener);
|
|
108
|
+
}
|
|
109
|
+
return () => {
|
|
110
|
+
__privateGet(this, _observers).delete(listener);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Submit a command and await its actual participant settlement. Failures
|
|
114
|
+
* reject and emit an error; superseded work cannot claim a committed result.
|
|
115
|
+
* Pause/stop take effect synchronously and await any late-start reconciliation.
|
|
116
|
+
* Call this authority exclusively while coordinating a session. */
|
|
117
|
+
dispatch(command) {
|
|
118
|
+
return __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, command, true);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Register a follower. While the group is playing, the follower joins the
|
|
122
|
+
* running timeline on the next scheduled join.
|
|
123
|
+
*/
|
|
124
|
+
addFollower(transport, options = {}) {
|
|
125
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
126
|
+
const offset = options.offsetSeconds ?? 0;
|
|
127
|
+
assertFiniteNonNegative("offsetSeconds", offset);
|
|
128
|
+
const scale = options.positionScale ?? 1;
|
|
129
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new RangeError("positionScale must be finite and > 0.");
|
|
130
|
+
if (scale !== 1 && !transport.setRate) throw new Error("A scaled follower must support setRate.");
|
|
131
|
+
if (options.loop) assertValidLoop(options.loop);
|
|
132
|
+
const record = {
|
|
133
|
+
transport,
|
|
134
|
+
offset,
|
|
135
|
+
scale,
|
|
136
|
+
loop: options.loop ? { ...options.loop } : null,
|
|
137
|
+
joinAt: 0,
|
|
138
|
+
consecutiveDriftJoins: 0,
|
|
139
|
+
driftJoinsSuppressed: false
|
|
140
|
+
};
|
|
141
|
+
__privateGet(this, _followers).push(record);
|
|
142
|
+
if (!this.clock.paused) {
|
|
143
|
+
__privateMethod(this, _TransportGroup_instances, observeReconciliation_fn).call(this, "follower join", () => __privateMethod(this, _TransportGroup_instances, queueJoin_fn).call(this, __privateGet(this, _generation), "follower join", [record]));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Remove a follower from the group (the transport itself is left as-is,
|
|
148
|
+
* still playing if it was; the caller owns its lifecycle from here).
|
|
149
|
+
* Returns false when the transport was not a member.
|
|
150
|
+
*/
|
|
151
|
+
removeFollower(transport) {
|
|
152
|
+
const index = __privateGet(this, _followers).findIndex((record) => record.transport === transport);
|
|
153
|
+
if (index < 0) return false;
|
|
154
|
+
__privateGet(this, _followers).splice(index, 1);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
/** Number of registered followers. */
|
|
158
|
+
get followerCount() {
|
|
159
|
+
return __privateGet(this, _followers).length;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Set (or clear) a loop region on the master axis, live. The wrap runs
|
|
163
|
+
* through {@link seek}, so it inherits the shared re-entry origin; the
|
|
164
|
+
* boundary is detected by a worker-backed tick watcher, so the wrap
|
|
165
|
+
* instant may trail the boundary by the watcher/preparation delay and lead-in.
|
|
166
|
+
* Browser throttling means this is not a bounded timing guarantee.
|
|
167
|
+
*/
|
|
168
|
+
setLoop(loop) {
|
|
169
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
170
|
+
if (loop) assertValidLoop(loop);
|
|
171
|
+
void __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "loop", loop }, false).catch((error) => __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop", error));
|
|
172
|
+
}
|
|
173
|
+
get loop() {
|
|
174
|
+
return __privateGet(this, _loop) ? { ...__privateGet(this, _loop) } : null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Start master and followers on one shared origin. The group proposes
|
|
178
|
+
* `now + leadInSeconds` to the master; one that supports scheduled starts
|
|
179
|
+
* arms there and every follower joins at that very instant. A master that
|
|
180
|
+
* ignores the proposal starts immediately and followers join a lead-in
|
|
181
|
+
* later, offset-matched to its anchor.
|
|
182
|
+
*/
|
|
183
|
+
async play() {
|
|
184
|
+
await __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "play" }, false);
|
|
185
|
+
}
|
|
186
|
+
pause() {
|
|
187
|
+
if (__privateGet(this, _disposed)) return;
|
|
188
|
+
void __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "pause" }, false).catch((error) => __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "pause", error));
|
|
189
|
+
}
|
|
190
|
+
stop() {
|
|
191
|
+
if (__privateGet(this, _disposed)) return;
|
|
192
|
+
void __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "stop" }, false).catch((error) => __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "stop", error));
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Seek master and followers to a master-axis position. While playing, the
|
|
196
|
+
* group proposes a shared re-entry origin exactly as {@link play} does
|
|
197
|
+
* and re-joins the followers there, so all sides come back in together.
|
|
198
|
+
* Loop wraps run through this path and inherit the same shared origin.
|
|
199
|
+
*/
|
|
200
|
+
async seek(position) {
|
|
201
|
+
await __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "seek", position }, false);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Set the playback rate on the master and every follower. Followers
|
|
205
|
+
* re-join immediately on the shared clock. NOTE: the group does not clamp
|
|
206
|
+
* the rate beyond finite-and-positive — a domain wrapper owns any shared
|
|
207
|
+
* range its transports require.
|
|
208
|
+
*/
|
|
209
|
+
setRate(rate) {
|
|
210
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
211
|
+
validateCommand({ type: "rate", rate });
|
|
212
|
+
void __privateMethod(this, _TransportGroup_instances, dispatch_fn).call(this, { type: "rate", rate }, false).catch((error) => __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "rate", error));
|
|
213
|
+
}
|
|
214
|
+
dispose() {
|
|
215
|
+
if (__privateGet(this, _disposed)) return;
|
|
216
|
+
__privateSet(this, _lastSnapshot, this.snapshot);
|
|
217
|
+
__privateSet(this, _disposed, true);
|
|
218
|
+
++__privateWrapper(this, _revision)._;
|
|
219
|
+
++__privateWrapper(this, _generation)._;
|
|
220
|
+
__privateSet(this, _intent, "disposed");
|
|
221
|
+
const ticker = __privateGet(this, _ticker);
|
|
222
|
+
__privateSet(this, _ticker, null);
|
|
223
|
+
const errors = [];
|
|
224
|
+
const releases = [() => ticker?.dispose()];
|
|
225
|
+
for (const record of __privateGet(this, _followers)) {
|
|
226
|
+
releases.push(() => record.transport.dispose?.());
|
|
227
|
+
}
|
|
228
|
+
releases.push(() => __privateGet(this, _master).dispose?.());
|
|
229
|
+
for (const release of releases) {
|
|
230
|
+
try {
|
|
231
|
+
release();
|
|
232
|
+
} catch (error) {
|
|
233
|
+
errors.push(error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "snapshot", snapshot: this.snapshot });
|
|
237
|
+
__privateGet(this, _observers).clear();
|
|
238
|
+
if (errors.length > 0) throw errors[0];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* One drift check: every follower is measured against the master clock,
|
|
242
|
+
* and each one out of tolerance is re-joined on the shared clock (the
|
|
243
|
+
* same scheduled-start dance as {@link play}). Returns the largest
|
|
244
|
+
* absolute drift observed (0 with no followers or while holding off).
|
|
245
|
+
*/
|
|
246
|
+
checkDrift() {
|
|
247
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
248
|
+
if (__privateGet(this, _pendingTransitions) > 0) return 0;
|
|
249
|
+
const now = __privateGet(this, _now).call(this);
|
|
250
|
+
if (__privateGet(this, _master).reconcile) {
|
|
251
|
+
const verdict = __privateGet(this, _master).reconcile(now);
|
|
252
|
+
if (verdict === "stalled" && __privateGet(this, _intent) === "playing") {
|
|
253
|
+
__privateMethod(this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let worst = 0;
|
|
258
|
+
const stragglers = [];
|
|
259
|
+
for (const record of __privateGet(this, _followers)) {
|
|
260
|
+
if (now < record.joinAt) continue;
|
|
261
|
+
const expected = __privateMethod(this, _TransportGroup_instances, localPosition_fn).call(this, record, this.clock.positionAt(now));
|
|
262
|
+
const followerClock = record.transport.clock;
|
|
263
|
+
if (followerClock?.holding && now < followerClock.state.originTime) continue;
|
|
264
|
+
const followerPosition = followerClock ? followerClock.positionAt(now) : record.transport.position;
|
|
265
|
+
const followerRunning = followerClock ? !followerClock.paused : record.transport.running !== false;
|
|
266
|
+
let localDrift = __privateMethod(this, _TransportGroup_instances, wrapLocal_fn).call(this, record, followerPosition) - expected;
|
|
267
|
+
if (record.loop && followerPosition >= record.loop.startSeconds && expected >= record.loop.startSeconds) {
|
|
268
|
+
const period = record.loop.endSeconds - record.loop.startSeconds;
|
|
269
|
+
localDrift = ((localDrift + period / 2) % period + period) % period - period / 2;
|
|
270
|
+
}
|
|
271
|
+
const drift = localDrift / record.scale;
|
|
272
|
+
if (Math.abs(drift) > Math.abs(worst)) worst = drift;
|
|
273
|
+
if (!followerRunning) continue;
|
|
274
|
+
const rateMismatch = followerClock !== void 0 && followerClock.rate !== this.clock.rate * record.scale;
|
|
275
|
+
if (Math.abs(drift) <= __privateGet(this, _driftTolerance) && !rateMismatch) {
|
|
276
|
+
record.consecutiveDriftJoins = 0;
|
|
277
|
+
record.driftJoinsSuppressed = false;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (record.driftJoinsSuppressed) continue;
|
|
281
|
+
record.consecutiveDriftJoins += 1;
|
|
282
|
+
if (record.consecutiveDriftJoins > MAX_CONSECUTIVE_DRIFT_JOINS) {
|
|
283
|
+
record.driftJoinsSuppressed = true;
|
|
284
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "drift re-join", new Error(
|
|
285
|
+
`TransportGroup: ${record.consecutiveDriftJoins} consecutive drift corrections failed to converge (drift ${drift.toFixed(4)}s, master rate ${this.clock.rate}). The follower cannot follow the master rate; automatic re-joins are paused until they agree again.`
|
|
286
|
+
));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
stragglers.push(record);
|
|
290
|
+
}
|
|
291
|
+
if (stragglers.length > 0) {
|
|
292
|
+
__privateMethod(this, _TransportGroup_instances, observeReconciliation_fn).call(this, "drift re-join", () => __privateMethod(this, _TransportGroup_instances, queueJoin_fn).call(this, __privateGet(this, _generation), "drift re-join", stragglers));
|
|
293
|
+
}
|
|
294
|
+
return worst;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
_master = new WeakMap();
|
|
298
|
+
_followers = new WeakMap();
|
|
299
|
+
_now = new WeakMap();
|
|
300
|
+
_leadIn = new WeakMap();
|
|
301
|
+
_driftTolerance = new WeakMap();
|
|
302
|
+
_driftIntervalMs = new WeakMap();
|
|
303
|
+
_ticker = new WeakMap();
|
|
304
|
+
_tickOptions = new WeakMap();
|
|
305
|
+
_ticksPerDriftCheck = new WeakMap();
|
|
306
|
+
_tickCount = new WeakMap();
|
|
307
|
+
_loop = new WeakMap();
|
|
308
|
+
_wrapping = new WeakMap();
|
|
309
|
+
_generation = new WeakMap();
|
|
310
|
+
_revision = new WeakMap();
|
|
311
|
+
_pendingCommands = new WeakMap();
|
|
312
|
+
_observers = new WeakMap();
|
|
313
|
+
_lastSnapshot = new WeakMap();
|
|
314
|
+
_pendingTransitions = new WeakMap();
|
|
315
|
+
_commandActive = new WeakMap();
|
|
316
|
+
_queuedCommands = new WeakMap();
|
|
317
|
+
_intent = new WeakMap();
|
|
318
|
+
_disposed = new WeakMap();
|
|
319
|
+
_onOperationError = new WeakMap();
|
|
320
|
+
_TransportGroup_instances = new WeakSet();
|
|
321
|
+
dispatch_fn = function(input, strict) {
|
|
322
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
323
|
+
validateCommand(input);
|
|
324
|
+
const command = Object.freeze(input.type === "loop" ? { ...input, loop: input.loop ? Object.freeze({ ...input.loop }) : null } : { ...input });
|
|
325
|
+
const revision = ++__privateWrapper(this, _revision)._;
|
|
326
|
+
__privateGet(this, _pendingCommands).add(revision);
|
|
327
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "invalidate", revision, command, snapshot: this.snapshot });
|
|
328
|
+
let operation = void 0;
|
|
329
|
+
try {
|
|
330
|
+
if (revision === __privateGet(this, _revision) && !__privateGet(this, _disposed)) {
|
|
331
|
+
switch (command.type) {
|
|
332
|
+
case "play":
|
|
333
|
+
operation = __privateMethod(this, _TransportGroup_instances, play_fn).call(this, strict);
|
|
334
|
+
break;
|
|
335
|
+
case "pause":
|
|
336
|
+
operation = __privateMethod(this, _TransportGroup_instances, pause_fn).call(this);
|
|
337
|
+
break;
|
|
338
|
+
case "stop":
|
|
339
|
+
operation = __privateMethod(this, _TransportGroup_instances, stop_fn).call(this);
|
|
340
|
+
break;
|
|
341
|
+
case "seek":
|
|
342
|
+
operation = __privateMethod(this, _TransportGroup_instances, seek_fn).call(this, command.position, strict);
|
|
343
|
+
break;
|
|
344
|
+
case "rate":
|
|
345
|
+
operation = __privateMethod(this, _TransportGroup_instances, setRate_fn).call(this, command.rate, strict, revision);
|
|
346
|
+
break;
|
|
347
|
+
case "loop":
|
|
348
|
+
operation = __privateMethod(this, _TransportGroup_instances, setLoop_fn).call(this, command.loop);
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} catch (error) {
|
|
353
|
+
operation = Promise.reject(error);
|
|
354
|
+
}
|
|
355
|
+
return Promise.resolve(operation).then(() => {
|
|
356
|
+
__privateGet(this, _pendingCommands).delete(revision);
|
|
357
|
+
const snapshot = this.snapshot;
|
|
358
|
+
const commit = Object.freeze({
|
|
359
|
+
revision,
|
|
360
|
+
command,
|
|
361
|
+
status: revision === __privateGet(this, _revision) && !__privateGet(this, _disposed) ? "committed" : "superseded",
|
|
362
|
+
snapshot
|
|
363
|
+
});
|
|
364
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "commit", commit, snapshot });
|
|
365
|
+
return commit;
|
|
366
|
+
}, (error) => {
|
|
367
|
+
if (strict && revision === __privateGet(this, _revision) && !__privateGet(this, _disposed)) __privateMethod(this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
368
|
+
__privateGet(this, _pendingCommands).delete(revision);
|
|
369
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "error", revision, command, error, snapshot: this.snapshot });
|
|
370
|
+
throw error;
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
publish_fn = function(event) {
|
|
374
|
+
for (const listener of [...__privateGet(this, _observers)]) {
|
|
375
|
+
if (!__privateGet(this, _observers).has(listener)) continue;
|
|
376
|
+
try {
|
|
377
|
+
listener(event);
|
|
378
|
+
} catch {
|
|
379
|
+
}
|
|
380
|
+
if (event.snapshot.revision !== __privateGet(this, _revision)) break;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
setLoop_fn = function(loop) {
|
|
384
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
385
|
+
if (loop) assertValidLoop(loop);
|
|
386
|
+
__privateSet(this, _loop, loop ? { ...loop } : null);
|
|
387
|
+
if (this.clock.paused) {
|
|
388
|
+
if (!__privateMethod(this, _TransportGroup_instances, needsMonitor_fn).call(this)) __privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
389
|
+
} else if (__privateMethod(this, _TransportGroup_instances, needsMonitor_fn).call(this)) {
|
|
390
|
+
__privateMethod(this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
|
|
391
|
+
} else {
|
|
392
|
+
__privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
play_fn = async function(strict) {
|
|
396
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
397
|
+
const generation = ++__privateWrapper(this, _generation)._;
|
|
398
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) + 1);
|
|
399
|
+
__privateSet(this, _intent, "playing");
|
|
400
|
+
__privateMethod(this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
401
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
402
|
+
try {
|
|
403
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
404
|
+
await __privateGet(this, _master).play(__privateGet(this, _now).call(this) + __privateGet(this, _leadIn));
|
|
405
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
406
|
+
__privateMethod(this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (strict && this.clock.paused) throw new Error("Master transport did not start.");
|
|
410
|
+
await __privateMethod(this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, __privateGet(this, _followers), strict);
|
|
411
|
+
if (__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) __privateMethod(this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
|
|
412
|
+
} catch (error) {
|
|
413
|
+
if (__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) __privateMethod(this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
414
|
+
throw error;
|
|
415
|
+
} finally {
|
|
416
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) - 1);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
pause_fn = function() {
|
|
421
|
+
if (__privateGet(this, _disposed)) return;
|
|
422
|
+
const hadPendingTransition = __privateGet(this, _pendingTransitions) > 0;
|
|
423
|
+
++__privateWrapper(this, _generation)._;
|
|
424
|
+
__privateSet(this, _intent, "paused");
|
|
425
|
+
__privateMethod(this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
426
|
+
__privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
427
|
+
__privateMethod(this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
428
|
+
if (hadPendingTransition) {
|
|
429
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
|
|
430
|
+
if (!__privateGet(this, _disposed)) __privateMethod(this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
stop_fn = function() {
|
|
435
|
+
if (__privateGet(this, _disposed)) return;
|
|
436
|
+
const hadPendingTransition = __privateGet(this, _pendingTransitions) > 0;
|
|
437
|
+
++__privateWrapper(this, _generation)._;
|
|
438
|
+
__privateSet(this, _intent, "stopped");
|
|
439
|
+
__privateMethod(this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
440
|
+
__privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
441
|
+
__privateMethod(this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
442
|
+
if (hadPendingTransition) {
|
|
443
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
|
|
444
|
+
if (!__privateGet(this, _disposed)) __privateMethod(this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
seek_fn = async function(position, strict) {
|
|
449
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
450
|
+
assertFiniteNonNegative("position", position);
|
|
451
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) + 1);
|
|
452
|
+
__privateMethod(this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
453
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
454
|
+
try {
|
|
455
|
+
if (__privateGet(this, _disposed)) return;
|
|
456
|
+
const generation = __privateGet(this, _generation);
|
|
457
|
+
const wasRunning = !this.clock.paused;
|
|
458
|
+
await __privateGet(this, _master).seekPosition(
|
|
459
|
+
position,
|
|
460
|
+
wasRunning ? __privateGet(this, _now).call(this) + __privateGet(this, _leadIn) : void 0
|
|
461
|
+
);
|
|
462
|
+
const settled = __privateMethod(this, _TransportGroup_instances, readSettledMasterPosition_fn).call(this);
|
|
463
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
464
|
+
__privateMethod(this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
|
|
465
|
+
__privateMethod(this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (this.clock.paused) {
|
|
469
|
+
if (wasRunning && __privateGet(this, _intent) === "playing") {
|
|
470
|
+
__privateMethod(this, _TransportGroup_instances, settleFailedResume_fn).call(this);
|
|
471
|
+
if (strict) throw new Error("Master transport stayed paused after seek.");
|
|
472
|
+
__privateMethod(this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
for (const record of [...__privateGet(this, _followers)]) {
|
|
476
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
477
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
478
|
+
record.transport.seek(__privateMethod(this, _TransportGroup_instances, localPosition_fn).call(this, record, settled));
|
|
479
|
+
}
|
|
480
|
+
} else {
|
|
481
|
+
await __privateMethod(this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, __privateGet(this, _followers), strict);
|
|
482
|
+
}
|
|
483
|
+
} finally {
|
|
484
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) - 1);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
setRate_fn = function(rate, strict, revision, queued = false) {
|
|
489
|
+
if (strict && !queued) {
|
|
490
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) + 1);
|
|
491
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
492
|
+
try {
|
|
493
|
+
if (revision !== __privateGet(this, _revision) || __privateGet(this, _disposed)) return;
|
|
494
|
+
await __privateMethod(this, _TransportGroup_instances, setRate_fn).call(this, rate, strict, revision, true);
|
|
495
|
+
} finally {
|
|
496
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) - 1);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
__privateMethod(this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
501
|
+
if (!Number.isFinite(rate) || rate <= 0) {
|
|
502
|
+
throw new RangeError(`rate must be finite and > 0, got ${rate}.`);
|
|
503
|
+
}
|
|
504
|
+
const generation = __privateGet(this, _generation);
|
|
505
|
+
__privateMethod(this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
506
|
+
try {
|
|
507
|
+
__privateGet(this, _master).setRate?.(rate);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
if (strict) throw error;
|
|
510
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "master rate match", error);
|
|
511
|
+
}
|
|
512
|
+
if (revision !== __privateGet(this, _revision) || __privateGet(this, _disposed)) return;
|
|
513
|
+
if (strict && this.clock.rate !== rate) throw new Error("Master transport did not accept the requested rate.");
|
|
514
|
+
for (const record of [...__privateGet(this, _followers)]) {
|
|
515
|
+
if (revision !== __privateGet(this, _revision) || __privateGet(this, _disposed)) return;
|
|
516
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
517
|
+
__privateMethod(this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, rate, strict);
|
|
518
|
+
}
|
|
519
|
+
if (revision !== __privateGet(this, _revision) || __privateGet(this, _disposed)) return;
|
|
520
|
+
if (!this.clock.paused) {
|
|
521
|
+
return queued ? __privateMethod(this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, __privateGet(this, _followers), strict) : __privateMethod(this, _TransportGroup_instances, queueJoin_fn).call(this, generation, "rate re-join", __privateGet(this, _followers), strict);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
wrapLocal_fn = function(record, position) {
|
|
525
|
+
const loop = record.loop;
|
|
526
|
+
if (!loop || position < loop.endSeconds) return position;
|
|
527
|
+
return loop.startSeconds + (position - loop.startSeconds) % (loop.endSeconds - loop.startSeconds);
|
|
528
|
+
};
|
|
529
|
+
localPosition_fn = function(record, masterPosition) {
|
|
530
|
+
return __privateMethod(this, _TransportGroup_instances, wrapLocal_fn).call(this, record, record.offset + masterPosition * record.scale);
|
|
531
|
+
};
|
|
532
|
+
joinFollowers_fn = async function(generation, targets, strict = false) {
|
|
533
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
534
|
+
const members = [...targets];
|
|
535
|
+
for (const record of members) {
|
|
536
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
537
|
+
if (__privateGet(this, _followers).includes(record)) record.transport.pause();
|
|
538
|
+
}
|
|
539
|
+
const clock = this.clock;
|
|
540
|
+
if (clock.paused) return;
|
|
541
|
+
const now = __privateGet(this, _now).call(this);
|
|
542
|
+
const armedOrigin = clock.holding ? clock.state.originTime : -Infinity;
|
|
543
|
+
const when = armedOrigin > now ? armedOrigin : now + __privateGet(this, _leadIn);
|
|
544
|
+
const position = clock.positionAt(when);
|
|
545
|
+
const starts = [];
|
|
546
|
+
for (const record of members) {
|
|
547
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
548
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
549
|
+
try {
|
|
550
|
+
record.joinAt = when;
|
|
551
|
+
__privateMethod(this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, clock.rate, strict);
|
|
552
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !__privateGet(this, _followers).includes(record)) continue;
|
|
553
|
+
record.transport.seek(__privateMethod(this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
|
|
554
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !__privateGet(this, _followers).includes(record)) continue;
|
|
555
|
+
starts.push(record.transport.play(when));
|
|
556
|
+
} catch (error) {
|
|
557
|
+
starts.push(Promise.reject(error));
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const settled = await Promise.allSettled(starts);
|
|
562
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) __privateMethod(this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
563
|
+
const failure = settled.find((result) => result.status === "rejected");
|
|
564
|
+
if (failure?.status === "rejected") throw failure.reason;
|
|
565
|
+
if (strict && __privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
566
|
+
for (const record of members) {
|
|
567
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
568
|
+
const followerClock = record.transport.clock;
|
|
569
|
+
const running = followerClock ? !followerClock.paused : record.transport.running;
|
|
570
|
+
if (running === false) throw new Error("Follower transport did not start.");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* Hand a follower a rate, skipping the call when it already runs at it.
|
|
576
|
+
* A follower with a clock is asked directly; for one without, the last
|
|
577
|
+
* applied value is remembered. Best-effort by contract: `setRate` is
|
|
578
|
+
* optional on {@link SyncFollowerTransport}, and a transport that has one
|
|
579
|
+
* may still clamp or refuse it — the convergence check below is what
|
|
580
|
+
* surfaces a mismatch neither side can resolve.
|
|
581
|
+
*/
|
|
582
|
+
applyFollowerRate_fn = function(record, rate, strict = false) {
|
|
583
|
+
rate *= record.scale;
|
|
584
|
+
if (!record.transport.setRate) {
|
|
585
|
+
if (strict && (record.transport.clock?.rate ?? 1) !== rate) {
|
|
586
|
+
throw new Error("Follower transport cannot accept the requested rate.");
|
|
587
|
+
}
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (!Number.isFinite(rate) || rate <= 0) return;
|
|
591
|
+
const current = record.transport.clock?.rate ?? record.lastRate;
|
|
592
|
+
if (current === rate) return;
|
|
593
|
+
try {
|
|
594
|
+
record.transport.setRate(rate);
|
|
595
|
+
if (strict && record.transport.clock && record.transport.clock.rate !== rate) {
|
|
596
|
+
throw new Error("Follower transport did not accept the requested rate.");
|
|
597
|
+
}
|
|
598
|
+
record.lastRate = rate;
|
|
599
|
+
} catch (error) {
|
|
600
|
+
if (strict) throw error;
|
|
601
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "follower rate match", error);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
/** Re-arm drift corrections; any explicit command counts as a fresh start. */
|
|
605
|
+
resetDriftConvergence_fn = function() {
|
|
606
|
+
for (const record of __privateGet(this, _followers)) {
|
|
607
|
+
record.consecutiveDriftJoins = 0;
|
|
608
|
+
record.driftJoinsSuppressed = false;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* One watcher drives every concern off a kernel tick source (worker-backed
|
|
613
|
+
* where the platform allows, so background-tab throttling does not starve
|
|
614
|
+
* it): master-stop reconciliation and the loop boundary every tick, drift
|
|
615
|
+
* every `driftCheckIntervalMs` worth of ticks.
|
|
616
|
+
*/
|
|
617
|
+
onTick_fn = function() {
|
|
618
|
+
if (__privateGet(this, _disposed)) return;
|
|
619
|
+
const revision = __privateGet(this, _revision);
|
|
620
|
+
try {
|
|
621
|
+
__privateMethod(this, _TransportGroup_instances, reconcileMasterStop_fn).call(this);
|
|
622
|
+
__privateMethod(this, _TransportGroup_instances, checkLoop_fn).call(this);
|
|
623
|
+
__privateSet(this, _tickCount, __privateGet(this, _tickCount) + 1);
|
|
624
|
+
if (__privateGet(this, _driftIntervalMs) > 0 && __privateGet(this, _tickCount) % __privateGet(this, _ticksPerDriftCheck) === 0) {
|
|
625
|
+
this.checkDrift();
|
|
626
|
+
}
|
|
627
|
+
} catch (error) {
|
|
628
|
+
if (__privateGet(this, _disposed)) return;
|
|
629
|
+
if (revision === __privateGet(this, _revision)) __privateMethod(this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
630
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "transport monitor", error);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
/**
|
|
634
|
+
* The master can stop on its own (a score player finishing at its natural
|
|
635
|
+
* end pauses and rewinds its clock, racing the group's boundary watcher
|
|
636
|
+
* tick-for-tick). A self-stopped clock while the group means to play
|
|
637
|
+
* either wraps (loop active — the loop's continuation intent outranks the
|
|
638
|
+
* master's own finish) or settles into the paused state.
|
|
639
|
+
*/
|
|
640
|
+
reconcileMasterStop_fn = function() {
|
|
641
|
+
if (__privateGet(this, _intent) !== "playing" || __privateGet(this, _wrapping) || __privateGet(this, _pendingTransitions) > 0) return;
|
|
642
|
+
if (!this.clock.paused) return;
|
|
643
|
+
__privateMethod(this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
|
|
644
|
+
};
|
|
645
|
+
handleMasterStopped_fn = function() {
|
|
646
|
+
if (__privateGet(this, _loop) && !__privateGet(this, _wrapping)) {
|
|
647
|
+
__privateMethod(this, _TransportGroup_instances, wrap_fn).call(this, __privateGet(this, _loop).startSeconds);
|
|
648
|
+
} else {
|
|
649
|
+
__privateMethod(this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
checkLoop_fn = function() {
|
|
653
|
+
const loop = __privateGet(this, _loop);
|
|
654
|
+
if (!loop || this.clock.paused || __privateGet(this, _wrapping) || __privateGet(this, _pendingTransitions) > 0) return;
|
|
655
|
+
if (this.clock.positionAt(__privateGet(this, _now).call(this)) >= loop.endSeconds) {
|
|
656
|
+
__privateMethod(this, _TransportGroup_instances, wrap_fn).call(this, loop.startSeconds);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
/**
|
|
660
|
+
* Wrap to the loop start. A running master re-joins inside seek(); a
|
|
661
|
+
* master that stopped on its own (natural finish at or past the loop end)
|
|
662
|
+
* is restarted afterwards. A failed wrap settles into the paused state
|
|
663
|
+
* instead of retrying every tick, and is reported as 'loop wrap'.
|
|
664
|
+
*/
|
|
665
|
+
wrap_fn = function(startSeconds) {
|
|
666
|
+
__privateSet(this, _wrapping, true);
|
|
667
|
+
void this.seek(startSeconds).then(() => {
|
|
668
|
+
if (!__privateGet(this, _disposed) && __privateGet(this, _intent) === "playing" && this.clock.paused) {
|
|
669
|
+
return this.play();
|
|
670
|
+
}
|
|
671
|
+
}).catch((error) => {
|
|
672
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop wrap", error);
|
|
673
|
+
if (!__privateGet(this, _disposed) && __privateGet(this, _intent) === "playing") __privateMethod(this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
674
|
+
}).finally(() => {
|
|
675
|
+
__privateSet(this, _wrapping, false);
|
|
676
|
+
});
|
|
677
|
+
};
|
|
678
|
+
startDriftMonitor_fn = function() {
|
|
679
|
+
if (!__privateMethod(this, _TransportGroup_instances, needsMonitor_fn).call(this)) {
|
|
680
|
+
__privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
__privateGet(this, _ticker) ?? __privateSet(this, _ticker, createTickSource(__privateGet(this, _tickOptions)));
|
|
684
|
+
__privateGet(this, _ticker).start(() => __privateMethod(this, _TransportGroup_instances, onTick_fn).call(this));
|
|
685
|
+
};
|
|
686
|
+
stopDriftMonitor_fn = function() {
|
|
687
|
+
__privateGet(this, _ticker)?.stop();
|
|
688
|
+
__privateSet(this, _tickCount, 0);
|
|
689
|
+
};
|
|
690
|
+
needsMonitor_fn = function() {
|
|
691
|
+
return __privateGet(this, _loop) !== null || __privateGet(this, _driftIntervalMs) > 0;
|
|
692
|
+
};
|
|
693
|
+
isCurrent_fn = function(generation) {
|
|
694
|
+
return !__privateGet(this, _disposed) && generation === __privateGet(this, _generation);
|
|
695
|
+
};
|
|
696
|
+
reportOperationError_fn = function(operation, error) {
|
|
697
|
+
var _a;
|
|
698
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "operation-error", operation, error, snapshot: this.snapshot });
|
|
699
|
+
try {
|
|
700
|
+
(_a = __privateGet(this, _onOperationError)) == null ? void 0 : _a.call(this, operation, error);
|
|
701
|
+
} catch {
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* The master stopped although the group meant to be playing (a swallowed
|
|
706
|
+
* restart failure, or the master ending on its own): pause the followers
|
|
707
|
+
* and settle, exactly as an explicit pause() would.
|
|
708
|
+
*/
|
|
709
|
+
settleMasterStopped_fn = function() {
|
|
710
|
+
this.pause();
|
|
711
|
+
};
|
|
712
|
+
settleFailedResume_fn = function() {
|
|
713
|
+
__privateMethod(this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
714
|
+
__privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, "resume after seek", new Error("TransportGroup: the master transport stayed paused after a mid-playback seek."));
|
|
715
|
+
};
|
|
716
|
+
assertActive_fn = function() {
|
|
717
|
+
if (__privateGet(this, _disposed)) throw new Error("TransportGroup has been disposed.");
|
|
718
|
+
};
|
|
719
|
+
observeReconciliation_fn = function(operation, apply) {
|
|
720
|
+
const revision = ++__privateWrapper(this, _revision)._;
|
|
721
|
+
__privateGet(this, _pendingCommands).add(revision);
|
|
722
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "invalidate", snapshot: this.snapshot });
|
|
723
|
+
const pending = revision === __privateGet(this, _revision) && !__privateGet(this, _disposed) ? apply() : Promise.resolve();
|
|
724
|
+
void pending.catch((error) => __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error)).finally(() => {
|
|
725
|
+
__privateGet(this, _pendingCommands).delete(revision);
|
|
726
|
+
__privateMethod(this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "settled", snapshot: this.snapshot });
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* Queue an independent re-join as a visible transition. Public pause/stop
|
|
731
|
+
* calls can then schedule one final reconciliation behind it, preventing
|
|
732
|
+
* a late follower play() settlement from reviving playback.
|
|
733
|
+
*/
|
|
734
|
+
queueJoin_fn = function(generation, operation, targets, strict = false) {
|
|
735
|
+
const revision = __privateGet(this, _revision);
|
|
736
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) + 1);
|
|
737
|
+
return __privateMethod(this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
738
|
+
try {
|
|
739
|
+
await __privateMethod(this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, targets, strict);
|
|
740
|
+
} finally {
|
|
741
|
+
__privateSet(this, _pendingTransitions, __privateGet(this, _pendingTransitions) - 1);
|
|
742
|
+
}
|
|
743
|
+
}).catch((error) => {
|
|
744
|
+
if (__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation) && revision === __privateGet(this, _revision)) __privateMethod(this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
745
|
+
if (!__privateGet(this, _disposed)) __privateMethod(this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error);
|
|
746
|
+
if (strict) throw error;
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
/**
|
|
750
|
+
* Run the first idle command immediately so master.play() remains inside
|
|
751
|
+
* the browser's transient user-activation stack. Only commands that
|
|
752
|
+
* actually have an async predecessor wait in the FIFO.
|
|
753
|
+
*/
|
|
754
|
+
enqueueCommand_fn = function(operation) {
|
|
755
|
+
return new Promise((resolve, reject) => {
|
|
756
|
+
const run = () => {
|
|
757
|
+
let result;
|
|
758
|
+
try {
|
|
759
|
+
result = operation();
|
|
760
|
+
} catch (error) {
|
|
761
|
+
reject(error);
|
|
762
|
+
__privateMethod(this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
Promise.resolve(result).then(
|
|
766
|
+
(value) => {
|
|
767
|
+
resolve(value);
|
|
768
|
+
__privateMethod(this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
769
|
+
},
|
|
770
|
+
(error) => {
|
|
771
|
+
reject(error);
|
|
772
|
+
__privateMethod(this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
773
|
+
}
|
|
774
|
+
);
|
|
775
|
+
};
|
|
776
|
+
if (__privateGet(this, _commandActive)) {
|
|
777
|
+
__privateGet(this, _queuedCommands).push(run);
|
|
778
|
+
} else {
|
|
779
|
+
__privateSet(this, _commandActive, true);
|
|
780
|
+
run();
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
finishCommand_fn = function() {
|
|
785
|
+
const next = __privateGet(this, _queuedCommands).shift();
|
|
786
|
+
if (next) {
|
|
787
|
+
next();
|
|
788
|
+
} else {
|
|
789
|
+
__privateSet(this, _commandActive, false);
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
/** Read the master's actual post-seek position (it may clamp). */
|
|
793
|
+
readSettledMasterPosition_fn = function() {
|
|
794
|
+
const position = __privateGet(this, _master).position;
|
|
795
|
+
if (!Number.isFinite(position) || position < 0) {
|
|
796
|
+
throw new RangeError("Master transport returned an invalid position after seek.");
|
|
797
|
+
}
|
|
798
|
+
return position;
|
|
799
|
+
};
|
|
800
|
+
/** Preserve the completed seek position when pause superseded it. */
|
|
801
|
+
reconcileStaleSeek_fn = function(position) {
|
|
802
|
+
if (__privateGet(this, _disposed) || __privateGet(this, _intent) !== "paused") return;
|
|
803
|
+
const generation = __privateGet(this, _generation);
|
|
804
|
+
for (const record of [...__privateGet(this, _followers)]) {
|
|
805
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
806
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
807
|
+
record.transport.seek(__privateMethod(this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
/** Re-apply pause/stop after an older async master command settles late. */
|
|
811
|
+
reapplySynchronousIntent_fn = function() {
|
|
812
|
+
if (__privateGet(this, _disposed)) return;
|
|
813
|
+
if (__privateGet(this, _intent) === "paused") {
|
|
814
|
+
__privateMethod(this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
815
|
+
} else if (__privateGet(this, _intent) === "stopped") {
|
|
816
|
+
__privateMethod(this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
applyPause_fn = function() {
|
|
820
|
+
const generation = __privateGet(this, _generation);
|
|
821
|
+
const errors = [];
|
|
822
|
+
for (const record of [...__privateGet(this, _followers)]) {
|
|
823
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
824
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
825
|
+
try {
|
|
826
|
+
record.transport.pause();
|
|
827
|
+
} catch (error) {
|
|
828
|
+
errors.push(error);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
832
|
+
try {
|
|
833
|
+
__privateGet(this, _master).pause();
|
|
834
|
+
} catch (error) {
|
|
835
|
+
errors.push(error);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (errors.length > 0) throw errors[0];
|
|
839
|
+
};
|
|
840
|
+
applyStop_fn = function() {
|
|
841
|
+
const generation = __privateGet(this, _generation);
|
|
842
|
+
const errors = [];
|
|
843
|
+
for (const record of [...__privateGet(this, _followers)]) {
|
|
844
|
+
if (!__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
845
|
+
if (!__privateGet(this, _followers).includes(record)) continue;
|
|
846
|
+
try {
|
|
847
|
+
record.transport.stop();
|
|
848
|
+
} catch (error) {
|
|
849
|
+
errors.push(error);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (__privateMethod(this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
853
|
+
try {
|
|
854
|
+
__privateGet(this, _master).stop();
|
|
855
|
+
} catch (error) {
|
|
856
|
+
errors.push(error);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (errors.length > 0) throw errors[0];
|
|
860
|
+
};
|
|
861
|
+
rollbackFailedPlay_fn = function() {
|
|
862
|
+
++__privateWrapper(this, _generation)._;
|
|
863
|
+
__privateSet(this, _intent, "paused");
|
|
864
|
+
__privateMethod(this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
865
|
+
try {
|
|
866
|
+
__privateMethod(this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
867
|
+
} catch {
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
var _inner, _mirror, _now2, _tolerance, _lastSample;
|
|
871
|
+
var MirrorClockMaster = class {
|
|
872
|
+
constructor(inner, now, options = {}) {
|
|
873
|
+
__privateAdd(this, _inner);
|
|
874
|
+
__privateAdd(this, _mirror);
|
|
875
|
+
__privateAdd(this, _now2);
|
|
876
|
+
__privateAdd(this, _tolerance);
|
|
877
|
+
__privateAdd(this, _lastSample, null);
|
|
878
|
+
__privateSet(this, _inner, inner);
|
|
879
|
+
__privateSet(this, _now2, now);
|
|
880
|
+
__privateSet(this, _tolerance, options.reconcileToleranceSeconds ?? 0.03);
|
|
881
|
+
assertFiniteNonNegative("reconcileToleranceSeconds", __privateGet(this, _tolerance));
|
|
882
|
+
__privateSet(this, _mirror, new TransportClock(now));
|
|
883
|
+
}
|
|
884
|
+
get clock() {
|
|
885
|
+
return __privateGet(this, _mirror);
|
|
886
|
+
}
|
|
887
|
+
get position() {
|
|
888
|
+
return __privateGet(this, _inner).position;
|
|
889
|
+
}
|
|
890
|
+
async play(when) {
|
|
891
|
+
await __privateGet(this, _inner).play(when);
|
|
892
|
+
__privateSet(this, _lastSample, null);
|
|
893
|
+
__privateGet(this, _mirror).start(__privateGet(this, _now2).call(this), __privateGet(this, _inner).position);
|
|
894
|
+
}
|
|
895
|
+
pause() {
|
|
896
|
+
__privateGet(this, _inner).pause();
|
|
897
|
+
__privateSet(this, _lastSample, null);
|
|
898
|
+
__privateGet(this, _mirror).pause(__privateGet(this, _now2).call(this));
|
|
899
|
+
}
|
|
900
|
+
stop() {
|
|
901
|
+
__privateGet(this, _inner).stop();
|
|
902
|
+
__privateSet(this, _lastSample, null);
|
|
903
|
+
const now = __privateGet(this, _now2).call(this);
|
|
904
|
+
__privateGet(this, _mirror).pause(now);
|
|
905
|
+
__privateGet(this, _mirror).seekTo(0, now);
|
|
906
|
+
}
|
|
907
|
+
async seekPosition(position, when) {
|
|
908
|
+
await __privateGet(this, _inner).seekPosition(position, when);
|
|
909
|
+
__privateSet(this, _lastSample, null);
|
|
910
|
+
__privateGet(this, _mirror).seekTo(__privateGet(this, _inner).position, __privateGet(this, _now2).call(this));
|
|
911
|
+
}
|
|
912
|
+
setRate(rate) {
|
|
913
|
+
__privateGet(this, _inner).setRate?.(rate);
|
|
914
|
+
__privateSet(this, _lastSample, null);
|
|
915
|
+
__privateGet(this, _mirror).setRate(rate, __privateGet(this, _now2).call(this));
|
|
916
|
+
}
|
|
917
|
+
reconcile(now) {
|
|
918
|
+
const actual = __privateGet(this, _inner).position;
|
|
919
|
+
if (!Number.isFinite(actual) || actual < 0) return "ok";
|
|
920
|
+
const mirrorPosition = __privateGet(this, _mirror).positionAt(now);
|
|
921
|
+
const sample = __privateGet(this, _lastSample);
|
|
922
|
+
__privateSet(this, _lastSample, { position: actual, mirrorPosition, time: now });
|
|
923
|
+
if (sample !== null && actual === sample.position && mirrorPosition - sample.mirrorPosition > __privateGet(this, _tolerance) && !__privateGet(this, _mirror).paused) {
|
|
924
|
+
__privateSet(this, _lastSample, null);
|
|
925
|
+
__privateGet(this, _mirror).pause(now);
|
|
926
|
+
return "stalled";
|
|
927
|
+
}
|
|
928
|
+
if (sample !== null && !__privateGet(this, _mirror).paused) {
|
|
929
|
+
const elapsed = now - sample.time;
|
|
930
|
+
const advanced = actual - sample.position;
|
|
931
|
+
if (elapsed > 0 && advanced > 0) {
|
|
932
|
+
const measured = advanced / elapsed;
|
|
933
|
+
const current = __privateGet(this, _mirror).rate;
|
|
934
|
+
if (Number.isFinite(measured) && measured > 0 && Math.abs(measured - current) > MIRROR_RATE_TOLERANCE * current) {
|
|
935
|
+
__privateGet(this, _mirror).setRate(measured, now);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (Math.abs(mirrorPosition - actual) > __privateGet(this, _tolerance)) {
|
|
940
|
+
__privateGet(this, _mirror).seekTo(actual, now);
|
|
941
|
+
}
|
|
942
|
+
return "ok";
|
|
943
|
+
}
|
|
944
|
+
dispose() {
|
|
945
|
+
__privateGet(this, _inner).dispose?.();
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
_inner = new WeakMap();
|
|
949
|
+
_mirror = new WeakMap();
|
|
950
|
+
_now2 = new WeakMap();
|
|
951
|
+
_tolerance = new WeakMap();
|
|
952
|
+
_lastSample = new WeakMap();
|
|
953
|
+
function assertFiniteNonNegative(name, value) {
|
|
954
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
955
|
+
throw new RangeError(`${name} must be finite and >= 0.`);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function assertValidLoop(loop) {
|
|
959
|
+
if (!Number.isFinite(loop.startSeconds) || loop.startSeconds < 0 || !Number.isFinite(loop.endSeconds) || !(loop.endSeconds > loop.startSeconds)) {
|
|
960
|
+
throw new RangeError("Loop bounds must be finite, non-negative, and endSeconds must be greater than startSeconds.");
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
function validateCommand(command) {
|
|
964
|
+
switch (command.type) {
|
|
965
|
+
case "play":
|
|
966
|
+
case "pause":
|
|
967
|
+
case "stop":
|
|
968
|
+
return;
|
|
969
|
+
case "seek":
|
|
970
|
+
assertFiniteNonNegative("position", command.position);
|
|
971
|
+
return;
|
|
972
|
+
case "rate":
|
|
973
|
+
if (!Number.isFinite(command.rate) || command.rate <= 0) throw new RangeError("rate must be finite and > 0.");
|
|
974
|
+
return;
|
|
975
|
+
case "loop":
|
|
976
|
+
if (command.loop) assertValidLoop(command.loop);
|
|
977
|
+
return;
|
|
978
|
+
default:
|
|
979
|
+
throw new TypeError("Unknown transport command.");
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export {
|
|
984
|
+
TransportGroup,
|
|
985
|
+
MirrorClockMaster
|
|
986
|
+
};
|
|
987
|
+
//# sourceMappingURL=chunk-XBJBY4J5.js.map
|