@caprid/relay-websocket 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/README.md +66 -2
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +41 -0
- package/dist/errors.js.map +1 -0
- package/dist/fallback.d.ts +55 -0
- package/dist/fallback.d.ts.map +1 -0
- package/dist/fallback.js +208 -0
- package/dist/fallback.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/streams.d.ts +23 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +158 -0
- package/dist/streams.js.map +1 -0
- package/dist/transport.d.ts +34 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +215 -0
- package/dist/transport.js.map +1 -0
- package/package.json +33 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @caprid/relay-websocket
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Relay SDK's transport adapter for QMux over WebSocket. It carries MOQT on
|
|
4
|
+
[QMux](https://datatracker.ietf.org/doc/draft-ietf-quic-qmux/) (QUIC's streams over a reliable byte stream, wire
|
|
5
|
+
format `qmux-01`) inside one WebSocket connection, the way moq-relay serves it on TCP 443
|
|
6
|
+
([draft-lcurley-qmux-websocket](https://github.com/moq-dev/moq/blob/main/drafts/draft-lcurley-qmux-websocket.md)). It
|
|
7
|
+
reaches the relay where WebTransport cannot: networks that block UDP, and browsers without a WebTransport that can
|
|
8
|
+
negotiate protocols. It works in browsers and in Node 24.
|
|
9
|
+
|
|
10
|
+
It follows the transport adapter contract in [`spec/transport-adapter.md`](../../../spec/transport-adapter.md), with
|
|
11
|
+
the deviations recorded there, and passes its conformance suite in Node, Chromium, Firefox and WebKit. QMux comes from
|
|
12
|
+
[`@moq/qmux`](https://www.npmjs.com/package/@moq/qmux), by the author of moq-relay's own QMux, at an exact version;
|
|
13
|
+
[ADR 0005](../../../docs/adr/0005-websocket-adapter-wraps-moq-qmux.md) records why.
|
|
14
|
+
|
|
15
|
+
The package is unpublished, like the rest of the SDK.
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
Pass one of its factories as the SDK's `createTransport`. Build it once and reuse it for every connection.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { connectRelaySubscriber } from '@caprid/relay';
|
|
23
|
+
import { createWebSocketTransport, withWebSocketFallback } from '@caprid/relay-websocket';
|
|
24
|
+
|
|
25
|
+
// WebTransport first; WebSocket when its handshake fails or takes longer than 4 s.
|
|
26
|
+
const subscriber = await connectRelaySubscriber({ url, getToken, createTransport: withWebSocketFallback() });
|
|
27
|
+
|
|
28
|
+
// Always WebSocket.
|
|
29
|
+
const other = await connectRelaySubscriber({ url, getToken, createTransport: createWebSocketTransport() });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `createWebSocketTransport()` dials the endpoint's `wss:` URL (`https:` becomes `wss:`, path and query unchanged, so
|
|
33
|
+
the token travels in the upgrade request), offering `qmux-01.moqt-22`, then `qmux-01.moqt-20`. Its factory declares
|
|
34
|
+
`framing: 'websocket'`.
|
|
35
|
+
- `withWebSocketFallback({ handshakeTimeoutMs, onFallback })` dials the runtime's `WebTransport`, and falls back to
|
|
36
|
+
WebSocket when that handshake fails or has not completed within `handshakeTimeoutMs` (default 4000). Where the runtime
|
|
37
|
+
has no usable `WebTransport` (Node, Safari without it) it dials WebSocket at once. `onFallback(reason)` is told each
|
|
38
|
+
time a connection falls back. The dials run one after the other, and every connection decides afresh. The factory's
|
|
39
|
+
`framing` and the transport's `carrier` say which transport is in use.
|
|
40
|
+
|
|
41
|
+
## What differs from WebTransport
|
|
42
|
+
|
|
43
|
+
- Every stream shares one TCP connection: a lost packet holds up every stream behind it (head-of-line blocking).
|
|
44
|
+
- No datagrams.
|
|
45
|
+
- A relay that refuses the token answers the WebSocket upgrade with HTTP 401, which no WebSocket API exposes, so the
|
|
46
|
+
SDK reports `TRANSPORT_ERROR` in phase `connecting`, not `UNAUTHORIZED`.
|
|
47
|
+
- A send stream's close resolves once the FIN is handed to the socket, not once the relay has it.
|
|
48
|
+
|
|
49
|
+
The relay's side, with measurements, is in [QMux over WebSocket](../../../spec/relay-interop.md#qmux-over-websocket).
|
|
50
|
+
|
|
51
|
+
## Trust
|
|
52
|
+
|
|
53
|
+
The adapter uses the runtime's WebSocket and its certificate checks. A browser offers no way to pin a WebSocket's
|
|
54
|
+
certificate. Node trusts the platform's roots, plus any in `NODE_EXTRA_CA_CERTS`, which Node reads only at start-up.
|
|
55
|
+
|
|
56
|
+
## Tests
|
|
57
|
+
|
|
58
|
+
- `pnpm test` runs the unit tests in `src/tests/` against an in-process accepting end over plain `ws://`.
|
|
59
|
+
- `pnpm test:conformance:websocket` runs the conformance suite in Node against `scripts/websocket-peer.js`, the
|
|
60
|
+
accepting end for QMux over WebSocket; `pnpm test:conformance:websocket:browsers` runs it in Chromium, Firefox and
|
|
61
|
+
WebKit (`BROWSERS=chromium` for one).
|
|
62
|
+
- `RELAY_RUNTIME=node-websocket,chromium-websocket pnpm test:relay` runs the live scenario over WebSocket.
|
|
63
|
+
|
|
64
|
+
## Stability
|
|
65
|
+
|
|
66
|
+
Before 1.0, a minor version can break the API. This package releases together with `@caprid/relay` at the same version;
|
|
67
|
+
see the [changelog](../../CHANGELOG.md).
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract's error shapes (spec/transport-adapter.md TA-22) for what `@moq/qmux` raises. Its stream errors already
|
|
3
|
+
* have the stream shape and pass through; a session failure becomes a {@link WebSocketSessionError}, which carries the
|
|
4
|
+
* peer's application close when there was one (TA-24).
|
|
5
|
+
*/
|
|
6
|
+
/** How `closed` resolves after an application close from either end (TA-9). */
|
|
7
|
+
export interface CloseInfo {
|
|
8
|
+
/** The application close code. */
|
|
9
|
+
closeCode: number;
|
|
10
|
+
/** The close reason. */
|
|
11
|
+
reason: string;
|
|
12
|
+
}
|
|
13
|
+
/** A session failure (TA-22): the session is over, or the dial failed. */
|
|
14
|
+
export declare class WebSocketSessionError extends Error {
|
|
15
|
+
/** Always `'WebSocketSessionError'`; not part of the contract, which classifies by `source`. */
|
|
16
|
+
readonly name = "WebSocketSessionError";
|
|
17
|
+
/** Always `'session'`. */
|
|
18
|
+
readonly source = "session";
|
|
19
|
+
/** The peer's application close code, when the peer closed the session (TA-24). */
|
|
20
|
+
readonly closeCode?: number;
|
|
21
|
+
/** The peer's close reason, when the peer closed the session (TA-24). */
|
|
22
|
+
readonly reason?: string;
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
close?: CloseInfo | undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** The code a reset or a stop carries for `reason` (TA-17): its integer `streamErrorCode` from 0 to 2³²−1, else 0. */
|
|
29
|
+
export declare function resetCode(reason: unknown): number;
|
|
30
|
+
/**
|
|
31
|
+
* The reason handed to `@moq/qmux` for a reset or a stop with `reason`'s code. It reads `streamErrorCode` by field and
|
|
32
|
+
* wraps it to 32 bits (`-1` would go out as 2³²−1), so the code is checked here first.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resetReason(reason: unknown): {
|
|
35
|
+
streamErrorCode: number;
|
|
36
|
+
};
|
|
37
|
+
/** Whether `error` is a stream failure: the peer reset or stopped the stream (TA-19, TA-20). */
|
|
38
|
+
export declare function isStreamError(error: unknown): boolean;
|
|
39
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,gGAAgG;IAChG,SAAkB,IAAI,2BAA2B;IACjD,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,aAAa;IAC5B,mFAAmF;IACnF,SAAiB,SAAS,CAAC,EAAE,MAAM,CAAC;IACpC,yEAAyE;IACzE,SAAiB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;KAAO;CAO9F;AAED,sHAAsH;AACtH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAMjD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,CAExE;AAMD,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract's error shapes (spec/transport-adapter.md TA-22) for what `@moq/qmux` raises. Its stream errors already
|
|
3
|
+
* have the stream shape and pass through; a session failure becomes a {@link WebSocketSessionError}, which carries the
|
|
4
|
+
* peer's application close when there was one (TA-24).
|
|
5
|
+
*/
|
|
6
|
+
/** A session failure (TA-22): the session is over, or the dial failed. */
|
|
7
|
+
export class WebSocketSessionError extends Error {
|
|
8
|
+
/** Always `'WebSocketSessionError'`; not part of the contract, which classifies by `source`. */
|
|
9
|
+
name = 'WebSocketSessionError';
|
|
10
|
+
/** Always `'session'`. */
|
|
11
|
+
source = 'session';
|
|
12
|
+
constructor(message, options = {}) {
|
|
13
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
14
|
+
if (options.close) {
|
|
15
|
+
this.closeCode = options.close.closeCode;
|
|
16
|
+
this.reason = options.close.reason;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The code a reset or a stop carries for `reason` (TA-17): its integer `streamErrorCode` from 0 to 2³²−1, else 0. */
|
|
21
|
+
export function resetCode(reason) {
|
|
22
|
+
const code = typeof reason === 'object' && reason !== null
|
|
23
|
+
? reason.streamErrorCode
|
|
24
|
+
: undefined;
|
|
25
|
+
return typeof code === 'number' && Number.isInteger(code) && code >= 0 && code <= 0xffff_ffff ? code : 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The reason handed to `@moq/qmux` for a reset or a stop with `reason`'s code. It reads `streamErrorCode` by field and
|
|
29
|
+
* wraps it to 32 bits (`-1` would go out as 2³²−1), so the code is checked here first.
|
|
30
|
+
*/
|
|
31
|
+
export function resetReason(reason) {
|
|
32
|
+
return { streamErrorCode: resetCode(reason) };
|
|
33
|
+
}
|
|
34
|
+
function sourceOf(error) {
|
|
35
|
+
return typeof error === 'object' && error !== null ? error.source : undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Whether `error` is a stream failure: the peer reset or stopped the stream (TA-19, TA-20). */
|
|
38
|
+
export function isStreamError(error) {
|
|
39
|
+
return sourceOf(error) === 'stream';
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=errors.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AAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAE,KAA8B,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1G,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebTransport first, then QMux over WebSocket: the fallback policy (spec/behavior.md, "Transport fallback"). One
|
|
3
|
+
* transport stands for whichever dial wins, so the SDK's connect call sees a single factory.
|
|
4
|
+
*/
|
|
5
|
+
import type { BidirectionalStreamLike, MoqtSendStreamOptions, MoqtTransport } from '@caprid/moq-core';
|
|
6
|
+
import { type CloseInfo } from './errors.js';
|
|
7
|
+
/** Which transport a {@link FallbackTransport} runs on. */
|
|
8
|
+
export type FallbackCarrier = 'webtransport' | 'websocket';
|
|
9
|
+
/** Options for {@link withWebSocketFallback}. */
|
|
10
|
+
export interface WebSocketFallbackOptions {
|
|
11
|
+
/**
|
|
12
|
+
* How long the WebTransport handshake may take before the dial gives up on it and opens a WebSocket instead, in
|
|
13
|
+
* milliseconds. Default 4000: Chromium itself gives up on an unanswered handshake after about 4 seconds. Keep it
|
|
14
|
+
* well inside the connection's `connectTimeoutMs`, which covers both handshakes and SETUP.
|
|
15
|
+
*/
|
|
16
|
+
handshakeTimeoutMs?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Called once when a dial falls back to WebSocket, with why WebTransport was not used: its handshake failed or timed
|
|
19
|
+
* out (the error), or the runtime has no usable `WebTransport` (`undefined`). For logging; it cannot stop the
|
|
20
|
+
* fallback.
|
|
21
|
+
*/
|
|
22
|
+
onFallback?: (reason: unknown) => void;
|
|
23
|
+
}
|
|
24
|
+
/** The handshake timeout `value` gives, 4 s when it is undefined; a TypeError or RangeError for one a timer cannot hold. */
|
|
25
|
+
export declare function assertHandshakeTimeout(value: unknown): number;
|
|
26
|
+
/**
|
|
27
|
+
* A transport that dials WebTransport and falls back to QMux over WebSocket when that handshake fails or takes longer
|
|
28
|
+
* than the timeout. Before `ready` it stands in for whichever dial is in progress; after, it is the winner's.
|
|
29
|
+
*/
|
|
30
|
+
export declare class FallbackTransport implements MoqtTransport {
|
|
31
|
+
#private;
|
|
32
|
+
/** Resolves once one of the dials is ready; rejects with the WebSocket dial's failure, or when closed first. */
|
|
33
|
+
readonly ready: Promise<void>;
|
|
34
|
+
/** The winner's `closed`; rejects with the dial's failure when neither dial came up (TA-9). */
|
|
35
|
+
readonly closed: Promise<CloseInfo>;
|
|
36
|
+
/** The winner's incoming unidirectional streams. */
|
|
37
|
+
readonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;
|
|
38
|
+
/** The winner's incoming bidirectional streams. */
|
|
39
|
+
readonly incomingBidirectionalStreams: ReadableStream<BidirectionalStreamLike>;
|
|
40
|
+
constructor(url: string, protocols: readonly string[], options?: WebSocketFallbackOptions);
|
|
41
|
+
/** The transport the session runs on: the one in progress before `ready`, the winner after. */
|
|
42
|
+
get carrier(): FallbackCarrier | undefined;
|
|
43
|
+
/** The protocol the winner's peer selected (TA-8); empty until `ready` resolves. */
|
|
44
|
+
get protocol(): string;
|
|
45
|
+
createUnidirectionalStream(options?: MoqtSendStreamOptions): Promise<WritableStream<Uint8Array>>;
|
|
46
|
+
createBidirectionalStream(): Promise<BidirectionalStreamLike>;
|
|
47
|
+
/** Close the winner (TA-10); before `ready`, cancel whichever dial is in progress (TA-11). */
|
|
48
|
+
close(info?: {
|
|
49
|
+
closeCode?: number;
|
|
50
|
+
reason?: string;
|
|
51
|
+
}): void;
|
|
52
|
+
}
|
|
53
|
+
/** The `wss:` URL for an `https:` endpoint (and `ws:` for `http:`), path and query unchanged. */
|
|
54
|
+
export declare function toWebSocketUrl(url: string): string;
|
|
55
|
+
//# sourceMappingURL=fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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AC,CAAC;IAIhG,yBAAyB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAInE,8FAA8F;IAC9F,KAAK,CAAC,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;CAsIhE;AAED,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAYlD"}
|
package/dist/fallback.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { WebSocketSessionError } from './errors.js';
|
|
2
|
+
import { WebSocketTransport } from './transport.js';
|
|
3
|
+
/** The runtime's WebTransport, when it can negotiate protocols; Deno 2.x has one that cannot. */
|
|
4
|
+
function usableWebTransport() {
|
|
5
|
+
if (typeof WebTransport === 'undefined')
|
|
6
|
+
return undefined;
|
|
7
|
+
return 'protocol' in WebTransport.prototype ? WebTransport : undefined;
|
|
8
|
+
}
|
|
9
|
+
/** The handshake timeout `value` gives, 4 s when it is undefined; a TypeError or RangeError for one a timer cannot hold. */
|
|
10
|
+
export function assertHandshakeTimeout(value) {
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return 4_000;
|
|
13
|
+
if (typeof value !== 'number')
|
|
14
|
+
throw new TypeError('handshakeTimeoutMs must be a number of milliseconds');
|
|
15
|
+
if (!Number.isFinite(value) || value <= 0 || value > 2_147_483_647)
|
|
16
|
+
throw new RangeError('handshakeTimeoutMs must be between 0 (exclusive) and 2147483647 milliseconds');
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
class HandshakeTimeout extends Error {
|
|
20
|
+
name = 'HandshakeTimeout';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A transport that dials WebTransport and falls back to QMux over WebSocket when that handshake fails or takes longer
|
|
24
|
+
* than the timeout. Before `ready` it stands in for whichever dial is in progress; after, it is the winner's.
|
|
25
|
+
*/
|
|
26
|
+
export class FallbackTransport {
|
|
27
|
+
/** Resolves once one of the dials is ready; rejects with the WebSocket dial's failure, or when closed first. */
|
|
28
|
+
ready;
|
|
29
|
+
/** The winner's `closed`; rejects with the dial's failure when neither dial came up (TA-9). */
|
|
30
|
+
closed;
|
|
31
|
+
/** The winner's incoming unidirectional streams. */
|
|
32
|
+
incomingUnidirectionalStreams;
|
|
33
|
+
/** The winner's incoming bidirectional streams. */
|
|
34
|
+
incomingBidirectionalStreams;
|
|
35
|
+
#current;
|
|
36
|
+
#carrier;
|
|
37
|
+
#winner;
|
|
38
|
+
#cancelled = false;
|
|
39
|
+
#won;
|
|
40
|
+
constructor(url, protocols, options = {}) {
|
|
41
|
+
const timeoutMs = assertHandshakeTimeout(options.handshakeTimeoutMs);
|
|
42
|
+
this.#won = this.#dial(url, protocols, timeoutMs, options.onFallback);
|
|
43
|
+
this.#won.catch(() => { });
|
|
44
|
+
this.ready = this.#won.then(() => undefined);
|
|
45
|
+
this.closed = this.#won.then((winner) => winner.closed);
|
|
46
|
+
this.closed.catch(() => { });
|
|
47
|
+
this.incomingUnidirectionalStreams = this.#incoming((winner) => winner.incomingUnidirectionalStreams);
|
|
48
|
+
this.incomingBidirectionalStreams = this.#incoming((winner) => winner.incomingBidirectionalStreams);
|
|
49
|
+
}
|
|
50
|
+
/** The transport the session runs on: the one in progress before `ready`, the winner after. */
|
|
51
|
+
get carrier() {
|
|
52
|
+
return this.#carrier;
|
|
53
|
+
}
|
|
54
|
+
/** The protocol the winner's peer selected (TA-8); empty until `ready` resolves. */
|
|
55
|
+
get protocol() {
|
|
56
|
+
return this.#winner?.protocol ?? '';
|
|
57
|
+
}
|
|
58
|
+
async createUnidirectionalStream(options) {
|
|
59
|
+
return (await this.#won).createUnidirectionalStream(options);
|
|
60
|
+
}
|
|
61
|
+
async createBidirectionalStream() {
|
|
62
|
+
return (await this.#won).createBidirectionalStream();
|
|
63
|
+
}
|
|
64
|
+
/** Close the winner (TA-10); before `ready`, cancel whichever dial is in progress (TA-11). */
|
|
65
|
+
close(info = {}) {
|
|
66
|
+
if (!this.#winner)
|
|
67
|
+
this.#cancelled = true;
|
|
68
|
+
try {
|
|
69
|
+
this.#current?.close(info);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// A failed handshake may leave a transport that already refuses close().
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async #dial(url, protocols, timeoutMs, onFallback) {
|
|
76
|
+
const NativeWebTransport = usableWebTransport();
|
|
77
|
+
let fallbackReason;
|
|
78
|
+
let webTransport;
|
|
79
|
+
if (NativeWebTransport) {
|
|
80
|
+
try {
|
|
81
|
+
webTransport = new NativeWebTransport(url, { protocols: [...protocols] });
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// A runtime that refuses the dial outright (a policy, a URL it will not take) falls back too.
|
|
85
|
+
fallbackReason = error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (webTransport) {
|
|
89
|
+
webTransport.closed.catch(() => { });
|
|
90
|
+
this.#current = webTransport;
|
|
91
|
+
this.#carrier = 'webtransport';
|
|
92
|
+
let timer;
|
|
93
|
+
const timeout = new Promise((_, reject) => {
|
|
94
|
+
timer = setTimeout(() => reject(new HandshakeTimeout(`the WebTransport handshake took longer than ${timeoutMs} ms`)), timeoutMs);
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
await Promise.race([webTransport.ready, timeout]);
|
|
98
|
+
this.#cancelIfClosed();
|
|
99
|
+
this.#winner = webTransport;
|
|
100
|
+
return this.#winner;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
this.#cancelIfClosed();
|
|
104
|
+
fallbackReason = error;
|
|
105
|
+
try {
|
|
106
|
+
webTransport.close();
|
|
107
|
+
}
|
|
108
|
+
catch { }
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
onFallback?.(fallbackReason);
|
|
116
|
+
}
|
|
117
|
+
catch { }
|
|
118
|
+
const webSocket = new WebSocketTransport(toWebSocketUrl(url), protocols);
|
|
119
|
+
this.#current = webSocket;
|
|
120
|
+
this.#carrier = 'websocket';
|
|
121
|
+
await webSocket.ready;
|
|
122
|
+
this.#cancelIfClosed();
|
|
123
|
+
this.#winner = webSocket;
|
|
124
|
+
return webSocket;
|
|
125
|
+
}
|
|
126
|
+
/** Throws once close() came while a dial was in progress (TA-11). */
|
|
127
|
+
#cancelIfClosed() {
|
|
128
|
+
if (!this.#cancelled)
|
|
129
|
+
return;
|
|
130
|
+
try {
|
|
131
|
+
this.#current?.close();
|
|
132
|
+
}
|
|
133
|
+
catch { }
|
|
134
|
+
throw new WebSocketSessionError('the dial was cancelled');
|
|
135
|
+
}
|
|
136
|
+
/** The winner's incoming streams, one at a time; the readable ends with the winner's (TA-12). */
|
|
137
|
+
#incoming(select) {
|
|
138
|
+
let reader;
|
|
139
|
+
let cancelled;
|
|
140
|
+
return new ReadableStream({
|
|
141
|
+
start: (controller) => {
|
|
142
|
+
this.#won.then((winner) => {
|
|
143
|
+
// Cancelled before the dial was won: the winner's streams are refused, not left unread.
|
|
144
|
+
if (cancelled) {
|
|
145
|
+
select(winner)
|
|
146
|
+
.cancel(cancelled.reason)
|
|
147
|
+
.catch(() => { });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
reader = select(winner).getReader();
|
|
151
|
+
reader.closed.then(() => {
|
|
152
|
+
try {
|
|
153
|
+
controller.close();
|
|
154
|
+
}
|
|
155
|
+
catch { }
|
|
156
|
+
}, (error) => {
|
|
157
|
+
try {
|
|
158
|
+
controller.error(error);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
});
|
|
162
|
+
}, (error) => {
|
|
163
|
+
try {
|
|
164
|
+
controller.error(error);
|
|
165
|
+
}
|
|
166
|
+
catch { }
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
pull: async (controller) => {
|
|
170
|
+
try {
|
|
171
|
+
await this.#won;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// `start` took the reader in the turn the dial was won, ahead of any pull.
|
|
177
|
+
const result = await reader.read().catch(() => undefined);
|
|
178
|
+
if (!result || result.done)
|
|
179
|
+
return;
|
|
180
|
+
try {
|
|
181
|
+
controller.enqueue(result.value);
|
|
182
|
+
}
|
|
183
|
+
catch { }
|
|
184
|
+
},
|
|
185
|
+
cancel: async (reason) => {
|
|
186
|
+
if (reader)
|
|
187
|
+
await reader.cancel(reason);
|
|
188
|
+
else
|
|
189
|
+
cancelled = { reason };
|
|
190
|
+
},
|
|
191
|
+
}, { highWaterMark: 0 });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** The `wss:` URL for an `https:` endpoint (and `ws:` for `http:`), path and query unchanged. */
|
|
195
|
+
export function toWebSocketUrl(url) {
|
|
196
|
+
const parsed = new URL(url);
|
|
197
|
+
switch (parsed.protocol) {
|
|
198
|
+
case 'https:':
|
|
199
|
+
case 'wss:':
|
|
200
|
+
return `wss:${url.slice(parsed.protocol.length)}`;
|
|
201
|
+
case 'http:':
|
|
202
|
+
case 'ws:':
|
|
203
|
+
return `ws:${url.slice(parsed.protocol.length)}`;
|
|
204
|
+
default:
|
|
205
|
+
throw new TypeError(`a WebSocket transport dials an https: URL, not ${parsed.protocol}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=fallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../src/fallback.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAwBpD,iGAAiG;AACjG,SAAS,kBAAkB;IACzB,IAAI,OAAO,YAAY,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IAC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