Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07d2a36
chore(quest): claim quest/m2/js-time-types.md
kixelated Nov 8, 2026
e7619d8
feat(clock,signals)!: Duration, Instant, and Wall are classes
kixelated Nov 8, 2026
22f1488
feat(net,qmux)!: durations and instants are Clock types
kixelated Nov 8, 2026
541e3fe
feat(hang,loc)!: media timestamps are Clock Durations
kixelated Nov 8, 2026
0f38263
feat(json,auth)!: adopt Clock Duration, Instant, and Wall
kixelated Nov 8, 2026
d4b60ba
docs: Clock types in the JS guides; retire the js-time-types quest
kixelated Nov 8, 2026
03831ac
feat(watch,publish,room,boy)!: adopt Clock Duration, Instant, and Wall
kixelated Nov 8, 2026
3167bce
docs: watch and publish take Clock durations
kixelated Nov 8, 2026
83a280c
test: interop, audio-quality, and bench clients take Clock types
kixelated Nov 8, 2026
b8f49e4
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 8, 2026
e772270
quest: peer-arithmetic carries the JS checked forms
kixelated Nov 8, 2026
ee08c26
fix(clock,publish): exact durations past 2^53 ns, signed file timestamps
kixelated Nov 8, 2026
5940f8a
fix(clock,publish): durations hold whole nanoseconds
kixelated Nov 8, 2026
d2b0500
perf(clock,hang): fewer allocations building durations and buffered r…
kixelated Nov 8, 2026
6c52b4e
test(publish): AAC group spacing matches to the nanosecond
kixelated Nov 8, 2026
3d92ace
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 8, 2026
7d4ca78
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 9, 2026
23e94ce
docs(clock,signals,net): Wall docs match its checks; clock values com…
kixelated Nov 9, 2026
1e69f34
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 9, 2026
9c10fe7
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 9, 2026
a371737
fix(watch,test): main's time stretch tests format; relay-bbb replay b…
kixelated Nov 9, 2026
150ef20
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 9, 2026
0a762e2
fix(publish): derive AAC continuity from the framer's timeline
kixelated Nov 9, 2026
fbe8682
Merge remote-tracking branch 'origin/main' into fix/aac-continuity-ro…
kixelated Nov 9, 2026
24ef62d
Merge remote-tracking branch 'origin/main' into quest/m2/js-time-types
kixelated Nov 9, 2026
2e12261
Merge remote-tracking branch 'origin/main' into HEAD
kixelated Nov 9, 2026
f3141ca
Merge base and adapt new audio counters to clock types
Nov 9, 2026
6a93db5
Merge origin/main into quest/m2/js-time-types
kixelated Nov 9, 2026
5688bc0
Merge origin/main into quest/m2/js-time-types
kixelated Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions bench/browser/page/media.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Publish a synthetic picture with @moq/publish and watch it with @moq/watch through the relay. */
import { Milli } from "@moq/clock";
import { Duration } from "@moq/clock";
import * as Moq from "@moq/net";
import * as Publish from "@moq/publish";
import * as Watch from "@moq/watch";
Expand Down Expand Up @@ -70,7 +70,7 @@ async function publish(config: Media): Promise<void> {
codec: config.codec,
frameRate: config.fps,
maxPixels: config.width * config.height,
join: Milli(config.keyframe_ms),
join: Duration.millis(config.keyframe_ms),
maxBitrate: config.bitrate,
},
});
Expand Down
4 changes: 2 additions & 2 deletions bench/browser/page/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* receive shape's publisher dials once with `Moq.Connection.connect`, which runs no loop, so it
* adds the same delivery work to every variant without sampling of its own.
*/
import { Milli } from "@moq/clock";
import { Duration } from "@moq/clock";
import * as Moq from "@moq/net";
import { Session } from "@moq/qmux";
import { check, payload } from "../fixture.ts";
Expand Down Expand Up @@ -177,7 +177,7 @@ async function receive(config: Sampling): Promise<void> {
const request = origin.follow(Moq.Path.from(`${config.path}/live`));
cleanup.push(() => request.close());
const broadcast = await active(request);
const subscriber = broadcast.track("data").subscribe({ delay: { max: Milli(1000) } });
const subscriber = broadcast.track("data").subscribe({ delay: { max: Duration.millis(1000) } });
cleanup.push(() => subscriber.close());
const reader = received.push(0) - 1;
readers.push(
Expand Down
11 changes: 8 additions & 3 deletions bench/browser/page/transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Publisher and consumer roles for the @moq/net stream path over a real WebTransport session. */
import { Milli } from "@moq/clock";
import { Duration } from "@moq/clock";
import * as Moq from "@moq/net";
import { check, payload } from "../fixture.ts";
import { longTasks, nextTask } from "./observe.ts";
Expand Down Expand Up @@ -35,7 +35,10 @@ async function publish(config: Transport): Promise<void> {
const publication = origin.route(Moq.Path.from(config.path), { hidden: true });
const producer = publication.broadcast;
// Retention covers the whole run, so a slow consumer cannot lose a group to eviction.
const track = producer.createTrack("data", { timescale: Moq.Time.Timescale.MILLI, maxAge: Milli(600_000) });
const track = producer.createTrack("data", {
timescale: Moq.Time.Timescale.MILLI,
maxAge: Duration.millis(600_000),
});
const demand = track.demand().wanted;
publication.announce();
const connection = await Moq.Connection.connect({
Expand Down Expand Up @@ -92,7 +95,9 @@ async function consume(config: Transport): Promise<Delivery> {
if (!broadcast) throw new Error("consume before prepare");
const groups = Math.ceil(config.frames / config.group);
const start = performance.now();
const subscriber = broadcast.track("data").subscribe({ delay: { max: Milli(600_000) }, order: "ascending" });
const subscriber = broadcast
.track("data")
.subscribe({ delay: { max: Duration.millis(600_000) }, order: "ascending" });
cleanup.push(() => subscriber.close());
let frames = 0;
let bytes = 0;
Expand Down
6 changes: 3 additions & 3 deletions demo/carla/web/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @module
*/

import { Milli, Nano } from "@moq/clock";
import { Duration } from "@moq/clock";
import * as Moq from "@moq/net";
import { COLLISION_ALERT_MS, collisionAge, collisionLabel, diverged, divergence } from "./feedback.ts";
import { drawDivergence, drawDriveHud, drawGuide } from "./guides.ts";
Expand Down Expand Up @@ -720,7 +720,7 @@ export function mount(root: ShadowRoot, connection: Moq.Connection, origin: Moq.
frame = requestAnimationFrame(tick);
}
signals.cleanup(() => cancelAnimationFrame(frame));
signals.interval(step, Nano.fromMilli(Milli(250)));
signals.interval(step, Duration.millis(250));

// --- Wheel status chip + calibration dialog. ---
let calibration: Calibration | undefined;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ export function mount(root: ShadowRoot, connection: Moq.Connection, origin: Moq.
// A collision's age is wall clock, not a status field, so it needs its own
// tick: without one the callout would freeze on a truck that stops moving
// and therefore stops changing its snapshot.
this.#signals.interval(() => this.#renderCollision(this.truck.status.peek()), Nano.fromMilli(Milli(1000)));
this.#signals.interval(() => this.#renderCollision(this.truck.status.peek()), Duration.millis(1000));

// Repaint on layout/resize (the initial effect run happens before layout,
// so the overlay has zero size until the first observation fires).
Expand Down
12 changes: 6 additions & 6 deletions demo/carla/web/src/truck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @module
*/
import { Milli, Nano } from "@moq/clock";
import { Duration } from "@moq/clock";
import * as Json from "@moq/json";
import * as Moq from "@moq/net";
import * as Watch from "@moq/watch";
Expand Down Expand Up @@ -44,7 +44,7 @@ interface Command {
/** A driver session: pending until the truck accepts, `null` once the dial or the session failed. */
type Session = Moq.Signals.Signal<Moq.Socket.TrackStream | null | undefined>;

const CONTROL_HEARTBEAT = Milli(250);
const CONTROL_HEARTBEAT = Duration.millis(250);
const MAX_PENDING_ACKS = 64;
const encoder = new TextEncoder();
const decoder = new TextDecoder();
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Truck {
this.#signals.run(this.#runActive.bind(this));
this.#signals.run(this.#runControlLease.bind(this));
this.#signals.run(this.#runRespawn.bind(this));
this.#signals.interval(() => this.#heartbeat(), Nano.fromMilli(CONTROL_HEARTBEAT));
this.#signals.interval(() => this.#heartbeat(), CONTROL_HEARTBEAT);

// Video pipeline.
this.broadcast = new Watch.Broadcast({
Expand Down Expand Up @@ -313,11 +313,11 @@ export class Truck {
#timestamps(): { label: string; ts: number }[] {
const entries: { label: string; ts: number }[] = [];
const received = this.sync.out.timestamp.peek();
if (received != null) entries.push({ label: "received", ts: received });
if (received != null) entries.push({ label: "received", ts: received.asMillis() });
const decoded = this.videoDecoder.out.timestamp.peek();
if (decoded != null) entries.push({ label: "decoded", ts: decoded });
if (decoded != null) entries.push({ label: "decoded", ts: decoded.asMillis() });
const rendered = this.videoRenderer.out.timestamp.peek();
if (rendered != null) entries.push({ label: "rendered", ts: rendered });
if (rendered != null) entries.push({ label: "rendered", ts: rendered.asMillis() });
return entries;
}

Expand Down
101 changes: 49 additions & 52 deletions demo/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import "./highlight";
import { Milli, Nano, now } from "@moq/clock";
import { Duration, now } from "@moq/clock";
import * as Json from "@moq/json";
import "@moq/watch/element"; // defines <moq-watch>
import "@moq/watch/ui"; // defines <moq-watch-ui>
Expand Down Expand Up @@ -509,58 +509,55 @@ viz.run((effect) => {

// Sample the active tile's byte/frame counters and push per-second rates.
let prevWatch: MoqWatch | undefined;
let prev = { frames: 0, videoBytes: 0, audioBytes: 0, when: Nano.toMilli(Nano(now())) };
viz.interval(
() => {
const watch = activeWatch.peek();
const at = Nano.toMilli(Nano(now()));

// Reset baselines when switching tiles (or when idle) so the first sample
// isn't a huge spike from the counter difference.
if (watch !== prevWatch || !watch) {
prevWatch = watch;
const video = watch?.video.out.stats.peek();
const audio = watch?.audio.out.stats.peek();
prev = {
frames: video?.frameCount ?? 0,
videoBytes: video?.bytesReceived ?? 0,
audioBytes: audio?.bytesReceived ?? 0,
when: at,
};
for (const g of allGraphs) g.push(undefined);
return;
}
let prev = { frames: 0, videoBytes: 0, audioBytes: 0, when: now() };
viz.interval(() => {
const watch = activeWatch.peek();
const at = now();

// Reset baselines when switching tiles (or when idle) so the first sample
// isn't a huge spike from the counter difference.
if (watch !== prevWatch || !watch) {
prevWatch = watch;
const video = watch?.video.out.stats.peek();
const audio = watch?.audio.out.stats.peek();
prev = {
frames: video?.frameCount ?? 0,
videoBytes: video?.bytesReceived ?? 0,
audioBytes: audio?.bytesReceived ?? 0,
when: at,
};
for (const g of allGraphs) g.push(undefined);
return;
}

const v = watch.video.out.stats.peek();
const a = watch.audio.out.stats.peek();
const videoBytes = v?.bytesReceived ?? 0;
const audioBytes = a?.bytesReceived ?? 0;
const frames = v?.frameCount ?? 0;
const elapsed = at - prev.when;

const perSec = (delta: number) => (delta >= 0 ? (delta * 1000) / elapsed : undefined);
let videoBitrate: number | undefined;
let audioBitrate: number | undefined;
let throughput: number | undefined;
let fps: number | undefined;
if (elapsed > 0) {
videoBitrate = perSec((videoBytes - prev.videoBytes) * 8);
audioBitrate = perSec((audioBytes - prev.audioBytes) * 8);
throughput = perSec((videoBytes - prev.videoBytes + audioBytes - prev.audioBytes) * 8);
fps = perSec(frames - prev.frames);
}
videoBitrateGraph.push(videoBitrate);
audioBitrateGraph.push(audioBitrate);
fpsGraph.push(fps);
throughputGraph.push(throughput);

const rtt = watch.connection.probe.peek()?.rtt as unknown as number | undefined;
rttGraph.push(rtt && rtt > 0 ? rtt : undefined);

prev = { frames, videoBytes, audioBytes, when: at };
},
Nano.fromMilli(Milli(250)),
);
const v = watch.video.out.stats.peek();
const a = watch.audio.out.stats.peek();
const videoBytes = v?.bytesReceived ?? 0;
const audioBytes = a?.bytesReceived ?? 0;
const frames = v?.frameCount ?? 0;
const elapsed = at.since(prev.when).asMillis();

const perSec = (delta: number) => (delta >= 0 ? (delta * 1000) / elapsed : undefined);
let videoBitrate: number | undefined;
let audioBitrate: number | undefined;
let throughput: number | undefined;
let fps: number | undefined;
if (elapsed > 0) {
videoBitrate = perSec((videoBytes - prev.videoBytes) * 8);
audioBitrate = perSec((audioBytes - prev.audioBytes) * 8);
throughput = perSec((videoBytes - prev.videoBytes + audioBytes - prev.audioBytes) * 8);
fps = perSec(frames - prev.frames);
}
videoBitrateGraph.push(videoBitrate);
audioBitrateGraph.push(audioBitrate);
fpsGraph.push(fps);
throughputGraph.push(throughput);

const rtt = watch.connection.probe.peek()?.rtt?.asMillis();
rttGraph.push(rtt && rtt > 0 ? rtt : undefined);

prev = { frames, videoBytes, audioBytes, when: at };
}, Duration.millis(250));

// Rebuild the buffer visualization whenever the active tile changes; it binds to
// one element and runs its own animation loop until its child effect closes.
Expand Down
49 changes: 23 additions & 26 deletions demo/web/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./highlight";
import * as Json from "@moq/json";
import "@moq/publish/element"; // defines <moq-publish>
import "@moq/publish/ui"; // defines <moq-publish-ui>
import { Milli, Nano, now } from "@moq/clock";
import { Duration, now } from "@moq/clock";
import { type Audio, Net, Signals, Source, type Video } from "@moq/publish";
import type MoqPublish from "@moq/publish/element";
import MoqPublishSupport from "@moq/publish/support/element";
Expand Down Expand Up @@ -142,7 +142,7 @@ function encoderConfig(effect: Signals.Effect, target: VideoTarget): Video.Confi
codec: effect.get(codec),
maxPixels: target.width && target.height ? target.width * target.height : undefined,
maxBitrate: br != null ? br * 1000 : undefined,
join: kf != null ? Milli(kf) : undefined,
join: kf != null ? Duration.millis(kf) : undefined,
frameRate: target.frameRate,
};
}
Expand Down Expand Up @@ -200,7 +200,7 @@ ui.run((effect) => {
const config: Audio.OpusConfig = {
mime: "opus",
...(bitrate != null ? { bitrate: bitrate * 1000 } : {}),
...(frameDuration != null ? { frameDuration: Milli(frameDuration) } : {}),
...(frameDuration != null ? { frameDuration: Duration.millis(frameDuration) } : {}),
...(complexity != null ? { complexity } : {}),
...(packetLoss != null ? { packetlossperc: packetLoss } : {}),
useinbandfec: effect.get(opusFec),
Expand Down Expand Up @@ -408,7 +408,7 @@ meta.run((effect) => {
// A day-long cache so a viewer joining long after the last edit still replays the value.
const track = net.createTrack(META_TRACK, {
timescale: Net.Time.Timescale.MILLI,
maxAge: Milli(86_400_000),
maxAge: Duration.millis(86_400_000),
});
effect.cleanup(() => {
track.finish();
Expand Down Expand Up @@ -488,28 +488,25 @@ viz.run((effect) => {
});

let prevFrames = 0;
let prevWhen = Nano.toMilli(Nano(now()));
viz.interval(
() => {
const at = Nano.toMilli(Nano(now()));
const elapsed = at - prevWhen;
captureGraph.push(elapsed > 0 ? ((frames - prevFrames) * 1000) / elapsed : undefined);
prevFrames = frames;
prevWhen = at;

const rtt = publish.connection.probe.peek()?.rtt as unknown as number | undefined;
rttGraph.push(rtt && rtt > 0 ? rtt : undefined);

void publish.connection.stats().then(
(stats) => {
const up = stats?.estimatedSendRate;
uploadGraph.push(up && up > 0 ? up : undefined);
},
() => uploadGraph.push(undefined),
);
},
Nano.fromMilli(Milli(250)),
);
let prevWhen = now();
viz.interval(() => {
const at = now();
const elapsed = at.since(prevWhen).asMillis();
captureGraph.push(elapsed > 0 ? ((frames - prevFrames) * 1000) / elapsed : undefined);
prevFrames = frames;
prevWhen = at;

const rtt = publish.connection.probe.peek()?.rtt?.asMillis();
rttGraph.push(rtt && rtt > 0 ? rtt : undefined);

void publish.connection.stats().then(
(stats) => {
const up = stats?.estimatedSendRate;
uploadGraph.push(up && up > 0 ? up : undefined);
},
() => uploadGraph.push(undefined),
);
}, Duration.millis(250));

// Vite re-evaluates this module on hot reload, dropping the references to the
// module-scoped effects above. Close them on dispose so they don't get garbage
Expand Down
6 changes: 3 additions & 3 deletions demo/web/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import "./highlight";
import { Milli, Nano, wall } from "@moq/clock";
import { Duration, wall } from "@moq/clock";
import { Net, Signals } from "@moq/hang";
import * as Json from "@moq/json";

Expand All @@ -33,7 +33,7 @@ const RELAY_URL = import.meta.env.VITE_RELAY_URL ?? "http://localhost:4443";
const STATS_PREFIX = ".stats/node";

// Rolling history window for the charts.
const SAMPLE = Nano.fromMilli(Milli(1000));
const SAMPLE = Duration.millis(1000);
const MAX_SAMPLES = 90;

const $ = <T extends HTMLElement>(id: string): T => {
Expand Down Expand Up @@ -354,7 +354,7 @@ sampler.run((effect) => {
effect.interval(() => {
const all = nodeStats.peek();
const nodes = Object.keys(all).sort();
const t = wall();
const t = wall().asUnixMillis();

const agg: Sample = {
t,
Expand Down
Loading