Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion doc/.vitepress/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@moq/signals": "workspace:*",
"@moq/obs": "workspace:*",
"@moq/stats": "workspace:*",
"@moq/ui": "workspace:*",
"@moq/video": "workspace:*",
"@moq/watch": "workspace:*",
"typedoc": "^0.28.20",
Expand Down
1 change: 0 additions & 1 deletion doc/lib/js/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ small examples. The [API reference](/lib/js/api/) covers every package; source l
| [@moq/watch](/lib/js/watch) | Subscribe, decode, and render. `<moq-watch>` plus an optional UI overlay. |
| [@moq/video](/lib/js/video) | Draw video frames into a canvas through WebGPU or Canvas2D. Used by `@moq/watch` and `@moq/publish`. |
| [@moq/publish](/lib/js/publish) | Capture, encode, and publish. `<moq-publish>` plus an optional UI overlay. |
| [@moq/ui](/lib/js/api/ui) | The base of the watch and publish browser support banners. |
| [@moq/room](/lib/js/room) | Headless rooms: announce-derived roster, local publish, remote watch, and a chat track. |
| [@moq/auth](/lib/js/auth) | Validate a relay's request, build its grant, and mint and verify relay JWTs. |
| [@moq/clock](/lib/js/clock) | Logical monotonic time, wall time, and deterministic timers. |
Expand Down
2 changes: 1 addition & 1 deletion doc/setup/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ replaces it.
- **Binaries:** [moq-relay](https://github.com/moq-dev/moq/blob/main/rs/moq-relay/MIGRATE.md), [moq-cli (`moq`)](https://github.com/moq-dev/moq/blob/main/rs/moq-cli/MIGRATE.md), [moq-gst](https://github.com/moq-dev/moq/blob/main/rs/moq-gst/MIGRATE.md), [obs-moq](https://github.com/moq-dev/moq/blob/main/cpp/obs/MIGRATE.md)
- **Bindings:** [moq-ffi (UniFFI)](https://github.com/moq-dev/moq/blob/main/rs/moq-ffi/MIGRATE.md), [moq-c (C)](https://github.com/moq-dev/moq/blob/main/rs/moq-c/MIGRATE.md), [Python](https://github.com/moq-dev/moq/blob/main/py/moq-rs/MIGRATE.md), [Go](https://github.com/moq-dev/moq/blob/main/go/wrapper/MIGRATE.md), [Swift](https://github.com/moq-dev/moq/blob/main/swift/MIGRATE.md), [Kotlin](https://github.com/moq-dev/moq/blob/main/kt/moq/MIGRATE.md), [Dart](https://github.com/moq-dev/moq/blob/main/dart/moq/MIGRATE.md), [C++](https://github.com/moq-dev/moq/blob/main/cpp/moq/MIGRATE.md)
- **Rust:** [hang](https://github.com/moq-dev/moq/blob/main/rs/hang/MIGRATE.md), [kio](https://github.com/moq-dev/moq/blob/main/rs/kio/MIGRATE.md), [kio-macros](https://github.com/moq-dev/moq/blob/main/rs/kio/macros/MIGRATE.md), [moq-archive](https://github.com/moq-dev/moq/blob/main/rs/moq-archive/MIGRATE.md), [moq-audio](https://github.com/moq-dev/moq/blob/main/rs/moq-audio/MIGRATE.md), [moq-auth](https://github.com/moq-dev/moq/blob/main/rs/moq-auth/MIGRATE.md), [moq-crypto](https://github.com/moq-dev/moq/blob/main/rs/moq-crypto/MIGRATE.md), [moq-hls](https://github.com/moq-dev/moq/blob/main/rs/moq-hls/MIGRATE.md), [moq-json](https://github.com/moq-dev/moq/blob/main/rs/moq-json/MIGRATE.md), [moq-loc](https://github.com/moq-dev/moq/blob/main/rs/moq-loc/MIGRATE.md), [moq-msf](https://github.com/moq-dev/moq/blob/main/rs/moq-msf/MIGRATE.md), [moq-mux](https://github.com/moq-dev/moq/blob/main/rs/moq-mux/MIGRATE.md), [moq-net](https://github.com/moq-dev/moq/blob/main/rs/moq-net/MIGRATE.md), [moq-nvenc](https://github.com/moq-dev/moq/blob/main/rs/moq-nvenc/MIGRATE.md), [moq-pattern](https://github.com/moq-dev/moq/blob/main/rs/moq-pattern/MIGRATE.md), [moq-rtmp](https://github.com/moq-dev/moq/blob/main/rs/moq-rtmp/MIGRATE.md), [moq-sock](https://github.com/moq-dev/moq/blob/main/rs/moq-sock/MIGRATE.md), [moq-srt](https://github.com/moq-dev/moq/blob/main/rs/moq-srt/MIGRATE.md), [moq-stats](https://github.com/moq-dev/moq/blob/main/rs/moq-stats/MIGRATE.md), [moq-tokio](https://github.com/moq-dev/moq/blob/main/rs/moq-tokio/MIGRATE.md), [moq-transcode](https://github.com/moq-dev/moq/blob/main/rs/moq-transcode/MIGRATE.md), [moq-uring](https://github.com/moq-dev/moq/blob/main/rs/moq-uring/MIGRATE.md), [moq-v4l](https://github.com/moq-dev/moq/blob/main/rs/moq-v4l/MIGRATE.md), [moq-video](https://github.com/moq-dev/moq/blob/main/rs/moq-video/MIGRATE.md), [moq-webrtc (was moq-rtc)](https://github.com/moq-dev/moq/blob/main/rs/moq-webrtc/MIGRATE.md), [qmux](https://github.com/moq-dev/moq/blob/main/rs/qmux/MIGRATE.md)
- **JavaScript:** [`@moq/auth`](https://github.com/moq-dev/moq/blob/main/js/auth/MIGRATE.md), [`@moq/clock`](https://github.com/moq-dev/moq/blob/main/js/clock/MIGRATE.md), [`@moq/hang`](https://github.com/moq-dev/moq/blob/main/js/hang/MIGRATE.md), [`@moq/json`](https://github.com/moq-dev/moq/blob/main/js/json/MIGRATE.md), [`@moq/loc`](https://github.com/moq-dev/moq/blob/main/js/loc/MIGRATE.md), [`@moq/msf`](https://github.com/moq-dev/moq/blob/main/js/msf/MIGRATE.md), [`@moq/net`](https://github.com/moq-dev/moq/blob/main/js/net/MIGRATE.md), [`@moq/pattern`](https://github.com/moq-dev/moq/blob/main/js/pattern/MIGRATE.md), [`@moq/publish`](https://github.com/moq-dev/moq/blob/main/js/publish/MIGRATE.md), [`@moq/qmux`](https://github.com/moq-dev/moq/blob/main/js/qmux/MIGRATE.md), [`@moq/room`](https://github.com/moq-dev/moq/blob/main/js/room/MIGRATE.md), [`@moq/signals`](https://github.com/moq-dev/moq/blob/main/js/signals/MIGRATE.md), [`@moq/ui`](https://github.com/moq-dev/moq/blob/main/js/ui/MIGRATE.md), [`@moq/video`](https://github.com/moq-dev/moq/blob/main/js/video/MIGRATE.md), [`@moq/watch`](https://github.com/moq-dev/moq/blob/main/js/watch/MIGRATE.md)
- **JavaScript:** [`@moq/auth`](https://github.com/moq-dev/moq/blob/main/js/auth/MIGRATE.md), [`@moq/clock`](https://github.com/moq-dev/moq/blob/main/js/clock/MIGRATE.md), [`@moq/hang`](https://github.com/moq-dev/moq/blob/main/js/hang/MIGRATE.md), [`@moq/json`](https://github.com/moq-dev/moq/blob/main/js/json/MIGRATE.md), [`@moq/loc`](https://github.com/moq-dev/moq/blob/main/js/loc/MIGRATE.md), [`@moq/msf`](https://github.com/moq-dev/moq/blob/main/js/msf/MIGRATE.md), [`@moq/net`](https://github.com/moq-dev/moq/blob/main/js/net/MIGRATE.md), [`@moq/pattern`](https://github.com/moq-dev/moq/blob/main/js/pattern/MIGRATE.md), [`@moq/publish`](https://github.com/moq-dev/moq/blob/main/js/publish/MIGRATE.md), [`@moq/qmux`](https://github.com/moq-dev/moq/blob/main/js/qmux/MIGRATE.md), [`@moq/room`](https://github.com/moq-dev/moq/blob/main/js/room/MIGRATE.md), [`@moq/signals`](https://github.com/moq-dev/moq/blob/main/js/signals/MIGRATE.md), [`@moq/video`](https://github.com/moq-dev/moq/blob/main/js/video/MIGRATE.md), [`@moq/watch`](https://github.com/moq-dev/moq/blob/main/js/watch/MIGRATE.md)

## Unreleased

Expand Down
13 changes: 13 additions & 0 deletions js/common/deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ describe("specifiers", () => {
]);
});

test("reads declaration files", () => {
const source = `
import { type Report, Support } from "@moq/static";
export { type Show } from "@moq/export";
export default class Banner extends Support {
protected detect(): Promise<Report>;
}
export declare function rows(): import("@moq/query").Rows;
`;

expect(specifiers(source)).toEqual(["@moq/static", "@moq/export", "@moq/query"]);
});

test("ignores comments and strings", () => {
const source = `
// import "@moq/comment";
Expand Down
27 changes: 22 additions & 5 deletions js/common/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Verifies that every workspace package declares the `@moq/*` packages it imports, and
// that every workspace whose tests can reach `@moq/clock` loads its test preload.
// Verifies that every workspace package declares the `@moq/*` packages it imports, that no
// published package depends on a private one, and that every workspace whose tests can reach
// `@moq/clock` loads its test preload.
//
// A bundler resolves an undeclared import through hoisting, so the tree builds and
// the tests pass while a published consumer with a stricter resolver gets `undefined`.
Expand All @@ -13,6 +14,7 @@ import { parse } from "@babel/parser";
/** A package.json, narrowed to the fields this script reads. */
type Manifest = {
name?: string;
private?: boolean;
dependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
Expand Down Expand Up @@ -100,7 +102,7 @@ function visit(value: unknown, found: string[]) {
for (const child of Object.values(value)) visit(child, found);
}

/** The module specifiers referenced by JavaScript or TypeScript source. */
/** The module specifiers referenced by JavaScript or TypeScript source, declarations included. */
export function specifiers(source: string): string[] {
const ast = parse(source, {
createImportExpressions: true,
Expand Down Expand Up @@ -164,6 +166,19 @@ function main() {
}

const runtime = new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.peerDependencies ?? {})]);
// A private package is never published, so a published one bundles it (common/package.ts)
// from its devDependencies instead of depending on it.
const bundled = new Set(Object.keys(pkg.devDependencies ?? {}).filter((name) => manifests.get(name)?.private));
if (pkg.scripts?.release) {
for (const name of [...runtime, ...Object.keys(pkg.optionalDependencies ?? {})]) {
if (manifests.get(name)?.private) {
problems.add(
`${workspace}/package.json: depends on the private ${name}, which only devDependencies may bundle`,
);
}
}
}
const shipping = new Set([...runtime, ...bundled]);
const dev = new Set([
...runtime,
...Object.keys(pkg.optionalDependencies ?? {}),
Expand All @@ -174,13 +189,15 @@ function main() {
// Only files that ship need a runtime dependency; configs, examples, and
// tests may lean on a devDependency instead.
const shipped = relative(dir, file).startsWith(`src${sep}`) && !TEST.test(file);
const declared = shipped ? runtime : dev;
const declared = shipped ? shipping : dev;

for (const specifier of specifiers(readFileSync(file, "utf8"))) {
const name = packageName(specifier);
if (!name || name === pkg.name || declared.has(name)) continue;

const where = shipped ? "dependencies or peerDependencies" : "any dependency list";
const where = shipped
? "dependencies, peerDependencies, or bundled devDependencies"
: "any dependency list";
problems.add(`${relative(root, file)}: imports ${name}, missing from ${pkg.name} ${where}`);
}
}
Expand Down
78 changes: 73 additions & 5 deletions js/common/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// This creates a dist/ folder with the correct paths and dependencies for publishing
// Split from release.ts to allow building packages without publishing

import { execFileSync } from "node:child_process";
import { copyFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { dirname, join, relative, resolve, sep } from "node:path";
import { publint } from "publint";
import { formatMessage } from "publint/utils";
import { checkPackageConstructors } from "./constructors.ts";
import { specifiers } from "./deps.ts";

checkPackageConstructors(process.cwd());

Expand Down Expand Up @@ -73,15 +75,21 @@ if (pkg.bin) {
}
}

// The directory of a workspace package, named without its scope.
function workspaceDir(name: string): string {
return `../${name.includes("/") ? name.split("/")[1] : name}`;
}

function rewriteWorkspaceDependency(dependencies?: Record<string, string>) {
if (!dependencies) return;
for (const [name, version] of Object.entries(dependencies)) {
if (typeof version === "string" && version.startsWith("workspace:")) {
// Read the actual version from the workspace package
// Handle both scoped (@scope/name) and unscoped (name) packages
const packageDir = name.includes("/") ? name.split("/")[1] : name;
const workspacePkgPath = `../${packageDir}/package.json`;
const workspacePkg = JSON.parse(readFileSync(workspacePkgPath, "utf8"));
const workspacePkg = JSON.parse(readFileSync(`${workspaceDir(name)}/package.json`, "utf8"));
if (workspacePkg.private && !pkg.private) {
console.error(`${pkg.name} depends on the private ${name}; bundle it from devDependencies instead`);
process.exit(1);
}
dependencies[name] = `^${workspacePkg.version}`;
console.log(`🔗 Converted ${name}: ${version} → ^${workspacePkg.version}`);
}
Expand All @@ -92,6 +100,66 @@ function rewriteWorkspaceDependency(dependencies?: Record<string, string>) {
rewriteWorkspaceDependency(pkg.dependencies);
rewriteWorkspaceDependency(pkg.peerDependencies);

function files(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const path = join(dir, entry.name);
return entry.isDirectory() ? files(path) : [path];
});
}

// A private workspace package ships inside each published package that imports it: Vite bundles
// its code and stylesheets, and here its declarations are emitted to dist/bundled/<dir>, with each
// import of it in this package's declarations pointed at that copy.
for (const [name, version] of Object.entries<string>(pkg.devDependencies ?? {})) {
if (!version.startsWith("workspace:")) continue;
const source = workspaceDir(name);
const bundled = JSON.parse(readFileSync(`${source}/package.json`, "utf8"));
if (!bundled.private) continue;

const imports = (file: string) =>
specifiers(readFileSync(file, "utf8")).some((s) => s === name || s.startsWith(`${name}/`));
const importers = files("dist").filter((file) => file.endsWith(".d.ts") && imports(file));
if (importers.length === 0) continue;

const out = join("dist", "bundled", source.slice("../".length));
console.log(`📎 Bundling the declarations of ${name} into ${out}...`);
const tsc = ["x", "--no-install", "tsc", "-p", `${source}/tsconfig.build.json`, "--outDir", out];
execFileSync(process.execPath, tsc, { stdio: "inherit" });
const literal = new RegExp(`(["'])${name}(/[^"']*)?\\1`, "g");
for (const file of importers) {
const body = readFileSync(file, "utf8").replace(literal, (_, quote: string, subpath = "") => {
const target = bundled.exports?.[`.${subpath}`];
if (typeof target !== "string" || !target.endsWith(".ts")) {
console.error(`${file}: imports ${name}${subpath}, which has no such code export`);
process.exit(1);
}
// A module specifier separates with "/" on every platform, unlike a Windows path.
const path = relative(dirname(file), join(out, rewritePath(target, "js")))
.split(sep)
.join("/");
return `${quote}${path.startsWith(".") ? path : `./${path}`}${quote}`;
});
writeFileSync(file, body);
}
}

// What ships imports no @moq package it does not depend on, such as a private one left unbundled.
const declared = new Set([
pkg.name,
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
]);
for (const file of files("dist")) {
if (!file.endsWith(".js") && !file.endsWith(".d.ts")) continue;
for (const specifier of specifiers(readFileSync(file, "utf8"))) {
const [scope, base] = specifier.split("/");
if (scope === "@moq" && base && !declared.has(`${scope}/${base}`)) {
console.error(`${file}: imports ${specifier}, which ${pkg.name} does not depend on`);
process.exit(1);
}
}
}

pkg.devDependencies = undefined;
pkg.scripts = undefined;

Expand Down
28 changes: 25 additions & 3 deletions js/publish/api/support-element.api.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# `@moq/publish/support/element`

```ts
import { Report } from "@moq/ui";
import { Support } from "@moq/ui";
import { Level } from "@moq/publish/support";

export { Show } from "@moq/ui";
export interface Report {
rows: [group: string, feature: string, status: Status][];
summary: Level;
}

export type Show = "always" | "warning" | "error" | "never";

export type Status = boolean | Level | {
hardware?: boolean;
software: boolean;
} | undefined;

export abstract class Support extends HTMLElement {
constructor();
attributeChangedCallback(name: "show" | "details", _oldValue: string | null, newValue: string | null): void;
connectedCallback(): void;
get details(): boolean;
set details(details: boolean);
protected abstract detect(): Promise<Report>;
disconnectedCallback(): void;
static observedAttributes: readonly ["show", "details"];
get show(): Show;
set show(show: Show);
}

export default class extends Support {
protected detect(): Promise<Report>;
Expand Down
2 changes: 1 addition & 1 deletion js/publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"@moq/json": "workspace:^",
"@moq/net": "workspace:^",
"@moq/signals": "workspace:^",
"@moq/ui": "workspace:^",
"@moq/video": "workspace:^",
"mediabunny": "^1.65.2"
},
"devDependencies": {
"@moq/libav": "workspace:^",
"@moq/ui": "workspace:^",
"@types/audioworklet": "^0.0.100",
"@types/bun": "^1.4.4",
"@typescript/lib-dom": "npm:@types/web@^0.0.358",
Expand Down
4 changes: 2 additions & 2 deletions js/publish/src/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Catalog from "@moq/hang/catalog";
import * as Container from "@moq/hang/container";
import * as Moq from "@moq/net";
import { Effect, type Getter, getter, type Inputs, type Readonlys, Signal } from "@moq/signals";
import { rotateVideoDimensions } from "@moq/video";
import { rotateDimensions } from "@moq/video";
import { CatalogProducer } from "./catalog";
import { Order } from "./order";
import { type Identity, identity, type Listing, Publication, type Slot } from "./publication";
Expand Down Expand Up @@ -335,7 +335,7 @@ export class Broadcast {
const section: Catalog.Video = { renditions: video };
// display is optional in the schema, so it gates only itself, not the whole section.
if (display) {
const { width, height } = rotateVideoDimensions(display, rotation);
const { width, height } = rotateDimensions(display, rotation);
section.display = { width: Catalog.u53(width), height: Catalog.u53(height) };
}
if (flip) section.flip = true;
Expand Down
2 changes: 1 addition & 1 deletion js/publish/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Renderer {
const display = current
? { width: current.displayWidth, height: current.displayHeight }
: effect.get(this.in.display);
return display ? Video.rotateVideoDimensions(display, effect.get(this.in.rotation)) : undefined;
return display ? Video.rotateDimensions(display, effect.get(this.in.rotation)) : undefined;
}),
presentation: this.#signals.computed((effect) => ({
flip: effect.get(this.in.flip),
Expand Down
6 changes: 3 additions & 3 deletions js/publish/src/support/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* @module
*/

import { type Level, type Report, Support } from "@moq/ui";
import { type Full, isSupported } from "./";
import { type Report, Support } from "@moq/ui";
import { type Full, isSupported, type Level } from "./";

export type { Show } from "@moq/ui";
export { type Report, type Show, type Status, Support } from "@moq/ui";

function summarize(support: Full): Level {
if (support.webtransport === "none") return "none";
Expand Down
3 changes: 2 additions & 1 deletion js/publish/src/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*/

import { Connection } from "@moq/net";
import type { Level } from "@moq/ui";
import { workerSupported } from "../video/processor";
import { probe } from "./video";

/** How well a feature works: natively, through a fallback, or not at all. */
export type Level = "full" | "partial" | "none";
export type { Level };

/** Whether a codec encodes in hardware and in software. */
export type Codec = {
Expand Down
Loading