feat(spf): publish through @caprid/moq-core's publish session

Merged
MM
24d ago
+465-9439

Summary

The publisher now drives @caprid/moq-core's publish session (createMoqtPublishSession, 0.1.1) instead of v10's own session. That session ran over a draft-20 copy of network/moqt, kept on this branch only so the #75 sync would build. The publisher now speaks moqt-22 with a moqt-20 fallback, like the player, and packages/spf/src/network/moqt/ is gone, tests included.

Changes

  • publish/session/publish-session.ts keeps only the session actor; the protocol driver is the package's. The default connect offers MOQT_PROTOCOL_IDS (moqt-22, moqt-20) when the browser's WebTransport exposes protocol, the same rule as the player's moq-session.ts. The real transport, including its protocol, goes to the session unchanged.

  • track-publisher.ts opens each group's stream with openUniStream(trackAlias) for the alias bound when the group started. The session now counts each subscription's data streams for PUBLISH_DONE, so the publisher's per-alias streamCount and setup-track-publishers.ts's getStreamCount wiring are removed.

  • setup-track-publishers.ts passes the microsecond TIMESCALE as an explicit trackProperties entry, since the package imposes none. It imports CLOSE_FLUSH_TIMEOUT_MS, RegisteredTrack and TRACK_PROPERTY from the package.

  • Test helpers: raw-peer.ts and transport-pair.ts move to network/tests/helpers/, beside moqt-wire.ts. moqt-wire.ts now also re-exports the package's relay-side SUBSCRIBE_NAMESPACE/SUBSCRIBE/GOAWAY encoders, deframer, object-stream readers and varint codec. The relay hub's publisher side uses them, so the whole hub speaks moqt-22. A new withServerRequestIds wrapper gives a subscribe session standing in for the relay odd Request IDs. The package's publish session closes on a peer request with the client's (even) parity (§6.4.2.1); the wrapper offsets each request's ID by an odd constant and re-frames the message.

  • Tests: dropped v10's driver and codec tests, which the package now owns and tests: network/moqt/tests/* and the createMoqtPublishSession block of publish-session.test.ts. Kept and adapted the actor, behavior, engine, relay-hub and cross-engine tests. Added three tests:

    • The default connect offers ['moqt-22', 'moqt-20'].
    • Every registered track declares TIMESCALE in SUBSCRIBE_OK.
    • Each group's stream is opened for its bound alias.

    The catalog + LOC end-to-end test now runs through the session actor.

  • Prose: the spec README's "Implemented in" row, the publish engine doc, the cross-engine and relay-hub notes, the publish design notes (moq-publish.md, clusters.md) and the migration plan now name the package. The publisher sandbox's loopback relay cited draft-20 sections. Its one Location Filter (relative start, StartGroup 1) encodes the same bytes on draft-22, so it now uses draft-22 numbering, as the player's loopback already does. No skill under .agents/skills/ cited the deleted modules.

v10-side wrappers kept

  • createPublishSessionActor: the reactive snapshot the behaviors consume (status, subscriber count, track bindings), plus the connect (?jwt= URL, protocol offer, implementation name @videojs/spf moqt publisher).
  • addTrackPublisher's openUniStream closure, which adds the per-track sendOrder (-1 - priority).
  • endTrack and endCatalogTrack, which flush the publisher's last groups within CLOSE_FLUSH_TIMEOUT_MS / 2 before handle.end({ after }).

PUBLISH_DONE "unknown stream count"

v10 doesn't need it. Every track setupTrackPublishers registers reported an exact count, so the unknown encoding was only reachable from tests that registered tracks without getStreamCount. The package counts every data stream itself.

Verification

  • pnpm -F @videojs/spf test: 163 files, 2557 tests pass (11 skipped), including the publish-engines Chromium project; no type errors.

  • pnpm build:packages, pnpm typecheck (stale packages/*/types and nested tsbuildinfo deleted first), and pnpm lint: all pass.

  • Bundle size (esbuild bundle of dist/default, minify + brotli):

    EntryBeforeAfter
    /moq33,694 B33,694 B
    /moq-publish22,281 B23,726 B (+1,445)
    /moq-publish-video23,531 B24,996 B (+1,465)

    The growth is the package's session: the dual-version codec, the close end-ack wait and fill handling on REQUEST_UPDATE.

  • Live against relay.mux.global (token root huddle/videojs-testing): headless Chromium ran the v10 publish engine (canvas camera + oscillator mic, default H.264 + Opus), the v10 MoQ player, and a raw @caprid/moq-core viewer.

    • All three sessions offered ["moqt-22","moqt-20"] and negotiated moqt-22.
    • The relay's SUBSCRIBE_OK carried our TIMESCALE ({8: 1000000}).
    • Player: first video frame decoded after 732 ms and first audio scheduled after 106 ms. Over 15 s it decoded 429 frames with 0 dropped, scheduled 733 audio frames with 0 underruns, and its audio clock advanced 9,926 ms over 10,030 ms of wall time.
    • Publisher stats: 0 dropped frames, 0 dropped groups.
    • On unpublish() the raw viewer got PUBLISH_DONE status 2 "track ended" for all three tracks within 8 ms, with Stream Counts audio 753, video 16 and catalog 3.
  • codex review --base origin/mmcc/moq-publisher: no actionable findings. It also ran an in-memory round trip through the publisher sandbox's loopback relay with the package's sessions.

Upstream follow-ups (@caprid/moq-core)

  • Relay-side codecs: the package exports no relay-side codec (server SETUP, SUBSCRIBE_NAMESPACE/SUBSCRIBE encoders, SUBSCRIBE_OK/PUBLISH_DONE encoders, object-stream readers). v10's fake relays deep-import dist/protocol/* through moqt-wire.ts. A test-support entry point would remove that.
  • Request-ID parity in tests: the subscribe driver can't be told to allocate server-parity Request IDs, so loopback tests need the withServerRequestIds byte rewrite. Upstream's tests use a similar transport wrapper. A config option such as requestIdParity: 'server' would serve both.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DaH4ifX9Vb6HuB2yg6TMt5


Summary by cubic

Replaces the publisher's local draft-20 MOQT driver with @caprid/moq-core's publish session, so the publisher now speaks moqt-22 with moqt-20 fallback, matching the player. Deletes packages/spf/src/network/moqt/ and its tests.

  • publish-session.ts keeps only the session actor; the protocol driver, version negotiation, and PUBLISH_DONE counting come from the package.
  • Track publishers open each group's stream for the alias bound at group start; the per-alias streamCount and getStreamCount wiring are removed.
  • setupTrackPublishers declares the microsecond TIMESCALE explicitly in trackProperties.
  • Test relays now use the package's relay-side codecs through moqt-wire; a new withServerRequestIds wrapper compensates for the package's client-parity-only request IDs in loopback tests.
  • Docs and design notes repointed at the package and draft-22, dropping stale draft-19 references from the publish feature record.