feat(spf): publish through @caprid/moq-core's publish session
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.tskeeps only the session actor; the protocol driver is the package's. The default connect offersMOQT_PROTOCOL_IDS(moqt-22,moqt-20) when the browser'sWebTransportexposesprotocol, the same rule as the player'smoq-session.ts. The real transport, including itsprotocol, goes to the session unchanged. -
track-publisher.tsopens each group's stream withopenUniStream(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-aliasstreamCountandsetup-track-publishers.ts'sgetStreamCountwiring are removed. -
setup-track-publishers.tspasses the microsecond TIMESCALE as an explicittrackPropertiesentry, since the package imposes none. It importsCLOSE_FLUSH_TIMEOUT_MS,RegisteredTrackandTRACK_PROPERTYfrom the package. -
Test helpers:
raw-peer.tsandtransport-pair.tsmove tonetwork/tests/helpers/, besidemoqt-wire.ts.moqt-wire.tsnow 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 newwithServerRequestIdswrapper 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 thecreateMoqtPublishSessionblock ofpublish-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.
- The default connect offers
-
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'sopenUniStreamclosure, which adds the per-tracksendOrder(-1 - priority).endTrackandendCatalogTrack, which flush the publisher's last groups withinCLOSE_FLUSH_TIMEOUT_MS / 2beforehandle.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 thepublish-enginesChromium project; no type errors. -
pnpm build:packages,pnpm typecheck(stalepackages/*/typesand nested tsbuildinfo deleted first), andpnpm lint: all pass. -
Bundle size (esbuild bundle of
dist/default, minify + brotli):Entry Before After /moq33,694 B 33,694 B /moq-publish22,281 B 23,726 B (+1,445) /moq-publish-video23,531 B 24,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-coreviewer.- All three sessions offered
["moqt-22","moqt-20"]and negotiatedmoqt-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.
- All three sessions offered
-
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/*throughmoqt-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
withServerRequestIdsbyte rewrite. Upstream's tests use a similar transport wrapper. A config option such asrequestIdParity: '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.tskeeps 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
streamCountandgetStreamCountwiring are removed. setupTrackPublishersdeclares the microsecond TIMESCALE explicitly intrackProperties.- Test relays now use the package's relay-side codecs through
moqt-wire; a newwithServerRequestIdswrapper 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.