@webmusic/kernel 0.1.0 → 0.4.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 +202 -21
- package/NOTICE +2 -0
- package/README.md +138 -101
- package/dist/audio-context.cjs.map +1 -1
- package/dist/build-receipt.json +3 -3
- package/dist/chunk-27LH6QLZ.cjs +277 -0
- package/dist/chunk-27LH6QLZ.cjs.map +1 -0
- package/dist/chunk-3INDOVUC.cjs.map +1 -1
- package/dist/chunk-3RR2VIKA.js +393 -0
- package/dist/chunk-3RR2VIKA.js.map +1 -0
- package/dist/chunk-3YTKIKKX.cjs +378 -0
- package/dist/chunk-3YTKIKKX.cjs.map +1 -0
- package/dist/chunk-4RG4WQKC.js +360 -0
- package/dist/chunk-4RG4WQKC.js.map +1 -0
- package/dist/chunk-5AHVQXTF.cjs +620 -0
- package/dist/chunk-5AHVQXTF.cjs.map +1 -0
- package/dist/chunk-624KWJWZ.js +170 -0
- package/dist/chunk-624KWJWZ.js.map +1 -0
- package/dist/chunk-6HGFEKD3.cjs +851 -0
- package/dist/chunk-6HGFEKD3.cjs.map +1 -0
- package/dist/chunk-7ZTZZ5PN.cjs.map +1 -1
- package/dist/chunk-ALWV4P7D.js +726 -0
- package/dist/chunk-ALWV4P7D.js.map +1 -0
- package/dist/chunk-BADJJ6DV.cjs +143 -0
- package/dist/chunk-BADJJ6DV.cjs.map +1 -0
- package/dist/chunk-C3LMS36L.cjs +393 -0
- package/dist/chunk-C3LMS36L.cjs.map +1 -0
- package/dist/chunk-C3YWUZW3.cjs.map +1 -1
- package/dist/chunk-CR6OUWBJ.cjs +726 -0
- package/dist/chunk-CR6OUWBJ.cjs.map +1 -0
- package/dist/chunk-CYWDZLWC.js +2141 -0
- package/dist/chunk-CYWDZLWC.js.map +1 -0
- package/dist/chunk-DDOGX2D5.js +378 -0
- package/dist/chunk-DDOGX2D5.js.map +1 -0
- package/dist/chunk-DVN6E5U3.js +620 -0
- package/dist/chunk-DVN6E5U3.js.map +1 -0
- package/dist/chunk-EURMRU2S.js +208 -0
- package/dist/chunk-EURMRU2S.js.map +1 -0
- package/dist/chunk-EXDCK2VL.cjs +20 -0
- package/dist/chunk-EXDCK2VL.cjs.map +1 -0
- package/dist/chunk-G5EIUP52.js +114 -0
- package/dist/chunk-G5EIUP52.js.map +1 -0
- package/dist/chunk-GB4DGKLZ.js +143 -0
- package/dist/chunk-GB4DGKLZ.js.map +1 -0
- package/dist/chunk-GPOEAYOW.js +2147 -0
- package/dist/chunk-GPOEAYOW.js.map +1 -0
- package/dist/chunk-I4YMA5VM.cjs +120 -0
- package/dist/chunk-I4YMA5VM.cjs.map +1 -0
- package/dist/chunk-IVWHMDCB.cjs +4383 -0
- package/dist/chunk-IVWHMDCB.cjs.map +1 -0
- package/dist/chunk-JFCBJMA7.cjs +2147 -0
- package/dist/chunk-JFCBJMA7.cjs.map +1 -0
- package/dist/chunk-JLVSAZ3K.cjs +813 -0
- package/dist/chunk-JLVSAZ3K.cjs.map +1 -0
- package/dist/chunk-K7FYH6UG.cjs +208 -0
- package/dist/chunk-K7FYH6UG.cjs.map +1 -0
- package/dist/chunk-L4MYCETM.cjs +970 -0
- package/dist/chunk-L4MYCETM.cjs.map +1 -0
- package/dist/chunk-MNCMYNYL.js +970 -0
- package/dist/chunk-MNCMYNYL.js.map +1 -0
- package/dist/chunk-NT2BZ3QM.js +120 -0
- package/dist/chunk-NT2BZ3QM.js.map +1 -0
- package/dist/chunk-O7SA5GLC.js +277 -0
- package/dist/chunk-O7SA5GLC.js.map +1 -0
- package/dist/chunk-OCKAHITL.cjs +548 -0
- package/dist/chunk-OCKAHITL.cjs.map +1 -0
- package/dist/{chunk-HOKRTYPV.js → chunk-OPBHDUZK.js} +39 -1
- package/dist/chunk-OPBHDUZK.js.map +1 -0
- package/dist/chunk-OTXYWCLA.js +206 -0
- package/dist/chunk-OTXYWCLA.js.map +1 -0
- package/dist/chunk-P6ZA63J7.js +548 -0
- package/dist/chunk-P6ZA63J7.js.map +1 -0
- package/dist/chunk-QLF3BOST.js +20 -0
- package/dist/chunk-QLF3BOST.js.map +1 -0
- package/dist/chunk-RCWFRZDR.js +4383 -0
- package/dist/chunk-RCWFRZDR.js.map +1 -0
- package/dist/chunk-RZBLPM3L.cjs +206 -0
- package/dist/chunk-RZBLPM3L.cjs.map +1 -0
- package/dist/chunk-TA3TNJZU.cjs +360 -0
- package/dist/chunk-TA3TNJZU.cjs.map +1 -0
- package/dist/chunk-TZSRPTQL.cjs +2141 -0
- package/dist/chunk-TZSRPTQL.cjs.map +1 -0
- package/dist/chunk-UMTPJ76S.cjs.map +1 -1
- package/dist/chunk-UY77FXDW.js +813 -0
- package/dist/chunk-UY77FXDW.js.map +1 -0
- package/dist/chunk-VFU3S7OC.js +851 -0
- package/dist/chunk-VFU3S7OC.js.map +1 -0
- package/dist/chunk-VY6WWZSW.cjs.map +1 -1
- package/dist/chunk-WN5DZOVT.cjs +170 -0
- package/dist/chunk-WN5DZOVT.cjs.map +1 -0
- package/dist/{chunk-HZQX4J2J.cjs → chunk-WOPW6WLR.cjs} +40 -2
- package/dist/chunk-WOPW6WLR.cjs.map +1 -0
- package/dist/chunk-XBSIYUHM.cjs +114 -0
- package/dist/chunk-XBSIYUHM.cjs.map +1 -0
- package/dist/chunk-ZMU72HJS.cjs.map +1 -1
- package/dist/context-DSa0ymyN.d.cts +664 -0
- package/dist/context-DaxfAg3b.d.ts +664 -0
- package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
- package/dist/effect-chain-Do75T7uK.d.cts +91 -0
- package/dist/effect.cjs +16 -1
- package/dist/effect.cjs.map +1 -1
- package/dist/effect.d.cts +56 -14
- package/dist/effect.d.ts +56 -14
- package/dist/effect.js +16 -1
- package/dist/elements.cjs +37 -2
- package/dist/elements.cjs.map +1 -1
- package/dist/elements.d.cts +197 -8
- package/dist/elements.d.ts +197 -8
- package/dist/elements.js +36 -1
- package/dist/events.cjs.map +1 -1
- package/dist/index.cjs +556 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +567 -20
- package/dist/message.cjs +104 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +738 -0
- package/dist/message.d.ts +738 -0
- package/dist/message.js +104 -0
- package/dist/meter.cjs +2 -2
- package/dist/meter.cjs.map +1 -1
- package/dist/meter.d.cts +9 -1
- package/dist/meter.d.ts +9 -1
- package/dist/meter.js +1 -1
- package/dist/module-control-C25BMtH7.d.ts +61 -0
- package/dist/module-control-yH6nTJM9.d.cts +61 -0
- package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
- package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
- package/dist/module.cjs +263 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.d.cts +1112 -0
- package/dist/module.d.ts +1112 -0
- package/dist/module.js +263 -0
- package/dist/parameter-DwQzFmBR.d.cts +172 -0
- package/dist/parameter-DwQzFmBR.d.ts +172 -0
- package/dist/player.cjs.map +1 -1
- package/dist/processor-worklet.cjs +18 -0
- package/dist/processor-worklet.cjs.map +1 -0
- package/dist/processor-worklet.d.cts +166 -0
- package/dist/processor-worklet.d.ts +166 -0
- package/dist/processor-worklet.js +18 -0
- package/dist/processor-worklet.js.map +1 -0
- package/dist/processor.cjs +51 -0
- package/dist/processor.cjs.map +1 -0
- package/dist/processor.d.cts +397 -0
- package/dist/processor.d.ts +397 -0
- package/dist/processor.js +51 -0
- package/dist/processor.js.map +1 -0
- package/dist/project-types-BU4awMnL.d.ts +323 -0
- package/dist/project-types-DufCV8Ma.d.cts +323 -0
- package/dist/ring-C-i9N90a.d.cts +139 -0
- package/dist/ring-DkcMt2Eg.d.ts +139 -0
- package/dist/sequence.cjs +68 -0
- package/dist/sequence.cjs.map +1 -0
- package/dist/sequence.d.cts +303 -0
- package/dist/sequence.d.ts +303 -0
- package/dist/sequence.js +68 -0
- package/dist/sequence.js.map +1 -0
- package/dist/session.cjs +16 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +407 -0
- package/dist/session.d.ts +407 -0
- package/dist/session.js +16 -0
- package/dist/session.js.map +1 -0
- package/dist/tick.cjs.map +1 -1
- package/dist/transport.cjs +50 -2
- package/dist/transport.cjs.map +1 -1
- package/dist/transport.d.cts +145 -1
- package/dist/transport.d.ts +145 -1
- package/dist/transport.js +51 -3
- package/dist/worker.cjs.map +1 -1
- package/package.json +62 -11
- package/dist/chunk-53YD73OY.js +0 -162
- package/dist/chunk-53YD73OY.js.map +0 -1
- package/dist/chunk-BR63OD53.cjs +0 -1
- package/dist/chunk-BR63OD53.cjs.map +0 -1
- package/dist/chunk-HOKRTYPV.js.map +0 -1
- package/dist/chunk-HZQX4J2J.cjs.map +0 -1
- package/dist/chunk-JNXB74G3.cjs +0 -987
- package/dist/chunk-JNXB74G3.cjs.map +0 -1
- package/dist/chunk-SM5YPDDI.cjs +0 -162
- package/dist/chunk-SM5YPDDI.cjs.map +0 -1
- package/dist/chunk-TEM2I2NN.js +0 -1
- package/dist/chunk-VVZX7DQ6.cjs +0 -254
- package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
- package/dist/chunk-WNFGDB7B.js +0 -254
- package/dist/chunk-WNFGDB7B.js.map +0 -1
- package/dist/chunk-XBJBY4J5.js +0 -987
- package/dist/chunk-XBJBY4J5.js.map +0 -1
- package/dist/sync.cjs +0 -12
- package/dist/sync.cjs.map +0 -1
- package/dist/sync.d.cts +0 -304
- package/dist/sync.d.ts +0 -304
- package/dist/sync.js +0 -12
- /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
- /package/dist/{sync.js.map → module.js.map} +0 -0
|
@@ -0,0 +1,2147 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk5AHVQXTFcjs = require('./chunk-5AHVQXTF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunk3INDOVUCcjs = require('./chunk-3INDOVUC.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkTA3TNJZUcjs = require('./chunk-TA3TNJZU.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkEXDCK2VLcjs = require('./chunk-EXDCK2VL.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
|
|
21
|
+
|
|
22
|
+
// src/session-scheduling.ts
|
|
23
|
+
var SessionSchedulingAuthority = class {
|
|
24
|
+
constructor(clock, now, loop) {
|
|
25
|
+
this.clock = clock;
|
|
26
|
+
this.now = now;
|
|
27
|
+
this.loop = loop;
|
|
28
|
+
this.identity = Object.freeze({});
|
|
29
|
+
this.generation = 0;
|
|
30
|
+
this.phase = "ready";
|
|
31
|
+
this.records = /* @__PURE__ */ new Set();
|
|
32
|
+
}
|
|
33
|
+
get epoch() {
|
|
34
|
+
return this.generation;
|
|
35
|
+
}
|
|
36
|
+
createBinding(axis, offset = 0, scale = 1) {
|
|
37
|
+
if (!axis.trim() || !Number.isFinite(offset) || !Number.isFinite(scale) || scale <= 0) throw new RangeError("Scheduling binding requires an axis and finite affine mapping with positive scale.");
|
|
38
|
+
const owner = () => this;
|
|
39
|
+
const mapped = Object.freeze({
|
|
40
|
+
get state() {
|
|
41
|
+
const state = owner().clock.state;
|
|
42
|
+
return Object.freeze({ ...state, paused: !record.alive || state.paused, originPosition: offset + state.originPosition * scale, rate: state.rate * scale });
|
|
43
|
+
},
|
|
44
|
+
get rate() {
|
|
45
|
+
return owner().clock.rate * scale;
|
|
46
|
+
},
|
|
47
|
+
get paused() {
|
|
48
|
+
return !record.alive || owner().clock.paused;
|
|
49
|
+
},
|
|
50
|
+
get holding() {
|
|
51
|
+
return owner().clock.holding;
|
|
52
|
+
},
|
|
53
|
+
positionAt: (time) => offset + owner().clock.positionAt(time) * scale,
|
|
54
|
+
timeAt: (position) => owner().clock.timeAt((position - offset) / scale)
|
|
55
|
+
});
|
|
56
|
+
const snapshot = () => {
|
|
57
|
+
const state = mapped.state, loop = owner().loop();
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
...state,
|
|
60
|
+
epoch: owner().generation,
|
|
61
|
+
phase: record.alive ? owner().phase : "disposed",
|
|
62
|
+
referenceTime: owner().now(),
|
|
63
|
+
paused: mapped.paused,
|
|
64
|
+
holding: mapped.holding,
|
|
65
|
+
loop: loop ? Object.freeze({ startSeconds: offset + loop.startSeconds * scale, endSeconds: offset + loop.endSeconds * scale }) : null
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const binding = Object.freeze({
|
|
69
|
+
authority: this.identity,
|
|
70
|
+
axis,
|
|
71
|
+
get epoch() {
|
|
72
|
+
return owner().generation;
|
|
73
|
+
},
|
|
74
|
+
clock: mapped,
|
|
75
|
+
get snapshot() {
|
|
76
|
+
return snapshot();
|
|
77
|
+
},
|
|
78
|
+
positionAt(time) {
|
|
79
|
+
return fold(mapped.positionAt(time), snapshot().loop);
|
|
80
|
+
},
|
|
81
|
+
segments(from, to) {
|
|
82
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || to < from) throw new RangeError("Scheduling windows require finite ordered reference times.");
|
|
83
|
+
const state = snapshot();
|
|
84
|
+
if (state.phase !== "ready" || state.paused || from === to) return Object.freeze([]);
|
|
85
|
+
let start = Math.max(from, state.holding ? state.originTime : from);
|
|
86
|
+
if (start >= to) return Object.freeze([]);
|
|
87
|
+
const results = [];
|
|
88
|
+
const loop = state.loop;
|
|
89
|
+
const raw = mapped.positionAt(start);
|
|
90
|
+
const period = loop ? loop.endSeconds - loop.startSeconds : 0;
|
|
91
|
+
let iteration = loop && raw >= loop.endSeconds ? Math.floor((raw - loop.startSeconds) / period) : 0;
|
|
92
|
+
let position = loop ? raw - iteration * period : raw;
|
|
93
|
+
while (start < to) {
|
|
94
|
+
if (results.length >= 1e4) throw new RangeError("Scheduling window exceeds 10000 loop segments; request a smaller window.");
|
|
95
|
+
let boundary = loop ? state.originTime + (loop.endSeconds + iteration * period - state.originPosition) / state.rate : Infinity;
|
|
96
|
+
if (loop && boundary <= start) {
|
|
97
|
+
iteration++;
|
|
98
|
+
position = loop.startSeconds;
|
|
99
|
+
boundary = state.originTime + (loop.endSeconds + iteration * period - state.originPosition) / state.rate;
|
|
100
|
+
}
|
|
101
|
+
const end = Math.min(to, boundary);
|
|
102
|
+
if (!(end > start)) throw new RangeError("Loop is too small for the reference-clock precision.");
|
|
103
|
+
results.push(Object.freeze({
|
|
104
|
+
epoch: state.epoch,
|
|
105
|
+
iteration,
|
|
106
|
+
referenceStart: start,
|
|
107
|
+
referenceEnd: end,
|
|
108
|
+
positionStart: position,
|
|
109
|
+
positionEnd: end === boundary && loop ? loop.endSeconds : position + (end - start) * state.rate,
|
|
110
|
+
rate: state.rate
|
|
111
|
+
}));
|
|
112
|
+
start = end;
|
|
113
|
+
if (loop && end === boundary) {
|
|
114
|
+
iteration++;
|
|
115
|
+
position = loop.startSeconds;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return Object.freeze(results);
|
|
119
|
+
},
|
|
120
|
+
subscribe(listener) {
|
|
121
|
+
if (!record.alive || owner().phase === "disposed") throw new Error("Scheduling binding is disposed.");
|
|
122
|
+
const registration = (event) => listener(event);
|
|
123
|
+
record.listeners.add(registration);
|
|
124
|
+
try {
|
|
125
|
+
deliver(registration, { type: owner().phase === "invalidated" ? "invalidate" : "anchor", snapshot: snapshot(), cause: owner().cause });
|
|
126
|
+
} catch (error) {
|
|
127
|
+
record.listeners.delete(registration);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
return () => {
|
|
131
|
+
record.listeners.delete(registration);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const record = { binding, alive: true, listeners: /* @__PURE__ */ new Set() };
|
|
136
|
+
this.records.add(record);
|
|
137
|
+
return binding;
|
|
138
|
+
}
|
|
139
|
+
invalidate(cause) {
|
|
140
|
+
if (this.phase === "disposed") return;
|
|
141
|
+
++this.generation;
|
|
142
|
+
this.cause = cause;
|
|
143
|
+
this.phase = "invalidated";
|
|
144
|
+
this.publish("invalidate");
|
|
145
|
+
}
|
|
146
|
+
anchor() {
|
|
147
|
+
if (this.phase === "disposed") return;
|
|
148
|
+
this.phase = "ready";
|
|
149
|
+
this.publish("anchor");
|
|
150
|
+
}
|
|
151
|
+
release(binding) {
|
|
152
|
+
const record = [...this.records].find((candidate) => candidate.binding === binding);
|
|
153
|
+
if (!record || !record.alive) return;
|
|
154
|
+
record.alive = false;
|
|
155
|
+
this.records.delete(record);
|
|
156
|
+
try {
|
|
157
|
+
this.publishRecord(record, "dispose", this.generation);
|
|
158
|
+
} finally {
|
|
159
|
+
record.listeners.clear();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
dispose() {
|
|
163
|
+
if (this.phase === "disposed") return;
|
|
164
|
+
++this.generation;
|
|
165
|
+
this.phase = "disposed";
|
|
166
|
+
let failure;
|
|
167
|
+
for (const record of [...this.records]) {
|
|
168
|
+
try {
|
|
169
|
+
this.release(record.binding);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (failure) throw failure;
|
|
175
|
+
}
|
|
176
|
+
publish(type) {
|
|
177
|
+
const epoch = this.generation;
|
|
178
|
+
let failure;
|
|
179
|
+
for (const record of [...this.records]) {
|
|
180
|
+
if (epoch !== this.generation) break;
|
|
181
|
+
if (!record.alive) continue;
|
|
182
|
+
try {
|
|
183
|
+
this.publishRecord(record, type, epoch);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (failure) throw failure;
|
|
189
|
+
}
|
|
190
|
+
publishRecord(record, type, epoch) {
|
|
191
|
+
const event = Object.freeze({ type, snapshot: record.binding.snapshot, cause: this.cause });
|
|
192
|
+
let failure;
|
|
193
|
+
for (const listener of [...record.listeners]) {
|
|
194
|
+
if (type !== "dispose" && epoch !== this.generation) break;
|
|
195
|
+
if (!record.listeners.has(listener)) continue;
|
|
196
|
+
try {
|
|
197
|
+
deliver(listener, event);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (failure) throw failure;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
function deliver(listener, event) {
|
|
206
|
+
const result = listener(event);
|
|
207
|
+
if (result && typeof result.then === "function") {
|
|
208
|
+
void Promise.resolve(result).catch(() => {
|
|
209
|
+
});
|
|
210
|
+
throw new TypeError("Scheduling callbacks must complete synchronously.");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function fold(position, loop) {
|
|
214
|
+
if (!loop || position < loop.endSeconds) return position;
|
|
215
|
+
return loop.startSeconds + (position - loop.startSeconds) % (loop.endSeconds - loop.startSeconds);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/sync.ts
|
|
219
|
+
var MAX_CONSECUTIVE_DRIFT_JOINS = 3;
|
|
220
|
+
var MASTER_RECONCILE_INTERVAL_MS = 250;
|
|
221
|
+
var _master, _followers, _now, _leadIn, _driftTolerance, _driftIntervalMs, _ticker, _tickOptions, _ticksPerDriftCheck, _ticksPerMasterReconcile, _tickCount, _loop, _wrapping, _generation, _revision, _lastCommandRevision, _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, 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;
|
|
222
|
+
var TransportGroup = class {
|
|
223
|
+
constructor(master, now, options = {}) {
|
|
224
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _TransportGroup_instances);
|
|
225
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _master);
|
|
226
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _followers, []);
|
|
227
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _now);
|
|
228
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _leadIn);
|
|
229
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _driftTolerance);
|
|
230
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _driftIntervalMs);
|
|
231
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticker, null);
|
|
232
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _tickOptions);
|
|
233
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticksPerDriftCheck);
|
|
234
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ticksPerMasterReconcile);
|
|
235
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _tickCount, 0);
|
|
236
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _loop, null);
|
|
237
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _wrapping, false);
|
|
238
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _generation, 0);
|
|
239
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _revision, 0);
|
|
240
|
+
/** Last submitted command, excluding background reconciliation revisions. */
|
|
241
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastCommandRevision, 0);
|
|
242
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pendingCommands, /* @__PURE__ */ new Set());
|
|
243
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _observers, /* @__PURE__ */ new Set());
|
|
244
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _lastSnapshot);
|
|
245
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pendingTransitions, 0);
|
|
246
|
+
/** Serializes transport commands so late async settlements cannot reorder state. */
|
|
247
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _commandActive, false);
|
|
248
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _queuedCommands, []);
|
|
249
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _intent, "paused");
|
|
250
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed, false);
|
|
251
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _onOperationError);
|
|
252
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _master, master);
|
|
253
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now, now);
|
|
254
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _leadIn, _nullishCoalesce(options.leadInSeconds, () => ( 0.06)));
|
|
255
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _driftTolerance, _nullishCoalesce(options.driftToleranceSeconds, () => ( 0.03)));
|
|
256
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _driftIntervalMs, _nullishCoalesce(options.driftCheckIntervalMs, () => ( 250)));
|
|
257
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _onOperationError, options.onOperationError);
|
|
258
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickOptions, { intervalMs: 25, ...options.tick });
|
|
259
|
+
assertFiniteNonNegative("leadInSeconds", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn));
|
|
260
|
+
assertFiniteNonNegative("driftToleranceSeconds", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftTolerance));
|
|
261
|
+
assertFiniteNonNegative("driftCheckIntervalMs", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs));
|
|
262
|
+
const tickInterval = _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickOptions).intervalMs, () => ( 25));
|
|
263
|
+
if (!Number.isSafeInteger(tickInterval) || tickInterval < 1 || tickInterval > _chunk3INDOVUCcjs.MAX_TIMER_DELAY_MS) {
|
|
264
|
+
throw new RangeError(
|
|
265
|
+
`tick.intervalMs must be a positive safe integer no greater than ${_chunk3INDOVUCcjs.MAX_TIMER_DELAY_MS}.`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticksPerDriftCheck, Math.max(1, Math.round(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) / tickInterval)));
|
|
269
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticksPerMasterReconcile, Math.max(1, Math.ceil(MASTER_RECONCILE_INTERVAL_MS / tickInterval)));
|
|
270
|
+
if (options.loop) {
|
|
271
|
+
assertValidLoop(options.loop);
|
|
272
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _loop, { ...options.loop });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/** The group timeline: a read-through to the master's own clock. */
|
|
276
|
+
get clock() {
|
|
277
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).clock;
|
|
278
|
+
}
|
|
279
|
+
/** Current position on the master axis. */
|
|
280
|
+
get position() {
|
|
281
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).position;
|
|
282
|
+
}
|
|
283
|
+
/** Read one coherent state on the master's stable position axis. */
|
|
284
|
+
get snapshot() {
|
|
285
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot)) {
|
|
286
|
+
return Object.freeze({ ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot), revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision), pending: false, disposed: true });
|
|
287
|
+
}
|
|
288
|
+
const referenceTime = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
|
|
289
|
+
const clock = this.clock;
|
|
290
|
+
const loop = this.loop;
|
|
291
|
+
const snapshot = Object.freeze({
|
|
292
|
+
revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision),
|
|
293
|
+
referenceTime,
|
|
294
|
+
position: clock.positionAt(referenceTime),
|
|
295
|
+
rate: clock.rate,
|
|
296
|
+
paused: clock.paused,
|
|
297
|
+
holding: clock.holding && clock.state.originTime > referenceTime,
|
|
298
|
+
loop: loop ? Object.freeze(loop) : null,
|
|
299
|
+
pending: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).size > 0 || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0,
|
|
300
|
+
disposed: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)
|
|
301
|
+
});
|
|
302
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, snapshot);
|
|
303
|
+
return snapshot;
|
|
304
|
+
}
|
|
305
|
+
/** Register before synchronously delivering the initial snapshot. Observer
|
|
306
|
+
* failures are contained. Unsubscribe never stops borrowed playback. */
|
|
307
|
+
subscribe(listener) {
|
|
308
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
309
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).add(listener);
|
|
310
|
+
try {
|
|
311
|
+
listener({ type: "snapshot", snapshot: this.snapshot });
|
|
312
|
+
} catch (e) {
|
|
313
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).delete(listener);
|
|
314
|
+
}
|
|
315
|
+
return () => {
|
|
316
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).delete(listener);
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** Submit a command and await its actual participant settlement. Failures
|
|
320
|
+
* reject and emit an error; superseded work cannot claim a committed result.
|
|
321
|
+
* Pause/stop take effect synchronously and await any late-start reconciliation.
|
|
322
|
+
* Call this authority exclusively while coordinating a session. */
|
|
323
|
+
dispatch(command) {
|
|
324
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, command, true);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Register a follower. While the group is playing, the follower joins the
|
|
328
|
+
* running timeline on the next scheduled join.
|
|
329
|
+
*/
|
|
330
|
+
addFollower(transport, options = {}) {
|
|
331
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
332
|
+
const offset = _nullishCoalesce(options.offsetSeconds, () => ( 0));
|
|
333
|
+
assertFiniteNonNegative("offsetSeconds", offset);
|
|
334
|
+
const scale = _nullishCoalesce(options.positionScale, () => ( 1));
|
|
335
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new RangeError("positionScale must be finite and > 0.");
|
|
336
|
+
if (scale !== 1 && !transport.setRate) throw new Error("A scaled follower must support setRate.");
|
|
337
|
+
if (options.loop) assertValidLoop(options.loop);
|
|
338
|
+
const record = {
|
|
339
|
+
transport,
|
|
340
|
+
offset,
|
|
341
|
+
scale,
|
|
342
|
+
loop: options.loop ? { ...options.loop } : null,
|
|
343
|
+
joinAt: 0,
|
|
344
|
+
consecutiveDriftJoins: 0,
|
|
345
|
+
driftJoinsSuppressed: false
|
|
346
|
+
};
|
|
347
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).push(record);
|
|
348
|
+
if (!this.clock.paused) {
|
|
349
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, observeReconciliation_fn).call(this, "follower join", () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation), "follower join", [record]));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Remove a follower from the group (the transport itself is left as-is,
|
|
354
|
+
* still playing if it was; the caller owns its lifecycle from here).
|
|
355
|
+
* Returns false when the transport was not a member.
|
|
356
|
+
*/
|
|
357
|
+
removeFollower(transport) {
|
|
358
|
+
const index = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).findIndex((record) => record.transport === transport);
|
|
359
|
+
if (index < 0) return false;
|
|
360
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).splice(index, 1);
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
/** Number of registered followers. */
|
|
364
|
+
get followerCount() {
|
|
365
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).length;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Set (or clear) a loop region on the master axis, live. The wrap runs
|
|
369
|
+
* through {@link seek}, so it inherits the shared re-entry origin; the
|
|
370
|
+
* boundary is detected by a worker-backed tick watcher, so the wrap
|
|
371
|
+
* instant may trail the boundary by the watcher/preparation delay and lead-in.
|
|
372
|
+
* Browser throttling means this is not a bounded timing guarantee.
|
|
373
|
+
*/
|
|
374
|
+
setLoop(loop) {
|
|
375
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
376
|
+
if (loop) assertValidLoop(loop);
|
|
377
|
+
void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "loop", loop }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop", error));
|
|
378
|
+
}
|
|
379
|
+
get loop() {
|
|
380
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) ? { ..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) } : null;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Start master and followers on one shared origin. The group proposes
|
|
384
|
+
* `now + leadInSeconds` to the master; one that supports scheduled starts
|
|
385
|
+
* arms there and every follower joins at that very instant. A master that
|
|
386
|
+
* ignores the proposal starts immediately and followers join a lead-in
|
|
387
|
+
* later, offset-matched to its anchor.
|
|
388
|
+
*/
|
|
389
|
+
async play() {
|
|
390
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "play" }, false);
|
|
391
|
+
}
|
|
392
|
+
pause() {
|
|
393
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
394
|
+
void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "pause" }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "pause", error));
|
|
395
|
+
}
|
|
396
|
+
stop() {
|
|
397
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
398
|
+
void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "stop" }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "stop", error));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Seek master and followers to a master-axis position. While playing, the
|
|
402
|
+
* group proposes a shared re-entry origin exactly as {@link play} does
|
|
403
|
+
* and re-joins the followers there, so all sides come back in together.
|
|
404
|
+
* Loop wraps run through this path and inherit the same shared origin.
|
|
405
|
+
*/
|
|
406
|
+
async seek(position) {
|
|
407
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "seek", position }, false);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Set the playback rate on the master and every follower. Followers
|
|
411
|
+
* re-join immediately on the shared clock. NOTE: the group does not clamp
|
|
412
|
+
* the rate beyond finite-and-positive — a domain wrapper owns any shared
|
|
413
|
+
* range its transports require.
|
|
414
|
+
*/
|
|
415
|
+
setRate(rate) {
|
|
416
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
417
|
+
validateCommand({ type: "rate", rate });
|
|
418
|
+
void _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, dispatch_fn).call(this, { type: "rate", rate }, false).catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "rate", error));
|
|
419
|
+
}
|
|
420
|
+
dispose() {
|
|
421
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
422
|
+
try {
|
|
423
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, this.snapshot);
|
|
424
|
+
} catch (e2) {
|
|
425
|
+
}
|
|
426
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed, true);
|
|
427
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
|
|
428
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
429
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "disposed");
|
|
430
|
+
const ticker = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker);
|
|
431
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticker, null);
|
|
432
|
+
const errors = [];
|
|
433
|
+
const releases = [() => _optionalChain([ticker, 'optionalAccess', _2 => _2.dispose, 'call', _3 => _3()])];
|
|
434
|
+
for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
|
|
435
|
+
releases.push(() => _optionalChain([record, 'access', _4 => _4.transport, 'access', _5 => _5.dispose, 'optionalCall', _6 => _6()]));
|
|
436
|
+
}
|
|
437
|
+
releases.push(() => _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _7 => _7.dispose, 'optionalCall', _8 => _8()]));
|
|
438
|
+
for (const release of releases) {
|
|
439
|
+
try {
|
|
440
|
+
release();
|
|
441
|
+
} catch (error) {
|
|
442
|
+
errors.push(error);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
let snapshot;
|
|
446
|
+
try {
|
|
447
|
+
snapshot = this.snapshot;
|
|
448
|
+
} catch (e3) {
|
|
449
|
+
}
|
|
450
|
+
if (snapshot) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "snapshot", snapshot });
|
|
451
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).clear();
|
|
452
|
+
if (errors.length > 0) throw errors[0];
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* One drift check: every follower is measured against the master clock,
|
|
456
|
+
* and each one out of tolerance is re-joined on the shared clock (the
|
|
457
|
+
* same scheduled-start dance as {@link play}). Returns the largest
|
|
458
|
+
* absolute drift observed (0 with no followers or while holding off).
|
|
459
|
+
*/
|
|
460
|
+
checkDrift() {
|
|
461
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
462
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return 0;
|
|
463
|
+
const now = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
|
|
464
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).reconcile) {
|
|
465
|
+
const revision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision);
|
|
466
|
+
const verdict = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).reconcile(now);
|
|
467
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) || revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) return 0;
|
|
468
|
+
if (verdict === "stalled" && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
|
|
469
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
let worst = 0;
|
|
474
|
+
const stragglers = [];
|
|
475
|
+
for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
|
|
476
|
+
if (now < record.joinAt) continue;
|
|
477
|
+
const expected = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, this.clock.positionAt(now));
|
|
478
|
+
const followerClock = record.transport.clock;
|
|
479
|
+
if (_optionalChain([followerClock, 'optionalAccess', _9 => _9.holding]) && now < followerClock.state.originTime) continue;
|
|
480
|
+
const followerPosition = followerClock ? followerClock.positionAt(now) : record.transport.position;
|
|
481
|
+
const followerRunning = followerClock ? !followerClock.paused : record.transport.running !== false;
|
|
482
|
+
let localDrift = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrapLocal_fn).call(this, record, followerPosition) - expected;
|
|
483
|
+
if (record.loop && followerPosition >= record.loop.startSeconds && expected >= record.loop.startSeconds) {
|
|
484
|
+
const period = record.loop.endSeconds - record.loop.startSeconds;
|
|
485
|
+
localDrift = ((localDrift + period / 2) % period + period) % period - period / 2;
|
|
486
|
+
}
|
|
487
|
+
const drift = localDrift / record.scale;
|
|
488
|
+
if (Math.abs(drift) > Math.abs(worst)) worst = drift;
|
|
489
|
+
if (!followerRunning) continue;
|
|
490
|
+
const rateMismatch = followerClock !== void 0 && followerClock.rate !== this.clock.rate * record.scale;
|
|
491
|
+
if (Math.abs(drift) <= _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftTolerance) && !rateMismatch) {
|
|
492
|
+
record.consecutiveDriftJoins = 0;
|
|
493
|
+
record.driftJoinsSuppressed = false;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (record.driftJoinsSuppressed) continue;
|
|
497
|
+
record.consecutiveDriftJoins += 1;
|
|
498
|
+
if (record.consecutiveDriftJoins > MAX_CONSECUTIVE_DRIFT_JOINS) {
|
|
499
|
+
record.driftJoinsSuppressed = true;
|
|
500
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "drift re-join", new Error(
|
|
501
|
+
`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.`
|
|
502
|
+
));
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
stragglers.push(record);
|
|
506
|
+
}
|
|
507
|
+
if (stragglers.length > 0) {
|
|
508
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, observeReconciliation_fn).call(this, "drift re-join", () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation), "drift re-join", stragglers));
|
|
509
|
+
}
|
|
510
|
+
return worst;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
_master = new WeakMap();
|
|
514
|
+
_followers = new WeakMap();
|
|
515
|
+
_now = new WeakMap();
|
|
516
|
+
_leadIn = new WeakMap();
|
|
517
|
+
_driftTolerance = new WeakMap();
|
|
518
|
+
_driftIntervalMs = new WeakMap();
|
|
519
|
+
_ticker = new WeakMap();
|
|
520
|
+
_tickOptions = new WeakMap();
|
|
521
|
+
_ticksPerDriftCheck = new WeakMap();
|
|
522
|
+
_ticksPerMasterReconcile = new WeakMap();
|
|
523
|
+
_tickCount = new WeakMap();
|
|
524
|
+
_loop = new WeakMap();
|
|
525
|
+
_wrapping = new WeakMap();
|
|
526
|
+
_generation = new WeakMap();
|
|
527
|
+
_revision = new WeakMap();
|
|
528
|
+
_lastCommandRevision = new WeakMap();
|
|
529
|
+
_pendingCommands = new WeakMap();
|
|
530
|
+
_observers = new WeakMap();
|
|
531
|
+
_lastSnapshot = new WeakMap();
|
|
532
|
+
_pendingTransitions = new WeakMap();
|
|
533
|
+
_commandActive = new WeakMap();
|
|
534
|
+
_queuedCommands = new WeakMap();
|
|
535
|
+
_intent = new WeakMap();
|
|
536
|
+
_disposed = new WeakMap();
|
|
537
|
+
_onOperationError = new WeakMap();
|
|
538
|
+
_TransportGroup_instances = new WeakSet();
|
|
539
|
+
dispatch_fn = function(input, strict) {
|
|
540
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
541
|
+
validateCommand(input);
|
|
542
|
+
const command = Object.freeze(input.type === "loop" ? { ...input, loop: input.loop ? Object.freeze({ ...input.loop }) : null } : { ...input });
|
|
543
|
+
const revision = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
|
|
544
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastCommandRevision, revision);
|
|
545
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).add(revision);
|
|
546
|
+
let invalidationError;
|
|
547
|
+
try {
|
|
548
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _10 => _10.invalidate, 'optionalCall', _11 => _11(command)]);
|
|
549
|
+
} catch (error) {
|
|
550
|
+
invalidationError = error;
|
|
551
|
+
}
|
|
552
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "invalidate", revision, command, snapshot: this.snapshot });
|
|
553
|
+
let operation = void 0;
|
|
554
|
+
try {
|
|
555
|
+
if (invalidationError !== void 0) throw invalidationError;
|
|
556
|
+
if (revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) {
|
|
557
|
+
switch (command.type) {
|
|
558
|
+
case "play":
|
|
559
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, play_fn).call(this, strict);
|
|
560
|
+
break;
|
|
561
|
+
case "pause":
|
|
562
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, pause_fn).call(this);
|
|
563
|
+
break;
|
|
564
|
+
case "stop":
|
|
565
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stop_fn).call(this);
|
|
566
|
+
break;
|
|
567
|
+
case "seek":
|
|
568
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, seek_fn).call(this, command.position, strict, revision);
|
|
569
|
+
break;
|
|
570
|
+
case "rate":
|
|
571
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setRate_fn).call(this, command.rate, strict, revision);
|
|
572
|
+
break;
|
|
573
|
+
case "loop":
|
|
574
|
+
operation = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setLoop_fn).call(this, command.loop, revision);
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
} catch (error) {
|
|
579
|
+
operation = Promise.reject(error);
|
|
580
|
+
}
|
|
581
|
+
return Promise.resolve(operation).then(() => {
|
|
582
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
|
|
583
|
+
const snapshot = this.snapshot;
|
|
584
|
+
const commit = Object.freeze({
|
|
585
|
+
revision,
|
|
586
|
+
command,
|
|
587
|
+
status: revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? "committed" : "superseded",
|
|
588
|
+
snapshot
|
|
589
|
+
});
|
|
590
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "commit", commit, snapshot });
|
|
591
|
+
return commit;
|
|
592
|
+
}, (error) => {
|
|
593
|
+
if (strict && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
594
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
|
|
595
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "error", revision, command, error, snapshot: this.snapshot });
|
|
596
|
+
throw error;
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
publish_fn = function(event) {
|
|
600
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers)]) {
|
|
601
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _observers).has(listener)) continue;
|
|
602
|
+
try {
|
|
603
|
+
listener(event);
|
|
604
|
+
} catch (e4) {
|
|
605
|
+
}
|
|
606
|
+
if (event.snapshot.revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) break;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
setLoop_fn = function(loop, revision, queued = false) {
|
|
610
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).continuousLoop && !queued) return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setLoop_fn).call(this, loop, revision, true));
|
|
611
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
612
|
+
if (loop) assertValidLoop(loop);
|
|
613
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _loop, loop ? { ...loop } : null);
|
|
614
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _12 => _12.loopChanged, 'optionalCall', _13 => _13(this.loop, () => !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision))]);
|
|
615
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
|
|
616
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
|
|
617
|
+
} else {
|
|
618
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
play_fn = async function(strict) {
|
|
622
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
623
|
+
const generation = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
624
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
|
|
625
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "playing");
|
|
626
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
627
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
628
|
+
try {
|
|
629
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
630
|
+
await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).play(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this) + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn));
|
|
631
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
632
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (strict && this.clock.paused) throw new Error("Master transport did not start.");
|
|
636
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
|
|
637
|
+
if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, startDriftMonitor_fn).call(this);
|
|
638
|
+
} catch (error) {
|
|
639
|
+
if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
640
|
+
throw error;
|
|
641
|
+
} finally {
|
|
642
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
};
|
|
646
|
+
pause_fn = function() {
|
|
647
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
648
|
+
const hadPendingTransition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0;
|
|
649
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
650
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "paused");
|
|
651
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
652
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
653
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
654
|
+
if (hadPendingTransition) {
|
|
655
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
|
|
656
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
stop_fn = function() {
|
|
661
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
662
|
+
const hadPendingTransition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0;
|
|
663
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
664
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "stopped");
|
|
665
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
666
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
667
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
668
|
+
if (hadPendingTransition) {
|
|
669
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, () => {
|
|
670
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
seek_fn = async function(position, strict, revision) {
|
|
675
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
676
|
+
assertFiniteNonNegative("position", position);
|
|
677
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
|
|
678
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
679
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
680
|
+
try {
|
|
681
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
682
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
683
|
+
const wasRunning = !this.clock.paused;
|
|
684
|
+
await _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).seekPosition(
|
|
685
|
+
position,
|
|
686
|
+
wasRunning ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this) + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn) : void 0,
|
|
687
|
+
..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).continuousLoop ? [() => !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)] : []
|
|
688
|
+
);
|
|
689
|
+
const settled = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, readSettledMasterPosition_fn).call(this);
|
|
690
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
691
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
|
|
692
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (this.clock.paused) {
|
|
696
|
+
if (wasRunning && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") {
|
|
697
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleFailedResume_fn).call(this);
|
|
698
|
+
if (strict) throw new Error("Master transport stayed paused after seek.");
|
|
699
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileStaleSeek_fn).call(this, settled);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
|
|
703
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
704
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
705
|
+
record.transport.pause();
|
|
706
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
707
|
+
record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, settled));
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
|
|
711
|
+
}
|
|
712
|
+
} finally {
|
|
713
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
setRate_fn = function(rate, strict, revision, queued = false) {
|
|
718
|
+
if (strict && !queued) {
|
|
719
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
|
|
720
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
721
|
+
try {
|
|
722
|
+
if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
723
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, setRate_fn).call(this, rate, strict, revision, true);
|
|
724
|
+
} finally {
|
|
725
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, assertActive_fn).call(this);
|
|
730
|
+
if (!Number.isFinite(rate) || rate <= 0) {
|
|
731
|
+
throw new RangeError(`rate must be finite and > 0, got ${rate}.`);
|
|
732
|
+
}
|
|
733
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
734
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, resetDriftConvergence_fn).call(this);
|
|
735
|
+
try {
|
|
736
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _14 => _14.setRate, 'optionalCall', _15 => _15(rate)]);
|
|
737
|
+
} catch (error) {
|
|
738
|
+
if (strict) throw error;
|
|
739
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "master rate match", error);
|
|
740
|
+
}
|
|
741
|
+
if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
742
|
+
if (strict && this.clock.rate !== rate) throw new Error("Master transport did not accept the requested rate.");
|
|
743
|
+
for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
|
|
744
|
+
if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
745
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
746
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, rate, strict);
|
|
747
|
+
}
|
|
748
|
+
if (revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
749
|
+
if (!this.clock.paused) {
|
|
750
|
+
return queued ? _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict) : _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, queueJoin_fn).call(this, generation, "rate re-join", _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers), strict);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
wrapLocal_fn = function(record, position) {
|
|
754
|
+
const loop = record.loop;
|
|
755
|
+
if (!loop || position < loop.endSeconds) return position;
|
|
756
|
+
return loop.startSeconds + (position - loop.startSeconds) % (loop.endSeconds - loop.startSeconds);
|
|
757
|
+
};
|
|
758
|
+
localPosition_fn = function(record, masterPosition) {
|
|
759
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).continuousLoop && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) && masterPosition >= _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).endSeconds) {
|
|
760
|
+
masterPosition = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).startSeconds + (masterPosition - _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).startSeconds) % (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).endSeconds - _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).startSeconds);
|
|
761
|
+
}
|
|
762
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrapLocal_fn).call(this, record, record.offset + masterPosition * record.scale);
|
|
763
|
+
};
|
|
764
|
+
joinFollowers_fn = async function(generation, targets, strict = false) {
|
|
765
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
766
|
+
const members = [...targets];
|
|
767
|
+
for (const record of members) {
|
|
768
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) return;
|
|
769
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) record.transport.pause();
|
|
770
|
+
}
|
|
771
|
+
const clock = this.clock;
|
|
772
|
+
if (clock.paused) return;
|
|
773
|
+
const now = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this);
|
|
774
|
+
const armedOrigin = clock.holding ? clock.state.originTime : -Infinity;
|
|
775
|
+
const when = armedOrigin > now ? armedOrigin : now + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn);
|
|
776
|
+
const position = clock.positionAt(when);
|
|
777
|
+
const starts = [];
|
|
778
|
+
for (const record of members) {
|
|
779
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
780
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
781
|
+
try {
|
|
782
|
+
record.joinAt = when;
|
|
783
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyFollowerRate_fn).call(this, record, clock.rate, strict);
|
|
784
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
785
|
+
record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
|
|
786
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
787
|
+
starts.push(record.transport.play(when));
|
|
788
|
+
} catch (error) {
|
|
789
|
+
starts.push(Promise.reject(error));
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
const settled = await Promise.allSettled(starts);
|
|
794
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reapplySynchronousIntent_fn).call(this);
|
|
795
|
+
const failure = settled.find((result) => result.status === "rejected");
|
|
796
|
+
if (_optionalChain([failure, 'optionalAccess', _16 => _16.status]) === "rejected") throw failure.reason;
|
|
797
|
+
if (strict && _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
798
|
+
for (const record of members) {
|
|
799
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
800
|
+
const followerClock = record.transport.clock;
|
|
801
|
+
const running = followerClock ? !followerClock.paused : record.transport.running;
|
|
802
|
+
if (running === false) throw new Error("Follower transport did not start.");
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
/**
|
|
807
|
+
* Hand a follower a rate, skipping the call when it already runs at it.
|
|
808
|
+
* A follower with a clock is asked directly; for one without, the last
|
|
809
|
+
* applied value is remembered. Best-effort by contract: `setRate` is
|
|
810
|
+
* optional on {@link SyncFollowerTransport}, and a transport that has one
|
|
811
|
+
* may still clamp or refuse it — the convergence check below is what
|
|
812
|
+
* surfaces a mismatch neither side can resolve.
|
|
813
|
+
*/
|
|
814
|
+
applyFollowerRate_fn = function(record, rate, strict = false) {
|
|
815
|
+
rate *= record.scale;
|
|
816
|
+
if (!record.transport.setRate) {
|
|
817
|
+
if (strict && (_nullishCoalesce(_optionalChain([record, 'access', _17 => _17.transport, 'access', _18 => _18.clock, 'optionalAccess', _19 => _19.rate]), () => ( 1))) !== rate) {
|
|
818
|
+
throw new Error("Follower transport cannot accept the requested rate.");
|
|
819
|
+
}
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
if (!Number.isFinite(rate) || rate <= 0) return;
|
|
823
|
+
const current = _nullishCoalesce(_optionalChain([record, 'access', _20 => _20.transport, 'access', _21 => _21.clock, 'optionalAccess', _22 => _22.rate]), () => ( record.lastRate));
|
|
824
|
+
if (current === rate) return;
|
|
825
|
+
try {
|
|
826
|
+
record.transport.setRate(rate);
|
|
827
|
+
if (strict && record.transport.clock && record.transport.clock.rate !== rate) {
|
|
828
|
+
throw new Error("Follower transport did not accept the requested rate.");
|
|
829
|
+
}
|
|
830
|
+
record.lastRate = rate;
|
|
831
|
+
} catch (error) {
|
|
832
|
+
if (strict) throw error;
|
|
833
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "follower rate match", error);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
/** Re-arm drift corrections; any explicit command counts as a fresh start. */
|
|
837
|
+
resetDriftConvergence_fn = function() {
|
|
838
|
+
for (const record of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)) {
|
|
839
|
+
record.consecutiveDriftJoins = 0;
|
|
840
|
+
record.driftJoinsSuppressed = false;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
/**
|
|
844
|
+
* One watcher drives every concern off a kernel tick source (worker-backed
|
|
845
|
+
* where the platform allows, so background-tab throttling does not starve
|
|
846
|
+
* it): clocked master-stop reconciliation and the loop boundary every
|
|
847
|
+
* tick, drift every `driftCheckIntervalMs` worth of ticks. A clockless
|
|
848
|
+
* adapter is sampled at the default drift cadence when drift is disabled.
|
|
849
|
+
*/
|
|
850
|
+
onTick_fn = function() {
|
|
851
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
852
|
+
const revision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision);
|
|
853
|
+
try {
|
|
854
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) === 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) % _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticksPerMasterReconcile) === 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing" && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) === 0) {
|
|
855
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master), 'access', _23 => _23.reconcile, 'optionalCall', _24 => _24(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this))]);
|
|
856
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) || revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) return;
|
|
857
|
+
}
|
|
858
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reconcileMasterStop_fn).call(this);
|
|
859
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, checkLoop_fn).call(this);
|
|
860
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickCount, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) + 1);
|
|
861
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _driftIntervalMs) > 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickCount) % _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticksPerDriftCheck) === 0) {
|
|
862
|
+
this.checkDrift();
|
|
863
|
+
}
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
866
|
+
if (revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
867
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "transport monitor", error);
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
/**
|
|
871
|
+
* The master can stop on its own (a score player finishing at its natural
|
|
872
|
+
* end pauses and rewinds its clock, racing the group's boundary watcher
|
|
873
|
+
* tick-for-tick). A self-stopped clock while the group means to play
|
|
874
|
+
* either wraps (loop active — the loop's continuation intent outranks the
|
|
875
|
+
* master's own finish) or settles into the paused state.
|
|
876
|
+
*/
|
|
877
|
+
reconcileMasterStop_fn = function() {
|
|
878
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "playing" || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return;
|
|
879
|
+
if (!this.clock.paused) return;
|
|
880
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, handleMasterStopped_fn).call(this);
|
|
881
|
+
};
|
|
882
|
+
handleMasterStopped_fn = function() {
|
|
883
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).continuousLoop) {
|
|
884
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrap_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop).startSeconds);
|
|
885
|
+
} else {
|
|
886
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
checkLoop_fn = function() {
|
|
890
|
+
const loop = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _loop);
|
|
891
|
+
if (!loop || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).continuousLoop || this.clock.paused || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _wrapping) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0) return;
|
|
892
|
+
if (this.clock.positionAt(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now).call(this)) >= loop.endSeconds) {
|
|
893
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, wrap_fn).call(this, loop.startSeconds);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
/**
|
|
897
|
+
* Wrap to the loop start. A running master re-joins inside seek(); a
|
|
898
|
+
* master that stopped on its own (natural finish at or past the loop end)
|
|
899
|
+
* is restarted afterwards. A failed wrap settles into the paused state
|
|
900
|
+
* instead of retrying every tick, and is reported as 'loop wrap'.
|
|
901
|
+
*/
|
|
902
|
+
wrap_fn = function(startSeconds) {
|
|
903
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _wrapping, true);
|
|
904
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
905
|
+
const wrapCommandRevision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) + 1;
|
|
906
|
+
const stillCurrent = () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastCommandRevision) === wrapCommandRevision;
|
|
907
|
+
void this.seek(startSeconds).then(() => {
|
|
908
|
+
if (stillCurrent() && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing" && this.clock.paused) {
|
|
909
|
+
return this.play();
|
|
910
|
+
}
|
|
911
|
+
}).catch((error) => {
|
|
912
|
+
if (!stillCurrent()) return;
|
|
913
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "loop wrap", error);
|
|
914
|
+
if (stillCurrent() && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "playing") _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
915
|
+
}).finally(() => {
|
|
916
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _wrapping, false);
|
|
917
|
+
});
|
|
918
|
+
};
|
|
919
|
+
startDriftMonitor_fn = function() {
|
|
920
|
+
_nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker), () => ( _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ticker, _chunk3INDOVUCcjs.createTickSource.call(void 0, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _tickOptions)))));
|
|
921
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker).start(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, onTick_fn).call(this));
|
|
922
|
+
};
|
|
923
|
+
stopDriftMonitor_fn = function() {
|
|
924
|
+
_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ticker), 'optionalAccess', _25 => _25.stop, 'call', _26 => _26()]);
|
|
925
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _tickCount, 0);
|
|
926
|
+
};
|
|
927
|
+
isCurrent_fn = function(generation) {
|
|
928
|
+
return !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) && generation === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
929
|
+
};
|
|
930
|
+
reportOperationError_fn = function(operation, error) {
|
|
931
|
+
var _a;
|
|
932
|
+
let snapshot;
|
|
933
|
+
try {
|
|
934
|
+
snapshot = this.snapshot;
|
|
935
|
+
} catch (e5) {
|
|
936
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot)) {
|
|
937
|
+
snapshot = Object.freeze({
|
|
938
|
+
..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _lastSnapshot),
|
|
939
|
+
revision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision),
|
|
940
|
+
paused: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "playing",
|
|
941
|
+
holding: false,
|
|
942
|
+
pending: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).size > 0 || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) > 0,
|
|
943
|
+
disposed: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)
|
|
944
|
+
});
|
|
945
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _lastSnapshot, snapshot);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (snapshot) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "operation-error", operation, error, snapshot });
|
|
949
|
+
try {
|
|
950
|
+
(_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onOperationError)) == null ? void 0 : _a.call(this, operation, error);
|
|
951
|
+
} catch (e6) {
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
/**
|
|
955
|
+
* The master stopped although the group meant to be playing (a swallowed
|
|
956
|
+
* restart failure, or the master ending on its own): pause the followers
|
|
957
|
+
* and settle, exactly as an explicit pause() would.
|
|
958
|
+
*/
|
|
959
|
+
settleMasterStopped_fn = function() {
|
|
960
|
+
this.pause();
|
|
961
|
+
};
|
|
962
|
+
settleFailedResume_fn = function() {
|
|
963
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, settleMasterStopped_fn).call(this);
|
|
964
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, "resume after seek", new Error("TransportGroup: the master transport stayed paused after a mid-playback seek."));
|
|
965
|
+
};
|
|
966
|
+
assertActive_fn = function() {
|
|
967
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("TransportGroup has been disposed.");
|
|
968
|
+
};
|
|
969
|
+
observeReconciliation_fn = function(operation, apply) {
|
|
970
|
+
const revision = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _revision)._;
|
|
971
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).add(revision);
|
|
972
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "invalidate", snapshot: this.snapshot });
|
|
973
|
+
const pending = revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision) && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? apply() : Promise.resolve();
|
|
974
|
+
void pending.catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error)).finally(() => {
|
|
975
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingCommands).delete(revision);
|
|
976
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, publish_fn).call(this, { type: "reconcile", operation, phase: "settled", snapshot: this.snapshot });
|
|
977
|
+
});
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Queue an independent re-join as a visible transition. Public pause/stop
|
|
981
|
+
* calls can then schedule one final reconciliation behind it, preventing
|
|
982
|
+
* a late follower play() settlement from reviving playback.
|
|
983
|
+
*/
|
|
984
|
+
queueJoin_fn = function(generation, operation, targets, strict = false) {
|
|
985
|
+
const revision = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision);
|
|
986
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) + 1);
|
|
987
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, enqueueCommand_fn).call(this, async () => {
|
|
988
|
+
try {
|
|
989
|
+
await _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, joinFollowers_fn).call(this, generation, targets, strict);
|
|
990
|
+
} finally {
|
|
991
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _pendingTransitions, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingTransitions) - 1);
|
|
992
|
+
}
|
|
993
|
+
}).catch((error) => {
|
|
994
|
+
if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation) && revision === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _revision)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, rollbackFailedPlay_fn).call(this);
|
|
995
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, reportOperationError_fn).call(this, operation, error);
|
|
996
|
+
if (strict) throw error;
|
|
997
|
+
});
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* Run the first idle command immediately so master.play() remains inside
|
|
1001
|
+
* the browser's transient user-activation stack. Only commands that
|
|
1002
|
+
* actually have an async predecessor wait in the FIFO.
|
|
1003
|
+
*/
|
|
1004
|
+
enqueueCommand_fn = function(operation) {
|
|
1005
|
+
return new Promise((resolve, reject) => {
|
|
1006
|
+
const run = () => {
|
|
1007
|
+
let result;
|
|
1008
|
+
try {
|
|
1009
|
+
result = operation();
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
reject(error);
|
|
1012
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
Promise.resolve(result).then(
|
|
1016
|
+
(value) => {
|
|
1017
|
+
resolve(value);
|
|
1018
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
1019
|
+
},
|
|
1020
|
+
(error) => {
|
|
1021
|
+
reject(error);
|
|
1022
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, finishCommand_fn).call(this);
|
|
1023
|
+
}
|
|
1024
|
+
);
|
|
1025
|
+
};
|
|
1026
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _commandActive)) {
|
|
1027
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _queuedCommands).push(run);
|
|
1028
|
+
} else {
|
|
1029
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _commandActive, true);
|
|
1030
|
+
run();
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
};
|
|
1034
|
+
finishCommand_fn = function() {
|
|
1035
|
+
const next = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _queuedCommands).shift();
|
|
1036
|
+
if (next) {
|
|
1037
|
+
next();
|
|
1038
|
+
} else {
|
|
1039
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _commandActive, false);
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
/** Read the master's actual post-seek position (it may clamp). */
|
|
1043
|
+
readSettledMasterPosition_fn = function() {
|
|
1044
|
+
const position = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).position;
|
|
1045
|
+
if (!Number.isFinite(position) || position < 0) {
|
|
1046
|
+
throw new RangeError("Master transport returned an invalid position after seek.");
|
|
1047
|
+
}
|
|
1048
|
+
return position;
|
|
1049
|
+
};
|
|
1050
|
+
/** Preserve the completed seek position when pause superseded it. */
|
|
1051
|
+
reconcileStaleSeek_fn = function(position) {
|
|
1052
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) !== "paused") return;
|
|
1053
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
1054
|
+
for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
|
|
1055
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
1056
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
1057
|
+
record.transport.seek(_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, localPosition_fn).call(this, record, position));
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
/** Re-apply pause/stop after an older async master command settles late. */
|
|
1061
|
+
reapplySynchronousIntent_fn = function() {
|
|
1062
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
|
|
1063
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "paused") {
|
|
1064
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
1065
|
+
} else if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _intent) === "stopped") {
|
|
1066
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyStop_fn).call(this);
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
applyPause_fn = function() {
|
|
1070
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
1071
|
+
const errors = [];
|
|
1072
|
+
for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
|
|
1073
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
1074
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
1075
|
+
try {
|
|
1076
|
+
record.transport.pause();
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
errors.push(error);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
1082
|
+
try {
|
|
1083
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).pause();
|
|
1084
|
+
} catch (error) {
|
|
1085
|
+
errors.push(error);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
if (errors.length > 0) throw errors[0];
|
|
1089
|
+
};
|
|
1090
|
+
applyStop_fn = function() {
|
|
1091
|
+
const generation = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation);
|
|
1092
|
+
const errors = [];
|
|
1093
|
+
for (const record of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers)]) {
|
|
1094
|
+
if (!_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) break;
|
|
1095
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _followers).includes(record)) continue;
|
|
1096
|
+
try {
|
|
1097
|
+
record.transport.stop();
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
errors.push(error);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
if (_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, isCurrent_fn).call(this, generation)) {
|
|
1103
|
+
try {
|
|
1104
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _master).stop();
|
|
1105
|
+
} catch (error) {
|
|
1106
|
+
errors.push(error);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
if (errors.length > 0) throw errors[0];
|
|
1110
|
+
};
|
|
1111
|
+
rollbackFailedPlay_fn = function() {
|
|
1112
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation)._;
|
|
1113
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _intent, "paused");
|
|
1114
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, stopDriftMonitor_fn).call(this);
|
|
1115
|
+
try {
|
|
1116
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _TransportGroup_instances, applyPause_fn).call(this);
|
|
1117
|
+
} catch (e7) {
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
function assertFiniteNonNegative(name, value) {
|
|
1121
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
1122
|
+
throw new RangeError(`${name} must be finite and >= 0.`);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function assertValidLoop(loop) {
|
|
1126
|
+
if (!Number.isFinite(loop.startSeconds) || loop.startSeconds < 0 || !Number.isFinite(loop.endSeconds) || !(loop.endSeconds > loop.startSeconds)) {
|
|
1127
|
+
throw new RangeError("Loop bounds must be finite, non-negative, and endSeconds must be greater than startSeconds.");
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
function validateCommand(command) {
|
|
1131
|
+
switch (command.type) {
|
|
1132
|
+
case "play":
|
|
1133
|
+
case "pause":
|
|
1134
|
+
case "stop":
|
|
1135
|
+
return;
|
|
1136
|
+
case "seek":
|
|
1137
|
+
assertFiniteNonNegative("position", command.position);
|
|
1138
|
+
return;
|
|
1139
|
+
case "rate":
|
|
1140
|
+
if (!Number.isFinite(command.rate) || command.rate <= 0) throw new RangeError("rate must be finite and > 0.");
|
|
1141
|
+
return;
|
|
1142
|
+
case "loop":
|
|
1143
|
+
if (command.loop) assertValidLoop(command.loop);
|
|
1144
|
+
return;
|
|
1145
|
+
default:
|
|
1146
|
+
throw new TypeError("Unknown transport command.");
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// src/session-modulation.ts
|
|
1151
|
+
var automationOwners = /* @__PURE__ */ new WeakMap();
|
|
1152
|
+
function attachSessionAutomation(binding, context, parameter, points, options = {}) {
|
|
1153
|
+
const lookahead = validateOptions(options);
|
|
1154
|
+
if (parameter.snapshot.disposed) throw new Error("Automation parameter is disposed.");
|
|
1155
|
+
if (parameter.descriptor.updateTiming !== "scheduled" || !parameter.descriptor.modulation || parameter.descriptor.modulation === "none") {
|
|
1156
|
+
throw new Error("Session automation requires a native scheduled parameter.");
|
|
1157
|
+
}
|
|
1158
|
+
if (_optionalChain([automationOwners, 'access', _27 => _27.get, 'call', _28 => _28(parameter), 'optionalAccess', _29 => _29.active])) throw new Error("Parameter already has a Session automation owner.");
|
|
1159
|
+
const baseline = _nullishCoalesce(options.initialValue, () => ( parameter.snapshot.baseValue));
|
|
1160
|
+
if (!Number.isFinite(baseline) || baseline < parameter.descriptor.range.min || baseline > parameter.descriptor.range.max) throw new RangeError("Automation initialValue must fit the target legal range.");
|
|
1161
|
+
const trajectory = validatePoints(points, baseline, parameter.descriptor.range);
|
|
1162
|
+
const ticker = _chunk3INDOVUCcjs.createTickSource.call(void 0, options.tick);
|
|
1163
|
+
let unbind = () => {
|
|
1164
|
+
}, unwatch = () => {
|
|
1165
|
+
};
|
|
1166
|
+
let lastTime = NaN, error;
|
|
1167
|
+
let ownedBaseRevision;
|
|
1168
|
+
let attaching = true, releaseNotified = false;
|
|
1169
|
+
let baseRevision = parameter.snapshot.baseRevision;
|
|
1170
|
+
const writeBase = (write) => {
|
|
1171
|
+
const previous = ownedBaseRevision;
|
|
1172
|
+
ownedBaseRevision = parameter.snapshot.baseRevision + 1;
|
|
1173
|
+
try {
|
|
1174
|
+
write();
|
|
1175
|
+
} finally {
|
|
1176
|
+
ownedBaseRevision = previous;
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
const notifyRelease = () => {
|
|
1180
|
+
if (attaching || releaseNotified || lease.active) return;
|
|
1181
|
+
releaseNotified = true;
|
|
1182
|
+
try {
|
|
1183
|
+
const result2 = _optionalChain([options, 'access', _30 => _30.onRelease, 'optionalCall', _31 => _31()]);
|
|
1184
|
+
if (result2 && typeof result2.then === "function") void Promise.resolve(result2).catch(() => {
|
|
1185
|
+
});
|
|
1186
|
+
} catch (e8) {
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
const lease = _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
|
|
1190
|
+
try {
|
|
1191
|
+
let failure;
|
|
1192
|
+
const attempt = (action) => {
|
|
1193
|
+
try {
|
|
1194
|
+
action();
|
|
1195
|
+
} catch (error2) {
|
|
1196
|
+
_nullishCoalesce(failure, () => ( (failure = error2)));
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
attempt(unbind);
|
|
1200
|
+
attempt(unwatch);
|
|
1201
|
+
attempt(() => ticker.dispose());
|
|
1202
|
+
if (automationOwners.get(parameter) === result) {
|
|
1203
|
+
automationOwners.delete(parameter);
|
|
1204
|
+
if (!parameter.snapshot.disposed) attempt(() => writeBase(() => parameter.cancelAutomation()));
|
|
1205
|
+
}
|
|
1206
|
+
if (failure !== void 0) throw failure;
|
|
1207
|
+
} finally {
|
|
1208
|
+
notifyRelease();
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
const result = Object.freeze({ get active() {
|
|
1212
|
+
return lease.active;
|
|
1213
|
+
}, get error() {
|
|
1214
|
+
return error;
|
|
1215
|
+
}, initialValue: baseline, release: () => lease.release() });
|
|
1216
|
+
const cancel = () => {
|
|
1217
|
+
ticker.stop();
|
|
1218
|
+
lastTime = NaN;
|
|
1219
|
+
if (!parameter.snapshot.disposed) writeBase(() => parameter.cancelAutomation());
|
|
1220
|
+
};
|
|
1221
|
+
const fill = () => {
|
|
1222
|
+
if (!lease.active || binding.snapshot.phase !== "ready" || binding.snapshot.paused) return;
|
|
1223
|
+
const now = context.currentTime;
|
|
1224
|
+
if (now === lastTime) return;
|
|
1225
|
+
const windows = windowsFor(binding, now, Math.max(now, binding.snapshot.originTime) + lookahead, options.loop);
|
|
1226
|
+
const events = planAutomation(windows, trajectory, baseline);
|
|
1227
|
+
if (!events.length) return;
|
|
1228
|
+
parameter.scheduleAutomation(context, events, now);
|
|
1229
|
+
lastTime = now;
|
|
1230
|
+
};
|
|
1231
|
+
const tick = () => {
|
|
1232
|
+
try {
|
|
1233
|
+
fill();
|
|
1234
|
+
} catch (failure) {
|
|
1235
|
+
error = failure;
|
|
1236
|
+
try {
|
|
1237
|
+
lease.release();
|
|
1238
|
+
} finally {
|
|
1239
|
+
try {
|
|
1240
|
+
_optionalChain([options, 'access', _32 => _32.onError, 'optionalCall', _33 => _33(failure)]);
|
|
1241
|
+
} catch (e9) {
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
automationOwners.set(parameter, result);
|
|
1247
|
+
try {
|
|
1248
|
+
unwatch = parameter.subscribe((snapshot) => {
|
|
1249
|
+
const baseChanged = snapshot.baseRevision !== baseRevision;
|
|
1250
|
+
baseRevision = snapshot.baseRevision;
|
|
1251
|
+
if (snapshot.disposed) lease.release();
|
|
1252
|
+
else if (baseChanged && snapshot.baseRevision !== ownedBaseRevision) lease.release();
|
|
1253
|
+
});
|
|
1254
|
+
unbind = binding.subscribe((event) => {
|
|
1255
|
+
if (!lease.active) return;
|
|
1256
|
+
if (event.type === "dispose") {
|
|
1257
|
+
lease.release();
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
if (event.type === "invalidate") {
|
|
1261
|
+
cancel();
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (event.snapshot.paused) {
|
|
1265
|
+
cancel();
|
|
1266
|
+
if (!lease.active) return;
|
|
1267
|
+
const position = options.loop === "once" ? binding.clock.positionAt(context.currentTime) : binding.positionAt(context.currentTime);
|
|
1268
|
+
writeBase(() => parameter.setBaseValue(valueAt(trajectory, baseline, position)));
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
lastTime = NaN;
|
|
1272
|
+
fill();
|
|
1273
|
+
const current = binding.snapshot;
|
|
1274
|
+
if (lease.active && current.epoch === event.snapshot.epoch && current.phase === "ready" && !current.paused) ticker.start(tick);
|
|
1275
|
+
});
|
|
1276
|
+
if (!lease.active) unbind();
|
|
1277
|
+
} catch (failure) {
|
|
1278
|
+
error = failure;
|
|
1279
|
+
lease.release();
|
|
1280
|
+
throw failure;
|
|
1281
|
+
} finally {
|
|
1282
|
+
attaching = false;
|
|
1283
|
+
notifyRelease();
|
|
1284
|
+
}
|
|
1285
|
+
return result;
|
|
1286
|
+
}
|
|
1287
|
+
var SessionLFO = class {
|
|
1288
|
+
constructor(context, binding, options = {}) {
|
|
1289
|
+
this.context = context;
|
|
1290
|
+
this.binding = binding;
|
|
1291
|
+
this.options = options;
|
|
1292
|
+
this.sources = /* @__PURE__ */ new Map();
|
|
1293
|
+
this.scheduledUntil = -Infinity;
|
|
1294
|
+
this.stopped = false;
|
|
1295
|
+
this.unbind = () => {
|
|
1296
|
+
};
|
|
1297
|
+
this.lookahead = validateOptions(options);
|
|
1298
|
+
this.shape = _nullishCoalesce(options.waveform, () => ( "sine"));
|
|
1299
|
+
validateWaveform(this.shape);
|
|
1300
|
+
this.cycles = _nullishCoalesce(options.frequency, () => ( 1));
|
|
1301
|
+
this.phaseOffset = _nullishCoalesce(options.phase, () => ( 0));
|
|
1302
|
+
if (!Number.isFinite(this.cycles) || this.cycles < 1e-3 || this.cycles > 1e3) throw new RangeError("Session LFO frequency must be in [0.001, 1000] cycles per axis second.");
|
|
1303
|
+
if (!Number.isFinite(this.phaseOffset) || this.phaseOffset < 0 || this.phaseOffset > 1) throw new RangeError("Session LFO phase must be in [0, 1] cycles.");
|
|
1304
|
+
this.output = context.createGain();
|
|
1305
|
+
this.signal = Object.freeze({ output: this.output, rate: "a-rate", range: Object.freeze({ min: -1, max: 1 }) });
|
|
1306
|
+
this.buffer = this.makeBuffer();
|
|
1307
|
+
this.ticker = _chunk3INDOVUCcjs.createTickSource.call(void 0, options.tick);
|
|
1308
|
+
this.frequency = new (0, _chunk5AHVQXTFcjs.ParamHandle)({
|
|
1309
|
+
id: "frequency",
|
|
1310
|
+
label: "Rate",
|
|
1311
|
+
unit: "cycles/axis-second",
|
|
1312
|
+
range: { min: 1e-3, max: 1e3 },
|
|
1313
|
+
displayRange: { min: 1e-3, max: 20 },
|
|
1314
|
+
defaultValue: 1,
|
|
1315
|
+
updateTiming: "synchronous",
|
|
1316
|
+
modulation: "none"
|
|
1317
|
+
}, { baseValue: this.cycles, apply: (value) => {
|
|
1318
|
+
this.cycles = value;
|
|
1319
|
+
this.rearm();
|
|
1320
|
+
} });
|
|
1321
|
+
this.phase = new (0, _chunk5AHVQXTFcjs.ParamHandle)({
|
|
1322
|
+
id: "phase",
|
|
1323
|
+
label: "Phase",
|
|
1324
|
+
unit: "cycles",
|
|
1325
|
+
range: { min: 0, max: 1 },
|
|
1326
|
+
defaultValue: 0,
|
|
1327
|
+
updateTiming: "synchronous",
|
|
1328
|
+
modulation: "none"
|
|
1329
|
+
}, { baseValue: this.phaseOffset, apply: (value) => {
|
|
1330
|
+
this.phaseOffset = value;
|
|
1331
|
+
this.rearm();
|
|
1332
|
+
} });
|
|
1333
|
+
try {
|
|
1334
|
+
this.unbind = binding.subscribe((event) => {
|
|
1335
|
+
if (event.type === "dispose") {
|
|
1336
|
+
this.dispose();
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
if (event.type === "invalidate" || event.snapshot.paused) this.cancel();
|
|
1340
|
+
else this.rearm();
|
|
1341
|
+
});
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
this.dispose();
|
|
1344
|
+
throw error;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
get waveform() {
|
|
1348
|
+
return this.shape;
|
|
1349
|
+
}
|
|
1350
|
+
get error() {
|
|
1351
|
+
return this.failure;
|
|
1352
|
+
}
|
|
1353
|
+
setWaveform(waveform) {
|
|
1354
|
+
if (this.stopped) throw new Error("Session LFO is disposed.");
|
|
1355
|
+
validateWaveform(waveform);
|
|
1356
|
+
this.shape = waveform;
|
|
1357
|
+
this.buffer = this.makeBuffer();
|
|
1358
|
+
this.rearm();
|
|
1359
|
+
}
|
|
1360
|
+
dispose() {
|
|
1361
|
+
if (this.stopped) return;
|
|
1362
|
+
this.stopped = true;
|
|
1363
|
+
let failure;
|
|
1364
|
+
for (const action of [
|
|
1365
|
+
() => this.unbind(),
|
|
1366
|
+
() => this.cancel(),
|
|
1367
|
+
() => this.ticker.dispose(),
|
|
1368
|
+
() => this.frequency.dispose(),
|
|
1369
|
+
() => this.phase.dispose(),
|
|
1370
|
+
() => this.output.disconnect()
|
|
1371
|
+
]) {
|
|
1372
|
+
try {
|
|
1373
|
+
action();
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
if (failure) throw failure;
|
|
1379
|
+
}
|
|
1380
|
+
rearm() {
|
|
1381
|
+
if (this.stopped) return;
|
|
1382
|
+
this.cancel();
|
|
1383
|
+
if (this.binding.snapshot.phase !== "ready" || this.binding.snapshot.paused) return;
|
|
1384
|
+
this.fill();
|
|
1385
|
+
this.ticker.start(() => {
|
|
1386
|
+
try {
|
|
1387
|
+
this.fill();
|
|
1388
|
+
} catch (error) {
|
|
1389
|
+
this.failure = error;
|
|
1390
|
+
try {
|
|
1391
|
+
this.dispose();
|
|
1392
|
+
} finally {
|
|
1393
|
+
try {
|
|
1394
|
+
_optionalChain([this, 'access', _34 => _34.options, 'access', _35 => _35.onError, 'optionalCall', _36 => _36(error)]);
|
|
1395
|
+
} catch (e10) {
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
cancel() {
|
|
1402
|
+
this.ticker.stop();
|
|
1403
|
+
this.scheduledUntil = -Infinity;
|
|
1404
|
+
let failure;
|
|
1405
|
+
for (const source of this.sources.keys()) {
|
|
1406
|
+
source.onended = null;
|
|
1407
|
+
try {
|
|
1408
|
+
source.stop();
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1411
|
+
}
|
|
1412
|
+
try {
|
|
1413
|
+
source.disconnect();
|
|
1414
|
+
} catch (error) {
|
|
1415
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
this.sources.clear();
|
|
1419
|
+
if (failure) throw failure;
|
|
1420
|
+
}
|
|
1421
|
+
fill() {
|
|
1422
|
+
if (this.stopped || this.binding.snapshot.phase !== "ready" || this.binding.snapshot.paused) return;
|
|
1423
|
+
const now = this.context.currentTime;
|
|
1424
|
+
for (const [source, end] of this.sources) if (end <= now) {
|
|
1425
|
+
source.onended = null;
|
|
1426
|
+
source.disconnect();
|
|
1427
|
+
this.sources.delete(source);
|
|
1428
|
+
}
|
|
1429
|
+
if (this.scheduledUntil > now + this.lookahead / 2) return;
|
|
1430
|
+
const from = Math.max(now, this.scheduledUntil);
|
|
1431
|
+
const to = Math.max(now, this.binding.snapshot.originTime) + this.lookahead;
|
|
1432
|
+
const segments = windowsFor(this.binding, from, to, this.options.loop);
|
|
1433
|
+
const epoch = this.binding.epoch;
|
|
1434
|
+
for (const segment of segments) {
|
|
1435
|
+
if (this.stopped || epoch !== this.binding.epoch) return;
|
|
1436
|
+
const source = this.context.createBufferSource();
|
|
1437
|
+
source.buffer = this.buffer;
|
|
1438
|
+
source.loop = true;
|
|
1439
|
+
source.loopStart = 0;
|
|
1440
|
+
source.loopEnd = this.buffer.duration;
|
|
1441
|
+
source.playbackRate.value = this.cycles * segment.rate * this.buffer.duration;
|
|
1442
|
+
const phase = modulo(segment.positionStart * this.cycles + this.phaseOffset);
|
|
1443
|
+
try {
|
|
1444
|
+
source.connect(this.output);
|
|
1445
|
+
source.start(segment.referenceStart, phase * this.buffer.duration);
|
|
1446
|
+
source.stop(segment.referenceEnd);
|
|
1447
|
+
if (this.stopped || epoch !== this.binding.epoch) {
|
|
1448
|
+
source.stop();
|
|
1449
|
+
source.disconnect();
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
this.sources.set(source, segment.referenceEnd);
|
|
1453
|
+
source.onended = () => {
|
|
1454
|
+
this.sources.delete(source);
|
|
1455
|
+
source.disconnect();
|
|
1456
|
+
};
|
|
1457
|
+
} catch (error) {
|
|
1458
|
+
try {
|
|
1459
|
+
source.stop();
|
|
1460
|
+
} catch (e11) {
|
|
1461
|
+
}
|
|
1462
|
+
source.disconnect();
|
|
1463
|
+
throw error;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (segments.length) this.scheduledUntil = segments[segments.length - 1].referenceEnd;
|
|
1467
|
+
}
|
|
1468
|
+
makeBuffer() {
|
|
1469
|
+
const buffer = this.context.createBuffer(1, 4096, this.context.sampleRate);
|
|
1470
|
+
const data = buffer.getChannelData(0);
|
|
1471
|
+
for (let index = 0; index < data.length; index++) {
|
|
1472
|
+
const phase = index / data.length;
|
|
1473
|
+
data[index] = this.shape === "sine" ? Math.sin(2 * Math.PI * phase) : this.shape === "square" ? phase < 0.5 ? 1 : -1 : this.shape === "sawtooth" ? 2 * phase - 1 : 1 - 4 * Math.abs(phase - 0.5);
|
|
1474
|
+
}
|
|
1475
|
+
return buffer;
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
function windowsFor(binding, from, to, loop) {
|
|
1479
|
+
if (loop !== "once") return binding.segments(from, to);
|
|
1480
|
+
const state = binding.snapshot;
|
|
1481
|
+
const start = Math.max(from, state.holding ? state.originTime : from);
|
|
1482
|
+
if (state.phase !== "ready" || state.paused || start >= to) return [];
|
|
1483
|
+
return [{
|
|
1484
|
+
epoch: state.epoch,
|
|
1485
|
+
iteration: 0,
|
|
1486
|
+
referenceStart: start,
|
|
1487
|
+
referenceEnd: to,
|
|
1488
|
+
positionStart: binding.clock.positionAt(start),
|
|
1489
|
+
positionEnd: binding.clock.positionAt(to),
|
|
1490
|
+
rate: state.rate
|
|
1491
|
+
}];
|
|
1492
|
+
}
|
|
1493
|
+
function validateOptions(options) {
|
|
1494
|
+
const lookahead = _nullishCoalesce(options.lookaheadSeconds, () => ( 0.25));
|
|
1495
|
+
if (!Number.isFinite(lookahead) || lookahead <= 0 || lookahead > 60) throw new RangeError("Lookahead must be in (0, 60] reference seconds.");
|
|
1496
|
+
if (options.loop !== void 0 && options.loop !== "repeat" && options.loop !== "once") throw new TypeError("Unknown Session modulation loop policy.");
|
|
1497
|
+
return lookahead;
|
|
1498
|
+
}
|
|
1499
|
+
function validatePoints(points, baseline, range) {
|
|
1500
|
+
if (!points.length) throw new RangeError("Session automation requires at least one point.");
|
|
1501
|
+
let time = 0, previous = baseline;
|
|
1502
|
+
return Object.freeze(points.map((point) => {
|
|
1503
|
+
if (!["set", "linear", "exponential"].includes(point.type)) throw new TypeError("Unknown automation event type.");
|
|
1504
|
+
if (!Number.isFinite(point.timeSeconds) || point.timeSeconds < time || !Number.isFinite(point.value) || point.value < range.min || point.value > range.max) throw new RangeError("Automation points require ordered nonnegative positions and values within the target range.");
|
|
1505
|
+
if (point.type === "exponential" && (point.value <= 0 || previous <= 0)) throw new RangeError("Exponential automation requires positive endpoints.");
|
|
1506
|
+
time = point.timeSeconds;
|
|
1507
|
+
previous = point.value;
|
|
1508
|
+
return Object.freeze({ ...point });
|
|
1509
|
+
}));
|
|
1510
|
+
}
|
|
1511
|
+
function planAutomation(windows, points, baseline) {
|
|
1512
|
+
const result = [];
|
|
1513
|
+
for (const window of windows) {
|
|
1514
|
+
result.push({ type: "set", value: valueAt(points, baseline, window.positionStart), time: window.referenceStart });
|
|
1515
|
+
for (const point of points) {
|
|
1516
|
+
if (point.timeSeconds <= window.positionStart || point.timeSeconds > window.positionEnd) continue;
|
|
1517
|
+
result.push({ type: point.type, value: point.value, time: Math.min(window.referenceEnd, window.referenceStart + (point.timeSeconds - window.positionStart) / window.rate) });
|
|
1518
|
+
}
|
|
1519
|
+
const next = points.find((point) => point.timeSeconds > window.positionEnd);
|
|
1520
|
+
if (next && next.type !== "set") result.push({ type: next.type, value: valueAt(points, baseline, window.positionEnd), time: window.referenceEnd });
|
|
1521
|
+
}
|
|
1522
|
+
return result;
|
|
1523
|
+
}
|
|
1524
|
+
function valueAt(points, baseline, position) {
|
|
1525
|
+
let time = 0, value = baseline;
|
|
1526
|
+
for (const point of points) {
|
|
1527
|
+
if (position < point.timeSeconds) {
|
|
1528
|
+
if (point.type === "set" || position <= time) return value;
|
|
1529
|
+
const ratio = (position - time) / (point.timeSeconds - time);
|
|
1530
|
+
return point.type === "linear" ? value + (point.value - value) * ratio : value * Math.pow(point.value / value, ratio);
|
|
1531
|
+
}
|
|
1532
|
+
value = point.value;
|
|
1533
|
+
time = point.timeSeconds;
|
|
1534
|
+
}
|
|
1535
|
+
return value;
|
|
1536
|
+
}
|
|
1537
|
+
function validateWaveform(waveform) {
|
|
1538
|
+
if (!["sine", "square", "triangle", "sawtooth"].includes(waveform)) throw new TypeError("Unsupported Session LFO waveform.");
|
|
1539
|
+
}
|
|
1540
|
+
function modulo(value) {
|
|
1541
|
+
return (value % 1 + 1) % 1;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// src/session.ts
|
|
1545
|
+
var timings = ["shared-anchor", "callback", "media-follower", "external"];
|
|
1546
|
+
var owners = /* @__PURE__ */ new WeakMap();
|
|
1547
|
+
var _now2, _clock, _reader, _scheduling, _group, _members, _pendingSources, _listeners, _range, _leadIn2, _requestedStart, _membershipRevision, _generation2, _ended, _disposed2, _SessionTransport_instances, start_fn, release_fn, settleReleased_fn, cancel_fn, participantError_fn, duration_fn, reconcile_fn, extend_fn, publish_fn2, deliver_fn, assertActive_fn2;
|
|
1548
|
+
var SessionTransport = class {
|
|
1549
|
+
constructor(now, options = {}) {
|
|
1550
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _SessionTransport_instances);
|
|
1551
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _now2);
|
|
1552
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _clock);
|
|
1553
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _reader);
|
|
1554
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _scheduling);
|
|
1555
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _group);
|
|
1556
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _members, /* @__PURE__ */ new Set());
|
|
1557
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _pendingSources, /* @__PURE__ */ new Set());
|
|
1558
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners, /* @__PURE__ */ new Set());
|
|
1559
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _range);
|
|
1560
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _leadIn2);
|
|
1561
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _requestedStart);
|
|
1562
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _membershipRevision, 0);
|
|
1563
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _generation2, 0);
|
|
1564
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ended, false);
|
|
1565
|
+
_chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed2, false);
|
|
1566
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now2, now);
|
|
1567
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _clock, new (0, _chunkTA3TNJZUcjs.TransportClock)(now));
|
|
1568
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _range, options.range ? Object.freeze({ ...options.range }) : null);
|
|
1569
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range) && (!Number.isFinite(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).startSeconds) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).startSeconds < 0 || !Number.isFinite(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).endSeconds) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).endSeconds <= _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).startSeconds)) {
|
|
1570
|
+
throw new RangeError("Session range requires finite 0 <= startSeconds < endSeconds.");
|
|
1571
|
+
}
|
|
1572
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range)) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).seekTo(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).startSeconds, now());
|
|
1573
|
+
const clock = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock);
|
|
1574
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _reader, Object.freeze({
|
|
1575
|
+
get state() {
|
|
1576
|
+
return clock.state;
|
|
1577
|
+
},
|
|
1578
|
+
get rate() {
|
|
1579
|
+
return clock.rate;
|
|
1580
|
+
},
|
|
1581
|
+
get paused() {
|
|
1582
|
+
return clock.paused;
|
|
1583
|
+
},
|
|
1584
|
+
get holding() {
|
|
1585
|
+
return clock.holding;
|
|
1586
|
+
},
|
|
1587
|
+
positionAt: (time) => clock.positionAt(time),
|
|
1588
|
+
timeAt: (position) => clock.timeAt(position)
|
|
1589
|
+
}));
|
|
1590
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _scheduling, new SessionSchedulingAuthority(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reader), now, () => _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group) ? _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).loop : _nullishCoalesce(options.loop, () => ( null))));
|
|
1591
|
+
this.scheduling = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).createBinding("session-seconds");
|
|
1592
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _leadIn2, _nullishCoalesce(options.leadInSeconds, () => ( 0.06)));
|
|
1593
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _group, new TransportGroup({
|
|
1594
|
+
clock: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reader),
|
|
1595
|
+
get position() {
|
|
1596
|
+
return clock.positionAt(now());
|
|
1597
|
+
},
|
|
1598
|
+
continuousLoop: true,
|
|
1599
|
+
invalidate: (command) => _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).invalidate(command.type),
|
|
1600
|
+
loopChanged: (_loop2, isCurrent) => {
|
|
1601
|
+
if (_optionalChain([isCurrent, 'optionalCall', _37 => _37()]) !== false) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
1602
|
+
},
|
|
1603
|
+
play: () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, start_fn).call(this),
|
|
1604
|
+
pause: () => {
|
|
1605
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation2)._;
|
|
1606
|
+
clock.pause(now());
|
|
1607
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
1608
|
+
},
|
|
1609
|
+
stop: () => {
|
|
1610
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation2)._;
|
|
1611
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ended, false);
|
|
1612
|
+
clock.pause(now());
|
|
1613
|
+
clock.seekTo(_nullishCoalesce(_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range), 'optionalAccess', _38 => _38.startSeconds]), () => ( 0)), now());
|
|
1614
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
1615
|
+
},
|
|
1616
|
+
seekPosition: (position, when, isCurrent) => {
|
|
1617
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ended, false);
|
|
1618
|
+
const target = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range) ? Math.max(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).startSeconds, Math.min(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).endSeconds, position)) : position;
|
|
1619
|
+
if (!clock.paused && when !== void 0) clock.startAt(when, target);
|
|
1620
|
+
else clock.seekTo(target, now());
|
|
1621
|
+
if (_optionalChain([isCurrent, 'optionalCall', _39 => _39()]) !== false) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
1622
|
+
},
|
|
1623
|
+
setRate: (rate) => {
|
|
1624
|
+
clock.setRate(rate, now());
|
|
1625
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
1626
|
+
},
|
|
1627
|
+
reconcile: (time) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, reconcile_fn).call(this, time),
|
|
1628
|
+
dispose: () => {
|
|
1629
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation2)._;
|
|
1630
|
+
clock.pause(now());
|
|
1631
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).dispose();
|
|
1632
|
+
}
|
|
1633
|
+
}, now, options));
|
|
1634
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).subscribe((event) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { ...event, snapshot: _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, extend_fn).call(this, event.snapshot) }));
|
|
1635
|
+
}
|
|
1636
|
+
get clock() {
|
|
1637
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _reader);
|
|
1638
|
+
}
|
|
1639
|
+
get position() {
|
|
1640
|
+
return this.scheduling.positionAt(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this));
|
|
1641
|
+
}
|
|
1642
|
+
get snapshot() {
|
|
1643
|
+
return _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, extend_fn).call(this, _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).snapshot);
|
|
1644
|
+
}
|
|
1645
|
+
get participantCount() {
|
|
1646
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).size;
|
|
1647
|
+
}
|
|
1648
|
+
holdPendingSource() {
|
|
1649
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, assertActive_fn2).call(this);
|
|
1650
|
+
let state = "pending";
|
|
1651
|
+
let resolve;
|
|
1652
|
+
let reject;
|
|
1653
|
+
const ready = new Promise((done, fail) => {
|
|
1654
|
+
resolve = done;
|
|
1655
|
+
reject = fail;
|
|
1656
|
+
});
|
|
1657
|
+
void ready.catch(() => {
|
|
1658
|
+
});
|
|
1659
|
+
const release = () => {
|
|
1660
|
+
if (state === "released") return;
|
|
1661
|
+
state = "released";
|
|
1662
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources).delete(lease);
|
|
1663
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
1664
|
+
resolve();
|
|
1665
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participants", snapshot: this.snapshot });
|
|
1666
|
+
};
|
|
1667
|
+
const lease = Object.freeze({
|
|
1668
|
+
token: /* @__PURE__ */ Symbol("pending-source"),
|
|
1669
|
+
get active() {
|
|
1670
|
+
return state !== "released";
|
|
1671
|
+
},
|
|
1672
|
+
ready,
|
|
1673
|
+
resolve: () => {
|
|
1674
|
+
if (state === "pending") release();
|
|
1675
|
+
},
|
|
1676
|
+
reject: (error) => {
|
|
1677
|
+
if (state !== "pending") return;
|
|
1678
|
+
state = "failed";
|
|
1679
|
+
reject(error);
|
|
1680
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
1681
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "source-error", error, snapshot: this.snapshot });
|
|
1682
|
+
},
|
|
1683
|
+
release
|
|
1684
|
+
});
|
|
1685
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources).add(lease);
|
|
1686
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
1687
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participants", snapshot: this.snapshot });
|
|
1688
|
+
return lease;
|
|
1689
|
+
}
|
|
1690
|
+
subscribe(listener) {
|
|
1691
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, assertActive_fn2).call(this);
|
|
1692
|
+
const registration = (event) => listener(event);
|
|
1693
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).add(registration);
|
|
1694
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, deliver_fn).call(this, registration, { type: "snapshot", snapshot: this.snapshot });
|
|
1695
|
+
return () => {
|
|
1696
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).delete(registration);
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
register(transport, options) {
|
|
1700
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, assertActive_fn2).call(this);
|
|
1701
|
+
if (!_optionalChain([options, 'access', _40 => _40.axis, 'optionalAccess', _41 => _41.trim, 'call', _42 => _42()])) throw new TypeError("A participant must name its local seconds axis.");
|
|
1702
|
+
if (options.timing !== void 0 && !timings.includes(options.timing)) {
|
|
1703
|
+
throw new TypeError(`Unknown participant timing: ${String(options.timing)}`);
|
|
1704
|
+
}
|
|
1705
|
+
if (options.timing === "shared-anchor" && !options.attachScheduling) {
|
|
1706
|
+
throw new TypeError("A shared-anchor participant must attach Session scheduling.");
|
|
1707
|
+
}
|
|
1708
|
+
readDuration(options);
|
|
1709
|
+
const offset = _nullishCoalesce(options.offsetSeconds, () => ( 0));
|
|
1710
|
+
const scale = _nullishCoalesce(options.positionScale, () => ( 1));
|
|
1711
|
+
if (!Number.isFinite(offset) || offset < 0 && !options.attachScheduling || !Number.isFinite(scale) || scale <= 0) {
|
|
1712
|
+
throw new RangeError("Participant mapping requires finite offsetSeconds (negative offsets need shared scheduling) and positionScale > 0.");
|
|
1713
|
+
}
|
|
1714
|
+
if (scale !== 1 && !transport.setRate && !options.attachScheduling) throw new Error("A scaled participant must support setRate.");
|
|
1715
|
+
if (options.loop && (!Number.isFinite(options.loop.startSeconds) || options.loop.startSeconds < 0 || !Number.isFinite(options.loop.endSeconds) || options.loop.endSeconds <= options.loop.startSeconds)) {
|
|
1716
|
+
throw new RangeError("Participant loop requires finite 0 <= startSeconds < endSeconds.");
|
|
1717
|
+
}
|
|
1718
|
+
const identity = _nullishCoalesce(options.identity, () => ( transport));
|
|
1719
|
+
if (owners.has(identity)) throw new Error("Participant engine already has an active or settling Session lease.");
|
|
1720
|
+
let settle;
|
|
1721
|
+
const settled = new Promise((resolve) => {
|
|
1722
|
+
settle = resolve;
|
|
1723
|
+
});
|
|
1724
|
+
let readyResolve;
|
|
1725
|
+
let readyReject;
|
|
1726
|
+
let readyState = "pending";
|
|
1727
|
+
const deferReady = () => {
|
|
1728
|
+
readyState = "pending";
|
|
1729
|
+
const promise = new Promise((resolve, reject) => {
|
|
1730
|
+
readyResolve = () => {
|
|
1731
|
+
if (readyState === "pending") {
|
|
1732
|
+
readyState = "resolved";
|
|
1733
|
+
resolve();
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
readyReject = (error) => {
|
|
1737
|
+
if (readyState === "pending") {
|
|
1738
|
+
readyState = "rejected";
|
|
1739
|
+
reject(error);
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
});
|
|
1743
|
+
void promise.catch(() => {
|
|
1744
|
+
});
|
|
1745
|
+
return promise;
|
|
1746
|
+
};
|
|
1747
|
+
const ready = deferReady();
|
|
1748
|
+
let releasedResolve;
|
|
1749
|
+
const released = new Promise((resolve) => {
|
|
1750
|
+
releasedResolve = resolve;
|
|
1751
|
+
});
|
|
1752
|
+
let preparation;
|
|
1753
|
+
const member = {
|
|
1754
|
+
identity,
|
|
1755
|
+
transport,
|
|
1756
|
+
options: { ...options, loop: options.loop ? { ...options.loop } : void 0 },
|
|
1757
|
+
proxy: transport,
|
|
1758
|
+
ready,
|
|
1759
|
+
active: true,
|
|
1760
|
+
preparing: false,
|
|
1761
|
+
attached: false,
|
|
1762
|
+
pendingStarts: 0,
|
|
1763
|
+
cancellationFailed: false,
|
|
1764
|
+
cancellationError: void 0,
|
|
1765
|
+
settle,
|
|
1766
|
+
cancelPreparationWait: () => {
|
|
1767
|
+
releasedResolve();
|
|
1768
|
+
readyResolve();
|
|
1769
|
+
},
|
|
1770
|
+
prepare: () => {
|
|
1771
|
+
if (!member.active) return Promise.resolve();
|
|
1772
|
+
if (member.preparing) return preparation;
|
|
1773
|
+
if (member.attached && !member.options.prepare) return member.ready;
|
|
1774
|
+
member.preparing = true;
|
|
1775
|
+
if (readyState === "rejected") member.ready = deferReady();
|
|
1776
|
+
let preparedResolve;
|
|
1777
|
+
let preparedReject;
|
|
1778
|
+
const progress = new Promise((resolve, reject) => {
|
|
1779
|
+
preparedResolve = resolve;
|
|
1780
|
+
preparedReject = reject;
|
|
1781
|
+
});
|
|
1782
|
+
preparation = Promise.race([progress, released]);
|
|
1783
|
+
let prepared;
|
|
1784
|
+
try {
|
|
1785
|
+
prepared = _optionalChain([member, 'access', _43 => _43.options, 'access', _44 => _44.prepare, 'optionalCall', _45 => _45()]);
|
|
1786
|
+
} catch (error) {
|
|
1787
|
+
prepared = Promise.reject(error);
|
|
1788
|
+
}
|
|
1789
|
+
const task = Promise.resolve(prepared).then(async () => {
|
|
1790
|
+
if (member.active && !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).paused) await _optionalChain([member, 'access', _46 => _46.options, 'access', _47 => _47.activate, 'optionalCall', _48 => _48()]);
|
|
1791
|
+
if (member.active && !member.attached) {
|
|
1792
|
+
if (member.options.attachScheduling) {
|
|
1793
|
+
const binding = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).createBinding(member.options.axis, offset, scale);
|
|
1794
|
+
member.scheduling = binding;
|
|
1795
|
+
try {
|
|
1796
|
+
member.schedulingLease = member.options.attachScheduling(binding);
|
|
1797
|
+
if (!member.schedulingLease.active) throw new Error("Participant scheduling attachment was released during preparation.");
|
|
1798
|
+
if (!member.active) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, cancel_fn).call(this, member);
|
|
1799
|
+
} catch (error) {
|
|
1800
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).release(binding);
|
|
1801
|
+
member.scheduling = void 0;
|
|
1802
|
+
throw error;
|
|
1803
|
+
}
|
|
1804
|
+
} else _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).addFollower(member.proxy, member.options);
|
|
1805
|
+
member.attached = member.active;
|
|
1806
|
+
}
|
|
1807
|
+
readyResolve();
|
|
1808
|
+
}).catch((error) => {
|
|
1809
|
+
readyReject(error);
|
|
1810
|
+
throw error;
|
|
1811
|
+
}).finally(() => {
|
|
1812
|
+
try {
|
|
1813
|
+
if (!member.active) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, cancel_fn).call(this, member);
|
|
1814
|
+
} finally {
|
|
1815
|
+
member.preparing = false;
|
|
1816
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, settleReleased_fn).call(this, member);
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
void task.then(preparedResolve, preparedReject);
|
|
1820
|
+
void task.catch((error) => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, participantError_fn).call(this, error));
|
|
1821
|
+
return preparation;
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
member.proxy = {
|
|
1825
|
+
play: async (when) => {
|
|
1826
|
+
if (!member.active) return;
|
|
1827
|
+
++member.pendingStarts;
|
|
1828
|
+
try {
|
|
1829
|
+
await transport.play(when);
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
if (member.active) throw error;
|
|
1832
|
+
} finally {
|
|
1833
|
+
try {
|
|
1834
|
+
if (!member.active) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, cancel_fn).call(this, member);
|
|
1835
|
+
} catch (error) {
|
|
1836
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, participantError_fn).call(this, error);
|
|
1837
|
+
} finally {
|
|
1838
|
+
--member.pendingStarts;
|
|
1839
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, settleReleased_fn).call(this, member);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
},
|
|
1843
|
+
pause: () => {
|
|
1844
|
+
if (member.active) transport.pause();
|
|
1845
|
+
},
|
|
1846
|
+
stop: () => {
|
|
1847
|
+
if (member.active) transport.stop();
|
|
1848
|
+
},
|
|
1849
|
+
seek: (position) => {
|
|
1850
|
+
if (member.active) transport.seek(position);
|
|
1851
|
+
},
|
|
1852
|
+
...transport.setRate ? { setRate: (rate) => {
|
|
1853
|
+
if (member.active) transport.setRate(rate);
|
|
1854
|
+
} } : {},
|
|
1855
|
+
get position() {
|
|
1856
|
+
return transport.position;
|
|
1857
|
+
},
|
|
1858
|
+
get running() {
|
|
1859
|
+
return transport.running;
|
|
1860
|
+
},
|
|
1861
|
+
get clock() {
|
|
1862
|
+
return transport.clock;
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
owners.set(identity, member);
|
|
1866
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).add(member);
|
|
1867
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
1868
|
+
if (!member.options.prepare || !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).paused) void member.prepare().catch(() => {
|
|
1869
|
+
});
|
|
1870
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participants", snapshot: this.snapshot });
|
|
1871
|
+
return Object.freeze({
|
|
1872
|
+
token: Symbol(options.axis),
|
|
1873
|
+
get active() {
|
|
1874
|
+
return member.active;
|
|
1875
|
+
},
|
|
1876
|
+
get ready() {
|
|
1877
|
+
return member.ready;
|
|
1878
|
+
},
|
|
1879
|
+
settled,
|
|
1880
|
+
get cancellationError() {
|
|
1881
|
+
return member.cancellationError;
|
|
1882
|
+
},
|
|
1883
|
+
release: () => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, release_fn).call(this, member),
|
|
1884
|
+
refresh: () => {
|
|
1885
|
+
if (!member.active || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
|
|
1886
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
1887
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participants", snapshot: this.snapshot });
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
dispatch(command) {
|
|
1892
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, assertActive_fn2).call(this);
|
|
1893
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).dispatch(command).then((commit) => Object.freeze({ ...commit, snapshot: _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, extend_fn).call(this, commit.snapshot) }));
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Start every participant from one shared origin. With `when` (a time on the
|
|
1897
|
+
* Session's reference clock) the origin is no earlier than `when`, so a
|
|
1898
|
+
* caller can schedule a start; an expired `when` starts after the lead-in.
|
|
1899
|
+
*/
|
|
1900
|
+
play(when) {
|
|
1901
|
+
if (when !== void 0) {
|
|
1902
|
+
if (!Number.isFinite(when)) return Promise.reject(new RangeError("Session start time must be finite."));
|
|
1903
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _requestedStart, when);
|
|
1904
|
+
}
|
|
1905
|
+
return this.dispatch({ type: "play" });
|
|
1906
|
+
}
|
|
1907
|
+
pause() {
|
|
1908
|
+
return this.dispatch({ type: "pause" });
|
|
1909
|
+
}
|
|
1910
|
+
stop() {
|
|
1911
|
+
return this.dispatch({ type: "stop" });
|
|
1912
|
+
}
|
|
1913
|
+
seek(position) {
|
|
1914
|
+
return this.dispatch({ type: "seek", position });
|
|
1915
|
+
}
|
|
1916
|
+
setRate(rate) {
|
|
1917
|
+
return this.dispatch({ type: "rate", rate });
|
|
1918
|
+
}
|
|
1919
|
+
setLoop(loop) {
|
|
1920
|
+
return this.dispatch({ type: "loop", loop });
|
|
1921
|
+
}
|
|
1922
|
+
checkDrift() {
|
|
1923
|
+
return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).checkDrift();
|
|
1924
|
+
}
|
|
1925
|
+
/** Explicit resource preparation; registration alone cannot allocate audio. */
|
|
1926
|
+
async preload() {
|
|
1927
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, assertActive_fn2).call(this);
|
|
1928
|
+
let observed = -1;
|
|
1929
|
+
while (observed !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision)) {
|
|
1930
|
+
observed = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision);
|
|
1931
|
+
await Promise.all([
|
|
1932
|
+
...[..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)].map((member) => member.prepare()),
|
|
1933
|
+
...[..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources)].map((source) => source.ready)
|
|
1934
|
+
]);
|
|
1935
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
dispose() {
|
|
1939
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
|
|
1940
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed2, true);
|
|
1941
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation2)._;
|
|
1942
|
+
const errors = [];
|
|
1943
|
+
for (const source of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources)]) source.release();
|
|
1944
|
+
for (const member of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)]) {
|
|
1945
|
+
try {
|
|
1946
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, release_fn).call(this, member);
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
errors.push(error);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
try {
|
|
1952
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).dispose();
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
errors.push(error);
|
|
1955
|
+
}
|
|
1956
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).clear();
|
|
1957
|
+
if (errors.length) throw errors[0];
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
_now2 = new WeakMap();
|
|
1961
|
+
_clock = new WeakMap();
|
|
1962
|
+
_reader = new WeakMap();
|
|
1963
|
+
_scheduling = new WeakMap();
|
|
1964
|
+
_group = new WeakMap();
|
|
1965
|
+
_members = new WeakMap();
|
|
1966
|
+
_pendingSources = new WeakMap();
|
|
1967
|
+
_listeners = new WeakMap();
|
|
1968
|
+
_range = new WeakMap();
|
|
1969
|
+
_leadIn2 = new WeakMap();
|
|
1970
|
+
_requestedStart = new WeakMap();
|
|
1971
|
+
_membershipRevision = new WeakMap();
|
|
1972
|
+
_generation2 = new WeakMap();
|
|
1973
|
+
_ended = new WeakMap();
|
|
1974
|
+
_disposed2 = new WeakMap();
|
|
1975
|
+
_SessionTransport_instances = new WeakSet();
|
|
1976
|
+
start_fn = async function() {
|
|
1977
|
+
for (const member of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)]) if (member.active) _optionalChain([member, 'access', _49 => _49.options, 'access', _50 => _50.assertStartable, 'optionalCall', _51 => _51()]);
|
|
1978
|
+
const generation = ++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _generation2)._;
|
|
1979
|
+
const epoch = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch;
|
|
1980
|
+
await this.preload();
|
|
1981
|
+
let observed = -1;
|
|
1982
|
+
while (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) && generation === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation2) && observed !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision)) {
|
|
1983
|
+
observed = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision);
|
|
1984
|
+
await Promise.all([..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)].map(async (member) => {
|
|
1985
|
+
if (!member.active) return;
|
|
1986
|
+
++member.pendingStarts;
|
|
1987
|
+
try {
|
|
1988
|
+
await _optionalChain([member, 'access', _52 => _52.options, 'access', _53 => _53.activate, 'optionalCall', _54 => _54()]);
|
|
1989
|
+
} finally {
|
|
1990
|
+
--member.pendingStarts;
|
|
1991
|
+
if (!member.active) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, settleReleased_fn).call(this, member);
|
|
1992
|
+
}
|
|
1993
|
+
}));
|
|
1994
|
+
if (observed !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision)) await this.preload();
|
|
1995
|
+
}
|
|
1996
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) || generation !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _generation2)) return;
|
|
1997
|
+
const time = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now2).call(this);
|
|
1998
|
+
const position = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ended) ? _nullishCoalesce(_optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range), 'optionalAccess', _55 => _55.startSeconds]), () => ( 0)) : _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).positionAt(time);
|
|
1999
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ended, false);
|
|
2000
|
+
const requested = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _requestedStart);
|
|
2001
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _requestedStart, void 0);
|
|
2002
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).startAt(Math.max(time + _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _leadIn2), _nullishCoalesce(requested, () => ( -Infinity))), position);
|
|
2003
|
+
if (epoch === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
2004
|
+
};
|
|
2005
|
+
release_fn = function(member) {
|
|
2006
|
+
if (owners.get(member.identity) !== member) return;
|
|
2007
|
+
if (member.active) {
|
|
2008
|
+
member.active = false;
|
|
2009
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).delete(member);
|
|
2010
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).removeFollower(member.proxy);
|
|
2011
|
+
++_chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _membershipRevision)._;
|
|
2012
|
+
member.cancelPreparationWait();
|
|
2013
|
+
} else if (!member.cancellationFailed) return;
|
|
2014
|
+
try {
|
|
2015
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, cancel_fn).call(this, member);
|
|
2016
|
+
} finally {
|
|
2017
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, settleReleased_fn).call(this, member);
|
|
2018
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participants", snapshot: this.snapshot });
|
|
2019
|
+
}
|
|
2020
|
+
};
|
|
2021
|
+
settleReleased_fn = function(member) {
|
|
2022
|
+
if (member.active || member.preparing || member.pendingStarts > 0 || member.cancellationFailed) return;
|
|
2023
|
+
if (owners.get(member.identity) === member) owners.delete(member.identity);
|
|
2024
|
+
member.settle();
|
|
2025
|
+
};
|
|
2026
|
+
cancel_fn = function(member) {
|
|
2027
|
+
try {
|
|
2028
|
+
if (member.options.attachScheduling) {
|
|
2029
|
+
let failure;
|
|
2030
|
+
if (member.scheduling) {
|
|
2031
|
+
try {
|
|
2032
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).release(member.scheduling);
|
|
2033
|
+
} catch (error) {
|
|
2034
|
+
failure = error;
|
|
2035
|
+
}
|
|
2036
|
+
member.scheduling = void 0;
|
|
2037
|
+
}
|
|
2038
|
+
try {
|
|
2039
|
+
_optionalChain([member, 'access', _56 => _56.schedulingLease, 'optionalAccess', _57 => _57.release, 'call', _58 => _58()]);
|
|
2040
|
+
} catch (error) {
|
|
2041
|
+
_nullishCoalesce(failure, () => ( (failure = error)));
|
|
2042
|
+
}
|
|
2043
|
+
if (failure) throw failure;
|
|
2044
|
+
} else member.transport.pause();
|
|
2045
|
+
member.cancellationFailed = false;
|
|
2046
|
+
member.cancellationError = void 0;
|
|
2047
|
+
} catch (error) {
|
|
2048
|
+
member.cancellationFailed = true;
|
|
2049
|
+
member.cancellationError = error;
|
|
2050
|
+
throw error;
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
participantError_fn = function(error) {
|
|
2054
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, publish_fn2).call(this, { type: "participant-error", error, snapshot: this.snapshot });
|
|
2055
|
+
};
|
|
2056
|
+
duration_fn = function() {
|
|
2057
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources).size > 0) return null;
|
|
2058
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range)) return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).endSeconds;
|
|
2059
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).size) return null;
|
|
2060
|
+
let duration = 0;
|
|
2061
|
+
let unknown = false;
|
|
2062
|
+
for (const { options } of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)) {
|
|
2063
|
+
const local = readDuration(options);
|
|
2064
|
+
if (local === Infinity || options.loop) return Infinity;
|
|
2065
|
+
if (local === null) {
|
|
2066
|
+
unknown = true;
|
|
2067
|
+
continue;
|
|
2068
|
+
}
|
|
2069
|
+
duration = Math.max(duration, (local - (_nullishCoalesce(options.offsetSeconds, () => ( 0)))) / (_nullishCoalesce(options.positionScale, () => ( 1))));
|
|
2070
|
+
}
|
|
2071
|
+
return unknown ? null : duration;
|
|
2072
|
+
};
|
|
2073
|
+
reconcile_fn = function(time) {
|
|
2074
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources).size > 0) return "ok";
|
|
2075
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).paused || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).loop || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).holding && time < _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).state.originTime) return "ok";
|
|
2076
|
+
const position = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).positionAt(time);
|
|
2077
|
+
const duration = _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, duration_fn).call(this);
|
|
2078
|
+
const complete = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range) ? position >= _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range).endSeconds : duration !== null && Number.isFinite(duration) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).size > 0 && [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)].every(({ options, preparing }) => !preparing && (options.endPolicy === "position" ? position * (_nullishCoalesce(options.positionScale, () => ( 1))) + (_nullishCoalesce(options.offsetSeconds, () => ( 0))) >= readDuration(options) : _optionalChain([options, 'access', _59 => _59.ended, 'optionalCall', _60 => _60()]) === true));
|
|
2079
|
+
if (!complete) return "ok";
|
|
2080
|
+
_chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _ended, true);
|
|
2081
|
+
const epoch = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch + 1;
|
|
2082
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).invalidate();
|
|
2083
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch !== epoch) return "ok";
|
|
2084
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).pause(time);
|
|
2085
|
+
if (duration !== null && position > duration) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock).seekTo(duration, time);
|
|
2086
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).anchor();
|
|
2087
|
+
return !_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch === epoch ? "stalled" : "ok";
|
|
2088
|
+
};
|
|
2089
|
+
extend_fn = function(snapshot) {
|
|
2090
|
+
const participantTiming = { "shared-anchor": 0, callback: 0, "media-follower": 0, external: 0 };
|
|
2091
|
+
let scheduled = 0;
|
|
2092
|
+
for (const { options } of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members)) {
|
|
2093
|
+
if (options.attachScheduling) scheduled++;
|
|
2094
|
+
participantTiming[_nullishCoalesce(options.timing, () => ( (options.attachScheduling ? "shared-anchor" : "media-follower")))]++;
|
|
2095
|
+
}
|
|
2096
|
+
const anchored = participantTiming["shared-anchor"];
|
|
2097
|
+
return Object.freeze({
|
|
2098
|
+
...snapshot,
|
|
2099
|
+
position: this.scheduling.positionAt(snapshot.referenceTime),
|
|
2100
|
+
axis: "session-seconds",
|
|
2101
|
+
durationSeconds: _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, duration_fn).call(this),
|
|
2102
|
+
schedulingEpoch: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduling).epoch,
|
|
2103
|
+
schedulingMode: anchored === _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).size ? "shared-anchor" : scheduled === 0 ? "legacy" : "mixed",
|
|
2104
|
+
participantTiming: Object.freeze(participantTiming),
|
|
2105
|
+
participantCount: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _members).size,
|
|
2106
|
+
pendingSourceCount: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _pendingSources).size,
|
|
2107
|
+
membershipRevision: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision),
|
|
2108
|
+
ended: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ended),
|
|
2109
|
+
range: _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _range)
|
|
2110
|
+
});
|
|
2111
|
+
};
|
|
2112
|
+
publish_fn2 = function(event) {
|
|
2113
|
+
for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners)]) {
|
|
2114
|
+
if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).has(listener)) continue;
|
|
2115
|
+
_chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _SessionTransport_instances, deliver_fn).call(this, listener, event);
|
|
2116
|
+
if (event.snapshot.membershipRevision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _membershipRevision) || event.snapshot.revision !== _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _group).snapshot.revision) break;
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
deliver_fn = function(listener, event) {
|
|
2120
|
+
try {
|
|
2121
|
+
const result = listener(event);
|
|
2122
|
+
if (result && typeof result.then === "function") {
|
|
2123
|
+
void Promise.resolve(result).catch(() => {
|
|
2124
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).delete(listener);
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
} catch (e12) {
|
|
2128
|
+
_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).delete(listener);
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
assertActive_fn2 = function() {
|
|
2132
|
+
if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("SessionTransport has been disposed.");
|
|
2133
|
+
};
|
|
2134
|
+
function readDuration(options) {
|
|
2135
|
+
const duration = typeof options.durationSeconds === "function" ? options.durationSeconds() : options.durationSeconds;
|
|
2136
|
+
if (duration !== null && duration !== Infinity && (!Number.isFinite(duration) || duration < 0)) {
|
|
2137
|
+
throw new RangeError("Participant durationSeconds must be nonnegative finite seconds, null, or Infinity.");
|
|
2138
|
+
}
|
|
2139
|
+
return duration;
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
exports.attachSessionAutomation = attachSessionAutomation; exports.SessionLFO = SessionLFO; exports.SessionTransport = SessionTransport;
|
|
2147
|
+
//# sourceMappingURL=chunk-JFCBJMA7.cjs.map
|