Constructor
new Session(webTransportnon-null, controlWriternon-null, dialectnon-null, confignon-null, messageWriterFactory)
Parameters:
| Name | Type | Description |
|---|---|---|
webTransport |
WebTransport | |
controlWriter |
shaka.msf.Writer | Our outgoing control stream, already carrying our SETUP. |
dialect |
shaka.extern.MsfDialect | |
config |
shaka.extern.MsfManifestConfiguration | |
messageWriterFactory |
function | Builds a writer for this draft's control messages. |
- Implements:
- Source:
Members
END_OF_RANGE_ :Array<number>
The Serialization Flags values that mark an End of Range: Objects that do
not exist, whose status is unknown, and (from draft-20) that timed out.
Type:
- Array<number>
FetchFlags_ :number
The Serialization Flags of an Object on a fetch stream (draft-18 section
11.4.4.1; draft-20 and draft-21 are the same).
Type:
- number
Properties:
| Name | Value | Type | Description |
|---|---|---|---|
SUBGROUP_MASK |
3 | number | |
SUBGROUP_ZERO |
0 | number | |
SUBGROUP_PRIOR |
1 | number | |
SUBGROUP_PRIOR_PLUS_ONE |
2 | number | |
SUBGROUP_PRESENT |
3 | number | |
OBJECT_ID_DELTA |
4 | number | |
GROUP_ID_DELTA |
8 | number | |
PRIORITY |
16 | number | |
PROPERTIES |
32 | number | |
DATAGRAM |
64 | number | |
MAX |
127 | number |
JOIN_TIMEOUT_SEC_ :number
How long a subscription that joins the current Group holds its own Objects
back waiting for that Group, in seconds. Only a publisher that ignores the
request runs into it.
Type:
- number
LARGEST_OBJECT_ :number
The LARGEST_OBJECT Message Parameter type.
Type:
- number
LOCATION_FILTER_FIELDS_ :Map<number, number>
How many var ints follow each draft-22 Location Filter Type (draft-22
section 9.20.9): none for None (0x00) and Next Object (0x05), and for the
rest as many as the type's own value.
Type:
- Map<number, number>
fetches_ :Map<bigint, shaka.msf.draft18.Session.PendingFetch>
The fetches in flight, by request ID. `accepted` settles once the
FETCH_OK or REQUEST_ERROR arrives: a publisher may start sending Objects
before it answers, and they are held until then, because the Track
Properties that say how to read them are in the FETCH_OK.
Type:
- Map<bigint, shaka.msf.draft18.Session.PendingFetch>
- Source:
joinGates_ :Map<bigint, !shaka.msf.JoinGate>
What puts the Objects of a subscription that joins the current Group in
order, by track alias, until the subscription goes.
Type:
- Map<bigint, !shaka.msf.JoinGate>
joiningFetches_ :Map<bigint, bigint>
The Request ID of the Joining FETCH sent for a subscription, by track
alias, so that withdrawing the subscription withdraws it too.
Type:
- Map<bigint, bigint>
messageWriterFactory_ :function(): !shaka.msf.draft18.MessageWriter
Type:
- function(): !shaka.msf.draft18.MessageWriter
- Source:
parameterFormat_ :shaka.msf.draft18.MessageWriter
Kept only to ask how this draft encodes each Message Parameter, which
the message layer owns because draft-22 changed one of them.
Type:
- Source:
publishNamespaceCallbacks_ :Set<function(Array<string>)>
Type:
- Set<function(Array<string>)>
- Source:
subscribeStreams_ :Map<bigint, {reader: !shaka.msf.Reader, writer: !shaka.msf.Writer}>
The request stream each subscription lives on, by track alias. The
stream IS the subscription, so it is what has to be torn down to
withdraw one.
Type:
- Map<bigint, {reader: !shaka.msf.Reader, writer: !shaka.msf.Writer}>
trackProperties_ :Map<bigint, !Uint8Array>
The Track Properties of each subscription's SUBSCRIBE_OK, by track
alias, for subscriptions that had any.
Type:
- Map<bigint, !Uint8Array>
Methods
awaitResponse_(readernon-null, okType, description) → {Promise<{type: number, length: number}>}
Waits for the response to a request, which is either a REQUEST_OK-shaped
acknowledgement or a REQUEST_ERROR.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | |
okType |
number | The success message type for this request. |
description |
string | Used in error messages. |
Returns:
The response header.
The reader is left positioned just after it.
- Type
- Promise<{type: number, length: number}>
buildSubscribeParams_(writernon-null, startLocationopt, nullable) → {Array<shaka.msf.Utils.KeyValuePair>}
Builds the parameter list carried by SUBSCRIBE. Draft-16 moved the
subscriber priority, forward flag, filter and group order out of fixed
fields into parameters, and draft-18 keeps them there. Every one of them
has a default, so the shortest legal list is the empty one.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
writer |
shaka.msf.draft18.MessageWriter | The writer this SUBSCRIBE is going out on, which owns how a start Location is encoded. | |
startLocation |
shaka.msf.Utils.Location |
<optional> <nullable> |
Returns:
- Type
- Array<shaka.msf.Utils.KeyValuePair>
close(codeopt, reasonopt) → {Promise}
Closes the underlying transport.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
code |
number |
<optional> |
|
reason |
string |
<optional> |
- Implements:
- Source:
Returns:
- Type
- Promise
configure(confignon-null)
Parameters:
| Name | Type | Description |
|---|---|---|
config |
shaka.extern.MsfManifestConfiguration |
- Implements:
- Source:
deliver_(trackAlias, obj) → {Promise}
Delivers an object, waiting briefly for the subscription to be registered
if the data stream beat the SUBSCRIBE_OK.
Parameters:
| Name | Type | Description |
|---|---|---|
trackAlias |
bigint | |
obj |
shaka.msf.Utils.MOQObject |
Returns:
- Type
- Promise
fetch(namespace, trackName, callback) → {Promise}
Retrieves a track once rather than subscribing to it. Resolves when the
request has been accepted; objects arrive on the callback.
Parameters:
| Name | Type | Description |
|---|---|---|
namespace |
Array<string> | |
trackName |
string | |
callback |
shaka.extern.MsfObjectCallback |
- Implements:
- Source:
Returns:
- Type
- Promise
forgetFetch_(requestId)
Stops handing on the Objects of a fetch, including the ones of a stream
that is already being read.
Parameters:
| Name | Type | Description |
|---|---|---|
requestId |
bigint |
getNextRequestId_() → {bigint}
Client Request IDs are even and start at 0.
Returns:
- Type
- bigint
handleFetchStream_(readernon-null) → {Promise}
Reads a fetch stream: a FETCH_HEADER naming the request, then Objects
until the stream ends. The request is a FETCH, or a SUBSCRIBE whose
FILL_PARAMETERS asked for Groups already published.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader |
Returns:
- Type
- Promise
handleIncomingStream_(streamnon-null) → {Promise}
Parameters:
| Name | Type | Description |
|---|---|---|
stream |
ReadableStream |
Returns:
- Type
- Promise
handlePeerControlStream_(readernon-null) → {Promise}
Reads the peer's SETUP and then keeps the control stream open for GOAWAY
and namespace announcements.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | Positioned just after the SETUP type. |
Returns:
- Type
- Promise
handleSubgroupStream_(readernon-null, streamType) → {Promise}
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | |
streamType |
bigint |
Returns:
- Type
- Promise
isSubgroupStreamType_(streamType) → {boolean}
Draft-18 SUBGROUP_HEADER types have bit 4 set, spanning 0x10-0x1F,
0x30-0x3F, 0x50-0x5F and 0x70-0x7F.
Parameters:
| Name | Type | Description |
|---|---|---|
streamType |
bigint |
Returns:
- Type
- boolean
joinSubscription_(subscribeRequestId, trackAlias, gatenon-null, description) → {Promise}
Sends the Joining FETCH that delivers a subscription's current Group from
its first Object, which the subscription itself starts after.
Nothing waits on it. It fails when nothing has been published on the
track yet, and then the subscription delivers everything there is.
Parameters:
| Name | Type | Description |
|---|---|---|
subscribeRequestId |
bigint | |
trackAlias |
bigint | |
gate |
shaka.msf.JoinGate | |
description |
string |
Returns:
- Type
- Promise
listenOnRequestStream_(readernon-null, trackAlias) → {Promise}
Keeps reading a subscription's request stream after the SUBSCRIBE_OK so
that PUBLISH_DONE closes the track.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | |
trackAlias |
bigint |
Returns:
- Type
- Promise
logStreamFailure_(context, error)
Streams end for reasons that are not a failure of ours: the peer resets
one it no longer needs, and every stream on a session fails at once when
the session goes away, which the session itself already reports. Neither
is worth an error in the log.
Parameters:
| Name | Type | Description |
|---|---|---|
context |
string | |
error |
* |
onNamespacePublished(callback) → {function}
Registers a callback for namespaces the peer announces it can serve.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function |
- Implements:
- Source:
Returns:
Unregisters the callback.
- Type
- function
openRequest_(requestBytesnon-null) → {Promise<{reader: !shaka.msf.Reader, writer: !shaka.msf.Writer}>}
Opens a bidirectional stream, writes a request onto it and returns both
halves: the reader the response arrives on, and the writer, which is
kept only so the stream can be torn down to withdraw the request. The
stream is the correlation, so nothing is registered anywhere.
Parameters:
| Name | Type | Description |
|---|---|---|
requestBytes |
Uint8Array |
Returns:
- Type
- Promise<{reader: !shaka.msf.Reader, writer: !shaka.msf.Writer}>
readFetchObjects_(readernon-null, requestId, pending) → {Promise}
Reads the Objects of a fetch stream, past its FETCH_HEADER, and hands
them to the fetch's callback until the stream ends or the fetch is
withdrawn.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | |
requestId |
bigint | |
pending |
shaka.msf.draft18.Session.PendingFetch |
Returns:
- Type
- Promise
readMessageHeader_(readernon-null) → {Promise<{type: number, length: number}>}
Reads one control message header from a stream.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader |
Returns:
- Type
- Promise<{type: number, length: number}>
readResponseTail_(payloadnon-null, offset, leadingVarInts, description) → {shaka.msf.draft18.Session.ResponseTail}
Finds the Track Properties at the end of a SUBSCRIBE_OK or FETCH_OK
payload, and the LARGEST_OBJECT parameter on the way. The Track
Properties run to the end of the message with no length of their own, so
they start wherever the Parameters before them end.
Parameters are the obstacle: since draft-18 a Parameter's value is
encoded however its type says, rather than by the parity rule Properties
use, so an unknown type cannot be stepped over. Only EXPIRES and
LARGEST_OBJECT may appear in these two responses at all; the others the
message layer knows are stepped over too so that a lenient publisher
costs us nothing.
Parameters:
| Name | Type | Description |
|---|---|---|
payload |
Uint8Array | |
offset |
number | Where the fields still to be read begin. |
leadingVarInts |
number | How many var int fields sit between the offset and the Number of Parameters field. |
description |
string | Used in log messages. |
Returns:
readRest_(readernon-null, header, bytesConsumed) → {Promise<!Uint8Array>}
Reads whatever is left of a message payload the caller stopped reading
part way through.
Parameters:
| Name | Type | Description |
|---|---|---|
reader |
shaka.msf.Reader | |
header |
{type: number, length: number} | |
bytesConsumed |
number |
Returns:
- Type
- Promise<!Uint8Array>
release()
Request that this object release all internal references.
- Inherited From:
- Implements:
- Source:
sendFetch_(requestBytesnon-null, requestId, callback, description, onEndopt, nullable) → {Promise}
Sends a FETCH and waits for its answer. The Objects arrive on a stream of
their own, which handleFetchStream_ hands to the callback.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
requestBytes |
Uint8Array | ||
requestId |
bigint | ||
callback |
shaka.msf.Utils.ObjectCallback | ||
description |
string | ||
onEnd |
?function()= |
<optional> <nullable> |
Called once no more Objects will be handed to the callback. |
Returns:
- Type
- Promise
startListeningForStreams_() → {Promise}
Reads incoming unidirectional streams. Each is either the peer's control
stream, which begins with SETUP, or object data.
Returns:
- Type
- Promise
subscribe(namespace, trackName, callback, startLocationopt, nullable, joinCurrentGroupopt) → {Promise<bigint>}
Subscribes to a track, delivering its objects to the callback until
unsubscribed. Resolves with the track alias assigned by the publisher.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
namespace |
Array<string> | ||
trackName |
string | ||
callback |
shaka.extern.MsfObjectCallback | ||
startLocation |
shaka.extern.MsfLocation |
<optional> <nullable> |
Where delivery should begin, for a subscription that is not meant to start at the live edge, which is what a seek into published-but-not-yet-received content needs. Every draft carries it, though not alike: draft-18 in the SUBSCRIPTION_FILTER parameter, draft-20 in LOCATION_FILTER. A publisher may still refuse it, in which case the subscription fails rather than silently starting somewhere else. |
joinCurrentGroup |
boolean |
<optional> |
Also deliver the Group the live edge is in from its first Object, rather than only what comes after the subscription starts. MSF requires it of the catalog, whose current state is the first Object of the latest Group plus the ones after it. Draft-18 does it with a Joining FETCH and draft-20 with FILL_PARAMETERS; the Objects arrive on the same callback as the subscription's, in Location order and without repeats. A session that cannot do it, or whose publisher does not answer in time, delivers only what the subscription does. |
- Implements:
- Source:
Returns:
- Type
- Promise<bigint>
unsubscribe(trackAlias) → {Promise}
Stops delivery for a subscription.
Parameters:
| Name | Type | Description |
|---|---|---|
trackAlias |
bigint |
- Implements:
- Source:
Returns:
- Type
- Promise
watchForSessionEnd_()
A session the peer hangs up on resets every stream on it at once, and
each of those failures would otherwise be logged as an error of its own.
Watch the transport instead: once the session is gone, its stream errors
are expected, and the reason the session ended is the one worth reporting.
Type Definitions
PendingFetch
Type:
- {callback: shaka.msf.Utils.ObjectCallback, accepted: !Promise.PromiseWithResolvers<boolean>, trackProperties: ?Uint8Array, onEnd: ?function()}
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
callback |
shaka.msf.Utils.ObjectCallback | Receives the fetched Objects. | |
accepted |
Promise.PromiseWithResolvers<boolean> | Resolves with true on FETCH_OK and with false when the fetch fails or the session is released. It never rejects, so nothing waiting on it can leave a rejection unhandled. | |
trackProperties |
Uint8Array |
<nullable> |
The Track Properties of the FETCH_OK, once it has arrived. |
onEnd |
function |
<nullable> |
Called once no more Objects will be handed to the callback: the fetch stream has ended or failed, or the fetch has been refused or withdrawn. |
ResponseTail
Type:
- {largestObject: (?shaka.msf.Utils.Location|undefined), trackProperties: ?Uint8Array}
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
largestObject |
shaka.msf.Utils.Location | undefined | The LARGEST_OBJECT parameter; null when the response has none, which means nothing has been published on the track, and undefined when the parameters could not be read. | |
trackProperties |
Uint8Array |
<nullable> |
The Track Properties block, or null when it is empty or cannot be located. |