@fails-components/webtransport 1.0.4 → 1.0.8

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 (121) hide show
  1. package/dist/main/lib/client.d.ts +95 -0
  2. package/dist/main/lib/client.d.ts.map +1 -0
  3. package/dist/main/lib/dom.d.ts +88 -0
  4. package/dist/main/lib/dom.d.ts.map +1 -0
  5. package/dist/main/lib/error.d.ts +8 -0
  6. package/dist/main/lib/error.d.ts.map +1 -0
  7. package/dist/main/lib/features.d.ts +2 -0
  8. package/dist/main/lib/features.d.ts.map +1 -0
  9. package/dist/main/lib/http2/browser/browser.d.ts +30 -0
  10. package/dist/main/lib/http2/browser/browser.d.ts.map +1 -0
  11. package/dist/main/lib/http2/browser/browserparser.d.ts +41 -0
  12. package/dist/main/lib/http2/browser/browserparser.d.ts.map +1 -0
  13. package/dist/main/lib/http2/flowcontroller.d.ts +70 -0
  14. package/dist/main/lib/http2/flowcontroller.d.ts.map +1 -0
  15. package/dist/main/lib/http2/node/capsuleparser.d.ts +24 -0
  16. package/dist/main/lib/http2/node/capsuleparser.d.ts.map +1 -0
  17. package/dist/main/lib/http2/node/client.d.ts +29 -0
  18. package/dist/main/lib/http2/node/client.d.ts.map +1 -0
  19. package/dist/main/lib/http2/node/index.d.ts +3 -0
  20. package/dist/main/lib/http2/node/index.d.ts.map +1 -0
  21. package/dist/main/lib/http2/node/server.d.ts +57 -0
  22. package/dist/main/lib/http2/node/server.d.ts.map +1 -0
  23. package/dist/main/lib/http2/node/websocketparser.d.ts +86 -0
  24. package/dist/main/lib/http2/node/websocketparser.d.ts.map +1 -0
  25. package/dist/main/lib/http2/parserbase.d.ts +84 -0
  26. package/dist/main/lib/http2/parserbase.d.ts.map +1 -0
  27. package/dist/main/lib/http2/parserbasehttp2.d.ts +31 -0
  28. package/dist/main/lib/http2/parserbasehttp2.d.ts.map +1 -0
  29. package/dist/main/lib/http2/session.d.ts +71 -0
  30. package/dist/main/lib/http2/session.d.ts.map +1 -0
  31. package/dist/main/lib/http2/stream.d.ts +112 -0
  32. package/dist/main/lib/http2/stream.d.ts.map +1 -0
  33. package/dist/main/lib/http2/websocketcommon.d.ts +2 -0
  34. package/dist/main/lib/http2/websocketcommon.d.ts.map +1 -0
  35. package/dist/main/lib/index.browser.d.ts +58 -0
  36. package/dist/main/lib/index.browser.d.ts.map +1 -0
  37. package/dist/main/lib/index.node.d.ts +59 -0
  38. package/dist/main/lib/index.node.d.ts.map +1 -0
  39. package/dist/main/lib/server.d.ts +102 -0
  40. package/dist/main/lib/server.d.ts.map +1 -0
  41. package/dist/main/lib/session.d.ts +296 -0
  42. package/dist/main/lib/session.d.ts.map +1 -0
  43. package/dist/main/lib/stream.d.ts +132 -0
  44. package/dist/main/lib/stream.d.ts.map +1 -0
  45. package/dist/main/lib/types.d.ts +277 -0
  46. package/dist/main/lib/types.d.ts.map +1 -0
  47. package/dist/main/lib/utils.d.ts +11 -0
  48. package/dist/main/lib/utils.d.ts.map +1 -0
  49. package/dist/main/lib/webstreams.browser.d.ts +5 -0
  50. package/dist/main/lib/webstreams.browser.d.ts.map +1 -0
  51. package/dist/main/lib/webstreams.d.ts +10 -0
  52. package/dist/main/lib/webstreams.d.ts.map +1 -0
  53. package/dist/main/lib/webtransport.browser.d.ts +60 -0
  54. package/dist/main/lib/webtransport.browser.d.ts.map +1 -0
  55. package/dist/main/lib/webtransport.node.d.ts +26 -0
  56. package/dist/main/lib/webtransport.node.d.ts.map +1 -0
  57. package/dist/main/lib/webtransportbase.d.ts +70 -0
  58. package/dist/main/lib/webtransportbase.d.ts.map +1 -0
  59. package/dist/main/test/bidirectional-streams.spec.d.ts +5 -0
  60. package/dist/main/test/bidirectional-streams.spec.d.ts.map +1 -0
  61. package/dist/main/test/datagrams.spec.d.ts +5 -0
  62. package/dist/main/test/datagrams.spec.d.ts.map +1 -0
  63. package/dist/main/test/fixtures/certificate.d.ts +21 -0
  64. package/dist/main/test/fixtures/certificate.d.ts.map +1 -0
  65. package/dist/main/test/fixtures/chai.d.ts +2 -0
  66. package/dist/main/test/fixtures/chai.d.ts.map +1 -0
  67. package/dist/main/test/fixtures/known-bytes.d.ts +8 -0
  68. package/dist/main/test/fixtures/known-bytes.d.ts.map +1 -0
  69. package/dist/main/test/fixtures/p-timeout.d.ts +8 -0
  70. package/dist/main/test/fixtures/p-timeout.d.ts.map +1 -0
  71. package/dist/main/test/fixtures/read-cert-hash.d.ts +6 -0
  72. package/dist/main/test/fixtures/read-cert-hash.d.ts.map +1 -0
  73. package/dist/main/test/fixtures/read-stream.d.ts +18 -0
  74. package/dist/main/test/fixtures/read-stream.d.ts.map +1 -0
  75. package/dist/main/test/fixtures/reader-value.d.ts +21 -0
  76. package/dist/main/test/fixtures/reader-value.d.ts.map +1 -0
  77. package/dist/main/test/fixtures/server.d.ts +5 -0
  78. package/dist/main/test/fixtures/server.d.ts.map +1 -0
  79. package/dist/main/test/fixtures/webtransport.browser.d.ts +4 -0
  80. package/dist/main/test/fixtures/webtransport.browser.d.ts.map +1 -0
  81. package/dist/main/test/fixtures/webtransport.d.ts +3 -0
  82. package/dist/main/test/fixtures/webtransport.d.ts.map +1 -0
  83. package/dist/main/test/fixtures/write-stream.d.ts +10 -0
  84. package/dist/main/test/fixtures/write-stream.d.ts.map +1 -0
  85. package/dist/main/test/index.d.ts +2 -0
  86. package/dist/main/test/index.d.ts.map +1 -0
  87. package/dist/main/test/session.spec.d.ts +5 -0
  88. package/dist/main/test/session.spec.d.ts.map +1 -0
  89. package/dist/main/test/unidirectional-streams.spec.d.ts +2 -0
  90. package/dist/main/test/unidirectional-streams.spec.d.ts.map +1 -0
  91. package/dist/main/tsconfig.tsbuildinfo +1 -0
  92. package/dist/transports/http3-quiche/lib/clientsocket.d.ts +19 -0
  93. package/dist/transports/http3-quiche/lib/clientsocket.d.ts.map +1 -0
  94. package/dist/transports/http3-quiche/lib/index.d.ts +11 -0
  95. package/dist/transports/http3-quiche/lib/index.d.ts.map +1 -0
  96. package/dist/transports/http3-quiche/lib/serversocket.d.ts +12 -0
  97. package/dist/transports/http3-quiche/lib/serversocket.d.ts.map +1 -0
  98. package/dist/transports/http3-quiche/lib/socket.d.ts +19 -0
  99. package/dist/transports/http3-quiche/lib/socket.d.ts.map +1 -0
  100. package/dist/transports/http3-quiche/lib/types.d.ts +21 -0
  101. package/dist/transports/http3-quiche/lib/types.d.ts.map +1 -0
  102. package/dist/transports/http3-quiche/lib/utils.d.ts +6 -0
  103. package/dist/transports/http3-quiche/lib/utils.d.ts.map +1 -0
  104. package/lib/features.js +16 -0
  105. package/lib/http2/browser/browser.js +52 -0
  106. package/lib/http2/node/capsuleparser.js +8 -0
  107. package/lib/http2/node/server.js +10 -4
  108. package/lib/http2/node/websocketparser.js +17 -3
  109. package/lib/http2/parserbase.js +7 -0
  110. package/lib/http2/session.js +1 -5
  111. package/lib/session.js +16 -10
  112. package/lib/stream.js +46 -39
  113. package/lib/webtransport.browser.js +8 -2
  114. package/package.json +8 -3
  115. package/test/bidirectional-streams.spec.js +17 -31
  116. package/test/datagrams.spec.js +17 -20
  117. package/test/fixtures/webtransport.browser.js +1 -1
  118. package/test/index.js +13 -4
  119. package/test/session.spec.js +43 -48
  120. package/test/unidirectional-streams.spec.js +17 -30
  121. package/tsconfig.json +15 -0
