@fails-components/webtransport 1.0.11 → 1.1.2
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/lib/client.d.ts.map +1 -1
- package/dist/lib/features.d.ts.map +1 -1
- package/dist/lib/http2/browser/browser.d.ts.map +1 -1
- package/dist/lib/http2/browser/browserparser.d.ts.map +1 -1
- package/dist/lib/http2/node/client.d.ts.map +1 -1
- package/dist/lib/http2/node/server.d.ts +4 -4
- package/dist/lib/http2/node/server.d.ts.map +1 -1
- package/dist/lib/http2/node/websocketparser.d.ts.map +1 -1
- package/dist/lib/http2/parserbase.d.ts.map +1 -1
- package/dist/lib/http2/session.d.ts.map +1 -1
- package/dist/lib/index.browser.d.ts.map +1 -1
- package/dist/lib/index.node.d.ts.map +1 -1
- package/dist/lib/index.types.d.ts.map +1 -1
- package/dist/lib/server.d.ts.map +1 -1
- package/dist/lib/session.d.ts +8 -4
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/stream.d.ts.map +1 -1
- package/dist/lib/types.d.ts +9 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/webtransport.browser.d.ts.map +1 -1
- package/dist/lib/webtransport.node.d.ts.map +1 -1
- package/dist/lib/webtransportbase.d.ts.map +1 -1
- package/eslint.config.js +51 -0
- package/lib/client.js +1 -0
- package/lib/features.js +2 -0
- package/lib/http2/browser/browser.js +2 -1
- package/lib/http2/browser/browserparser.js +1 -0
- package/lib/http2/node/client.js +7 -3
- package/lib/http2/node/server.js +66 -39
- package/lib/http2/node/websocketparser.js +1 -0
- package/lib/http2/parserbase.js +3 -0
- package/lib/http2/session.js +3 -0
- package/lib/http2/stream.js +1 -1
- package/lib/index.browser.js +0 -1
- package/lib/index.node.js +0 -1
- package/lib/index.types.js +0 -1
- package/lib/server.js +7 -4
- package/lib/session.js +8 -2
- package/lib/stream.js +11 -3
- package/lib/types.ts +9 -4
- package/lib/webtransport.browser.js +10 -6
- package/lib/webtransport.node.js +9 -6
- package/lib/webtransportbase.js +2 -0
- package/old_test/echoclient.js +0 -1
- package/old_test/testsuite.js +4 -4
- package/package.json +5 -5
- package/test/datagrams.spec.js +0 -1
- package/test/fixtures/read-stream.js +20 -7
- package/test/fixtures/reader-value.js +0 -5
- package/test/fixtures/server.js +51 -1
- package/test/fixtures/webtransport.browser.js +1 -2
- package/test/index.js +1 -0
- package/test/session.spec.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fails-components/webtransport",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A component to add webtransport support (server and client) to node.js using libquiche",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
"chai": "^4.3.6",
|
|
61
61
|
"chai-as-promised": "^7.1.1",
|
|
62
62
|
"dirty-chai": "^2.0.1",
|
|
63
|
-
"eslint": "^
|
|
64
|
-
"eslint-config-prettier": "^
|
|
63
|
+
"eslint": "^9.3.0",
|
|
64
|
+
"eslint-config-prettier": "^9.1.0",
|
|
65
65
|
"eslint-config-standard": "^16.0.2",
|
|
66
66
|
"eslint-plugin-import": "^2.25.2",
|
|
67
67
|
"eslint-plugin-node": "^11.1.0",
|
|
68
|
-
"eslint-plugin-prettier": "^
|
|
68
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
69
69
|
"eslint-plugin-promise": "^4.3.1",
|
|
70
70
|
"eslint-plugin-standard": "^4.1.0",
|
|
71
71
|
"execa": "^6.1.0",
|
|
72
72
|
"mocha": "^10.1.0",
|
|
73
73
|
"node-forge": "^1.3.1",
|
|
74
74
|
"playwright-test": "^12.3.4",
|
|
75
|
-
"prettier": "^2.
|
|
75
|
+
"prettier": "^3.2.5",
|
|
76
76
|
"typescript": "^4.8.4",
|
|
77
77
|
"uint8arrays": "^4.0.2"
|
|
78
78
|
},
|
package/test/datagrams.spec.js
CHANGED
|
@@ -65,7 +65,6 @@ describe('datagrams', function () {
|
|
|
65
65
|
// write datagrams until the server receives one and closes the connection
|
|
66
66
|
// eslint-disable-next-line promise/catch-or-return
|
|
67
67
|
Promise.resolve().then(async () => {
|
|
68
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
69
68
|
while (!closed) {
|
|
70
69
|
try {
|
|
71
70
|
await writer.ready
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @template T
|
|
3
|
-
* @typedef {import('../../lib/webstreams').ReadableStream<T>} ReadableStream<T>
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Read a stream contents to the end and return it
|
|
8
3
|
*
|
|
9
4
|
* @template T
|
|
10
5
|
* @param {ReadableStream<T>} readable
|
|
11
6
|
* @param {number} [expected]
|
|
12
|
-
* @returns
|
|
7
|
+
* @returns {T[]}
|
|
13
8
|
*/
|
|
14
9
|
export async function readStream(readable, expected) {
|
|
15
10
|
const reader = readable.getReader()
|
|
@@ -27,7 +22,6 @@ export async function readStream(readable, expected) {
|
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
if (value != null) {
|
|
30
|
-
// @ts-ignore
|
|
31
25
|
outputlength += value.length
|
|
32
26
|
output.push(value)
|
|
33
27
|
}
|
|
@@ -42,3 +36,22 @@ export async function readStream(readable, expected) {
|
|
|
42
36
|
reader.releaseLock()
|
|
43
37
|
}
|
|
44
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {ReadableStream<Uint8Array>} stream
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
export async function readStringFromStream(stream) {
|
|
45
|
+
const decoder = new TextDecoder()
|
|
46
|
+
let output = ''
|
|
47
|
+
|
|
48
|
+
for (const buf of await readStream(stream)) {
|
|
49
|
+
output += decoder.decode(buf, {
|
|
50
|
+
stream: true
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
output += decoder.decode()
|
|
55
|
+
|
|
56
|
+
return output
|
|
57
|
+
}
|
package/test/fixtures/server.js
CHANGED
|
@@ -55,6 +55,32 @@ export async function createServer() {
|
|
|
55
55
|
|
|
56
56
|
server.ready
|
|
57
57
|
.then(async () => {
|
|
58
|
+
server.setRequestCallback(async (args) => {
|
|
59
|
+
const url = args.header[':path']
|
|
60
|
+
const [path] = url.split('?')
|
|
61
|
+
|
|
62
|
+
if (server.sessionController[path] == null) {
|
|
63
|
+
return {
|
|
64
|
+
...args,
|
|
65
|
+
path,
|
|
66
|
+
status: 404
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...args,
|
|
72
|
+
path,
|
|
73
|
+
userData: {
|
|
74
|
+
search: url.substring(path.length)
|
|
75
|
+
},
|
|
76
|
+
header: {
|
|
77
|
+
...args.header,
|
|
78
|
+
':path': path
|
|
79
|
+
},
|
|
80
|
+
status: 200
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
58
84
|
// set up listeners for the different server paths used by the tests
|
|
59
85
|
console.log('server ready')
|
|
60
86
|
await Promise.all(
|
|
@@ -174,7 +200,6 @@ export async function createServer() {
|
|
|
174
200
|
// write datagrams until the client receives one and closes the connection
|
|
175
201
|
// eslint-disable-next-line promise/catch-or-return
|
|
176
202
|
Promise.resolve().then(async () => {
|
|
177
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
178
203
|
while (!closed) {
|
|
179
204
|
try {
|
|
180
205
|
await writer.ready
|
|
@@ -217,6 +242,7 @@ export async function createServer() {
|
|
|
217
242
|
}
|
|
218
243
|
await getReaderValue(session.incomingUnidirectionalStreams)
|
|
219
244
|
await session.close()
|
|
245
|
+
// eslint-disable-next-line no-unused-vars
|
|
220
246
|
} catch (error) {
|
|
221
247
|
// do not crash server, if a problem occurs...
|
|
222
248
|
}
|
|
@@ -236,6 +262,7 @@ export async function createServer() {
|
|
|
236
262
|
)
|
|
237
263
|
}
|
|
238
264
|
await session.close()
|
|
265
|
+
// eslint-disable-next-line no-unused-vars
|
|
239
266
|
} catch (error) {
|
|
240
267
|
// do not crash server, if a problem occurs...
|
|
241
268
|
}
|
|
@@ -265,6 +292,7 @@ export async function createServer() {
|
|
|
265
292
|
}
|
|
266
293
|
await getReaderValue(session.incomingBidirectionalStreams)
|
|
267
294
|
await session.close()
|
|
295
|
+
// eslint-disable-next-line no-unused-vars
|
|
268
296
|
} catch (error) {
|
|
269
297
|
// do not crash server, if a problem occurs...
|
|
270
298
|
}
|
|
@@ -284,6 +312,7 @@ export async function createServer() {
|
|
|
284
312
|
)
|
|
285
313
|
}
|
|
286
314
|
await session.close()
|
|
315
|
+
// eslint-disable-next-line no-unused-vars
|
|
287
316
|
} catch (error) {
|
|
288
317
|
// do not crash server, if a problem occurs...
|
|
289
318
|
}
|
|
@@ -310,6 +339,26 @@ export async function createServer() {
|
|
|
310
339
|
}
|
|
311
340
|
},
|
|
312
341
|
|
|
342
|
+
// support user data
|
|
343
|
+
async () => {
|
|
344
|
+
for await (const session of getReaderStream(
|
|
345
|
+
server.sessionStream('/session_with_userdata')
|
|
346
|
+
)) {
|
|
347
|
+
try {
|
|
348
|
+
const stream = await session.createUnidirectionalStream()
|
|
349
|
+
await writeStream(stream, [
|
|
350
|
+
new TextEncoder().encode(JSON.stringify(session.userData))
|
|
351
|
+
])
|
|
352
|
+
// session.close() // do not close it here, the stream is closed before a reader is attached on client side
|
|
353
|
+
} catch (err) {
|
|
354
|
+
session.close({
|
|
355
|
+
closeCode: 1,
|
|
356
|
+
reason: err.stack
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
|
|
313
362
|
// send data over unidirectional stream, initiated by remote
|
|
314
363
|
async () => {
|
|
315
364
|
for await (const session of getReaderStream(
|
|
@@ -332,6 +381,7 @@ export async function createServer() {
|
|
|
332
381
|
} else {
|
|
333
382
|
session.close()
|
|
334
383
|
}
|
|
384
|
+
// eslint-disable-next-line no-unused-vars
|
|
335
385
|
} catch (error) {
|
|
336
386
|
// in some tests the client closes the stream
|
|
337
387
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
|
|
6
6
|
/** @type {import('../../lib/dom').WebTransport} */
|
|
7
7
|
// @ts-ignore
|
|
8
|
-
// eslint-disable-next-line no-undef
|
|
9
8
|
let webtransport = globalThis.WebTransport
|
|
10
9
|
if (process.env.USE_POLYFILL === 'true') {
|
|
11
10
|
// @ts-ignore
|
|
@@ -17,4 +16,4 @@ if (process.env.USE_PONYFILL === 'true') {
|
|
|
17
16
|
webtransport = WebTransportPonyfill
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export default webtransport
|
|
19
|
+
export default webtransport
|
package/test/index.js
CHANGED
package/test/session.spec.js
CHANGED
|
@@ -4,6 +4,8 @@ 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
6
|
import { quicheLoaded } from './fixtures/quiche.js'
|
|
7
|
+
import { getReaderValue } from './fixtures/reader-value.js'
|
|
8
|
+
import { readStringFromStream } from './fixtures/read-stream.js'
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @template T
|
|
@@ -82,6 +84,20 @@ describe('session', function () {
|
|
|
82
84
|
expect(result).to.have.property('closeCode', 7)
|
|
83
85
|
expect(result).to.have.property('reason', 'this is the reason')
|
|
84
86
|
})
|
|
87
|
+
|
|
88
|
+
it('should parse user data', async () => {
|
|
89
|
+
client = new WebTransport(
|
|
90
|
+
`${process.env.SERVER_URL}/session_with_userdata?foo=bar`,
|
|
91
|
+
wtOptions
|
|
92
|
+
)
|
|
93
|
+
await client.ready
|
|
94
|
+
|
|
95
|
+
const stream = await getReaderValue(client.incomingUnidirectionalStreams)
|
|
96
|
+
const string = await readStringFromStream(stream)
|
|
97
|
+
const userData = JSON.parse(string)
|
|
98
|
+
expect(userData).to.have.property('search', '?foo=bar')
|
|
99
|
+
})
|
|
100
|
+
|
|
85
101
|
if (browser === 'firefox') this.timeout(31000) // really firefox?
|
|
86
102
|
it('should error when connecting to a server that does not exist', async () => {
|
|
87
103
|
client = new WebTransport(`https://127.0.0.1:39821`, {
|