@fails-components/webtransport 1.0.9 → 1.0.11

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.
Files changed (48) hide show
  1. package/dist/lib/http2/browser/browser.d.ts.map +1 -1
  2. package/dist/lib/http2/browser/browserparser.d.ts +4 -3
  3. package/dist/lib/http2/browser/browserparser.d.ts.map +1 -1
  4. package/dist/lib/http2/node/capsuleparser.d.ts +3 -2
  5. package/dist/lib/http2/node/capsuleparser.d.ts.map +1 -1
  6. package/dist/lib/http2/node/client.d.ts.map +1 -1
  7. package/dist/lib/http2/node/server.d.ts.map +1 -1
  8. package/dist/lib/http2/node/websocketparser.d.ts +7 -6
  9. package/dist/lib/http2/node/websocketparser.d.ts.map +1 -1
  10. package/dist/lib/http2/parserbase.d.ts +16 -4
  11. package/dist/lib/http2/parserbase.d.ts.map +1 -1
  12. package/dist/lib/http2/parserbasehttp2.d.ts +9 -1
  13. package/dist/lib/http2/parserbasehttp2.d.ts.map +1 -1
  14. package/dist/lib/http2/session.d.ts.map +1 -1
  15. package/dist/lib/index.node.d.ts +1 -1
  16. package/dist/lib/index.node.d.ts.map +1 -1
  17. package/dist/lib/index.types.d.ts +60 -0
  18. package/dist/lib/index.types.d.ts.map +1 -0
  19. package/dist/lib/types.d.ts +9 -2
  20. package/dist/lib/types.d.ts.map +1 -1
  21. package/dist/lib/webtransport.node.d.ts +1 -0
  22. package/dist/lib/webtransport.node.d.ts.map +1 -1
  23. package/lib/http2/browser/browser.js +2 -1
  24. package/lib/http2/browser/browserparser.js +43 -7
  25. package/lib/http2/node/capsuleparser.js +41 -10
  26. package/lib/http2/node/client.js +23 -5
  27. package/lib/http2/node/server.js +53 -16
  28. package/lib/http2/node/websocketparser.js +42 -20
  29. package/lib/http2/parserbase.js +44 -7
  30. package/lib/http2/parserbasehttp2.js +15 -2
  31. package/lib/http2/session.js +1 -5
  32. package/lib/index.browser.js +1 -0
  33. package/lib/index.node.js +2 -1
  34. package/lib/index.types.js +33 -0
  35. package/lib/types.ts +10 -2
  36. package/lib/webtransport.node.js +10 -1
  37. package/lib/webtransportbase.js +1 -1
  38. package/old_test/test.js +13 -1
  39. package/package.json +4 -3
  40. package/readme.md +4 -1
  41. package/test/bidirectional-streams.spec.js +31 -0
  42. package/test/datagrams.spec.js +12 -0
  43. package/test/fixtures/quiche.browser.js +2 -0
  44. package/test/fixtures/quiche.js +1 -0
  45. package/test/fixtures/server.js +24 -0
  46. package/test/session.spec.js +13 -3
  47. package/test/stream-limits.spec.js +12 -0
  48. package/test/unidirectional-streams.spec.js +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fails-components/webtransport",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "A component to add webtransport support (server and client) to node.js using libquiche",