package/lib/stream.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ReadableStream, WritableStream } from './webstreams.js'
2
2
  import { logger } from './utils.js'
3
3
  import { WebTransportError } from './error.js'
4
+ import { canByteStream } from './features.js'
4
5
 
5
6
  const pid = typeof process !== 'undefined' ? process.pid : 0
6
7
  const log = logger(`webtransport:http3wtstream(${pid})`)
@@ -60,48 +61,54 @@ export class HttpWTStream {
60
61
  this.pendingresRead = null
61
62
 
62
63
  if (this.bidirectional || this.incoming) {
64
+ const readableopts = {
65
+ start: (
66
+ /** @type {import("stream/web").ReadableByteStreamController} */ controller
67
+ ) => {
68
+ this.readableController = controller
69
+ this.objint.startReading()
70
+ },
71
+ pull: async (
72
+ /** @type {import("stream/web").ReadableByteStreamController} */ controller
73
+ ) => {
74
+ if (this.readableclosed) {
75
+ return Promise.resolve()
76
+ }
77
+
78
+ this.pendingoperationRead = new Promise((resolve, reject) => {
79
+ this.pendingresRead = resolve
80
+ })
81
+ this.objint.startReading()
82
+ await this.pendingoperationRead
83
+ },
84
+ cancel: (/** @type {{ code: number; }} */ reason) => {
85
+ /** @type {Promise<void>} */
86
+ const promise = new Promise((resolve, reject) => {
87
+ this.cancelres = resolve
88
+ })
89
+ let code = 0
90
+ if (reason && reason.code) {
91
+ if (reason.code < 0) code = 0
92
+ else if (reason.code > 255) code = 255
93
+ else code = reason.code
94
+ }
95
+ this.readableclosed = true
96
+ this.objint.stopSending(code)
97
+ return promise
98
+ },
99
+ type: 'bytes',
100
+ autoAllocateChunkSize: 4096 // lets take this as buffer size
101
+ }
102
+
103
+ if (!canByteStream) {
104
+ // @ts-ignore
105
+ delete readableopts.type
106
+ }
63
107
  /** @type {WebTransportReceiveStream} */
64
108
  // @ts-expect-error `getStats` property is missing from ReadableStream
65
109
  this.readable = new ReadableStream(
66
- {
67
- start: (
68
- /** @type {import("stream/web").ReadableByteStreamController} */ controller
69
- ) => {
70
- this.readableController = controller
71
- this.objint.startReading()
72
- },
73
- pull: async (
74
- /** @type {import("stream/web").ReadableByteStreamController} */ controller
75
- ) => {
76
- if (this.readableclosed) {
77
- return Promise.resolve()
78
- }
79
-
80
- this.pendingoperationRead = new Promise((resolve, reject) => {
81
- this.pendingresRead = resolve
82
- })
83
- this.objint.startReading()
84
- await this.pendingoperationRead
85
- },
86
- cancel: (/** @type {{ code: number; }} */ reason) => {
87
- /** @type {Promise<void>} */
88
- const promise = new Promise((resolve, reject) => {
89
- this.cancelres = resolve
90
- })
91
- let code = 0
92
- if (reason && reason.code) {
93
- if (reason.code < 0) code = 0
94
- else if (reason.code > 255) code = 255
95
- else code = reason.code
96
- }
97
- this.readableclosed = true
98
- this.objint.stopSending(code)
99
- return promise
100
- },
101
- type: 'bytes',
102
- autoAllocateChunkSize: 4096 // lets take this as buffer size
103
- }
104
- // TODO fix stretegy
110
+ // @ts-ignore
111
+ readableopts
105
112
  )
106
113
  this.readable.getStats = () => {
107
114
  return Promise.resolve({
@@ -28,10 +28,16 @@ if (globalThis.WebTransport) {
28
28
  try {
29
29
  // @ts-ignore
30
30
  // eslint-disable-next-line no-undef
31
- const transport = new WebTransport('https://example.org/test', {
31
+ const transport = new WebTransport('https://127.0.0.1:23333/test', {
32
32
  serverCertificateHashes: []
33
33
  })
34
- transport.close()
34
+ transport.ready
35
+ .then(() => {
36
+ try {
37
+ transport.close()
38
+ } catch (error) {}
39
+ })
40
+ .catch(() => {})
35
41
  } catch (error) {
36
42
  // @ts-ignore
37
43
  if (error?.name === 'NotSupportedError') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fails-components/webtransport",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "description": "A component to add webtransport support (server and client) to node.js using libquiche",
5
5
  "exports": {
6
6
  ".": {
@@ -15,15 +15,20 @@
15
15
  "types": "./dist/lib/index.d.ts",
16
16
  "scripts": {
17
17
  "start": "node test/echoserver.js",
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",
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",
19
19
  "test:node": "node test/index.js node http3",
20
20
  "test:node:http2": "node test/index.js node http2",
21
21
  "test:chromium": "node test/index.js chromium http3",
22
22
  "test:chromium:http2:polyfill": "node test/index.js chromium http2 polyfill",
23
23
  "test:chromium:http2:ponyfill": "node test/index.js chromium http2 ponyfill",
24
+ "test:firefox": "node test/index.js firefox http3",
25
+ "test:firefox:http2:polyfill": "node test/index.js firefox http2 polyfill",
26
+ "test:firefox:http2:ponyfill": "node test/index.js firefox http2 ponyfill",
27
+ "test:webkit": "node test/index.js webkit http3",
28
+ "test:webkit:http2:polyfill": "node test/index.js webkit http2 polyfill",
29
+ "test:webkit:http2:ponyfill": "node test/index.js webkit http2 ponyfill",
24
30
  "oldtest": "node old_test/test.js",
25
31
  "oldtesthttp2": "node old_test/test.js http2",
26
- "types": "tsc",
27
32
  "lint": "eslint lib test old_test"
28
33
  },
29
34
  "repository": {
@@ -18,13 +18,26 @@ import {
18
18
  * @template T
19
19
  * @typedef {import('../lib/types').Deferred<T>} Deferred<T>
20
20
  */
21
-
22
21
  describe('bidirectional streams', function () {
23
22
  let forceReliable = false
24
23
  if (process.env.USE_HTTP2 === 'true') forceReliable = true
25
24
  /** @type {import('../lib/dom').WebTransport | undefined} */
26
25
  let client
27
26
 
27
+ const wtOptions = {
28
+ serverCertificateHashes: [
29
+ {
30
+ algorithm: 'sha-256',
31
+ value: readCertHash(process.env.CERT_HASH)
32
+ }
33
+ ],
34
+ // @ts-ignore
35
+ forceReliable
36
+ }
37
+ if (process.env.NO_CERT_HASHES === 'true')
38
+ // @ts-ignore
39
+ delete wtOptions.serverCertificateHashes
40
+
28
41
  // @ts-ignore
29
42
  afterEach(async () => {
30
43
  if (client != null) {
@@ -37,16 +50,7 @@ describe('bidirectional streams', function () {
37
50
  // client context - connects to the server, opens a bidi stream, sends some data and reads the response
38
51
  client = new WebTransport(
39
52
  `${process.env.SERVER_URL}/bidirectional_client_initiated_echo`,
40
- {
41
- serverCertificateHashes: [
42
- {
43
- algorithm: 'sha-256',
44
- value: readCertHash(process.env.CERT_HASH)
45
- }
46
- ],
47
- // @ts-ignore
48
- forceReliable
49
- }
53
+ wtOptions
50
54
  )
51
55
  await client.ready
52
56
 
@@ -64,16 +68,7 @@ describe('bidirectional streams', function () {
64
68
  // client context - connects to the server, opens a bidi stream, sends some data and reads the response
65
69
  client = new WebTransport(
66
70
  `${process.env.SERVER_URL}/bidirectional_client_initiated_echo`,
67
- {
68
- serverCertificateHashes: [
69
- {
70
- algorithm: 'sha-256',
71
- value: readCertHash(process.env.CERT_HASH)
72
- }
73
- ],
74
- // @ts-ignore
75
- forceReliable
76
- }
71
+ wtOptions
77
72
  )
78
73
  await client.ready
79
74
 
@@ -101,16 +96,7 @@ describe('bidirectional streams', function () {
101
96
  // client context - waits for the server to open a bidi stream then pipes it back to them
102
97
  client = new WebTransport(
103
98
  `${process.env.SERVER_URL}/bidirectional_server_initiated_echo`,
104
- {
105
- serverCertificateHashes: [
106
- {
107
- algorithm: 'sha-256',
108
- value: readCertHash(process.env.CERT_HASH)
109
- }
110
- ],
111
- // @ts-ignore
112
- forceReliable
113
- }
99
+ wtOptions
114
100
  )
115
101
  await client.ready
116
102
 
@@ -17,6 +17,21 @@ describe('datagrams', function () {
17
17
  let forceReliable = false
18
18
  if (process.env.USE_HTTP2 === 'true') forceReliable = true
19
19
 
20
+ const wtOptions = {
21
+ serverCertificateHashes: [
22
+ {
23
+ algorithm: 'sha-256',
24
+ value: readCertHash(process.env.CERT_HASH)
25
+ }
26
+ ],
27
+ // @ts-ignore
28
+ forceReliable
29
+ }
30
+
31
+ if (process.env.NO_CERT_HASHES === 'true')
32
+ // @ts-ignore
33
+ delete wtOptions.serverCertificateHashes
34
+
20
35
  // @ts-ignore
21
36
  afterEach(async () => {
22
37
  if (client != null) {
@@ -28,16 +43,7 @@ describe('datagrams', function () {
28
43
  // client context - connects to the server, sends some datagrams and reads the response
29
44
  client = new WebTransport(
30
45
  `${process.env.SERVER_URL}/datagrams_client_send`,
31
- {
32
- serverCertificateHashes: [
33
- {
34
- algorithm: 'sha-256',
35
- value: readCertHash(process.env.CERT_HASH)
36
- }
37
- ],
38
- // @ts-ignore
39
- forceReliable
40
- }
46
+ wtOptions
41
47
  )
42
48
  await client.ready
43
49
 
@@ -71,16 +77,7 @@ describe('datagrams', function () {
71
77
  // client context - pipes the server's datagrams back to them
72
78
  client = new WebTransport(
73
79
  `${process.env.SERVER_URL}/datagrams_server_send`,
74
- {
75
- serverCertificateHashes: [
76
- {
77
- algorithm: 'sha-256',
78
- value: readCertHash(process.env.CERT_HASH)
79
- }
80
- ],
81
- // @ts-ignore
82
- forceReliable
83
- }
80
+ wtOptions
84
81
  )
85
82
  await client.ready
86
83
 
@@ -6,7 +6,7 @@ import {
6
6
  /** @type {import('../../lib/dom').WebTransport} */
7
7
  // @ts-ignore
8
8
  // eslint-disable-next-line no-undef
9
- let webtransport = WebTransport
9
+ let webtransport = globalThis.WebTransport
10
10
  if (process.env.USE_POLYFILL === 'true') {
11
11
  // @ts-ignore
12
12
  webtransport = WebTransportPolyfill
package/test/index.js CHANGED
@@ -70,12 +70,18 @@ async function runTests(certificate, serverAddress) {
70
70
  })
71
71
 
72
72
  await tests
73
- } else if (env === 'chromium') {
73
+ } else if (env === 'chromium' || env === 'firefox' || env === 'webkit') {
74
74
  command = 'playwright-test'
75
75
  const otheropts = []
76
- if (polyfill || ponyfill)
76
+ if (polyfill || ponyfill || env === 'firefox')
77
77
  otheropts.push('--config', './test/pw-no-https-errors.json')
78
- args = ['./test/*.spec.js', ...otheropts, ...process.argv.slice(slice)]
78
+ args = [
79
+ './test/*.spec.js',
80
+ '-b',
81
+ env /* the browser */,
82
+ ...otheropts,
83
+ ...process.argv.slice(slice)
84
+ ]
79
85
  const tests = execa(command, args, {
80
86
  env: {
81
87
  DEBUG_COLORS: process.env.CI ? '' : 'true',
@@ -83,7 +89,10 @@ async function runTests(certificate, serverAddress) {
83
89
  SERVER_URL: serverAddress,
84
90
  USE_HTTP2: http2 ? 'true' : 'false',
85
91
  USE_POLYFILL: polyfill ? 'true' : 'false',
86
- USE_PONYFILL: ponyfill ? 'true' : 'false'
92
+ USE_PONYFILL: ponyfill ? 'true' : 'false',
93
+ NO_CERT_HASHES:
94
+ env === 'firefox' && !ponyfill && !polyfill ? 'true' : 'false',
95
+ BROWSER: env
87
96
  },
88
97
  stdio: ['inherit', 'inherit', 'inherit']
89
98
  })
@@ -12,10 +12,32 @@ import { expect } from './fixtures/chai.js'
12
12
  describe('session', function () {
13
13
  let forceReliable = false
14
14
  if (process.env.USE_HTTP2 === 'true') forceReliable = true
15
+ const browser = process.env.BROWSER
16
+ const handshakemess =
17
+ browser !== 'firefox' ||
18
+ process.env.USE_POLYFILL === 'true' ||
19
+ process.env.USE_PONYFILL === 'true'
20
+ ? 'Opening handshake failed.'
21
+ : 'WebTransport connection rejected'
15
22
 
16
23
  /** @type {import('../lib/dom').WebTransport | undefined} */
17
24
  let client
18
25
 
26
+ const wtOptions = {
27
+ serverCertificateHashes: [
28
+ {
29
+ algorithm: 'sha-256',
30
+ value: readCertHash(process.env.CERT_HASH)
31
+ }
32
+ ],
33
+ // @ts-ignore
34
+ forceReliable
35
+ }
36
+
37
+ if (process.env.NO_CERT_HASHES === 'true')
38
+ // @ts-ignore
39
+ delete wtOptions.serverCertificateHashes
40
+
19
41
  // @ts-ignore
20
42
  afterEach(async () => {
21
43
  if (client != null) {
@@ -25,16 +47,10 @@ describe('session', function () {
25
47
  })
26
48
 
27
49
  it('should detect session closure', async () => {
28
- client = new WebTransport(`${process.env.SERVER_URL}/session_close`, {
29
- serverCertificateHashes: [
30
- {
31
- algorithm: 'sha-256',
32
- value: readCertHash(process.env.CERT_HASH)
33
- }
34
- ],
35
- // @ts-ignore
36
- forceReliable
37
- })
50
+ client = new WebTransport(
51
+ `${process.env.SERVER_URL}/session_close`,
52
+ wtOptions
53
+ )
38
54
  await client.ready
39
55
 
40
56
  const result = await client.closed
@@ -46,16 +62,7 @@ describe('session', function () {
46
62
  // client context - connects to the server, sends some datagrams and reads the response
47
63
  client = new WebTransport(
48
64
  `${process.env.SERVER_URL}/session_close_with_reason`,
49
- {
50
- serverCertificateHashes: [
51
- {
52
- algorithm: 'sha-256',
53
- value: readCertHash(process.env.CERT_HASH)
54
- }
55
- ],
56
- // @ts-ignore
57
- forceReliable
58
- }
65
+ wtOptions
59
66
  )
60
67
  await client.ready
61
68
 
@@ -65,19 +72,12 @@ describe('session', function () {
65
72
  // unsupported for http2
66
73
  expect(result).to.have.property('reason', 'this is the reason')
67
74
  })
68
-
75
+ if (browser === 'firefox') this.timeout(31000) // really firefox?
69
76
  it('should error when connecting to a server that does not exist', async () => {
70
77
  client = new WebTransport(`https://127.0.0.1:39821`, {
71
- serverCertificateHashes: [
72
- {
73
- algorithm: 'sha-256',
74
- value: readCertHash(process.env.CERT_HASH)
75
- }
76
- ],
77
78
  quicConnectTimeout: 100,
78
79
  webTransportConnectTimeout: 100,
79
- // @ts-ignore
80
- forceReliable
80
+ ...wtOptions
81
81
  })
82
82
 
83
83
  const [closedResult, readyResult] = await Promise.all([
@@ -87,23 +87,17 @@ describe('session', function () {
87
87
 
88
88
  expect(closedResult)
89
89
  .to.be.a('WebTransportError')
90
- .with.property('message', 'Opening handshake failed.')
90
+ .with.property('message', handshakemess)
91
91
  expect(readyResult)
92
92
  .to.be.a('WebTransportError')
93
- .with.property('message', 'Opening handshake failed.')
93
+ .with.property('message', handshakemess)
94
94
  })
95
95
 
96
96
  it('should error when connecting to a path that does not exist', async () => {
97
- client = new WebTransport(`${process.env.SERVER_URL}/non_existant`, {
98
- serverCertificateHashes: [
99
- {
100
- algorithm: 'sha-256',
101
- value: readCertHash(process.env.CERT_HASH)
102
- }
103
- ],
104
- // @ts-ignore
105
- forceReliable
106
- })
97
+ client = new WebTransport(
98
+ `${process.env.SERVER_URL}/non_existant`,
99
+ wtOptions
100
+ )
107
101
 
108
102
  const [closedResult, readyResult] = await Promise.all([
109
103
  client.closed.catch((err) => err),
@@ -112,15 +106,16 @@ describe('session', function () {
112
106
 
113
107
  expect(closedResult)
114
108
  .to.be.a('WebTransportError')
115
- .with.property('message', 'Opening handshake failed.')
109
+ .with.property('message', handshakemess)
116
110
  expect(readyResult)
117
111
  .to.be.a('WebTransportError')
118
- .with.property('message', 'Opening handshake failed.')
112
+ .with.property('message', handshakemess)
119
113
  })
120
114
 
121
115
  if (
122
116
  process.env.USE_POLYFILL !== 'true' &&
123
- process.env.USE_PONYFILL !== 'true'
117
+ process.env.USE_PONYFILL !== 'true' &&
118
+ wtOptions.serverCertificateHashes
124
119
  ) {
125
120
  // deactivated in polyfill case, no test necessary
126
121
  it('should error when connecting with a bad certificate', async () => {
@@ -142,10 +137,10 @@ describe('session', function () {
142
137
 
143
138
  expect(closedResult)
144
139
  .to.be.a('WebTransportError')
145
- .with.property('message', 'Opening handshake failed.')
140
+ .with.property('message', handshakemess)
146
141
  expect(readyResult)
147
142
  .to.be.a('WebTransportError')
148
- .with.property('message', 'Opening handshake failed.')
143
+ .with.property('message', handshakemess)
149
144
  })
150
145
 
151
146
  it('should error when connecting with the wrong certificate', async () => {
@@ -169,10 +164,10 @@ describe('session', function () {
169
164
 
170
165
  expect(closedResult)
171
166
  .to.be.a('WebTransportError')
172
- .with.property('message', 'Opening handshake failed.')
167
+ .with.property('message', handshakemess)
173
168
  expect(readyResult)
174
169
  .to.be.a('WebTransportError')
175
- .with.property('message', 'Opening handshake failed.')
170
+ .with.property('message', handshakemess)
176
171
  })
177
172
  }
178
173
  })
@@ -15,6 +15,20 @@ describe('unidirectional streams', function () {
15
15
  let forceReliable = false
16
16
  if (process.env.USE_HTTP2 === 'true') forceReliable = true
17
17
 
18
+ const wtOptions = {
19
+ serverCertificateHashes: [
20
+ {
21
+ algorithm: 'sha-256',
22
+ value: readCertHash(process.env.CERT_HASH)
23
+ }
24
+ ],
25
+ // @ts-ignore
26
+ forceReliable
27
+ }
28
+ if (process.env.NO_CERT_HASHES === 'true')
29
+ // @ts-ignore
30
+ delete wtOptions.serverCertificateHashes
31
+
18
32
  // @ts-ignore
19
33
  afterEach(async () => {
20
34
  if (client != null) {
@@ -28,16 +42,7 @@ describe('unidirectional streams', function () {
28
42
  try {
29
43
  client = new WebTransport(
30
44
  `${process.env.SERVER_URL}/unidirectional_client_send`,
31
- {
32
- serverCertificateHashes: [
33
- {
34
- algorithm: 'sha-256',
35
- value: readCertHash(process.env.CERT_HASH)
36
- }
37
- ],
38
- // @ts-ignore
39
- forceReliable
40
- }
45
+ wtOptions
41
46
  )
42
47
  await client.ready
43
48
  } catch (error) {
@@ -62,16 +67,7 @@ describe('unidirectional streams', function () {
62
67
  // client context - waits for the server to open a bidi stream then pipes it back to them
63
68
  client = new WebTransport(
64
69
  `${process.env.SERVER_URL}/unidirectional_server_send`,
65
- {
66
- serverCertificateHashes: [
67
- {
68
- algorithm: 'sha-256',
69
- value: readCertHash(process.env.CERT_HASH)
70
- }
71
- ],
72
- // @ts-ignore
73
- forceReliable
74
- }
70
+ wtOptions
75
71
  )
76
72
  await client.ready
77
73
 
@@ -93,16 +89,7 @@ describe('unidirectional streams', function () {
93
89
  this.timeout(6000 + addpolyfill)
94
90
  client = new WebTransport(
95
91
  `${process.env.SERVER_URL}/unidirectional_server_delay_before_read`,
96
- {
97
- serverCertificateHashes: [
98
- {
99
- algorithm: 'sha-256',
100
- value: readCertHash(process.env.CERT_HASH)
101
- }
102
- ],
103
- // @ts-ignore
104
- forceReliable
105
- }
92
+ wtOptions
106
93
  )
107
94
  await client.ready
108
95
 
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "rootDir": "../",
5
+ },
6
+ "extends": "../tsconfig.base.json",
7
+ "include": [
8
+ "lib",
9
+ "test",
10
+ "../transports/http3-quiche/lib"
11
+ ],
12
+ "exclude": [
13
+ "test/testinone.js"
14
+ ]
15
+ }