@freedome/client 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -94,6 +94,9 @@ var ApiCaller = class _ApiCaller {
94
94
  "patchAudioZone",
95
95
  "startAudioSession",
96
96
  "stopAudioSession",
97
+ "pauseAudioSession",
98
+ "resumeAudioSession",
99
+ "startAudioDeviceSweep",
97
100
  "setSourcePosition"
98
101
  ]);
99
102
  async call(op, o = {}) {
@@ -329,7 +332,8 @@ var BackoffPolicy = class {
329
332
  // src/client.ts
330
333
  import {
331
334
  Operations as Operations13,
332
- ProtocolVersions,
335
+ ProtocolVersions as ProtocolVersions2,
336
+ SemVer as SemVer2,
333
337
  WS_SUBPROTOCOL
334
338
  } from "@freedome/protocol";
335
339
 
@@ -373,7 +377,7 @@ function nextValue(e, pred = () => true, timeoutMs = 5e3) {
373
377
 
374
378
  // src/context.ts
375
379
  var RepositoryContext = class {
376
- constructor(api, hub, cache, outbox, offline, isOffline, cacheScope, realtimeUp, positionHz, onEngineHealth, logger) {
380
+ constructor(api, hub, cache, outbox, offline, isOffline, cacheScope, realtimeUp, positionHz, onEngineHealth, logger, contractVersion = () => void 0) {
377
381
  this.api = api;
378
382
  this.hub = hub;
379
383
  this.cache = cache;
@@ -385,6 +389,7 @@ var RepositoryContext = class {
385
389
  this.positionHz = positionHz;
386
390
  this.onEngineHealth = onEngineHealth;
387
391
  this.logger = logger;
392
+ this.contractVersion = contractVersion;
388
393
  }
389
394
  api;
390
395
  hub;
@@ -397,7 +402,21 @@ var RepositoryContext = class {
397
402
  positionHz;
398
403
  onEngineHealth;
399
404
  logger;
405
+ contractVersion;
400
406
  outboxOutcomes = new Emitter();
407
+ /** Whether the server reports a contract of at least [version]. False while it is not known. */
408
+ contractAtLeast(version) {
409
+ const v = this.contractVersion();
410
+ return v !== void 0 && v.compareTo(version) >= 0;
411
+ }
412
+ /**
413
+ * Whether the server reports a contract older than [version]. False while it is not known: the call is then sent,
414
+ * and the server's answer decides.
415
+ */
416
+ contractBelow(version) {
417
+ const v = this.contractVersion();
418
+ return v !== void 0 && v.compareTo(version) < 0;
419
+ }
401
420
  log(level, message, error) {
402
421
  this.logger?.({ level, message, ...error === void 0 ? {} : { error } });
403
422
  }
@@ -1486,6 +1505,7 @@ import {
1486
1505
  DomeTopics as DomeTopics2,
1487
1506
  EventKinds as EventKinds2,
1488
1507
  Operations as Operations3,
1508
+ ProtocolVersions,
1489
1509
  jsonMergePatch as jsonMergePatch2,
1490
1510
  rfc3339Millis as rfc3339Millis2
1491
1511
  } from "@freedome/protocol";
@@ -1508,6 +1528,21 @@ var AudioRepository = class _AudioRepository {
1508
1528
  get v() {
1509
1529
  return { venueId: this.venueId };
1510
1530
  }
1531
+ /**
1532
+ * Whether the server has the audio additions of contract 1.1.0: [pauseSession], [resumeSession], [startDeviceSweep],
1533
+ * `roleZones` of [startSession] and the `multi` block of the generator. False against a 1.0 server and while its
1534
+ * contract version is not known.
1535
+ */
1536
+ get supportsAudioControl() {
1537
+ return this.c.contractAtLeast(ProtocolVersions.audioControl);
1538
+ }
1539
+ /** @internal A 1.0 server would answer 404 or 422: says why instead. Sent as it is when the version is not known. */
1540
+ requireAudioControl(what) {
1541
+ if (this.c.contractBelow(ProtocolVersions.audioControl))
1542
+ throw new UnsupportedCapabilityError(
1543
+ `${what} needs contract ${ProtocolVersions.audioControl.toString()}; the server reports ${String(this.c.contractVersion())}`
1544
+ );
1545
+ }
1511
1546
  /** The same repository for another venue. */
1512
1547
  venue(id) {
1513
1548
  if (id === this.venueId) return this;
@@ -1689,6 +1724,20 @@ var AudioRepository = class _AudioRepository {
1689
1724
  body: patch
1690
1725
  });
1691
1726
  }
1727
+ /**
1728
+ * Resonance sweep of one resonator channel of [deviceId] (scope `audio:calibrate`): answers a calibration job of kind
1729
+ * `audio-device-sweep`. Follow it with `client.calibration.progress`; progress is elapsed time, not measurement, and
1730
+ * the job's `sweep` member holds `peaks`, and with `modelHz` also `partials` and `warnings`, once it has succeeded.
1731
+ * There is nothing to apply. 409 while a session uses the device, another sweep runs or the device is in emergency
1732
+ * stop; 422 without such a resonator channel. Needs [supportsAudioControl].
1733
+ */
1734
+ async startDeviceSweep(deviceId, sweep = {}) {
1735
+ this.requireAudioControl("startDeviceSweep");
1736
+ return this.c.api.json(Operations3.startAudioDeviceSweep, {
1737
+ params: { ...this.v, deviceId },
1738
+ body: sweep
1739
+ });
1740
+ }
1692
1741
  /** Ping / tone / self-test / strike of a device. */
1693
1742
  testDevice(deviceId, test = { kind: "ping" }) {
1694
1743
  return this.c.api.json(Operations3.testAudioDevice, {
@@ -1747,10 +1796,12 @@ var AudioRepository = class _AudioRepository {
1747
1796
  }
1748
1797
  // ---- sessions ----
1749
1798
  /** Runs an installed preset (live control). */
1750
- startSession(s) {
1799
+ async startSession(s) {
1800
+ if (s.roleZones !== void 0) this.requireAudioControl("roleZones");
1751
1801
  const body = { presetId: s.presetId };
1752
1802
  if (s.gainDb !== void 0) body.gainDb = s.gainDb;
1753
1803
  if (s.targets !== void 0) body.targets = s.targets;
1804
+ if (s.roleZones !== void 0) body.roleZones = s.roleZones;
1754
1805
  if (s.at !== void 0) body.at = s.at instanceof Date ? rfc3339Millis2(s.at) : s.at;
1755
1806
  if (s.loop !== void 0) body.loop = s.loop;
1756
1807
  return this.c.api.json(Operations3.startAudioSession, {
@@ -1784,6 +1835,29 @@ var AudioRepository = class _AudioRepository {
1784
1835
  }
1785
1836
  );
1786
1837
  }
1838
+ /**
1839
+ * Pauses a session (live control, scope `audio:control`): every engine holds its position, `audioSession.state`
1840
+ * follows. A paused session answers as it is; 409 for one that is starting or has ended. Needs
1841
+ * [supportsAudioControl].
1842
+ */
1843
+ async pauseSession(sessionId) {
1844
+ this.requireAudioControl("pauseSession");
1845
+ return this.c.api.json(Operations3.pauseAudioSession, {
1846
+ params: { ...this.v, sessionId },
1847
+ preferRealtime: true
1848
+ });
1849
+ }
1850
+ /**
1851
+ * Resumes a paused session from its position (live control, scope `audio:control`). A running session answers as it
1852
+ * is; 409 for one that is starting or has ended. Needs [supportsAudioControl].
1853
+ */
1854
+ async resumeSession(sessionId) {
1855
+ this.requireAudioControl("resumeSession");
1856
+ return this.c.api.json(Operations3.resumeAudioSession, {
1857
+ params: { ...this.v, sessionId },
1858
+ preferRealtime: true
1859
+ });
1860
+ }
1787
1861
  /** Stops a session (live control). */
1788
1862
  async stopSession(sessionId) {
1789
1863
  await this.c.api.call(Operations3.stopAudioSession, {
@@ -1862,8 +1936,12 @@ var GeneratorSession = class {
1862
1936
  this.push(s);
1863
1937
  return s;
1864
1938
  }
1865
- /** Starts the generator or replaces its settings (live control, scope `audio:control`). */
1939
+ /**
1940
+ * Starts the generator or replaces its settings (live control, scope `audio:control`). The `multi` block needs
1941
+ * [AudioRepository.supportsAudioControl].
1942
+ */
1866
1943
  async start(settings) {
1944
+ if (settings.multi !== void 0) this.r.requireAudioControl("generator multi");
1867
1945
  const s = await this.r.ctx.api.json(Operations3.setGenerator, {
1868
1946
  params: this.v,
1869
1947
  body: settings,
@@ -1872,6 +1950,17 @@ var GeneratorSession = class {
1872
1950
  this.push(s);
1873
1951
  return s;
1874
1952
  }
1953
+ /**
1954
+ * Plays a MULTI programme: `signal: multi` with the block [multi], the same object a phone gives to `setParams`
1955
+ * (contract 1.1.0, `docs/audio-control.md`).
1956
+ */
1957
+ startMulti(multi, o = {}) {
1958
+ return this.start({
1959
+ ...o,
1960
+ signal: "multi",
1961
+ multi: { ...multi, compatJava: multi.compatJava ?? false }
1962
+ });
1963
+ }
1875
1964
  /** Stops the generator (live control). */
1876
1965
  async stop() {
1877
1966
  await this.r.ctx.api.call(Operations3.stopGenerator, { params: this.v, preferRealtime: true });
@@ -3279,7 +3368,7 @@ var VenuesRepository = class {
3279
3368
  };
3280
3369
 
3281
3370
  // src/client.ts
3282
- var FREEDOME_CLIENT_VERSION = "1.0.0-rc.1";
3371
+ var FREEDOME_CLIENT_VERSION = "1.1.0";
3283
3372
  function defaultTransports() {
3284
3373
  return { rest: (e) => new FetchTransport(e), sockets: webSocketConnector() };
3285
3374
  }
@@ -3373,7 +3462,8 @@ var FreedomeClient = class {
3373
3462
  () => this.channel !== void 0,
3374
3463
  this.options.positionHz,
3375
3464
  (s) => this.onEngineHealth(s),
3376
- init.logger
3465
+ init.logger,
3466
+ () => this.contractVersion
3377
3467
  );
3378
3468
  this.graphql = new GraphqlClient(this.api);
3379
3469
  this.venues = new VenuesRepository(this.ctx);
@@ -3396,6 +3486,15 @@ var FreedomeClient = class {
3396
3486
  get server() {
3397
3487
  return this.serverInfo;
3398
3488
  }
3489
+ /**
3490
+ * Contract version the server reports (`contractVersion` of `GET /info`); undefined before [open], or when the server
3491
+ * reports none or an unreadable one. This is how an app tells what a server offers: a 1.0 server has no audio control
3492
+ * (`ProtocolVersions.audioControl`, `AudioRepository.supportsAudioControl`).
3493
+ */
3494
+ get contractVersion() {
3495
+ const v = this.serverInfo?.contractVersion;
3496
+ return typeof v === "string" ? SemVer2.tryParse(v) ?? void 0 : void 0;
3497
+ }
3399
3498
  get state() {
3400
3499
  return this.stateValue;
3401
3500
  }
@@ -3492,17 +3591,17 @@ var FreedomeClient = class {
3492
3591
  throw new IncompatibleServerError(
3493
3592
  `no Freedome API v1 at ${this.endpointValue.apiBase} (${e.message})`,
3494
3593
  [],
3495
- ProtocolVersions.apiMajors
3594
+ ProtocolVersions2.apiMajors
3496
3595
  );
3497
3596
  }
3498
3597
  const versions = (info.apiVersions ?? []).map(String);
3499
3598
  const majors = versions.map((v) => Number.parseInt(v.replace(/^v/, ""), 10));
3500
- if (!majors.some((m) => ProtocolVersions.apiMajors.includes(m))) {
3599
+ if (!majors.some((m) => ProtocolVersions2.apiMajors.includes(m))) {
3501
3600
  this.set("incompatible");
3502
3601
  throw new IncompatibleServerError(
3503
- `server speaks ${versions.join(", ")}, this client v${ProtocolVersions.apiMajors.join(", v")}`,
3602
+ `server speaks ${versions.join(", ")}, this client v${ProtocolVersions2.apiMajors.join(", v")}`,
3504
3603
  versions,
3505
- ProtocolVersions.apiMajors
3604
+ ProtocolVersions2.apiMajors
3506
3605
  );
3507
3606
  }
3508
3607
  this.serverInfo = info;
@@ -3990,7 +4089,7 @@ var CompositeDiscovery = class {
3990
4089
  };
3991
4090
 
3992
4091
  // src/index.ts
3993
- import { Operations as Operations15, DomeTopics as DomeTopics10, EventKinds as EventKinds6 } from "@freedome/protocol";
4092
+ import { Operations as Operations15, DomeTopics as DomeTopics10, EventKinds as EventKinds6, ProtocolVersions as ProtocolVersions3, SemVer as SemVer3 } from "@freedome/protocol";
3994
4093
  var PACKAGE_NAME = "@freedome/client";
3995
4094
  export {
3996
4095
  ApiCaller,
@@ -4043,10 +4142,12 @@ export {
4043
4142
  PlayTargets,
4044
4143
  PlaybackRepository,
4045
4144
  PlayerHandle,
4145
+ ProtocolVersions3 as ProtocolVersions,
4046
4146
  QueuedForReplayError,
4047
4147
  RateLimitedError,
4048
4148
  RepositoryContext,
4049
4149
  RequestTimeoutError,
4150
+ SemVer3 as SemVer,
4050
4151
  ServerError,
4051
4152
  Sha256,
4052
4153
  ShowParts,
package/dist/node.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { F as FormatInput } from './input-CxW5zgc-.cjs';
2
- import { C as ContentSource, t as Discovery, s as DiscoveredDome } from './discovery-BsEQfHam.cjs';
2
+ import { C as ContentSource, t as Discovery, s as DiscoveredDome } from './discovery-Do_9mAzB.cjs';
3
3
  import { a as FreedomeTransportFactory } from './transport-dvmDQyvB.cjs';
4
4
  import '@freedome/protocol';
5
5
  import './errors-L_bIF-OR.cjs';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { F as FormatInput } from './input-CxW5zgc-.js';
2
- import { C as ContentSource, t as Discovery, s as DiscoveredDome } from './discovery-DTV9yp9S.js';
2
+ import { C as ContentSource, t as Discovery, s as DiscoveredDome } from './discovery-BkrBFXwA.js';
3
3
  import { a as FreedomeTransportFactory } from './transport-dvmDQyvB.js';
4
4
  import '@freedome/protocol';
5
5
  import './errors-L_bIF-OR.js';
package/dist/testing.cjs CHANGED
@@ -388,10 +388,13 @@ var FreedomeResponse = class _FreedomeResponse {
388
388
 
389
389
  // src/testing/fake-audio.ts
390
390
  var ENDED = /* @__PURE__ */ new Set(["finished", "stopped", "failed"]);
391
+ var JOB_ENDED = /* @__PURE__ */ new Set(["succeeded", "failed", "cancelled"]);
391
392
  var FakeAudio = class {
392
- constructor(publish, problem2) {
393
+ constructor(publish, problem2, jobs = /* @__PURE__ */ new Map(), audioControl = () => true) {
393
394
  this.publish = publish;
394
395
  this.problem = problem2;
396
+ this.jobs = jobs;
397
+ this.audioControl = audioControl;
395
398
  this.zones.set("front", {
396
399
  id: "front",
397
400
  name: "Front",
@@ -431,6 +434,8 @@ var FakeAudio = class {
431
434
  }
432
435
  publish;
433
436
  problem;
437
+ jobs;
438
+ audioControl;
434
439
  state = {
435
440
  venueId: "default",
436
441
  mode: "combined",
@@ -458,6 +463,12 @@ var FakeAudio = class {
458
463
  generator = { running: false };
459
464
  /** Last position per source id. */
460
465
  sources = /* @__PURE__ */ new Map();
466
+ /** Devices in emergency stop: a sweep answers 409. */
467
+ estopped = /* @__PURE__ */ new Set();
468
+ /** What a sweep of a device finds (`{hz, db, q?}`); without an entry, the model's partials. */
469
+ sweepPeaks = /* @__PURE__ */ new Map();
470
+ /** Milliseconds between the steps of a sweep. */
471
+ sweepStepMs = 1;
461
472
  /** Test hook: publishes `audio.levels` (`{meter id: dBFS}`) on `venues/{v}/audio/levels`. */
462
473
  emitLevels(levels) {
463
474
  this.publish("audio/levels", "audio.levels", { resource: { levels } });
@@ -484,6 +495,143 @@ var FakeAudio = class {
484
495
  publishSession(s) {
485
496
  this.publish(`audio/sessions/${s.id}`, "audioSession.state", { resource: s });
486
497
  }
498
+ /** 422 for a `roleZones` a 1.0 server would refuse, a role not of class `speakers` or an unknown zone; 409 without speakers. */
499
+ checkRoleZones(body) {
500
+ const roleZones = body?.roleZones;
501
+ if (roleZones === void 0) return void 0;
502
+ if (!this.audioControl())
503
+ return this.problem(422, "validation-failed", "unknown member roleZones");
504
+ if (!this.layout.body.speakers?.length)
505
+ return this.problem(409, "conflict", "the venue has no speakers");
506
+ const roles = this.presets.get(body.presetId)?.document?.roles;
507
+ for (const [role, zones] of Object.entries(roleZones)) {
508
+ if (roles && !roles[role]) return this.problem(422, "validation-failed", `no role ${role}`);
509
+ if (roles && roles[role].class !== "speakers")
510
+ return this.problem(422, "validation-failed", `role ${role} is not of class speakers`);
511
+ for (const z of zones)
512
+ if (!this.zones.has(z)) return this.problem(422, "validation-failed", `no zone ${z}`);
513
+ }
514
+ return void 0;
515
+ }
516
+ /** 422 for a `multi` block a 1.0 server would refuse, next to anything but `signal: multi`, or with `frequencies`. */
517
+ checkGeneratorMulti(body) {
518
+ if (body?.multi === void 0) return void 0;
519
+ if (!this.audioControl()) return this.problem(422, "validation-failed", "unknown member multi");
520
+ if (body.signal !== "multi")
521
+ return this.problem(422, "validation-failed", "multi needs signal: multi");
522
+ if (body.frequencies !== void 0)
523
+ return this.problem(422, "validation-failed", "multi excludes frequencies");
524
+ return void 0;
525
+ }
526
+ /** The state table of `docs/audio-control.md`. */
527
+ sessionControl(sessionId, pause) {
528
+ const s = this.sessions.get(sessionId);
529
+ if (!this.audioControl() || !s) return this.problem(404, "not-found", "session");
530
+ const [from, to] = pause ? ["running", "paused"] : ["paused", "running"];
531
+ if (s.status === from) {
532
+ s.status = to;
533
+ this.publishSession(s);
534
+ } else if (s.status !== to) {
535
+ return this.problem(409, "conflict", `session is ${s.status}`);
536
+ }
537
+ return FreedomeResponse.json(200, s);
538
+ }
539
+ startSweep(p, body) {
540
+ if (!this.audioControl()) return this.problem(404, "not-found", "no such route");
541
+ const deviceId = p.deviceId;
542
+ const d = this.devices.get(deviceId);
543
+ if (!d) return this.problem(404, "not-found", "device");
544
+ const from = body?.fromHz ?? 20;
545
+ const to = body?.toHz ?? 2e3;
546
+ const actuators = d.config?.actuators;
547
+ if (d.kind !== "resonator" || body?.actuator && actuators?.includes(body.actuator) === false)
548
+ return this.problem(422, "validation-failed", `no resonator channel on ${deviceId}`);
549
+ if (to <= from) return this.problem(422, "validation-failed", "toHz not above fromHz");
550
+ if (this.estopped.has(deviceId))
551
+ return this.problem(409, "conflict", `${deviceId} is in emergency stop`);
552
+ for (const s of this.sessions.values())
553
+ if (!ENDED.has(s.status) && s.targets?.devices?.includes(deviceId))
554
+ return this.problem(409, "conflict", `a session uses ${deviceId}`);
555
+ for (const j2 of this.jobs.values())
556
+ if (j2.kind === "audio-device-sweep" && !JOB_ENDED.has(j2.status))
557
+ return this.problem(409, "conflict", "another sweep runs");
558
+ const id = uuidV7();
559
+ const now = (0, import_protocol.rfc3339Millis)();
560
+ const j = {
561
+ id,
562
+ venueId: p.venueId,
563
+ kind: "audio-device-sweep",
564
+ status: "queued",
565
+ progress: 0,
566
+ steps: [{ id: "sweep", status: "pending" }],
567
+ currentStep: null,
568
+ awaiting: null,
569
+ result: null,
570
+ sweep: {
571
+ deviceId,
572
+ ...body?.actuator ? { actuator: body.actuator } : {},
573
+ fromHz: from,
574
+ toHz: to,
575
+ durationS: body?.durationS ?? 5,
576
+ level: body?.level ?? 0.3
577
+ },
578
+ createdAt: now,
579
+ updatedAt: now
580
+ };
581
+ this.jobs.set(id, j);
582
+ const answer = FreedomeResponse.json(202, structuredClone(j), {
583
+ location: `/api/v1/venues/${p.venueId}/calibration/jobs/${id}`
584
+ });
585
+ this.runSweep(j, body?.modelHz ?? [], body?.tolerance ?? 0.01, 0);
586
+ return answer;
587
+ }
588
+ /** queued → running, progress in steps of a third (time in the real server), then the result. */
589
+ runSweep(j, modelHz, tolerance, tick) {
590
+ const timer = setTimeout(() => {
591
+ if (JOB_ENDED.has(j.status)) return;
592
+ const step = j.steps[0];
593
+ j.updatedAt = (0, import_protocol.rfc3339Millis)();
594
+ const topic = `calibration/jobs/${j.id}`;
595
+ if (tick === 0) {
596
+ step.status = "running";
597
+ j.status = "running";
598
+ j.currentStep = "sweep";
599
+ this.publish(topic, "calibrationJob.state", { resource: j });
600
+ } else if (tick < 3) {
601
+ j.progress = tick / 3;
602
+ this.publish(topic, "calibrationJob.progress", { patch: { progress: j.progress } });
603
+ } else {
604
+ step.status = "done";
605
+ this.finishSweep(j, modelHz, tolerance);
606
+ j.status = "succeeded";
607
+ j.progress = 1;
608
+ j.currentStep = null;
609
+ this.publish(topic, "calibrationJob.state", { resource: j });
610
+ return;
611
+ }
612
+ this.runSweep(j, modelHz, tolerance, tick + 1);
613
+ }, this.sweepStepMs);
614
+ timer.unref?.();
615
+ }
616
+ /** `detuned`: a partial further than `tolerance` from its model. `cracked`: no peak within four times `tolerance`. */
617
+ finishSweep(j, modelHz, tolerance) {
618
+ const found = this.sweepPeaks.get(j.sweep.deviceId) ?? (modelHz.length ? modelHz : [440]).map((hz) => ({ hz, db: -6, q: 40 }));
619
+ const peaks = [...found].sort((a, b) => b.db - a.db);
620
+ j.sweep.peaks = peaks;
621
+ if (!modelHz.length) return;
622
+ const warnings = /* @__PURE__ */ new Set();
623
+ j.sweep.partials = modelHz.map((modelHz2) => {
624
+ const off = (hz) => Math.abs(hz - modelHz2) / modelHz2;
625
+ const near = peaks.map((x) => x.hz).sort((a, b) => off(a) - off(b))[0];
626
+ if (near === void 0 || off(near) > 4 * tolerance) {
627
+ warnings.add("cracked");
628
+ return { modelHz: modelHz2 };
629
+ }
630
+ if (off(near) > tolerance) warnings.add("detuned");
631
+ return { modelHz: modelHz2, measuredHz: near };
632
+ });
633
+ j.sweep.warnings = [...warnings];
634
+ }
487
635
  publishGenerator() {
488
636
  this.publish("audio/generator", "generator.state", { resource: this.generator });
489
637
  }
@@ -632,6 +780,8 @@ var FakeAudio = class {
632
780
  case "startAudioSession": {
633
781
  if (!this.presets.has(body?.presetId))
634
782
  return this.problem(404, "not-found", `preset ${body?.presetId}`);
783
+ const bad = this.checkRoleZones(body);
784
+ if (bad) return bad;
635
785
  const s = {
636
786
  id: uuidV7(),
637
787
  venueId: p.venueId,
@@ -641,6 +791,7 @@ var FakeAudio = class {
641
791
  position: 0,
642
792
  itemIndex: 0,
643
793
  ...body.targets ? { targets: body.targets } : {},
794
+ ...body.roleZones ? { roleZones: body.roleZones } : {},
644
795
  startedAt: body.at ?? (0, import_protocol.rfc3339Millis)()
645
796
  };
646
797
  this.sessions.set(s.id, s);
@@ -661,10 +812,18 @@ var FakeAudio = class {
661
812
  }
662
813
  return noContent();
663
814
  }
815
+ case "pauseAudioSession":
816
+ return this.sessionControl(p.sessionId, true);
817
+ case "resumeAudioSession":
818
+ return this.sessionControl(p.sessionId, false);
819
+ case "startAudioDeviceSweep":
820
+ return this.startSweep(p, body);
664
821
  case "getGenerator":
665
822
  return json(200, this.generator);
666
- case "setGenerator":
823
+ case "setGenerator": {
667
824
  if (!body?.signal) return this.problem(422, "validation", "signal is required");
825
+ const bad = this.checkGeneratorMulti(body);
826
+ if (bad) return bad;
668
827
  this.generator = {
669
828
  running: true,
670
829
  settings: body,
@@ -672,6 +831,7 @@ var FakeAudio = class {
672
831
  };
673
832
  this.publishGenerator();
674
833
  return json(200, this.generator);
834
+ }
675
835
  case "stopGenerator":
676
836
  this.generator = { running: false };
677
837
  this.publishGenerator();
@@ -950,6 +1110,11 @@ var FakeDomeServer = class {
950
1110
  pairings = /* @__PURE__ */ new Map();
951
1111
  /** Approve every pairing request at once (role = requested role or operator). */
952
1112
  autoApprovePairings = false;
1113
+ /**
1114
+ * Contract version the fake reports in `getInfo` and behaves as: below 1.1.0 the operations of 1.1.0 answer 404 and
1115
+ * its members 422, as a 1.0 server does.
1116
+ */
1117
+ contractVersion = "1.1.0";
953
1118
  /** Calibration jobs by id. */
954
1119
  calibrationJobs = /* @__PURE__ */ new Map();
955
1120
  /** Audio model + hooks (`emitLevels`, `advanceSession`). */
@@ -958,7 +1123,12 @@ var FakeDomeServer = class {
958
1123
  for (const v of /* @__PURE__ */ new Set(["default", this.activeVenue]))
959
1124
  this.publish(`venues/${v}/${t}`, kind, data);
960
1125
  },
961
- (status, code, detail) => problem(status, code, detail)
1126
+ (status, code, detail) => problem(status, code, detail),
1127
+ this.calibrationJobs,
1128
+ () => {
1129
+ const v = import_protocol3.SemVer.tryParse(this.contractVersion);
1130
+ return v !== null && v.compareTo(import_protocol3.ProtocolVersions.audioControl) >= 0;
1131
+ }
962
1132
  );
963
1133
  /** Live analysis, AudioReactive scenes, texture sources and gateways (`seed`, `publishFrame`). */
964
1134
  audioReactive = new FakeAudioReactive(
@@ -1137,6 +1307,7 @@ var FakeDomeServer = class {
1137
1307
  instanceId: this.instanceId,
1138
1308
  apiVersions: ["v1"],
1139
1309
  version: "1.0.0-rc.1",
1310
+ contractVersion: this.contractVersion,
1140
1311
  capabilities: { realtime: ["ws"], audio: true },
1141
1312
  transports: { ws: true, graphql: false, socketIo: false }
1142
1313
  });
@@ -1301,6 +1472,8 @@ var FakeDomeServer = class {
1301
1472
  return json(200, x);
1302
1473
  }
1303
1474
  case "startCalibrationJob": {
1475
+ if (body?.kind === "audio-device-sweep")
1476
+ return problem(422, "validation-failed", "a sweep starts with startAudioDeviceSweep");
1304
1477
  const id = uuidV7();
1305
1478
  const now = (0, import_protocol3.rfc3339Millis)();
1306
1479
  const j = {
@@ -1323,6 +1496,24 @@ var FakeDomeServer = class {
1323
1496
  const j = this.calibrationJobs.get(p.jobId);
1324
1497
  return j ? json(200, j) : problem(404, "not-found", "calibration job");
1325
1498
  }
1499
+ case "cancelCalibrationJob": {
1500
+ const j = this.calibrationJobs.get(p.jobId);
1501
+ if (!j) return problem(404, "not-found", "calibration job");
1502
+ if (!["succeeded", "failed", "cancelled"].includes(j.status)) {
1503
+ j.status = "cancelled";
1504
+ this.publish(`venues/${p.venueId}/calibration/jobs/${j.id}`, "calibrationJob.state", {
1505
+ resource: j
1506
+ });
1507
+ }
1508
+ return json(200, j);
1509
+ }
1510
+ case "applyCalibrationJob": {
1511
+ const j = this.calibrationJobs.get(p.jobId);
1512
+ if (!j) return problem(404, "not-found", "calibration job");
1513
+ if (j.status !== "succeeded" || !j.result)
1514
+ return problem(409, "conflict", `job ${j.id} has nothing to apply`);
1515
+ return json(200, j.result);
1516
+ }
1326
1517
  case "listShows":
1327
1518
  return json(200, {
1328
1519
  items: [...this.shows.entries()].map(([id, s]) => ({
@@ -8,6 +8,10 @@ type Problem$1 = (status: number, code: string, detail: string) => FreedomeRespo
8
8
  declare class FakeAudio {
9
9
  private readonly publish;
10
10
  private readonly problem;
11
+ /** Calibration jobs of the fake, which a sweep joins. */
12
+ private readonly jobs;
13
+ /** False: behaves as a 1.0 server (404 for the 1.1 operations, 422 for their members). */
14
+ private readonly audioControl;
11
15
  state: Json$2;
12
16
  layout: {
13
17
  body: Json$2;
@@ -20,7 +24,17 @@ declare class FakeAudio {
20
24
  generator: Json$2;
21
25
  /** Last position per source id. */
22
26
  readonly sources: Map<string, any>;
23
- constructor(publish: Publish$1, problem: Problem$1);
27
+ /** Devices in emergency stop: a sweep answers 409. */
28
+ readonly estopped: Set<string>;
29
+ /** What a sweep of a device finds (`{hz, db, q?}`); without an entry, the model's partials. */
30
+ readonly sweepPeaks: Map<string, any[]>;
31
+ /** Milliseconds between the steps of a sweep. */
32
+ sweepStepMs: number;
33
+ constructor(publish: Publish$1, problem: Problem$1,
34
+ /** Calibration jobs of the fake, which a sweep joins. */
35
+ jobs?: Map<string, Json$2>,
36
+ /** False: behaves as a 1.0 server (404 for the 1.1 operations, 422 for their members). */
37
+ audioControl?: () => boolean);
24
38
  /** Test hook: publishes `audio.levels` (`{meter id: dBFS}`) on `venues/{v}/audio/levels`. */
25
39
  emitLevels(levels: Record<string, number>): void;
26
40
  /** Test hook: advances session [id] to [positionSec] (and optionally a new [status]); publishes the state. */
@@ -28,6 +42,17 @@ declare class FakeAudio {
28
42
  private bumpState;
29
43
  private publishZone;
30
44
  private publishSession;
45
+ /** 422 for a `roleZones` a 1.0 server would refuse, a role not of class `speakers` or an unknown zone; 409 without speakers. */
46
+ private checkRoleZones;
47
+ /** 422 for a `multi` block a 1.0 server would refuse, next to anything but `signal: multi`, or with `frequencies`. */
48
+ private checkGeneratorMulti;
49
+ /** The state table of `docs/audio-control.md`. */
50
+ private sessionControl;
51
+ private startSweep;
52
+ /** queued → running, progress in steps of a third (time in the real server), then the result. */
53
+ private runSweep;
54
+ /** `detuned`: a partial further than `tolerance` from its model. `cracked`: no peak within four times `tolerance`. */
55
+ private finishSweep;
31
56
  private publishGenerator;
32
57
  private page;
33
58
  /** Serves audio operation [op]; undefined = not an audio operation. */
@@ -121,6 +146,11 @@ declare class FakeDomeServer {
121
146
  readonly pairings: Map<string, any>;
122
147
  /** Approve every pairing request at once (role = requested role or operator). */
123
148
  autoApprovePairings: boolean;
149
+ /**
150
+ * Contract version the fake reports in `getInfo` and behaves as: below 1.1.0 the operations of 1.1.0 answer 404 and
151
+ * its members 422, as a 1.0 server does.
152
+ */
153
+ contractVersion: string;
124
154
  /** Calibration jobs by id. */
125
155
  readonly calibrationJobs: Map<string, any>;
126
156
  /** Audio model + hooks (`emitLevels`, `advanceSession`). */
package/dist/testing.d.ts CHANGED
@@ -8,6 +8,10 @@ type Problem$1 = (status: number, code: string, detail: string) => FreedomeRespo
8
8
  declare class FakeAudio {
9
9
  private readonly publish;
10
10
  private readonly problem;
11
+ /** Calibration jobs of the fake, which a sweep joins. */
12
+ private readonly jobs;
13
+ /** False: behaves as a 1.0 server (404 for the 1.1 operations, 422 for their members). */
14
+ private readonly audioControl;
11
15
  state: Json$2;
12
16
  layout: {
13
17
  body: Json$2;
@@ -20,7 +24,17 @@ declare class FakeAudio {
20
24
  generator: Json$2;
21
25
  /** Last position per source id. */
22
26
  readonly sources: Map<string, any>;
23
- constructor(publish: Publish$1, problem: Problem$1);
27
+ /** Devices in emergency stop: a sweep answers 409. */
28
+ readonly estopped: Set<string>;
29
+ /** What a sweep of a device finds (`{hz, db, q?}`); without an entry, the model's partials. */
30
+ readonly sweepPeaks: Map<string, any[]>;
31
+ /** Milliseconds between the steps of a sweep. */
32
+ sweepStepMs: number;
33
+ constructor(publish: Publish$1, problem: Problem$1,
34
+ /** Calibration jobs of the fake, which a sweep joins. */
35
+ jobs?: Map<string, Json$2>,
36
+ /** False: behaves as a 1.0 server (404 for the 1.1 operations, 422 for their members). */
37
+ audioControl?: () => boolean);
24
38
  /** Test hook: publishes `audio.levels` (`{meter id: dBFS}`) on `venues/{v}/audio/levels`. */
25
39
  emitLevels(levels: Record<string, number>): void;
26
40
  /** Test hook: advances session [id] to [positionSec] (and optionally a new [status]); publishes the state. */
@@ -28,6 +42,17 @@ declare class FakeAudio {
28
42
  private bumpState;
29
43
  private publishZone;
30
44
  private publishSession;
45
+ /** 422 for a `roleZones` a 1.0 server would refuse, a role not of class `speakers` or an unknown zone; 409 without speakers. */
46
+ private checkRoleZones;
47
+ /** 422 for a `multi` block a 1.0 server would refuse, next to anything but `signal: multi`, or with `frequencies`. */
48
+ private checkGeneratorMulti;
49
+ /** The state table of `docs/audio-control.md`. */
50
+ private sessionControl;
51
+ private startSweep;
52
+ /** queued → running, progress in steps of a third (time in the real server), then the result. */
53
+ private runSweep;
54
+ /** `detuned`: a partial further than `tolerance` from its model. `cracked`: no peak within four times `tolerance`. */
55
+ private finishSweep;
31
56
  private publishGenerator;
32
57
  private page;
33
58
  /** Serves audio operation [op]; undefined = not an audio operation. */
@@ -121,6 +146,11 @@ declare class FakeDomeServer {
121
146
  readonly pairings: Map<string, any>;
122
147
  /** Approve every pairing request at once (role = requested role or operator). */
123
148
  autoApprovePairings: boolean;
149
+ /**
150
+ * Contract version the fake reports in `getInfo` and behaves as: below 1.1.0 the operations of 1.1.0 answer 404 and
151
+ * its members 422, as a 1.0 server does.
152
+ */
153
+ contractVersion: string;
124
154
  /** Calibration jobs by id. */
125
155
  readonly calibrationJobs: Map<string, any>;
126
156
  /** Audio model + hooks (`emitLevels`, `advanceSession`). */