Skip to content

Class: Subscription ​

Owns the single consumer-facing stream for a SUBSCRIBE that may be switched to a new track one or more times. A soft switch can keep producing from the old track for an unknown time after SUBSCRIBE_OK, and a second switch may be issued before the first target ever delivers anything, so only the first object actually delivered by the newest tracked request is the guarantee that nothing older will send again.

That first delivery is the handover, not the end of the old track: a soft switch leaves it delivering up to the group the new one starts at, so the two meet without a hole. Those objects keep coming through here until the publisher says the subscription is done, or until it has been quiet long enough to say so itself.

Constructors ​

Constructor ​

new Subscription(initial): Subscription

Parameters ​

initial ​

SubscribeRequest

Returns ​

Subscription

Properties ​

done ​

readonly done: Promise<PublishDone | undefined>

Resolves once every tracked request is over, with the newest one's PUBLISH_DONE, or undefined if it ended without one. Never rejects.


drainTimeoutMs ​

drainTimeoutMs: number = DEFAULT_SWITCH_DRAIN_TIMEOUT_MS

How long a drained request may stay quiet before it is retired anyway, in milliseconds. The publisher normally ends the drain with a PUBLISH_DONE; this is what keeps a request that never gets one from being tracked forever.


objects ​

readonly objects: ObjectStream


onDrainDecision ​

onDrainDecision: (request) => boolean

Set by the client to decide whether draining a request should continue.

Parameters ​

request ​

SubscribeRequest

Returns ​

boolean


onSuperseded? ​

optional onSuperseded?: (superseded) => void

Set once by MOQtailClient.switch; invoked with everything older on cutover.

Parameters ​

superseded ​

SubscribeRequest[]

Returns ​

void


stream ​

readonly stream: ReadableStream<MoqtObject>

Accessors ​

newest ​

Get Signature ​

get newest(): SubscribeRequest

The request most recently switched to; must deliver data to win the handover.

Returns ​

SubscribeRequest


requests ​

Get Signature ​

get requests(): readonly SubscribeRequest[]

Requests still tracked, oldest first, draining ones last.

Returns ​

readonly SubscribeRequest[]

Methods ​

addSwitchTarget() ​

addSwitchTarget(request, drainSuperseded?): void

Track a newly issued switch target alongside whatever is still delivering.

drainSuperseded says what its handover does to the requests it takes over from: a soft switch leaves them delivering to the end of what the publisher was told to finish, a hard one retires them on the spot.

Parameters ​

request ​

SubscribeRequest

drainSuperseded? ​

boolean = false

Returns ​

void


clear() ​

clear(): void

Stop tracking everything (used when the whole switch chain is torn down at once).

Returns ​

void


deliver() ​

deliver(request, obj, previous?): boolean

Delivers an object received for request. The first object delivered by the newest tracked request retires everything older — only then is it guaranteed no more data is coming from them.

Returns true if the object was delivered to the caller, false if it was not consumed, and client should cancel the stream.

Parameters ​

request ​

SubscribeRequest

obj ​

MoqtObject

previous? ​

Location

Returns ​

boolean


drop() ​

drop(request): void

Stop tracking request (e.g. it naturally completed without ever losing/winning a handover).

Parameters ​

request ​

SubscribeRequest

Returns ​

void


output() ​

output(request, obj): void

Writes an object request released. While older requests still deliver, the newest one's ordered objects wait, so the old track's tail comes first.

Parameters ​

request ​

SubscribeRequest

obj ​

MoqtObject

Returns ​

void