import { D as DatagramObject, h as DatagramStatus, n as MoqtObject, m as FullTrackName, L as Location, f as ObjectForwardingPreference, K as KeyValuePair, c as Tuple, o as SubgroupObject, j as FetchObject } from '../byte_buffer-BOK6VPTF.js'; import { w as ControlMessage, b as PublishNamespaceOk, a as PublishNamespaceError, P as PublishNamespace, A as FetchOk, z as FetchError, x as Fetch, U as SubscribeOk, Q as SubscribeError, S as Subscribe, V as SubscribeUpdate, q as PublishDoneStatusCode, a5 as SetupParameters, G as GroupOrder, F as FilterType, a7 as VersionSpecificParameters, h as FetchType, a2 as RequestIdMap, Z as PublishNamespaceDone, B as GoAway, a1 as SubgroupHeader, a0 as FetchHeader, E as ServerSetup, c as PublishNamespaceCancel, H as SubscribeNamespace, $ as UnsubscribeNamespace, J as SubscribeNamespaceOk, I as SubscribeNamespaceError, a3 as Header } from '../version_parameter-B9sjihEd.js'; /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class ControlStream { #private; readonly stream: ReadableStream; onMessageSent?: (msg: ControlMessage) => void; onMessageReceived?: (msg: ControlMessage) => void; private constructor(); static new(bidirectionalStream: WebTransportBidirectionalStream, partialMessageTimeoutMs?: number, onMessageSent?: (msg: ControlMessage) => void, onMessageReceived?: (msg: ControlMessage) => void): ControlStream; send(message: ControlMessage): Promise; close(): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Sends MoqtObjects as WebTransport datagrams. * Parallel to SendStream but for datagram-based delivery. * * @example * ```ts * const sender = new SendDatagramStream(client.webTransport.datagrams.writable, trackAlias); * await sender.write(moqtObject); * ``` */ declare class SendDatagramStream { #private; readonly onDataSent?: (data: DatagramObject | DatagramStatus) => void; constructor(writer: WritableStreamDefaultWriter, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void); /** * Create a new datagram sender for a specific track. * * @param writeStream - WebTransport datagram writable stream * @param trackAlias - Track alias for this datagram stream * @param onDataSent - Optional callback fired when datagram is sent * @returns SendDatagramStream instance */ static new(writeStream: WritableStream, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void): Promise; /** * Create a datagram sender using an existing shared writer. * Use this when multiple senders need to share a single writer. * * @param writer - Existing WritableStreamDefaultWriter * @param trackAlias - Track alias for this datagram stream * @param onDataSent - Optional callback fired when datagram is sent * @returns SendDatagramStream instance */ static fromWriter(writer: WritableStreamDefaultWriter, trackAlias: bigint, onDataSent?: (data: DatagramObject | DatagramStatus) => void): SendDatagramStream; /** * Write a MoqtObject as a datagram. * Converts to DatagramObject or DatagramStatus automatically. * * @param object - MoqtObject to send (must have Datagram forwarding preference) * @throws ProtocolViolationError if object is not datagram-compatible */ write(object: MoqtObject): Promise; /** * Close the datagram writer. */ close(): Promise; /** * Release the writer lock without closing. */ releaseLock(): void; } /** * Receives and parses WebTransport datagrams as MoqtObjects. * Parallel to RecvStream but for datagram-based delivery. * * Automatically handles: * - DatagramObject parsing (objects with payloads) * - DatagramStatus parsing (status-only objects) * - Track alias to full track name resolution * * @example * ```ts * const receiver = new RecvDatagramStream( * client.webTransport.datagrams.readable, * (trackAlias) => client.requestIdMap.getNameByTrackAlias(trackAlias) * ); * * for await (const object of receiver.stream) { * console.log('Received:', object); * } * ``` */ declare class RecvDatagramStream { #private; readonly stream: ReadableStream; readonly onDataReceived?: (data: DatagramObject | DatagramStatus) => void; private constructor(); /** * Create a new datagram receiver. * * @param readStream - WebTransport datagram readable stream * @param trackAliasResolver - Function to resolve track alias to full track name * @param onDataReceived - Optional callback fired when datagram is received * @returns RecvDatagramStream instance */ static new(readStream: ReadableStream, trackAliasResolver: (trackAlias: bigint) => FullTrackName, onDataReceived?: (data: DatagramObject | DatagramStatus) => void): Promise; /** * Cancel the datagram reader. */ cancel(): Promise; /** * Release the reader lock without canceling. */ releaseLock(): void; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * In‑memory index of {@link MoqtObject} instances keyed by their {@link Location} (group/subgroup/object), * providing ordered insertion and range queries. * * Implementations MUST keep objects sorted ascending by (groupId, objectId) so binary searches can * locate insertion points / range bounds efficiently. Subgroup ordinality is currently ignored for ordering * (adjust if protocol semantics require finer granularity later). * * @example Typical usage * ```ts * const cache: ObjectCache = new MemoryObjectCache() * cache.add(obj) * const window = cache.getRange(startLoc, endLoc) * const exact = cache.getByLocation(loc) * ``` * * Concurrency: Implementations here are not thread‑safe; callers avoid concurrent mutation from workers. */ interface ObjectCache { /** Insert a new {@link MoqtObject}, preserving sorted order (duplicates allowed or replaced impl‑defined). */ add(obj: MoqtObject): void; /** Return a shallow copy array of objects whose Location is \>= start and \< end (end exclusive). */ getRange(start?: Location, end?: Location): MoqtObject[]; /** Return the object whose Location exactly matches (group & object) or undefined if absent. */ getByLocation(location: Location): MoqtObject | undefined; /** Current number of cached objects. */ size(): number; /** Remove all cached objects. */ clear(): void; } declare class MemoryObjectCache implements ObjectCache { private objects; add(obj: MoqtObject): void; getRange(start?: Location, end?: Location): MoqtObject[]; getByLocation(location: Location): MoqtObject | undefined; size(): number; clear(): void; private _findInsertIndex; private _findIndex; } declare class RingBufferObjectCache implements ObjectCache { private buffer; private maxSize; constructor(maxSize?: number); add(obj: MoqtObject): void; getRange(start?: Location, end?: Location): MoqtObject[]; getByLocation(location: Location): MoqtObject | undefined; size(): number; clear(): void; private _findInsertIndex; private _findIndex; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Source of already-produced (historical) objects for a track. * Backed by an {@link ObjectCache} allowing range retrieval using protocol {@link Location}s. * Implementations MUST return objects in ascending location order and MAY return an empty array * if the requested window is outside the cached range. */ interface PastObjectSource { /** Underlying cache from which objects are served */ readonly cache: ObjectCache; /** * Fetch a (closed) range of objects. `start`/`end` are inclusive when provided. * Omitted bounds mean: from earliest cached (when `start` undefined) or up to latest cached (when `end` undefined). */ getRange(start?: Location, end?: Location): Promise; } /** * Push-oriented live object feed. Wraps a {@link https://developer.mozilla.org/docs/Web/API/ReadableStream | ReadableStream} plus lightweight event subscription helpers. * Implementations advance {@link LiveObjectSource.largestLocation | largestLocation} monotonically as objects arrive. */ interface LiveObjectSource { /** Continuous stream yielding objects as they are produced */ readonly stream: ReadableStream; /** Highest (latest) location observed so far; undefined until first object */ readonly largestLocation: Location | undefined; /** Register a listener invoked (async) for each new object. Returns an unsubscribe function. */ onNewObject(listener: (obj: MoqtObject) => void): () => void; /** Register a listener invoked when the live stream ends (normal or error). Returns an unsubscribe function. */ onDone(listener: () => void): () => void; /** Stop ingestion and release underlying reader (idempotent). */ stop(): void; } /** * Aggregates optional historical (`past`) and (`live`) sources for a single track. * Either facet may be omitted: * - VOD / static content: supply only {@link TrackSource.past | past} * - Pure live: supply only {@link TrackSource.live | live} * - Hybrid (catch-up + live tail): supply both. * * Priority handling note: publisher priority is defined on the Track metadata (see `Track.publisherPriority`). * The library rounds non-integer values and clamps priority into [0,255] there; this interface simply * expresses what content is available, independent of priority semantics. */ interface TrackSource { /** Historical object access (optional) */ readonly past?: PastObjectSource; /** Live object feed (optional) */ readonly live?: LiveObjectSource; } declare class StaticTrackSource implements PastObjectSource { readonly cache: ObjectCache; constructor(cache: ObjectCache); getRange(start?: Location, end?: Location): Promise; } declare class LiveTrackSource implements LiveObjectSource { #private; readonly stream: ReadableStream; constructor(stream: ReadableStream); get largestLocation(): Location | undefined; onNewObject(listener: (obj: MoqtObject) => void): () => void; onDone(listener: () => void): () => void; stop(): void; } declare class HybridTrackSource implements TrackSource { readonly past: PastObjectSource; readonly live: LiveObjectSource; constructor(cache: ObjectCache, stream: ReadableStream); } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Describes a media/data track known to the client (either published locally or subscribed to). * * * @example Live only track * ```ts * const liveStream: ReadableStream = buildCameraStream() * const track: Track = { * fullTrackName, * forwardingPreference: ObjectForwardingPreference.Latest, * trackSource: { live: liveStream }, * publisherPriority: 0 * } * client.addOrUpdateTrack(track) * ``` * * @example Past only track (pre‑recorded cache) * ```ts * const cache = new MemoryObjectCache() * recording.forEach(obj => cache.add(obj)) * const track: Track = { * fullTrackName, * forwardingPreference: ObjectForwardingPreference.All, * trackSource: { past: cache }, * publisherPriority: 64 * } * client.addOrUpdateTrack(track) * ``` * * @example Hybrid (cache + live) * ```ts * const cache = new MemoryObjectCache() * const liveStream = buildLiveReadableStream() * const track: Track = { * fullTrackName, * forwardingPreference: ObjectForwardingPreference.Latest, * trackSource: { past: cache, live: liveStream }, * publisherPriority: 8 * } * client.addOrUpdateTrack(track) * ``` */ type Track = { /** * Globally unique identifier for the track. */ fullTrackName: FullTrackName; /** * Hint controlling which objects SHOULD be forwarded / prioritized. */ forwardingPreference: ObjectForwardingPreference; /** * Accessors for live and/or past objects belonging to this track. */ trackSource: TrackSource; /** * 0 (highest) .. 255 (lowest) priority advertised with objects. * Values are rounded to nearest integer then clamped between 0 and 255. */ publisherPriority: number; /** * Optional compact numeric alias assigned during protocol negotiation. */ trackAlias?: bigint; }; /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class PublishNamespaceRequest implements PromiseLike { readonly requestId: bigint; readonly message: PublishNamespace; private _resolve; private _reject; private promise; constructor(requestId: bigint, message: PublishNamespace); resolve(value: PublishNamespaceOk | PublishNamespaceError | PromiseLike): void; reject(reason?: any): void; then(onfulfilled?: ((value: PublishNamespaceOk | PublishNamespaceError) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class FetchRequest implements PromiseLike { readonly requestId: bigint; readonly message: Fetch; private _resolve; private _reject; private promise; controller?: ReadableStreamDefaultController; stream: ReadableStream; isActive: boolean; isResolved: boolean; constructor(message: Fetch); resolve(value: FetchOk | FetchError | PromiseLike): void; reject(reason?: any): void; then(onfulfilled?: ((value: FetchOk | FetchError) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class SubscribeRequest implements PromiseLike { #private; readonly requestId: bigint; readonly fullTrackName: FullTrackName; isCanceled: boolean; startLocation: Location | undefined; endGroup: bigint | undefined; priority: number; forward: boolean; subscribeParameters: KeyValuePair[]; largestLocation: Location | undefined; streamsAccepted: bigint; expectedStreams: bigint | undefined; readonly controller: ReadableStreamDefaultController; readonly stream: ReadableStream; constructor(msg: Subscribe); update(msg: SubscribeUpdate): void; unsubscribe(): void; resolve(value: SubscribeOk | SubscribeError | PromiseLike): void; reject(reason?: any): void; then(onfulfilled?: ((value: SubscribeOk | SubscribeError) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @public * Manages the publication of MOQT objects to a subscriber for a specific track. * Handles live object streaming, subscription lifecycle, and stream management. */ declare class SubscribePublication { #private; private readonly client; readonly track: Track; private readonly subscribeMsg; /** * The latest location that was published to the subscriber. */ latestLocation: Location | undefined; /** * Creates a new SubscribePublication instance. * @param client - The MOQT client managing the subscription. * @param track - The track being published. * @param subscribeMsg - The subscribe message containing subscription details. * @param largestLocation - The largest location seen so far, used for determining start location. */ constructor(client: MOQtailClient, track: Track, subscribeMsg: Subscribe, largestLocation?: Location); /** * Cancels the publication and cleans up resources. * Removes the publication from the client's publication map. */ cancel(): void; /** * Marks the publication as done and sends a PublishDone message to the client. * @param statusCode - The status code indicating why the publication ended. * @throws :{@link InternalError} If sending the message fails. */ done(statusCode: PublishDoneStatusCode): Promise; /** * Updates the subscription parameters and locations based on a SubscribeUpdate message. * @param msg - The update message containing new subscription details. */ update(msg: SubscribeUpdate): void; /** * Publishes MOQT objects to the subscriber as they become available. * Handles stream creation, object writing, and stream closure based on subscription parameters. * @throws :{@link InternalError} If the track does not support live content. */ publish(): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class FetchPublication { #private; constructor(client: MOQtailClient, track: Track, fetchRequest: Fetch); cancel(): void; publish(): Promise; } /** * Union type of all possible MOQtail requests */ type MOQtailRequest = PublishNamespaceRequest | FetchRequest | SubscribeRequest; /** * Callbacks related to datagram events */ type DatagramCallbacks = { /** * Invoked for each decoded datagram object/status arriving * Use to process or display incoming datagram-based media/data */ onDatagramReceived?: (data: DatagramObject | DatagramStatus) => void; /** * Invoked after enqueuing each outbound datagram object/status * Use for monitoring or analytics */ onDatagramSent?: (data: DatagramObject | DatagramStatus) => void; }; /** * Extended options for the MOQtail client * * @example Minimal * ```ts * const client = await MOQtailClient.new({ * url: 'https://relay.example.com/moq', * supportedVersions: [0xff00000b] * }) * ``` * * @example With datagram support * ```ts * const client = await MOQtailClient.new({ * url: relayUrl, * supportedVersions: [0xff00000b], * enableDatagrams: true, * callbacks: { * onDatagramReceived: (data) => console.log('Datagram received:', data), * onDatagramSent: (data) => console.log('Datagram sent:', data), * } * }) * ``` */ type MOQtailClientOptions = { /** Relay / server endpoint for the underlying WebTransport session. */ url: string | URL; /** Ordered preference list of MOQT protocol version numbers (e.g. `0xff00000b`). */ supportedVersions: number[]; /** SetupParameters customizations; if omitted a default instance is built. */ setupParameters?: SetupParameters; /** Passed directly to the browser's WebTransport constructor. */ transportOptions?: WebTransportOptions; /** Per *data* uni-stream idle timeout in milliseconds. */ dataStreamTimeoutMs?: number; /** Control stream read timeout in milliseconds. */ controlStreamTimeoutMs?: number; /** * Enable datagram support. When true, datagrams will be automatically started * after connection is established. Default: false */ enableDatagrams?: boolean; /** Callbacks for observability and logging purposes. */ callbacks?: { /** Called after a control message is successfully written to the ControlStream. */ onMessageSent?: (msg: ControlMessage) => void; /** Called for each incoming control message before protocol handling. */ onMessageReceived?: (msg: ControlMessage) => void; /** Fired once when the session ends (normal or error). */ onSessionTerminated?: (reason?: unknown) => void; /** Invoked for each decoded datagram object/status arriving. */ onDatagramReceived?: (data: DatagramObject | DatagramStatus) => void; /** Invoked after enqueuing each outbound datagram object/status. */ onDatagramSent?: (data: DatagramObject | DatagramStatus) => void; }; }; /** * Parameters for subscribing to a track's live objects */ type SubscribeOptions = { fullTrackName: FullTrackName; priority: number; groupOrder: GroupOrder; forward: boolean; filterType: FilterType; parameters?: VersionSpecificParameters; startLocation?: Location; endGroup?: bigint | number; }; /** * Narrowing update constraints applied to an existing SUBSCRIBE */ type SubscribeUpdateOptions = { subscriptionRequestId: bigint; startLocation: Location; endGroup: bigint; priority: number; forward: boolean; parameters?: VersionSpecificParameters; }; /** * Options for performing a FETCH operation for historical or relative object ranges */ type FetchOptions = { priority: number; groupOrder: GroupOrder; typeAndProps: { type: FetchType.StandAlone; props: { fullTrackName: FullTrackName; startLocation: Location; endLocation: Location; }; } | { type: FetchType.Relative; props: { joiningRequestId: bigint; joiningStart: bigint; }; } | { type: FetchType.Absolute; props: { joiningRequestId: bigint; joiningStart: bigint; }; }; parameters?: VersionSpecificParameters; }; /** * @public * MOQtailClient is the main entry point for interacting with a MOQT server over WebTransport. * * It manages the underlying WebTransport session, control stream, data streams, * track subscriptions, publications, and datagram support. * * Clients can register tracks for publishing, subscribe to tracks for receiving data, * perform fetch operations, and send/receive datagrams. * * Extensive callback hooks are provided for observability and custom handling of events. * * Example usage: * ```ts * const client = await MOQtailClient.new({ * url: 'https://relay.example.com/moq', * supportedVersions: [0xff00000b], * enableDatagrams: true, * callbacks: { * onDatagramReceived: (data) => console.log('Datagram received:', data), * onDatagramSent: (data) => console.log('Datagram sent:', data), * } * }) * ``` * */ declare class MOQtailClient { #private; /** * Namespace prefixes (tuples) the peer has requested announce notifications for via SUBSCRIBE_NAMESPACE */ readonly peerSubscribeNamespace: Set; /** * Namespace prefixes this client has subscribed to (issued SUBSCRIBE_NAMESPACE) */ readonly subscribedAnnounces: Set; /** * Track namespaces this client has successfully announced (received ANNOUNCE_OK) */ readonly announcedNamespaces: Set; /** * Locally registered track definitions keyed by full track name string */ readonly trackSources: Map; /** * All in‑flight request objects keyed by requestId */ readonly requests: Map; /** * Active publications keyed by requestId */ readonly publications: Map; /** * Active SUBSCRIBE request wrappers keyed by track alias */ readonly subscriptions: Map; /** * Bidirectional track alias-subscription requestId mapping */ readonly subscriptionAliasMap: Map; /** * Bidirectional requestId-full track name mapping */ readonly requestIdMap: RequestIdMap; /** Underlying WebTransport session. */ webTransport: WebTransport; /** Outgoing / incoming control message bidirectional stream wrapper. */ controlStream: ControlStream; /** Timeout (ms) applied to reading incoming data streams. */ dataStreamTimeoutMs?: number; /** Timeout (ms) for control stream read operations. */ controlStreamTimeoutMs?: number; /** Optional highest request id allowed. */ maxRequestId?: bigint; /** Fired when a PUBLISH_NAMESPACE control message is processed. */ onNamespacePublished?: (msg: PublishNamespace) => void; /** Fired when a PUBLISH_NAMESPACE_DONE control message is processed. */ onNamespaceDone?: (msg: PublishNamespaceDone) => void; /** Fired on GOAWAY reception signaling graceful session wind-down. */ onGoaway?: (msg: GoAway) => void; /** Fired if the underlying WebTransport session fails. */ onWebTransportFail?: () => void; /** Fired exactly once when the client transitions to terminated. */ onSessionTerminated?: (reason?: unknown) => void; /** Invoked after each outbound control message is sent. */ onMessageSent?: (msg: ControlMessage) => void; /** Invoked upon receiving each inbound control message. */ onMessageReceived?: (msg: ControlMessage) => void; /** Invoked for each decoded data object/header arriving on a uni stream. */ onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void; /** Invoked after enqueuing each outbound data object/header. */ onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void; /** General-purpose error callback. */ onError?: (er: unknown) => void; /** Invoked for each decoded datagram object/status arriving. */ onDatagramReceived?: (data: DatagramObject | DatagramStatus) => void; /** Invoked after enqueuing each outbound datagram object/status. */ onDatagramSent?: (data: DatagramObject | DatagramStatus) => void; /** * Stream of all received MoqtObjects from datagrams across all tracks * Consumer should filter by fullTrackName as needed * * WARNING: Only one reader should be active. For multiple subscribers, * use subscribeToTrackDatagrams() instead */ readonly receivedDatagramObjects: ReadableStream; /** * Gets the current server setup configuration */ get serverSetup(): ServerSetup; /** * Returns true if datagram support is currently active */ get isDatagramsEnabled(): boolean; private constructor(); /** * Establishes a new MOQtailClient session over WebTransport and performs the MOQT setup handshake. * * @param args - {@link MOQtailClientOptions} * @returns Promise resolving to a ready MOQtailClient instance. * @throws ProtocolViolationError If the server sends an unexpected or invalid message during setup. * * @example Minimal connection * ```ts * const client = await MOQtailClient.new({ * url: 'https://relay.example.com/transport', * supportedVersions: [0xff00000b] * }); * ``` * * @example With datagram support and callbacks * ```ts * const client = await MOQtailClient.new({ * url, * supportedVersions: [0xff00000b], * enableDatagrams: true, * callbacks: { * onMessageSent: msg => console.log('Sent:', msg), * onDatagramReceived: data => console.log('Datagram:', data), * onSessionTerminated: reason => console.warn('Session ended:', reason) * } * }); * ``` */ static new(args: MOQtailClientOptions): Promise; /** * Start receiving datagrams from the WebTransport connection. * Must be called before datagrams can be received (unless enableDatagrams: true was set in options). * * @throws MOQtailError if client is destroyed or datagrams already started */ startDatagrams(): Promise; /** * Stop receiving datagrams and release resources. * Idempotent - safe to call multiple times. */ stopDatagrams(): Promise; /** * Subscribe to receive datagrams for a specific track. * Multiple tracks can have separate handlers that run concurrently. * * @param trackAlias - Track alias to subscribe to * @param handler - Function called for each received MoqtObject on this track * @returns Unsubscribe function to remove the handler * * @example * ```ts * const unsubscribe = client.subscribeToTrackDatagrams(trackAlias, (obj) => { * console.log('Received datagram:', obj.payload); * }); * // Later: unsubscribe(); * ``` */ subscribeToTrackDatagrams(trackAlias: bigint, handler: (obj: MoqtObject) => void): () => void; /** * Unsubscribe from datagram delivery for a specific track. * * @param trackAlias - Track alias to unsubscribe from */ unsubscribeFromTrackDatagrams(trackAlias: bigint): void; /** * Create a datagram sender for a specific track. * * @param trackAlias - Track alias for outgoing datagrams * @returns SendDatagramStream for writing MoqtObjects as datagrams * @throws MOQtailError if datagram writer not initialized (call startDatagrams() first) * * @example * ```ts * const sender = client.createDatagramSender(trackAlias); * await sender.write(moqtObject); * ``` */ createDatagramSender(trackAlias: bigint): SendDatagramStream; /** * Send a single MoqtObject as a datagram. * Convenience method for one-off datagram sends. * * @param trackAlias - Track alias for this object * @param object - MoqtObject to send * @throws MOQtailError if datagram writer not initialized * * @example * ```ts * await client.sendDatagram(trackAlias, moqtObject); * ``` */ sendDatagram(trackAlias: bigint, object: MoqtObject): Promise; /** * Gracefully terminates this session and releases underlying WebTransport resources. * * @param reason - Optional application-level reason * @returns Promise that resolves once shutdown logic completes. Subsequent calls are safe no-ops. */ disconnect(reason?: unknown): Promise; /** * Registers or updates a Track definition for local publishing or serving. */ addOrUpdateTrack(track: Track): void; /** * Removes a previously registered Track from this client's local catalog. */ removeTrack(track: Track): void; /** * Subscribes to a track and returns a stream of MoqtObjects. */ subscribe(args: SubscribeOptions): Promise; }>; /** * Stops an active subscription identified by its original SUBSCRIBE requestId. */ unsubscribe(requestId: bigint | number): Promise; /** * Narrows or updates an active subscription window and/or relay forwarding behavior. */ subscribeUpdate(args: SubscribeUpdateOptions): Promise; /** * Performs a FETCH operation and returns a stream of MoqtObjects. */ fetch(args: FetchOptions): Promise; }>; /** * Sends a FETCH_CANCEL for an active fetch request. */ fetchCancel(requestId: bigint | number): Promise; /** * Publish a namespace to the relay */ publishNamespace(trackNamespace: Tuple, parameters?: VersionSpecificParameters): Promise; /** * Send a PublishNamespaceDone to signal the end of publishing for a namespace. */ publishNamespaceDone(trackNamespace: Tuple): Promise; /** * Cancel a previously sent PUBLISH_NAMESPACE request. */ publishNamespaceCancel(msg: PublishNamespaceCancel): Promise; /** * Subscribe to a namespace */ subscribeNamespace(msg: SubscribeNamespace): Promise; /** * Unsubscribe from a namespace */ unsubscribeNamespace(msg: UnsubscribeNamespace): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class SubscribeNamespaceRequest implements PromiseLike { readonly requestId: bigint; readonly message: SubscribeNamespace; private _resolve; private _reject; private promise; constructor(requestId: bigint, message: SubscribeNamespace); resolve(value: SubscribeNamespaceOk | SubscribeNamespaceError | PromiseLike): void; reject(reason?: any): void; then(onfulfilled?: ((value: SubscribeNamespaceOk | SubscribeNamespaceError) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; finally(onfinally?: (() => void) | undefined | null): Promise; } /** * Copyright 2025 The MOQtail Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ declare class SendStream { #private; readonly header: Header; readonly onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void; private constructor(); static new(writeStream: WritableStream, header: Header, onDataSent?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void): Promise; write(object: FetchObject | SubgroupObject): Promise; close(): Promise; } declare class RecvStream { #private; readonly header: Header; readonly stream: ReadableStream; readonly onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void; private constructor(); static new(readStream: ReadableStream, partialDataTimeout?: number, onDataReceived?: (data: SubgroupObject | SubgroupHeader | FetchObject | FetchHeader) => void): Promise; } export { ControlStream, type DatagramCallbacks, type FetchOptions, FetchPublication, FetchRequest, HybridTrackSource, type LiveObjectSource, LiveTrackSource, MOQtailClient, type MOQtailClientOptions, type MOQtailRequest, MemoryObjectCache, type ObjectCache, type PastObjectSource, PublishNamespaceRequest, RecvDatagramStream, RecvStream, RingBufferObjectCache, SendDatagramStream, SendStream, StaticTrackSource, SubscribeNamespaceRequest, type SubscribeOptions, SubscribePublication, SubscribeRequest, type SubscribeUpdateOptions, type Track, type TrackSource };