5
5
  "exports": {
6
6
  ".": {
@@ -12,7 +12,7 @@
12
12
  "node": ">=16.5"
13
13
  },
14
14
  "type": "module",
15
- "types": "./dist/lib/index.d.ts",
15
+ "types": "./dist/lib/index.types.d.ts",
16
16
  "scripts": {
17
17
  "start": "node test/echoserver.js",
18
18
  "test": "npm run test:node && npm run test:node:http2 && npm run test:chromium && npm run test:chromium:http2:polyfill && npm run test:chromium:http2:ponyfill && npm run test:firefox:http2:polyfill && npm run test:firefox:http2:ponyfill && npm run test:webkit:http2:polyfill && npm run test:webkit:http2:ponyfill",
@@ -43,7 +43,7 @@
43
43
  "bugs": {
44
44
  "url": "https://github.com/fails-components/webtransport/issues"
45
45
  },
46
- "homepage": "https://github.com/fails-components/webtransport/main/#readme",
46
+ "homepage": "https://github.com/fails-components/webtransport/tree/master/main#readme",
47
47
  "dependencies": {
48
48
  "@types/debug": "^4.1.7",
49
49
  "bindings": "^1.5.0",
@@ -83,6 +83,7 @@
83
83
  },
84
84
  "browser": {
85
85
  "./test/fixtures/webtransport.js": "./test/fixtures/webtransport.browser.js",
86
+ "./test/fixtures/quiche.js": "./test/fixtures/quiche.browser.js",
86
87
  "./lib/webstreams.js": "./lib/webstreams.browser.js"
87
88
  }
88
89
  }
package/readme.md CHANGED
@@ -35,7 +35,7 @@ Note, that it is only partially implemented and also some http2 features require
35
35
  Use for the server side either `HttpServer` for http/2 and http/3 support (including WebTransport over WebSocket), Http3Server for http/3 only and Http2Server for http/2 only.
36
36
  For the client side pass the options `forceReliable`, `requireUnreliable` etc. to force/select a type of transport.
37
37
 
38
- **Note, that the http/2 webtransport protocol (not supported by any browser yet), is implemented without the support of receiving initial settings, which can cause a problem with the initial flow control of the WebTransport streams. This is a current limitation in node.js, but a patch to add support will soon be part of new node versions. Note, that for sending the required initial setting you need a very recent version (>=21.6.1) of node.js.** This limitation does not apply to the polyfill/ponyfill and the webtransport over websocket protocol.
38
+ **Note, that the http/2 webtransport protocol (not supported by any browser yet), requires support for sending and receiving initial a node version with support for receiving customSettings. Versions without support can cause a problem with the initial flow control of the WebTransport streams. Note, that for sending and receiving the required initial setting you need a very recent version (>=21.6.1 sending >= 21.7.0 receiving) of node.js.** This limitation does not apply to the polyfill/ponyfill and the webtransport over websocket protocol.
39
39
 
40
40
  The current proposal for the WebTransport over WebSocket protocol can be found [here] (https://datatracker.ietf.org/doc/draft-richter-webtransport-websocket/).
41
41
 
@@ -126,6 +126,9 @@ The `WebTransportSession` should behave most like a WebTransport object on the b
126
126
  ### Using a client
127
127
  The `WebTransport` object for node or the `WebTransportPonyfill`, `WebTransportPolyfill` objects for the browser, behave like the `WebTransport` client object for the browser with few additions and some missing features.
128
128
 
129
+ As the http/3 package is loaded dynamically and the WebTransport object is created synchronously, you may want to make sure, that the modules are already loaded. You can do so, by waiting for the promise `quicheLoaded` exported by the package.
130
+
131
+
129
132
  ## Specification divergence
130
133
 
131
134
  This module implements parts of the [WebTransport spec](https://datatracker.ietf.org/doc/html/draft-vvv-webtransport-quic-00) but not all of it.
@@ -6,6 +6,7 @@ import { readStream } from './fixtures/read-stream.js'
6
6
  import { writeStream } from './fixtures/write-stream.js'
7
7
  import { readCertHash } from './fixtures/read-cert-hash.js'
8
8
  import WebTransport from './fixtures/webtransport.js'
9
+ import { quicheLoaded } from './fixtures/quiche.js'
9
10
  import * as ui8 from 'uint8arrays'
10
11
  import {
11
12
  KNOWN_BYTES,
@@ -38,6 +39,17 @@ describe('bidirectional streams', function () {
38
39
  // @ts-ignore
39
40
  delete wtOptions.serverCertificateHashes
40
41
 
42
+ // @ts-ignore
43
+ beforeEach(async () => {
44
+ if (
45
+ process.env.USE_HTTP2 !== 'true' &&
46
+ process.env.USE_PONYFILL !== 'true' &&
47
+ process.env.USE_POLYFILL !== 'true'
48
+ ) {
49
+ await quicheLoaded
50
+ }
51
+ })
52
+
41
53
  // @ts-ignore
42
54
  afterEach(async () => {
43
55
  if (client != null) {
@@ -116,4 +128,23 @@ describe('bidirectional streams', function () {
116
128
  expect(result).to.have.property('reason', '')
117
129
  expect(result).to.have.property('closeCode', 0)
118
130
  })
131
+
132
+ it('receives data from server and checks receiving stream fin', async () => {
133
+ // client context - waits for the server to open a bidi stream then pipes it back to them
134
+ client = new WebTransport(
135
+ `${process.env.SERVER_URL}/bidirectional_server_fin_send`,
136
+ wtOptions
137
+ )
138
+ await client.ready
139
+
140
+ const bidiStream = await getReaderValue(client.incomingBidirectionalStreams)
141
+ const reader = bidiStream.readable.getReader()
142
+
143
+ while (true) {
144
+ const res = await reader.read()
145
+ if (res.done) {
146
+ break
147
+ }
148
+ }
149
+ })
119
150
  })
@@ -5,6 +5,7 @@ import { expect } from './fixtures/chai.js'
5
5
  import { readStream } from './fixtures/read-stream.js'
6
6
  import { readCertHash } from './fixtures/read-cert-hash.js'
7
7
  import { pTimeout } from './fixtures/p-timeout.js'
8
+ import { quicheLoaded } from './fixtures/quiche.js'
8
9
 
9
10
  /**
10
11
  * @template T
@@ -32,6 +33,17 @@ describe('datagrams', function () {
32
33
  // @ts-ignore
33
34
  delete wtOptions.serverCertificateHashes
34
35
 
36
+ // @ts-ignore
37
+ beforeEach(async () => {
38
+ if (
39
+ process.env.USE_HTTP2 !== 'true' &&
40
+ process.env.USE_PONYFILL !== 'true' &&
41
+ process.env.USE_POLYFILL !== 'true'
42
+ ) {
43
+ await quicheLoaded
44
+ }
45
+ })
46
+
35
47
  // @ts-ignore
36
48
  afterEach(async () => {
37
49
  if (client != null) {
@@ -0,0 +1,2 @@
1
+ const quicheLoaded = Promise.resolve()
2
+ export { quicheLoaded }
@@ -0,0 +1 @@
1
+ export { quicheLoaded } from '../../lib/index.node.js'
@@ -110,6 +110,30 @@ export async function createServer() {
110
110
  }
111
111
  },
112
112
 
113
+ // echo server, initiated by local
114
+ async () => {
115
+ for await (const session of getReaderStream(
116
+ server.sessionStream('/bidirectional_server_fin_send')
117
+ )) {
118
+ try {
119
+ // adapted from issue of achingbrain
120
+ const stream = await session.createBidirectionalStream()
121
+
122
+ const writer = stream.writable.getWriter()
123
+
124
+ await writer.ready
125
+
126
+ writer.write(Uint8Array.from([0, 1, 2, 3])).catch((err) => {
127
+ console.info('error writing to stream', err)
128
+ })
129
+
130
+ await writer.close()
131
+ } catch {
132
+ // in some tests the client closes the stream
133
+ }
134
+ }
135
+ },
136
+
113
137
  // echo datagrams, initiated by remote
114
138
  async () => {
115
139
  for await (const session of getReaderStream(
@@ -3,6 +3,7 @@
3
3
  import { readCertHash } from './fixtures/read-cert-hash.js'
4
4
  import WebTransport from './fixtures/webtransport.js'
5
5
  import { expect } from './fixtures/chai.js'
6
+ import { quicheLoaded } from './fixtures/quiche.js'
6
7
 
7
8
  /**
8
9
  * @template T
@@ -38,6 +39,17 @@ describe('session', function () {
38
39
  // @ts-ignore
39
40
  delete wtOptions.serverCertificateHashes
40
41
 
42
+ // @ts-ignore
43
+ beforeEach(async () => {
44
+ if (
45
+ process.env.USE_HTTP2 !== 'true' &&
46
+ process.env.USE_PONYFILL !== 'true' &&
47
+ process.env.USE_POLYFILL !== 'true'
48
+ ) {
49
+ await quicheLoaded
50
+ }
51
+ })
52
+
41
53
  // @ts-ignore
42
54
  afterEach(async () => {
43
55
  if (client != null) {
@@ -68,9 +80,7 @@ describe('session', function () {
68
80
 
69
81
  const result = await client.closed
70
82
  expect(result).to.have.property('closeCode', 7)
71
- if (process.env.USE_HTTP2 !== 'true')
72
- // unsupported for http2
73
- expect(result).to.have.property('reason', 'this is the reason')
83
+ expect(result).to.have.property('reason', 'this is the reason')
74
84
  })
75
85
  if (browser === 'firefox') this.timeout(31000) // really firefox?
76
86
  it('should error when connecting to a server that does not exist', async () => {
@@ -3,6 +3,7 @@
3
3
  import { readCertHash } from './fixtures/read-cert-hash.js'
4
4
  import WebTransport from './fixtures/webtransport.js'
5
5
  import { expect } from './fixtures/chai.js'
6
+ import { quicheLoaded } from './fixtures/quiche.js'
6
7
 
7
8
  /**
8
9
  * @template T
@@ -44,6 +45,17 @@ describe('streamlimits', function () {
44
45
  // @ts-ignore
45
46
  delete wtOptions.serverCertificateHashes
46
47
 
48
+ // @ts-ignore
49
+ beforeEach(async () => {
50
+ if (
51
+ process.env.USE_HTTP2 !== 'true' &&
52
+ process.env.USE_PONYFILL !== 'true' &&
53
+ process.env.USE_POLYFILL !== 'true'
54
+ ) {
55
+ await quicheLoaded
56
+ }
57
+ })
58
+
47
59
  // @ts-ignore
48
60
  afterEach(async () => {
49
61
  if (client != null) {
@@ -8,6 +8,7 @@ import { writeStream } from './fixtures/write-stream.js'
8
8
  import { readCertHash } from './fixtures/read-cert-hash.js'
9
9
  import * as ui8 from 'uint8arrays'
10
10
  import { KNOWN_BYTES, KNOWN_BYTES_LENGTH } from './fixtures/known-bytes.js'
11
+ import { quicheLoaded } from './fixtures/quiche.js'
11
12
 
12
13
  describe('unidirectional streams', function () {
13
14
  /** @type {import('../lib/dom').WebTransport | undefined} */
@@ -29,6 +30,17 @@ describe('unidirectional streams', function () {
29
30
  // @ts-ignore
30
31
  delete wtOptions.serverCertificateHashes
31
32
 
33
+ // @ts-ignore
34
+ beforeEach(async () => {
35
+ if (
36
+ process.env.USE_HTTP2 !== 'true' &&
37
+ process.env.USE_PONYFILL !== 'true' &&
38
+ process.env.USE_POLYFILL !== 'true'
39
+ ) {
40
+ await quicheLoaded
41
+ }
42
+ })
43
+
32
44
  // @ts-ignore
33
45
  afterEach(async () => {
34
46
  if (client != null) {