@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.
- package/dist/main/lib/client.d.ts +95 -0
- package/dist/main/lib/client.d.ts.map +1 -0
- package/dist/main/lib/dom.d.ts +88 -0
- package/dist/main/lib/dom.d.ts.map +1 -0
- package/dist/main/lib/error.d.ts +8 -0
- package/dist/main/lib/error.d.ts.map +1 -0
- package/dist/main/lib/features.d.ts +2 -0
- package/dist/main/lib/features.d.ts.map +1 -0
- package/dist/main/lib/http2/browser/browser.d.ts +30 -0
- package/dist/main/lib/http2/browser/browser.d.ts.map +1 -0
- package/dist/main/lib/http2/browser/browserparser.d.ts +41 -0
- package/dist/main/lib/http2/browser/browserparser.d.ts.map +1 -0
- package/dist/main/lib/http2/flowcontroller.d.ts +70 -0
- package/dist/main/lib/http2/flowcontroller.d.ts.map +1 -0
- package/dist/main/lib/http2/node/capsuleparser.d.ts +24 -0
- package/dist/main/lib/http2/node/capsuleparser.d.ts.map +1 -0
- package/dist/main/lib/http2/node/client.d.ts +29 -0
- package/dist/main/lib/http2/node/client.d.ts.map +1 -0
- package/dist/main/lib/http2/node/index.d.ts +3 -0
- package/dist/main/lib/http2/node/index.d.ts.map +1 -0
- package/dist/main/lib/http2/node/server.d.ts +57 -0
- package/dist/main/lib/http2/node/server.d.ts.map +1 -0
- package/dist/main/lib/http2/node/websocketparser.d.ts +86 -0
- package/dist/main/lib/http2/node/websocketparser.d.ts.map +1 -0
- package/dist/main/lib/http2/parserbase.d.ts +84 -0
- package/dist/main/lib/http2/parserbase.d.ts.map +1 -0
- package/dist/main/lib/http2/parserbasehttp2.d.ts +31 -0
- package/dist/main/lib/http2/parserbasehttp2.d.ts.map +1 -0
- package/dist/main/lib/http2/session.d.ts +71 -0
- package/dist/main/lib/http2/session.d.ts.map +1 -0
- package/dist/main/lib/http2/stream.d.ts +112 -0
- package/dist/main/lib/http2/stream.d.ts.map +1 -0
- package/dist/main/lib/http2/websocketcommon.d.ts +2 -0
- package/dist/main/lib/http2/websocketcommon.d.ts.map +1 -0
- package/dist/main/lib/index.browser.d.ts +58 -0
- package/dist/main/lib/index.browser.d.ts.map +1 -0
- package/dist/main/lib/index.node.d.ts +59 -0
- package/dist/main/lib/index.node.d.ts.map +1 -0
- package/dist/main/lib/server.d.ts +102 -0
- package/dist/main/lib/server.d.ts.map +1 -0
- package/dist/main/lib/session.d.ts +296 -0
- package/dist/main/lib/session.d.ts.map +1 -0
- package/dist/main/lib/stream.d.ts +132 -0
- package/dist/main/lib/stream.d.ts.map +1 -0
- package/dist/main/lib/types.d.ts +277 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/utils.d.ts +11 -0
- package/dist/main/lib/utils.d.ts.map +1 -0
- package/dist/main/lib/webstreams.browser.d.ts +5 -0
- package/dist/main/lib/webstreams.browser.d.ts.map +1 -0
- package/dist/main/lib/webstreams.d.ts +10 -0
- package/dist/main/lib/webstreams.d.ts.map +1 -0
- package/dist/main/lib/webtransport.browser.d.ts +60 -0
- package/dist/main/lib/webtransport.browser.d.ts.map +1 -0
- package/dist/main/lib/webtransport.node.d.ts +26 -0
- package/dist/main/lib/webtransport.node.d.ts.map +1 -0
- package/dist/main/lib/webtransportbase.d.ts +70 -0
- package/dist/main/lib/webtransportbase.d.ts.map +1 -0
- package/dist/main/test/bidirectional-streams.spec.d.ts +5 -0
- package/dist/main/test/bidirectional-streams.spec.d.ts.map +1 -0
- package/dist/main/test/datagrams.spec.d.ts +5 -0
- package/dist/main/test/datagrams.spec.d.ts.map +1 -0
- package/dist/main/test/fixtures/certificate.d.ts +21 -0
- package/dist/main/test/fixtures/certificate.d.ts.map +1 -0
- package/dist/main/test/fixtures/chai.d.ts +2 -0
- package/dist/main/test/fixtures/chai.d.ts.map +1 -0
- package/dist/main/test/fixtures/known-bytes.d.ts +8 -0
- package/dist/main/test/fixtures/known-bytes.d.ts.map +1 -0
- package/dist/main/test/fixtures/p-timeout.d.ts +8 -0
- package/dist/main/test/fixtures/p-timeout.d.ts.map +1 -0
- package/dist/main/test/fixtures/read-cert-hash.d.ts +6 -0
- package/dist/main/test/fixtures/read-cert-hash.d.ts.map +1 -0
- package/dist/main/test/fixtures/read-stream.d.ts +18 -0
- package/dist/main/test/fixtures/read-stream.d.ts.map +1 -0
- package/dist/main/test/fixtures/reader-value.d.ts +21 -0
- package/dist/main/test/fixtures/reader-value.d.ts.map +1 -0
- package/dist/main/test/fixtures/server.d.ts +5 -0
- package/dist/main/test/fixtures/server.d.ts.map +1 -0
- package/dist/main/test/fixtures/webtransport.browser.d.ts +4 -0
- package/dist/main/test/fixtures/webtransport.browser.d.ts.map +1 -0
- package/dist/main/test/fixtures/webtransport.d.ts +3 -0
- package/dist/main/test/fixtures/webtransport.d.ts.map +1 -0
- package/dist/main/test/fixtures/write-stream.d.ts +10 -0
- package/dist/main/test/fixtures/write-stream.d.ts.map +1 -0
- package/dist/main/test/index.d.ts +2 -0
- package/dist/main/test/index.d.ts.map +1 -0
- package/dist/main/test/session.spec.d.ts +5 -0
- package/dist/main/test/session.spec.d.ts.map +1 -0
- package/dist/main/test/unidirectional-streams.spec.d.ts +2 -0
- package/dist/main/test/unidirectional-streams.spec.d.ts.map +1 -0
- package/dist/main/tsconfig.tsbuildinfo +1 -0
- package/dist/transports/http3-quiche/lib/clientsocket.d.ts +19 -0
- package/dist/transports/http3-quiche/lib/clientsocket.d.ts.map +1 -0
- package/dist/transports/http3-quiche/lib/index.d.ts +11 -0
- package/dist/transports/http3-quiche/lib/index.d.ts.map +1 -0
- package/dist/transports/http3-quiche/lib/serversocket.d.ts +12 -0
- package/dist/transports/http3-quiche/lib/serversocket.d.ts.map +1 -0
- package/dist/transports/http3-quiche/lib/socket.d.ts +19 -0
- package/dist/transports/http3-quiche/lib/socket.d.ts.map +1 -0
- package/dist/transports/http3-quiche/lib/types.d.ts +21 -0
- package/dist/transports/http3-quiche/lib/types.d.ts.map +1 -0
- package/dist/transports/http3-quiche/lib/utils.d.ts +6 -0
- package/dist/transports/http3-quiche/lib/utils.d.ts.map +1 -0
- package/lib/features.js +16 -0
- package/lib/http2/browser/browser.js +52 -0
- package/lib/http2/node/capsuleparser.js +8 -0
- package/lib/http2/node/server.js +10 -4
- package/lib/http2/node/websocketparser.js +17 -3
- package/lib/http2/parserbase.js +7 -0
- package/lib/http2/session.js +1 -5
- package/lib/session.js +16 -10
- package/lib/stream.js +46 -39
- package/lib/webtransport.browser.js +8 -2
- package/package.json +8 -3
- package/test/bidirectional-streams.spec.js +17 -31
- package/test/datagrams.spec.js +17 -20
- package/test/fixtures/webtransport.browser.js +1 -1
- package/test/index.js +13 -4
- package/test/session.spec.js +43 -48
- package/test/unidirectional-streams.spec.js +17 -30
- 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
|
-
|
|
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://
|
|
31
|
+
const transport = new WebTransport('https://127.0.0.1:23333/test', {
|
|
32
32
|
serverCertificateHashes: []
|
|
33
33
|
})
|
|
34
|
-
transport.
|
|
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.
|
|
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
|
|
package/test/datagrams.spec.js
CHANGED
|
@@ -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 = [
|
|
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
|
})
|
package/test/session.spec.js
CHANGED
|
@@ -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(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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',
|
|
90
|
+
.with.property('message', handshakemess)
|
|
91
91
|
expect(readyResult)
|
|
92
92
|
.to.be.a('WebTransportError')
|
|
93
|
-
.with.property('message',
|
|
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(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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',
|
|
109
|
+
.with.property('message', handshakemess)
|
|
116
110
|
expect(readyResult)
|
|
117
111
|
.to.be.a('WebTransportError')
|
|
118
|
-
.with.property('message',
|
|
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',
|
|
140
|
+
.with.property('message', handshakemess)
|
|
146
141
|
expect(readyResult)
|
|
147
142
|
.to.be.a('WebTransportError')
|
|
148
|
-
.with.property('message',
|
|
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',
|
|
167
|
+
.with.property('message', handshakemess)
|
|
173
168
|
expect(readyResult)
|
|
174
169
|
.to.be.a('WebTransportError')
|
|
175
|
-
.with.property('message',
|
|
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