@moq/net 0.4.1 → 0.4.3
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/broadcast.d.ts +21 -7
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +38 -16
- package/broadcast.js.map +1 -1
- package/connection/accept.js +6 -4
- package/connection/accept.js.map +1 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +5 -4
- package/connection/connect.js.map +1 -1
- package/connection/forward.js +54 -47
- package/connection/forward.js.map +1 -1
- package/connection/goaway.d.ts +34 -0
- package/connection/goaway.d.ts.map +1 -0
- package/connection/goaway.js +176 -0
- package/connection/goaway.js.map +1 -0
- package/connection/handshake.d.ts +4 -2
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +42 -10
- package/connection/handshake.js.map +1 -1
- package/connection/pool.d.ts +16 -1
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +32 -10
- package/connection/pool.js.map +1 -1
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +184 -30
- package/connection/reload.js.map +1 -1
- package/error.d.ts +11 -0
- package/error.d.ts.map +1 -1
- package/error.js +14 -0
- package/error.js.map +1 -1
- package/errors.d.ts +1 -1
- package/errors.d.ts.map +1 -1
- package/errors.js +1 -1
- package/errors.js.map +1 -1
- package/group.d.ts.map +1 -1
- package/group.js +5 -4
- package/group.js.map +1 -1
- package/hop.d.ts +8 -0
- package/hop.d.ts.map +1 -1
- package/hop.js +16 -0
- package/hop.js.map +1 -1
- package/ietf/adapter.d.ts +4 -0
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +19 -8
- package/ietf/adapter.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +3 -3
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +110 -37
- package/ietf/connection.js.map +1 -1
- package/ietf/fetch.d.ts +7 -20
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +52 -22
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +20 -4
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +165 -17
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +9 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +20 -0
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.js +1 -1
- package/ietf/hidden.js.map +1 -1
- package/ietf/index.d.ts +1 -1
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +1 -1
- package/ietf/index.js.map +1 -1
- package/ietf/object.d.ts +9 -6
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +47 -38
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +13 -8
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +177 -30
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish.d.ts +1 -0
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +1 -0
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +2 -2
- package/ietf/publish_namespace.js +2 -2
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +404 -202
- package/ietf/publisher.js.map +1 -1
- package/ietf/request_stream.d.ts +7 -0
- package/ietf/request_stream.d.ts.map +1 -0
- package/ietf/request_stream.js +20 -0
- package/ietf/request_stream.js.map +1 -0
- package/ietf/subscribe.d.ts +7 -1
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +24 -17
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +7 -3
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +83 -56
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.d.ts +2 -0
- package/ietf/token.d.ts.map +1 -0
- package/ietf/token.js +99 -0
- package/ietf/token.js.map +1 -0
- package/ietf/track.d.ts +4 -0
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +6 -20
- package/ietf/track.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/internal.d.ts +12 -3
- package/internal.d.ts.map +1 -1
- package/internal.js +32 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +7 -4
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +22 -7
- package/lite/connection.js.map +1 -1
- package/lite/datagram.d.ts +3 -2
- package/lite/datagram.d.ts.map +1 -1
- package/lite/datagram.js +7 -8
- package/lite/datagram.js.map +1 -1
- package/lite/group.d.ts +12 -8
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +37 -16
- package/lite/group.js.map +1 -1
- package/lite/message.d.ts +2 -2
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +14 -5
- package/lite/message.js.map +1 -1
- package/lite/publisher.js +39 -45
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +1 -1
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +22 -19
- package/lite/setup.js.map +1 -1
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +4 -5
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +210 -127
- package/lite/subscriber.js.map +1 -1
- package/origin.d.ts +9 -1
- package/origin.d.ts.map +1 -1
- package/origin.js +341 -146
- package/origin.js.map +1 -1
- package/package.json +2 -2
- package/stream.d.ts +77 -12
- package/stream.d.ts.map +1 -1
- package/stream.js +359 -122
- package/stream.js.map +1 -1
- package/tail.d.ts +7 -0
- package/tail.d.ts.map +1 -1
- package/tail.js +68 -22
- package/tail.js.map +1 -1
- package/track.d.ts +14 -3
- package/track.d.ts.map +1 -1
- package/track.js +170 -76
- package/track.js.map +1 -1
- package/util/abort.d.ts +2 -0
- package/util/abort.d.ts.map +1 -0
- package/util/abort.js +20 -0
- package/util/abort.js.map +1 -0
- package/util/u64.d.ts +39 -0
- package/util/u64.d.ts.map +1 -0
- package/util/u64.js +83 -0
- package/util/u64.js.map +1 -0
- package/util/varint.d.ts +29 -0
- package/util/varint.d.ts.map +1 -0
- package/util/varint.js +198 -0
- package/util/varint.js.map +1 -0
- package/varint.d.ts +10 -6
- package/varint.d.ts.map +1 -1
- package/varint.js +40 -237
- package/varint.js.map +1 -1
- package/wire.d.ts +17 -3
- package/wire.d.ts.map +1 -1
- package/wire.js.map +1 -1
- package/ietf/control.d.ts +0 -135
- package/ietf/control.d.ts.map +0 -1
- package/ietf/control.js +0 -242
- package/ietf/control.js.map +0 -1
package/lite/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAA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AAC,GAAY,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;CACD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAkB,EAAE,OAAgB;IACpE,MAAM,QAAQ,GACb,IAGA,CAAC,QAAQ,CAAC;IACX,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC;IAE3D,6EAA6E;IAC7E,IAAI,KAAwE,CAAC;IAC7E,IAAI,CAAC;QACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,UAAU,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,OAAO,KAAK,CAAC,iBAAiB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;AAC7F,CAAC","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { closeError, error, fromClose, StreamCode, StreamError, sessionCause } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasProbeRtt, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\tpublish?: OriginConsumer;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection Hop ID. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly hop: Hop;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true, publish }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.hop = randomHop();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\tlet fatal: Error | undefined;\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t// A session-sourced failure is the peer's close, not the raw transport error.\n\t\t\tfatal = await sessionCause(this.#quic, err);\n\t\t} finally {\n\t\t\t// The session died under every track it was receiving, so they end with its\n\t\t\t// error. A deliberate close() already ended them cleanly, which makes this a no-op.\n\t\t\tthis.#subscriber.close(fatal ?? (await closeError(this.#quic)));\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: the publish origin starts empty and fills later, and consume is\n\t// called after this point, so there is nothing to narrow yet. The origin declares\n\t// our session identity so the peer can filter\n\t// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic);\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, hop: this.hop }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream, this.#version);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,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AC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,OAAO,KAAK,CAAC,iBAAiB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;AAC7F,CAAC","sourcesContent":["import { type Getter, Once, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport type { Drain } from \"../connection/goaway.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { closeError, error, fromClose, ProtocolViolation, StreamCode, StreamError, sessionCause } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasProbeRtt, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\tpublish?: OriginConsumer;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection Hop ID. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly hop: Hop;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t// The peer's GOAWAY. Lite carries no deadline, so only the URI is set.\n\t#goaway = new Once<Drain>();\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true, publish }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\t// The session stream was opened at the SETUP exchange's version; the rest of it speaks this one.\n\t\tif (session) {\n\t\t\tsession.reader.version = version;\n\t\t\tsession.writer.version = version;\n\t\t}\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.hop = randomHop();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway });\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\tlet fatal: Error | undefined;\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t// A session-sourced failure is the peer's close, not the raw transport error.\n\t\t\tfatal = await sessionCause(this.#quic, err);\n\t\t} finally {\n\t\t\t// The session died under every track it was receiving, so they end with its\n\t\t\t// error. A deliberate close() already ended them cleanly, which makes this a no-op.\n\t\t\tthis.#subscriber.close(fatal ?? (await closeError(this.#quic)));\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: the publish origin starts empty and fills later, and consume is\n\t// called after this point, so there is nothing to narrow yet. The origin declares\n\t// our session identity so the peer can filter\n\t// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic, { version: this.#version });\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, hop: this.hop }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic, this.#version);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t\t// A protocol violation on one stream is the peer breaking the session.\n\t\t\t\t\t// Resetting that stream leaves it free to repeat the violation; a duplicate\n\t\t\t\t\t// GOAWAY is the one this dispatcher raises.\n\t\t\t\t\tif (err instanceof ProtocolViolation) this.close();\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\t// A peer sends at most one; a second is a protocol violation.\n\t\t\tif (this.#goaway.peek() !== undefined) throw new ProtocolViolation(\"duplicate GOAWAY\");\n\t\t\tthis.#goaway.set({ uri: msg.uri });\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic, this.#version);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream, this.#version);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}
|
package/lite/datagram.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Version } from "./version";
|
|
1
2
|
/**
|
|
2
3
|
* A QUIC datagram body: `subscribe (i) | sequence (i) | timestamp (i) | payload (b)`.
|
|
3
4
|
*
|
|
@@ -16,8 +17,8 @@ export declare class Datagram {
|
|
|
16
17
|
payload: Uint8Array;
|
|
17
18
|
constructor(subscribe: bigint, sequence: number, timestamp: number, payload: Uint8Array);
|
|
18
19
|
/** Encode the body to a single `Uint8Array` (no length prefix; the datagram boundary delimits it). */
|
|
19
|
-
encode(): Uint8Array;
|
|
20
|
+
encode(version: Version): Uint8Array;
|
|
20
21
|
/** Decode a datagram body from the raw bytes of one QUIC datagram. */
|
|
21
|
-
static decode(data: Uint8Array): Promise<Datagram>;
|
|
22
|
+
static decode(data: Uint8Array, version: Version): Promise<Datagram>;
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=datagram.d.ts.map
|
package/lite/datagram.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datagram.d.ts","sourceRoot":"","sources":["../../src/lite/datagram.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datagram.d.ts","sourceRoot":"","sources":["../../src/lite/datagram.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;GAMG;AACH,qBAAa,QAAQ;IACpB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,OAAO,EAAE,UAAU,CAAC;IAEpB,YAAY,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAKtF;IAED,sGAAsG;IACtG,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAiBnC;IAED,sEAAsE;IACtE,OAAa,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAOzE;CACD"}
|
package/lite/datagram.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import { Reader } from "../stream.js";
|
|
8
|
-
import * as Varint from "../varint.js";
|
|
7
|
+
import { encodeVarint, Reader } from "../stream.js";
|
|
9
8
|
/**
|
|
10
9
|
* A QUIC datagram body: `subscribe (i) | sequence (i) | timestamp (i) | payload (b)`.
|
|
11
10
|
*
|
|
@@ -29,10 +28,10 @@ export class Datagram {
|
|
|
29
28
|
this.payload = payload;
|
|
30
29
|
}
|
|
31
30
|
/** Encode the body to a single `Uint8Array` (no length prefix; the datagram boundary delimits it). */
|
|
32
|
-
encode() {
|
|
33
|
-
const subscribe =
|
|
34
|
-
const sequence =
|
|
35
|
-
const timestamp =
|
|
31
|
+
encode(version) {
|
|
32
|
+
const subscribe = encodeVarint(this.subscribe, version);
|
|
33
|
+
const sequence = encodeVarint(this.sequence, version);
|
|
34
|
+
const timestamp = encodeVarint(this.timestamp, version);
|
|
36
35
|
const out = new Uint8Array(subscribe.byteLength + sequence.byteLength + timestamp.byteLength + this.payload.byteLength);
|
|
37
36
|
let offset = 0;
|
|
38
37
|
out.set(subscribe, offset);
|
|
@@ -45,8 +44,8 @@ export class Datagram {
|
|
|
45
44
|
return out;
|
|
46
45
|
}
|
|
47
46
|
/** Decode a datagram body from the raw bytes of one QUIC datagram. */
|
|
48
|
-
static async decode(data) {
|
|
49
|
-
const r = new Reader(undefined, data);
|
|
47
|
+
static async decode(data, version) {
|
|
48
|
+
const r = new Reader(undefined, data, version);
|
|
50
49
|
const subscribe = await r.u62();
|
|
51
50
|
const sequence = await r.u53();
|
|
52
51
|
const timestamp = await r.u53();
|
package/lite/datagram.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datagram.js","sourceRoot":"","sources":["../../src/lite/datagram.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"datagram.js","sourceRoot":"","sources":["../../src/lite/datagram.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,OAAO,QAAQ;IACpB,kDAAkD;IAClD,SAAS,CAAS;IAClB,uEAAuE;IACvE,QAAQ,CAAS;IACjB,4EAA4E;IAC5E,SAAS,CAAS;IAClB,6DAA6D;IAC7D,OAAO,CAAa;IAEpB,YAAY,SAAiB,EAAE,QAAgB,EAAE,SAAiB,EAAE,OAAmB;QACtF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,sGAAsG;IACtG,MAAM,CAAC,OAAgB;QACtB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AAC,OAAO,EAAE,CAAC;QAClC,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;CACD","sourcesContent":["/**\n * Wire-level QUIC datagram body for moq-lite-05 (§6.4).\n *\n * @module\n */\nimport { encodeVarint, Reader } from \"../stream.ts\";\nimport type { Version } from \"./version.ts\";\n\n/**\n * A QUIC datagram body: `subscribe (i) | sequence (i) | timestamp (i) | payload (b)`.\n *\n * The payload runs to the datagram boundary, so unlike a size-prefixed lite message there is no\n * inner length prefix. Mirrors the Rust `lite::Datagram`; the model counterpart is\n * {@link Datagram} in `../datagram.ts`.\n */\nexport class Datagram {\n\t/** Subscribe ID this datagram is delivered on. */\n\tsubscribe: bigint;\n\t/** Group sequence number (shared with the track's group namespace). */\n\tsequence: number;\n\t/** Absolute presentation timestamp, in the track's negotiated timescale. */\n\ttimestamp: number;\n\t/** The frame payload, delimited by the datagram boundary. */\n\tpayload: Uint8Array;\n\n\tconstructor(subscribe: bigint, sequence: number, timestamp: number, payload: Uint8Array) {\n\t\tthis.subscribe = subscribe;\n\t\tthis.sequence = sequence;\n\t\tthis.timestamp = timestamp;\n\t\tthis.payload = payload;\n\t}\n\n\t/** Encode the body to a single `Uint8Array` (no length prefix; the datagram boundary delimits it). */\n\tencode(version: Version): Uint8Array {\n\t\tconst subscribe = encodeVarint(this.subscribe, version);\n\t\tconst sequence = encodeVarint(this.sequence, version);\n\t\tconst timestamp = encodeVarint(this.timestamp, version);\n\n\t\tconst out = new Uint8Array(\n\t\t\tsubscribe.byteLength + sequence.byteLength + timestamp.byteLength + this.payload.byteLength,\n\t\t);\n\t\tlet offset = 0;\n\t\tout.set(subscribe, offset);\n\t\toffset += subscribe.byteLength;\n\t\tout.set(sequence, offset);\n\t\toffset += sequence.byteLength;\n\t\tout.set(timestamp, offset);\n\t\toffset += timestamp.byteLength;\n\t\tout.set(this.payload, offset);\n\t\treturn out;\n\t}\n\n\t/** Decode a datagram body from the raw bytes of one QUIC datagram. */\n\tstatic async decode(data: Uint8Array, version: Version): Promise<Datagram> {\n\t\tconst r = new Reader(undefined, data, version);\n\t\tconst subscribe = await r.u62();\n\t\tconst sequence = await r.u53();\n\t\tconst timestamp = await r.u53();\n\t\tconst payload = await r.readAll();\n\t\treturn new Datagram(subscribe, sequence, timestamp, payload);\n\t}\n}\n"]}
|
package/lite/group.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as netGroup from "../group";
|
|
2
|
+
import type { Cursor, Reader, Writer } from "../stream";
|
|
2
3
|
import { type Version } from "./version";
|
|
3
4
|
export declare class Group {
|
|
4
5
|
#private;
|
|
@@ -22,11 +23,14 @@ export declare class Group {
|
|
|
22
23
|
static decode(r: Reader, version: Version): Promise<Group>;
|
|
23
24
|
static decodeMaybe(r: Reader, version: Version): Promise<Group | undefined>;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A synchronous decode for one frame of a group or FETCH response stream.
|
|
28
|
+
*
|
|
29
|
+
* A non-zero `scale` means every frame is prefixed with a zigzag-delta timestamp (the lite-05
|
|
30
|
+
* FRAME format), decoded into a Timestamp at that scale. Scale 0 (pre-lite-05) carries no
|
|
31
|
+
* timestamp, so frames are wall-clock stamped on arrival.
|
|
32
|
+
*/
|
|
33
|
+
export declare function frameDecoder(scale: number): (c: Cursor) => netGroup.Frame;
|
|
34
|
+
/** Write a group stream's frames into `producer` until the stream ends or the producer closes. */
|
|
35
|
+
export declare function readFrames(stream: Reader, producer: netGroup.Producer, scale: number): Promise<void>;
|
|
32
36
|
//# sourceMappingURL=group.d.ts.map
|
package/lite/group.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":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* @ts-self-types="./group.d.ts" */
|
|
2
|
+
import { race } from "@moq/signals";
|
|
3
|
+
import * as Time from "../time.js";
|
|
2
4
|
import * as Message from "./message.js";
|
|
3
5
|
import { hasFrameBounds } from "./version.js";
|
|
4
6
|
export class Group {
|
|
@@ -45,23 +47,42 @@ export class Group {
|
|
|
45
47
|
return Message.decodeMaybe(r, (r) => Group.#decode(r, version));
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
50
|
+
/** Decode an unsigned zigzag varint back to a signed delta (mirrors Rust `VarInt::to_zigzag`). */
|
|
51
|
+
function unzigzag(v) {
|
|
52
|
+
return (v >> 1n) ^ -(v & 1n);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A synchronous decode for one frame of a group or FETCH response stream.
|
|
56
|
+
*
|
|
57
|
+
* A non-zero `scale` means every frame is prefixed with a zigzag-delta timestamp (the lite-05
|
|
58
|
+
* FRAME format), decoded into a Timestamp at that scale. Scale 0 (pre-lite-05) carries no
|
|
59
|
+
* timestamp, so frames are wall-clock stamped on arrival.
|
|
60
|
+
*/
|
|
61
|
+
export function frameDecoder(scale) {
|
|
62
|
+
if (scale === 0) {
|
|
63
|
+
return (c) => ({ payload: c.read(c.u53()), timestamp: Time.Timestamp.now() });
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const timescale = Time.Timescale(scale);
|
|
66
|
+
let prevTs = 0n;
|
|
67
|
+
return (c) => {
|
|
68
|
+
const delta = unzigzag(c.u62());
|
|
69
|
+
const payload = c.read(c.u53());
|
|
70
|
+
// After the last read, so a decode that ran short and gets retried adds the delta once.
|
|
71
|
+
prevTs += delta;
|
|
72
|
+
return { payload, timestamp: new Time.Timestamp(Number(prevTs), timescale) };
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Write a group stream's frames into `producer` until the stream ends or the producer closes. */
|
|
76
|
+
export async function readFrames(stream, producer, scale) {
|
|
77
|
+
const decode = frameDecoder(scale);
|
|
78
|
+
for (;;) {
|
|
79
|
+
// Every frame already buffered is written without an await, so the reader wakes once
|
|
80
|
+
// per batch rather than once per frame. Only the group's own stream ends it: a track
|
|
81
|
+
// that closes first has already closed (or aborted) this group through its cache.
|
|
82
|
+
const frame = stream.tryDecode(decode) ?? (await race([stream.decodeMaybe(decode), producer.closed]));
|
|
83
|
+
if (!frame || frame instanceof Error)
|
|
84
|
+
return;
|
|
85
|
+
producer.writeFrame(frame);
|
|
65
86
|
}
|
|
66
87
|
}
|
|
67
88
|
//# sourceMappingURL=group.js.map
|
package/lite/group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,MAAM,OAAO,KAAK;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IAEjB;;;;;;;OAOG;IACH,UAAU,CAAS;IAEnB,YAAY,EACX,SAAS,EACT,QAAQ,EACR,UAAU,GAAG,CAAC,GAKd;QACA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS,EAAE,OAAgB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,EAAE,KAAa;IAC1F,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAEnC,SAAS,CAAC;QACT,qFAAqF;QACrF,qFAAqF;QACrF,kFAAkF;QAClF,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACtG,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;YAAE,OAAO;QAC7C,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACF,CAAC","sourcesContent":["import { race } from \"@moq/signals\";\nimport type * as netGroup from \"../group.ts\";\nimport type { Cursor, Reader, Writer } from \"../stream.ts\";\nimport * as Time from \"../time.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasFrameBounds, type Version } from \"./version.ts\";\n\nexport class Group {\n\tsubscribe: bigint;\n\tsequence: number;\n\n\t/**\n\t * The index of the first frame on this stream within the group.\n\t *\n\t * 0 (the common case) means the stream carries the group from its beginning. A\n\t * higher value means the leading frames are not here, either because the\n\t * subscription started partway into the group or because the publisher only holds\n\t * the tail. Lite-06+; older versions always start at 0.\n\t */\n\tframeStart: number;\n\n\tconstructor({\n\t\tsubscribe,\n\t\tsequence,\n\t\tframeStart = 0,\n\t}: {\n\t\tsubscribe: bigint;\n\t\tsequence: number;\n\t\tframeStart?: number;\n\t}) {\n\t\tthis.subscribe = subscribe;\n\t\tthis.sequence = sequence;\n\t\tthis.frameStart = frameStart;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.u62(this.subscribe);\n\t\tawait w.u53(this.sequence);\n\t\tif (hasFrameBounds(version)) {\n\t\t\tawait w.u53(this.frameStart);\n\t\t} else if (this.frameStart !== 0) {\n\t\t\t// The peer would number the frames from 0 and silently misalign the group.\n\t\t\tthrow new Error(\"frame offsets not supported for this version\");\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<Group> {\n\t\tconst subscribe = await r.u62();\n\t\tconst sequence = await r.u53();\n\t\tconst frameStart = hasFrameBounds(version) ? await r.u53() : 0;\n\t\treturn new Group({ subscribe, sequence, frameStart });\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Group> {\n\t\treturn Message.decode(r, (r) => Group.#decode(r, version));\n\t}\n\n\tstatic async decodeMaybe(r: Reader, version: Version): Promise<Group | undefined> {\n\t\treturn Message.decodeMaybe(r, (r) => Group.#decode(r, version));\n\t}\n}\n\n/** Decode an unsigned zigzag varint back to a signed delta (mirrors Rust `VarInt::to_zigzag`). */\nfunction unzigzag(v: bigint): bigint {\n\treturn (v >> 1n) ^ -(v & 1n);\n}\n\n/**\n * A synchronous decode for one frame of a group or FETCH response stream.\n *\n * A non-zero `scale` means every frame is prefixed with a zigzag-delta timestamp (the lite-05\n * FRAME format), decoded into a Timestamp at that scale. Scale 0 (pre-lite-05) carries no\n * timestamp, so frames are wall-clock stamped on arrival.\n */\nexport function frameDecoder(scale: number): (c: Cursor) => netGroup.Frame {\n\tif (scale === 0) {\n\t\treturn (c) => ({ payload: c.read(c.u53()), timestamp: Time.Timestamp.now() });\n\t}\n\n\tconst timescale = Time.Timescale(scale);\n\tlet prevTs = 0n;\n\treturn (c) => {\n\t\tconst delta = unzigzag(c.u62());\n\t\tconst payload = c.read(c.u53());\n\t\t// After the last read, so a decode that ran short and gets retried adds the delta once.\n\t\tprevTs += delta;\n\t\treturn { payload, timestamp: new Time.Timestamp(Number(prevTs), timescale) };\n\t};\n}\n\n/** Write a group stream's frames into `producer` until the stream ends or the producer closes. */\nexport async function readFrames(stream: Reader, producer: netGroup.Producer, scale: number): Promise<void> {\n\tconst decode = frameDecoder(scale);\n\n\tfor (;;) {\n\t\t// Every frame already buffered is written without an await, so the reader wakes once\n\t\t// per batch rather than once per frame. Only the group's own stream ends it: a track\n\t\t// that closes first has already closed (or aborted) this group through its cache.\n\t\tconst frame = stream.tryDecode(decode) ?? (await race([stream.decodeMaybe(decode), producer.closed]));\n\t\tif (!frame || frame instanceof Error) return;\n\t\tproducer.writeFrame(frame);\n\t}\n}\n"]}
|
package/lite/message.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Reader, Writer } from "../stream";
|
|
2
|
-
export declare function encode(writer: Writer, f: (w: Writer) => Promise<void
|
|
3
|
-
export declare function decode<T>(reader: Reader, f: (r: Reader) => Promise<T
|
|
2
|
+
export declare function encode(writer: Writer, f: (w: Writer) => Promise<void>, max?: number): Promise<void>;
|
|
3
|
+
export declare function decode<T>(reader: Reader, f: (r: Reader) => Promise<T>, max?: number): Promise<T>;
|
|
4
4
|
export declare function decodeMaybe<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T | undefined>;
|
|
5
5
|
//# sourceMappingURL=message.d.ts.map
|
package/lite/message.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAM9C,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,SAAW,iBA0C3F;AAGD,wBAAsB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,SAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAgBxG;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAGzG"}
|
package/lite/message.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./message.d.ts" */
|
|
2
2
|
import { Reader, Writer } from "../stream.js";
|
|
3
|
-
|
|
3
|
+
/** The largest message body either side accepts, matching the Rust implementation. */
|
|
4
|
+
const MAX_SIZE = 64 * 1024 * 1024;
|
|
5
|
+
// Encodes a message with a varint size prefix, refusing a body the peer would reject.
|
|
6
|
+
export async function encode(writer, f, max = MAX_SIZE) {
|
|
4
7
|
let scratch = new Uint8Array();
|
|
5
8
|
const temp = new Writer(new WritableStream({
|
|
6
9
|
write(chunk) {
|
|
@@ -22,20 +25,26 @@ export async function encode(writer, f) {
|
|
|
22
25
|
scratch.set(chunk, needed - chunk.byteLength);
|
|
23
26
|
}
|
|
24
27
|
},
|
|
25
|
-
}));
|
|
28
|
+
}), writer.version);
|
|
26
29
|
await f(temp);
|
|
27
30
|
temp.close();
|
|
28
31
|
await temp.closed;
|
|
32
|
+
if (scratch.byteLength > max) {
|
|
33
|
+
throw new Error(`message too large: ${scratch.byteLength} bytes (max ${max})`);
|
|
34
|
+
}
|
|
29
35
|
await writer.u53(scratch.byteLength);
|
|
30
36
|
if (scratch.byteLength > 0) {
|
|
31
37
|
await writer.write(scratch);
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
|
-
// Reads a message with a varint size prefix.
|
|
35
|
-
export async function decode(reader, f) {
|
|
40
|
+
// Reads a message with a varint size prefix, refusing an oversized body before reading it.
|
|
41
|
+
export async function decode(reader, f, max = MAX_SIZE) {
|
|
36
42
|
const size = await reader.u53();
|
|
43
|
+
if (size > max) {
|
|
44
|
+
throw new Error(`message too large: ${size} bytes (max ${max})`);
|
|
45
|
+
}
|
|
37
46
|
const data = await reader.read(size);
|
|
38
|
-
const limit = new Reader(undefined, data);
|
|
47
|
+
const limit = new Reader(undefined, data, reader.version);
|
|
39
48
|
const msg = await f(limit);
|
|
40
49
|
// Check that we consumed exactly the right number of bytes
|
|
41
50
|
if (!(await limit.done())) {
|
package/lite/message.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAc,EAAE,CAA+B;
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE9C,sFAAsF;AACtF,MAAM,QAAQ,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAElC,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAc,EAAE,CAA+B,EAAE,GAAG,GAAG,QAAQ;IAC3F,IAAI,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;IAE/B,MAAM,IAAI,GAAG,IAAI,MAAM,CACtB,IAAI,cAAc,CAAC;QAClB,KAAK,CAAC,KAAiB;YACtB,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;YACrD,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;gBACxC,wCAAwC;gBACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;gBACjE,MAAM,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AAC;IAChC,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,eAAe,GAAG,GAAG,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAErC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAE3B,2DAA2D;IAC3D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,MAAc,EAAE,CAA4B;IAChF,IAAI,MAAM,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO;IAChC,OAAO,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { Reader, Writer } from \"../stream.ts\";\n\n/** The largest message body either side accepts, matching the Rust implementation. */\nconst MAX_SIZE = 64 * 1024 * 1024;\n\n// Encodes a message with a varint size prefix, refusing a body the peer would reject.\nexport async function encode(writer: Writer, f: (w: Writer) => Promise<void>, max = MAX_SIZE) {\n\tlet scratch = new Uint8Array();\n\n\tconst temp = new Writer(\n\t\tnew WritableStream({\n\t\t\twrite(chunk: Uint8Array) {\n\t\t\t\tconst needed = scratch.byteLength + chunk.byteLength;\n\t\t\t\tif (needed > scratch.buffer.byteLength) {\n\t\t\t\t\t// Resize the buffer to the needed size.\n\t\t\t\t\tconst capacity = Math.max(needed, scratch.buffer.byteLength * 2);\n\t\t\t\t\tconst newBuffer = new ArrayBuffer(capacity);\n\t\t\t\t\tconst newScratch = new Uint8Array(newBuffer, 0, needed);\n\n\t\t\t\t\t// Copy the old data into the new buffer.\n\t\t\t\t\tnewScratch.set(scratch);\n\n\t\t\t\t\t// Copy the new chunk into the new buffer.\n\t\t\t\t\tnewScratch.set(chunk, scratch.byteLength);\n\n\t\t\t\t\tscratch = newScratch;\n\t\t\t\t} else {\n\t\t\t\t\t// Copy chunk data into buffer\n\t\t\t\t\tscratch = new Uint8Array(scratch.buffer, 0, needed);\n\t\t\t\t\tscratch.set(chunk, needed - chunk.byteLength);\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t\twriter.version,\n\t);\n\n\tawait f(temp);\n\ttemp.close();\n\tawait temp.closed;\n\n\tif (scratch.byteLength > max) {\n\t\tthrow new Error(`message too large: ${scratch.byteLength} bytes (max ${max})`);\n\t}\n\n\tawait writer.u53(scratch.byteLength);\n\tif (scratch.byteLength > 0) {\n\t\tawait writer.write(scratch);\n\t}\n}\n\n// Reads a message with a varint size prefix, refusing an oversized body before reading it.\nexport async function decode<T>(reader: Reader, f: (r: Reader) => Promise<T>, max = MAX_SIZE): Promise<T> {\n\tconst size = await reader.u53();\n\tif (size > max) {\n\t\tthrow new Error(`message too large: ${size} bytes (max ${max})`);\n\t}\n\tconst data = await reader.read(size);\n\n\tconst limit = new Reader(undefined, data, reader.version);\n\tconst msg = await f(limit);\n\n\t// Check that we consumed exactly the right number of bytes\n\tif (!(await limit.done())) {\n\t\tthrow new Error(\"Message decoding consumed too few bytes\");\n\t}\n\n\treturn msg;\n}\n\nexport async function decodeMaybe<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T | undefined> {\n\tif (await reader.done()) return;\n\treturn await decode(reader, f);\n}\n"]}
|
package/lite/publisher.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* @ts-self-types="./publisher.d.ts" */
|
|
2
2
|
import { race, Signal } from "@moq/signals";
|
|
3
3
|
import { error, NotFound, reason, StreamCode, StreamError } from "../error.js";
|
|
4
|
-
import { routesEqual } from "../hop.js";
|
|
5
|
-
import { hiddenBelow, hooks } from "../internal.js";
|
|
6
|
-
import * as Path from "../path.js";
|
|
4
|
+
import { Cost, routesEqual } from "../hop.js";
|
|
5
|
+
import { hiddenBelow, hooks, presented } from "../internal.js";
|
|
7
6
|
import { Writer } from "../stream.js";
|
|
8
7
|
import { Milli, Timescale } from "../time.js";
|
|
9
8
|
import { wireOf } from "../wire.js";
|
|
@@ -15,30 +14,7 @@ import { Priority, sendOrder } from "./priority.js";
|
|
|
15
14
|
import { Probe } from "./probe.js";
|
|
16
15
|
import { encodeSubscribeResponse, exclusiveGroupEnd, SubscribeEnd, SubscribeOk, SubscribeStart, SubscribeUpdate, } from "./subscribe.js";
|
|
17
16
|
import { TrackInfo as TrackInfoMessage } from "./track.js";
|
|
18
|
-
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, hasProbeRtt, hasStreamCount, resolvesStart, Version, } from "./version.js";
|
|
19
|
-
// Where each originated route lands under the requested prefix: its suffix beneath
|
|
20
|
-
// the prefix, or the empty suffix for a route above it, where the most specific
|
|
21
|
-
// such route wins the way a request through the prefix would resolve.
|
|
22
|
-
function presented(prefix, table, hidden) {
|
|
23
|
-
const out = new Map();
|
|
24
|
-
let rootLen = -1;
|
|
25
|
-
for (const [covered, snap] of table) {
|
|
26
|
-
if (Path.hasPrefix(covered, prefix)) {
|
|
27
|
-
if (covered.length < rootLen)
|
|
28
|
-
continue;
|
|
29
|
-
rootLen = covered.length;
|
|
30
|
-
out.set(Path.empty(), snap);
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
// A hidden route stays off the wire unless the request opted in.
|
|
34
|
-
if (!hidden && hiddenBelow(prefix, covered))
|
|
35
|
-
continue;
|
|
36
|
-
const suffix = Path.stripPrefix(prefix, covered);
|
|
37
|
-
if (suffix !== null)
|
|
38
|
-
out.set(suffix, snap);
|
|
39
|
-
}
|
|
40
|
-
return out;
|
|
41
|
-
}
|
|
17
|
+
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, hasProbeRtt, hasRouteCost, hasStreamCount, resolvesStart, Version, } from "./version.js";
|
|
42
18
|
const PROBE_INTERVAL = 100; // ms
|
|
43
19
|
const PROBE_MAX_AGE = 10_000; // ms
|
|
44
20
|
const PROBE_MAX_DELTA = 0.25;
|
|
@@ -301,6 +277,9 @@ export class Publisher {
|
|
|
301
277
|
return route.hops;
|
|
302
278
|
return [...route.hops, this.hop];
|
|
303
279
|
};
|
|
280
|
+
// What the peer decodes for a route: pre-lite-06 wires carry no cost, so a re-price
|
|
281
|
+
// there must not restart.
|
|
282
|
+
const onWire = (route) => (hasRouteCost(this.version) ? route : { ...route, cost: Cost.zero });
|
|
304
283
|
const announce = async (suffix, route) => {
|
|
305
284
|
console.debug(`announce: broadcast=${suffix} active=true`);
|
|
306
285
|
if (hasAnnounceId(this.version))
|
|
@@ -344,11 +323,13 @@ export class Publisher {
|
|
|
344
323
|
let changed = new Promise((resolve) => {
|
|
345
324
|
dispose = this.#advertised.changed(resolve);
|
|
346
325
|
});
|
|
326
|
+
// A hidden route stays off the wire unless the request opted in.
|
|
327
|
+
const carries = (covered) => msg.hidden || !hiddenBelow(msg.prefix, covered);
|
|
347
328
|
try {
|
|
348
329
|
const initial = this.#advertised.peek();
|
|
349
330
|
if (!initial)
|
|
350
331
|
return; // closed
|
|
351
|
-
for (const [name, snap] of presented(msg.prefix, initial,
|
|
332
|
+
for (const [name, snap] of presented(msg.prefix, initial, carries)) {
|
|
352
333
|
active.set(name, snap);
|
|
353
334
|
}
|
|
354
335
|
switch (this.version) {
|
|
@@ -389,7 +370,7 @@ export class Publisher {
|
|
|
389
370
|
if (!latest)
|
|
390
371
|
break;
|
|
391
372
|
const updated = new Map();
|
|
392
|
-
for (const [name, snap] of presented(msg.prefix, latest,
|
|
373
|
+
for (const [name, snap] of presented(msg.prefix, latest, carries)) {
|
|
393
374
|
updated.set(name, snap);
|
|
394
375
|
}
|
|
395
376
|
for (const [suffix, snap] of active) {
|
|
@@ -402,7 +383,7 @@ export class Publisher {
|
|
|
402
383
|
if (!prev || prev.identity !== snap.identity) {
|
|
403
384
|
await announce(suffix, snap.route);
|
|
404
385
|
}
|
|
405
|
-
else if (!routesEqual(prev.route, snap.route)) {
|
|
386
|
+
else if (!routesEqual(onWire(prev.route), onWire(snap.route))) {
|
|
406
387
|
await restart(suffix, snap.route);
|
|
407
388
|
}
|
|
408
389
|
}
|
|
@@ -648,8 +629,16 @@ export class Publisher {
|
|
|
648
629
|
case "update": {
|
|
649
630
|
const update = control.update;
|
|
650
631
|
console.debug(`subscribe update: broadcast=${broadcast} track=${track.name}`);
|
|
632
|
+
// `positionCursor` pins an unfloored pre-06 SUBSCRIBE to the latest
|
|
633
|
+
// group, so an update that drops a named floor re-pins there too. On
|
|
634
|
+
// an empty track the next group is the latest, whatever its sequence.
|
|
635
|
+
const start = update.startGroup === undefined &&
|
|
636
|
+
bounds.startGroup !== undefined &&
|
|
637
|
+
!resolvesStart(this.version)
|
|
638
|
+
? (track.latest() ?? 0)
|
|
639
|
+
: update.startGroup;
|
|
651
640
|
hooks.replaceGroups(track, {
|
|
652
|
-
start:
|
|
641
|
+
start: start === undefined ? undefined : { included: start },
|
|
653
642
|
end: update.endGroup === undefined ? undefined : { included: update.endGroup },
|
|
654
643
|
});
|
|
655
644
|
bounds.startGroup = update.startGroup;
|
|
@@ -711,13 +700,17 @@ export class Publisher {
|
|
|
711
700
|
const range = frameRange(bounds, group.sequence);
|
|
712
701
|
if (emitRange && !startSent) {
|
|
713
702
|
startSent = true;
|
|
714
|
-
// SUBSCRIBE_START
|
|
715
|
-
//
|
|
716
|
-
//
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
703
|
+
// SUBSCRIBE_START names the first group served now. A later group at or
|
|
704
|
+
// above an explicit floor is still delivered, so the cursor stays put.
|
|
705
|
+
// A pre-06 subscribe that named no group is the exception: an absent
|
|
706
|
+
// Group Start is the latest group, and this sequence becomes the floor.
|
|
707
|
+
// Lite-06 encodes a floor of group 0 as 0, so an omitted start is not pinned.
|
|
708
|
+
if (bounds.startGroup === undefined && !resolvesStart(this.version)) {
|
|
709
|
+
hooks.replaceGroups(track, {
|
|
710
|
+
start: { included: group.sequence },
|
|
711
|
+
end: bounds.endGroup === undefined ? undefined : { included: bounds.endGroup },
|
|
712
|
+
});
|
|
713
|
+
}
|
|
721
714
|
if (!(await controls.response(encodeSubscribeResponse(stream, { start: new SubscribeStart(group.sequence) }, this.version))))
|
|
722
715
|
return;
|
|
723
716
|
}
|
|
@@ -784,7 +777,7 @@ export class Publisher {
|
|
|
784
777
|
this.#trackInfo.set(front, tracks);
|
|
785
778
|
}
|
|
786
779
|
const cached = tracks.get(track);
|
|
787
|
-
if (cached)
|
|
780
|
+
if (cached !== undefined)
|
|
788
781
|
return cached;
|
|
789
782
|
const pending = (async () => {
|
|
790
783
|
const info = await wireOf(front).resolveTrackInfo(track);
|
|
@@ -823,7 +816,7 @@ export class Publisher {
|
|
|
823
816
|
return; // Track finished; #runTrack tears the subscription down.
|
|
824
817
|
// Convert the timestamp to the track's advertised timescale, matching #serveGroup.
|
|
825
818
|
const ts = Math.round(datagram.timestamp.as(timescale));
|
|
826
|
-
const body = new DatagramMessage(sub, datagram.sequence, ts, datagram.payload).encode();
|
|
819
|
+
const body = new DatagramMessage(sub, datagram.sequence, ts, datagram.payload).encode(this.version);
|
|
827
820
|
// No group fallback: drop anything that doesn't fit a single datagram.
|
|
828
821
|
if (body.byteLength > maxSize) {
|
|
829
822
|
console.debug(`dropping oversize datagram: sub=${sub} size=${body.byteLength} max=${maxSize}`);
|
|
@@ -878,6 +871,7 @@ export class Publisher {
|
|
|
878
871
|
// in the order we asked, which is oldest-first, exactly backwards for live media.
|
|
879
872
|
// Failing here drops the group and lets the next one compete for the next slot.
|
|
880
873
|
const stream = await Writer.tryOpen(this.#quic, {
|
|
874
|
+
version: this.version,
|
|
881
875
|
sendOrder: priority.rank(group.sequence),
|
|
882
876
|
cancel: unsubscribed,
|
|
883
877
|
waitUntilAvailable: false,
|
|
@@ -907,10 +901,10 @@ export class Publisher {
|
|
|
907
901
|
// A SUBSCRIBE_UPDATE re-ranks the subscription, so a group already on the wire
|
|
908
902
|
// follows it too rather than keeping a stale rank until it finishes.
|
|
909
903
|
priority.add(stream, group.sequence);
|
|
910
|
-
await hooks.guardGroup(group,
|
|
904
|
+
await hooks.guardGroup(group, async () => {
|
|
911
905
|
await stream.u53(0); // stream type
|
|
912
906
|
await msg.encode(stream, this.version);
|
|
913
|
-
})
|
|
907
|
+
});
|
|
914
908
|
// Lite05+ prefixes every frame with a zigzag-delta timestamp at the track's
|
|
915
909
|
// advertised timescale; older drafts omit it.
|
|
916
910
|
const timestamps = supportsTrackStream(this.version);
|
|
@@ -942,11 +936,11 @@ export class Publisher {
|
|
|
942
936
|
if (timestamps) {
|
|
943
937
|
// Convert each frame to the track's advertised timescale.
|
|
944
938
|
const ts = BigInt(Math.round(read.frame.timestamp.as(timescale)));
|
|
945
|
-
await hooks.guardGroup(group, stream.u62(zigzag(ts - prevTs)));
|
|
939
|
+
await hooks.guardGroup(group, () => stream.u62(zigzag(ts - prevTs)));
|
|
946
940
|
prevTs = ts;
|
|
947
941
|
}
|
|
948
|
-
await hooks.guardGroup(group, stream.u53(read.frame.payload.byteLength));
|
|
949
|
-
await hooks.guardGroup(group, stream.write(read.frame.payload));
|
|
942
|
+
await hooks.guardGroup(group, () => stream.u53(read.frame.payload.byteLength));
|
|
943
|
+
await hooks.guardGroup(group, () => stream.write(read.frame.payload));
|
|
950
944
|
}
|
|
951
945
|
finally {
|
|
952
946
|
read.complete();
|