@fails-components/webtransport 0.2.1 → 0.3.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.
Files changed (101) hide show
  1. package/CMakeLists.txt +3 -0
  2. package/dist/lib/client.d.ts +7 -3
  3. package/dist/lib/client.d.ts.map +1 -1
  4. package/dist/lib/dom.d.ts +15 -4
  5. package/dist/lib/dom.d.ts.map +1 -1
  6. package/dist/lib/error.d.ts +8 -0
  7. package/dist/lib/error.d.ts.map +1 -0
  8. package/dist/lib/event-loop.d.ts +4 -2
  9. package/dist/lib/event-loop.d.ts.map +1 -1
  10. package/dist/lib/native.d.ts.map +1 -1
  11. package/dist/lib/server.d.ts +5 -2
  12. package/dist/lib/server.d.ts.map +1 -1
  13. package/dist/lib/session.d.ts +36 -23
  14. package/dist/lib/session.d.ts.map +1 -1
  15. package/dist/lib/stream.d.ts +15 -4
  16. package/dist/lib/stream.d.ts.map +1 -1
  17. package/dist/lib/transport.d.ts +12 -3
  18. package/dist/lib/transport.d.ts.map +1 -1
  19. package/dist/lib/types.d.ts +43 -4
  20. package/dist/lib/types.d.ts.map +1 -1
  21. package/dist/lib/utils.d.ts +5 -0
  22. package/dist/lib/utils.d.ts.map +1 -1
  23. package/dist/lib/webtransport.d.ts +11 -21
  24. package/dist/lib/webtransport.d.ts.map +1 -1
  25. package/dist/test/datagrams.spec.d.ts.map +1 -1
  26. package/dist/test/event-loop.node.d.ts +2 -0
  27. package/dist/test/event-loop.node.d.ts.map +1 -0
  28. package/dist/test/fixtures/chai.d.ts.map +1 -1
  29. package/dist/test/fixtures/known-bytes.d.ts +6 -0
  30. package/dist/test/fixtures/known-bytes.d.ts.map +1 -0
  31. package/dist/test/fixtures/read-cert-hash.d.ts +6 -0
  32. package/dist/test/fixtures/read-cert-hash.d.ts.map +1 -0
  33. package/dist/test/fixtures/read-stream.d.ts +10 -1
  34. package/dist/test/fixtures/read-stream.d.ts.map +1 -1
  35. package/dist/test/fixtures/reader-value.d.ts +16 -1
  36. package/dist/test/fixtures/reader-value.d.ts.map +1 -1
  37. package/dist/test/fixtures/server.d.ts +0 -5
  38. package/dist/test/fixtures/server.d.ts.map +1 -1
  39. package/dist/test/fixtures/webtransport.browser.d.ts +3 -0
  40. package/dist/test/fixtures/webtransport.browser.d.ts.map +1 -0
  41. package/dist/test/fixtures/webtransport.d.ts +3 -0
  42. package/dist/test/fixtures/webtransport.d.ts.map +1 -0
  43. package/dist/test/fixtures/write-stream.d.ts.map +1 -1
  44. package/dist/test/index.d.ts +2 -0
  45. package/dist/test/index.d.ts.map +1 -0
  46. package/dist/test/session.spec.d.ts +5 -0
  47. package/dist/test/session.spec.d.ts.map +1 -0
  48. package/dist/test/unidirectional-streams.spec.d.ts +1 -4
  49. package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
  50. package/lib/client.js +57 -43
  51. package/lib/dom.ts +18 -4
  52. package/lib/error.js +10 -0
  53. package/lib/event-loop.js +8 -5
  54. package/lib/native.js +4 -1
  55. package/lib/server.js +18 -10
  56. package/lib/session.js +145 -32
  57. package/lib/stream.js +52 -24
  58. package/lib/transport.js +48 -10
  59. package/lib/types.ts +53 -5
  60. package/lib/utils.js +13 -0
  61. package/lib/webtransport.js +10 -18
  62. package/{test → old_test}/echoserver.js +1 -2
  63. package/{test → old_test}/test.js +5 -3
  64. package/package.json +16 -5
  65. package/readme.md +64 -0
  66. package/src/http3client.cc +2 -2
  67. package/src/http3dispatcher.cc +3 -2
  68. package/src/http3dispatcher.h +2 -1
  69. package/src/http3eventloop.cc +106 -2
  70. package/src/http3eventloop.h +13 -0
  71. package/src/http3wtsessionvisitor.cc +2 -0
  72. package/src/http3wtsessionvisitor.h +41 -1
  73. package/test/bidirectional-streams.spec.js +41 -97
  74. package/test/datagrams.spec.js +50 -99
  75. package/test/fixtures/chai.js +2 -0
  76. package/test/fixtures/known-bytes.js +15 -0
  77. package/test/fixtures/read-cert-hash.js +7 -0
  78. package/test/fixtures/read-stream.js +5 -0
  79. package/test/fixtures/reader-value.js +32 -0
  80. package/test/fixtures/server.js +237 -21
  81. package/test/fixtures/webtransport.browser.js +2 -0
  82. package/test/fixtures/webtransport.js +3 -0
  83. package/test/fixtures/write-stream.js +8 -1
  84. package/test/index.js +87 -0
  85. package/test/session.spec.js +159 -0
  86. package/test/unidirectional-streams.spec.js +67 -138
  87. package/tsconfig.json +0 -1
  88. package/dist/test/echoclient.d.ts +0 -2
  89. package/dist/test/echoclient.d.ts.map +0 -1
  90. package/dist/test/echoserver.d.ts +0 -2
  91. package/dist/test/echoserver.d.ts.map +0 -1
  92. package/dist/test/event-loop.spec.d.ts +0 -2
  93. package/dist/test/event-loop.spec.d.ts.map +0 -1
  94. package/dist/test/test.d.ts +0 -2
  95. package/dist/test/test.d.ts.map +0 -1
  96. package/dist/test/testsuite.d.ts +0 -25
  97. package/dist/test/testsuite.d.ts.map +0 -1
  98. package/platform/base/strings/utf_ostream_operators.h +0 -5
  99. /package/{test → old_test}/echoclient.js +0 -0
  100. /package/{test → old_test}/testsuite.js +0 -0
  101. /package/test/{event-loop.spec.js → event-loop.node.js} +0 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Bytes send by tests
3
+ */
4
+ export const KNOWN_BYTES: Uint8Array[];
5
+ export const KNOWN_BYTES_LENGTH: number;
6
+ //# sourceMappingURL=known-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"known-bytes.d.ts","sourceRoot":"","sources":["../../../test/fixtures/known-bytes.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,uCAMC;AAED,wCAGC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {string} [certHash]
3
+ * @returns {Uint8Array}
4
+ */
5
+ export function readCertHash(certHash?: string | undefined): Uint8Array;
6
+ //# sourceMappingURL=read-cert-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-cert-hash.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-cert-hash.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,6DAFa,UAAU,CAItB"}
@@ -1,3 +1,8 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * @template T
4
+ * @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
5
+ */
1
6
  /**
2
7
  * Read a stream contents to the end and return it
3
8
  *
@@ -6,5 +11,9 @@
6
11
  * @param {number} [expected]
7
12
  * @returns
8
13
  */
9
- export function readStream<T>(readable: ReadableStream<T>, expected?: number | undefined): Promise<T[]>;
14
+ export function readStream<T>(readable: import("stream/web").ReadableStream<T>, expected?: number | undefined): Promise<T[]>;
15
+ /**
16
+ * <T>
17
+ */
18
+ export type ReadableStream<T> = import('node:stream/web').ReadableStream<T>;
10
19
  //# sourceMappingURL=read-stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wGA8BC"}
1
+ {"version":3,"file":"read-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/read-stream.js"],"names":[],"mappings":";AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,6HA8BC;;;;gCAzCY,OAAO,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC"}
@@ -1,7 +1,22 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * @template T
4
+ * @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
5
+ */
1
6
  /**
2
7
  * @template T
3
8
  * @param {ReadableStream<T>} readableStream
4
9
  * @returns {Promise<T>}
5
10
  */
6
- export function getReaderValue<T>(readableStream: ReadableStream<T>): Promise<T>;
11
+ export function getReaderValue<T>(readableStream: import("stream/web").ReadableStream<T>): Promise<T>;
12
+ /**
13
+ * @template T
14
+ * @param {ReadableStream<T>} readableStream
15
+ * @returns {AsyncGenerator<T>}
16
+ */
17
+ export function getReaderStream<T>(readableStream: import("stream/web").ReadableStream<T>): AsyncGenerator<T, any, any>;
18
+ /**
19
+ * <T>
20
+ */
21
+ export type ReadableStream<T> = import('node:stream/web').ReadableStream<T>;
7
22
  //# sourceMappingURL=reader-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reader-value.d.ts","sourceRoot":"","sources":["../../../test/fixtures/reader-value.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,iFAkBC"}
1
+ {"version":3,"file":"reader-value.d.ts","sourceRoot":"","sources":["../../../test/fixtures/reader-value.js"],"names":[],"mappings":";AAAA;;;GAGG;AAEH;;;;GAIG;AACH,sGAkBC;AAED;;;;GAIG;AACH,wHAoBC;;;;gCArDY,OAAO,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC"}
@@ -2,9 +2,4 @@ export function createServer(): Promise<{
2
2
  server: Http3Server;
3
3
  certificate: import("./certificate.js").Certificate;
4
4
  }>;
5
- /**
6
- * @param {import('../../lib/server.js').Http3Server} server
7
- * @param {string} path
8
- */
9
- export function getServerSession(server: import('../../lib/server.js').Http3Server, path: string): Promise<import("../../lib/types.js").WebTransportSession>;
10
5
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../test/fixtures/server.js"],"names":[],"mappings":"AAGA;;;GA6BC;AAED;;;GAGG;AACH,yCAHW,OAAO,qBAAqB,EAAE,WAAW,QACzC,MAAM,6DAqBhB"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../test/fixtures/server.js"],"names":[],"mappings":"AASA;;;GAkPC"}
@@ -0,0 +1,3 @@
1
+ declare const WebTransport: any;
2
+ export default WebTransport;
3
+ //# sourceMappingURL=webtransport.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webtransport.browser.d.ts","sourceRoot":"","sources":["../../../test/fixtures/webtransport.browser.js"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export default WebTransport;
2
+ import { WebTransport } from "../../lib/index.js";
3
+ //# sourceMappingURL=webtransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webtransport.d.ts","sourceRoot":"","sources":["../../../test/fixtures/webtransport.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"write-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/write-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,uFAQC"}
1
+ {"version":3,"file":"write-stream.d.ts","sourceRoot":"","sources":["../../../test/fixtures/write-stream.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,uFAeC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../test/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * <T>
3
+ */
4
+ export type Deferred<T> = import('../lib/types').Deferred<T>;
5
+ //# sourceMappingURL=session.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.spec.d.ts","sourceRoot":"","sources":["../../test/session.spec.js"],"names":[],"mappings":";;;0BAQa,OAAO,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC"}
@@ -1,5 +1,2 @@
1
- /**
2
- * <T>
3
- */
4
- export type Deferred<T> = import('../lib/types').Deferred<T>;
1
+ export {};
5
2
  //# sourceMappingURL=unidirectional-streams.spec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unidirectional-streams.spec.d.ts","sourceRoot":"","sources":["../../test/unidirectional-streams.spec.js"],"names":[],"mappings":";;;0BAaa,OAAO,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"unidirectional-streams.spec.d.ts","sourceRoot":"","sources":["../../test/unidirectional-streams.spec.js"],"names":[],"mappings":""}
package/lib/client.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import { Http3WebTransport } from './transport.js'
2
+ import { WebTransportError } from './error.js'
3
+ import { logger } from './utils.js'
4
+
5
+ const log = logger(`webtransport:http3client(${process.pid})`)
2
6
 
3
7
  /**
4
8
  * @typedef {import('./session').Http3WTSession} Http3WTSession
9
+ * @typedef {import('./types').Http3ClientInit} Http3ClientInit
5
10
  *
6
11
  * Http3Client events
7
12
  * @typedef {import('./types').Http3ClientEventHandler} Http3ClientEventHandler
@@ -15,7 +20,7 @@ import { Http3WebTransport } from './transport.js'
15
20
  */
16
21
  export class Http3Client extends Http3WebTransport {
17
22
  /**
18
- * @param {*} args
23
+ * @param {Http3ClientInit} args
19
24
  */
20
25
  constructor(args) {
21
26
  super(args, 'client')
@@ -35,9 +40,14 @@ export class Http3Client extends Http3WebTransport {
35
40
  this.webtransportProm = null
36
41
  /** @type {{ resolve: (value?: any) => void, reject: (err?: Error) => void} | null | undefined} */
37
42
  this.quicconnectedProm = null
43
+
44
+ this._quicConnectTimeout = args.quicConnectTimeout ?? 8000
45
+ this._webTransportConnectTimeout = args.webTransportConnectTimeout ?? 2000
38
46
  }
39
47
 
40
48
  async handleConnection() {
49
+ this.createTransportInt()
50
+
41
51
  this.quicconnected = new Promise((resolve, reject) => {
42
52
  this.quicconnectedProm = { resolve, reject }
43
53
  })
@@ -45,26 +55,18 @@ export class Http3Client extends Http3WebTransport {
45
55
  this.webtransportProm = { resolve, reject }
46
56
  })
47
57
 
48
- try {
49
- setTimeout(() => {
50
- if (this.quicconnectedProm) {
51
- this.quicconnectedProm.reject(new Error('Timeout client connection'))
52
- delete this.quicconnectedProm
53
- }
54
- }, 8000)
55
- await this.quicconnected
56
- // now create Webtransport session
57
- setTimeout(() => {
58
- if (this.webtransportProm) {
59
- this.webtransportProm.reject(
60
- new Error('Timeout webtransport support')
61
- )
62
- delete this.webtransportProm
63
- }
64
- }, 2000)
65
- } catch (error) {
66
- throw new Error('Cl:' + error)
67
- }
58
+ const timeout = setTimeout(() => {
59
+ if (this.quicconnectedProm) {
60
+ log.error('quic connection timeout')
61
+ this.quicconnectedProm.reject(
62
+ new WebTransportError('Opening handshake failed.')
63
+ )
64
+ delete this.quicconnectedProm
65
+ }
66
+ }, this._quicConnectTimeout)
67
+
68
+ await this.quicconnected
69
+ clearTimeout(timeout)
68
70
  }
69
71
 
70
72
  /**
@@ -73,26 +75,36 @@ export class Http3Client extends Http3WebTransport {
73
75
  * @returns
74
76
  */
75
77
  async createWTSession(sessionobj, path) {
76
- // TODO
77
- try {
78
- await this.webtransport // wait for webtransport support
79
- // ok now we open the session
80
- this.sessionobjint = sessionobj
81
- this.transportInt.openWTSession(path)
82
- console.log('wait for session')
83
- // we wait for a new session
84
- const sessobj = await this.sessionobj
85
-
86
- delete this.sessionobj
87
-
88
- return sessobj
89
- } catch (error) {
90
- throw new Error('createWTSession failed ' + error)
91
- }
78
+ // now create Webtransport session
79
+ const timeout = setTimeout(() => {
80
+ if (this.webtransportProm) {
81
+ log.error('webtransport connection timeout')
82
+ this.webtransportProm.reject(
83
+ new WebTransportError('Opening handshake failed.')
84
+ )
85
+ delete this.webtransportProm
86
+ }
87
+ }, this._webTransportConnectTimeout)
88
+ await this.webtransport // wait for webtransport support
89
+ clearTimeout(timeout)
90
+
91
+ // ok now we open the session
92
+ this.sessionobjint = sessionobj
93
+ this.transportInt.openWTSession(path)
94
+
95
+ // we wait for a new session
96
+ const sessobj = await this.sessionobj
97
+
98
+ delete this.sessionobj
99
+
100
+ return sessobj
92
101
  }
93
102
 
94
103
  closeHookSession() {
95
- this.transportInt.closeClient()
104
+ if (this.transportInt != null) {
105
+ this.transportInt.closeClient()
106
+ }
107
+
96
108
  this.stopped = true
97
109
  }
98
110
 
@@ -104,10 +116,11 @@ export class Http3Client extends Http3WebTransport {
104
116
  if (args.success) this.quicconnectedProm.resolve()
105
117
  else
106
118
  this.quicconnectedProm.reject(
107
- new Error('Connecting quic client failed')
119
+ new WebTransportError('Opening handshake failed.')
108
120
  )
109
121
  delete this.quicconnectedProm
110
- } else throw new Error('Client connected with no pending promise')
122
+ } else
123
+ throw new WebTransportError('Client connected with no pending promise')
111
124
  }
112
125
 
113
126
  /**
@@ -132,7 +145,7 @@ export class Http3Client extends Http3WebTransport {
132
145
  this.sessionProm.resolve(args.session)
133
146
  delete this.sessionProm
134
147
  } else {
135
- throw new Error(
148
+ throw new WebTransportError(
136
149
  'Http3WTSessionVisitor no object session or nor sessionprom'
137
150
  )
138
151
  }
@@ -142,7 +155,8 @@ export class Http3Client extends Http3WebTransport {
142
155
  * @param {ClientConnectedEvent | ClientWebtransportSupportEvent | Http3WTSessionVisitorEvent} args
143
156
  */
144
157
  customCallback(args) {
145
- // console.log('incoming callback custom client', args)
158
+ log('callback', args?.purpose)
159
+ log.trace(args)
146
160
  if (args.purpose) {
147
161
  switch (args.purpose) {
148
162
  case 'ClientConnected':
@@ -155,7 +169,7 @@ export class Http3Client extends Http3WebTransport {
155
169
  this.onHttp3WTSessionVisitor(args)
156
170
  break
157
171
  default: {
158
- throw new Error('unknown purpose')
172
+ throw new WebTransportError('unknown purpose')
159
173
  }
160
174
  }
161
175
  }
package/lib/dom.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ReadableStream } from 'node:stream/web'
2
+
1
3
  // Types taken from https://www.w3.org/TR/webtransport
2
4
  // These can be removed when they are added to the default typescript types
3
5
 
@@ -20,6 +22,7 @@ export interface WebTransportStats {
20
22
  smoothedRtt: number
21
23
  rttVariation: number
22
24
  minRtt: number
25
+ estimatedSendRate: bigint
23
26
  datagrams: WebTransportDatagramStats
24
27
  }
25
28
 
@@ -38,10 +41,6 @@ export interface WebTransportDatagramDuplexStream {
38
41
  // outgoingHighWaterMark: number
39
42
  }
40
43
 
41
- export interface WebTransportBidirectionalStream {
42
- readonly readable: WebTransportReceiveStream
43
- readonly writable: WebTransportSendStream
44
- }
45
44
 
46
45
  export interface WebTransportSendStreamStats {
47
46
  timestamp: number
@@ -64,6 +63,11 @@ export interface WebTransportReceiveStream extends ReadableStream<Uint8Array> {
64
63
  getStats: () => Promise<WebTransportReceiveStreamStats>
65
64
  }
66
65
 
66
+ export interface WebTransportBidirectionalStream {
67
+ readonly readable: WebTransportReceiveStream
68
+ readonly writable: WebTransportSendStream
69
+ }
70
+
67
71
  export interface WebTransportHash {
68
72
  algorithm: string
69
73
  value: BufferSource
@@ -73,6 +77,16 @@ export interface WebTransportOptions {
73
77
  allowPooling?: boolean
74
78
  requireUnreliable?: boolean
75
79
  serverCertificateHashes?: WebTransportHash[]
80
+
81
+ /**
82
+ * Nonstandard option - when a new connection is opened, how long to wait for the quic handshake to complete in ms before rejecting
83
+ */
84
+ quicConnectTimeout?: number
85
+
86
+ /**
87
+ * Nonstandard option - when a new connection is opened, how long to wait for the webtransport handshake to complete in ms before rejecting
88
+ */
89
+ webTransportConnectTimeout?: number
76
90
  congestionControl?: WebTransportCongestionControl
77
91
  }
78
92
 
package/lib/error.js ADDED
@@ -0,0 +1,10 @@
1
+ export class WebTransportError extends Error {
2
+ /**
3
+ * @param {string} message
4
+ */
5
+ constructor(message) {
6
+ super(message)
7
+
8
+ this.name = this[Symbol.toStringTag] = 'WebTransportError'
9
+ }
10
+ }
package/lib/event-loop.js CHANGED
@@ -2,13 +2,16 @@ import { Http3WebTransport } from './transport.js'
2
2
  import { Http3WTStream } from './stream.js'
3
3
  import { Http3WTSession } from './session.js'
4
4
  import { wtrouter } from './native.js'
5
+ import { logger } from './utils.js'
6
+
7
+ const log = logger(`webtransport:event-loop(${process.pid})`)
5
8
 
6
9
  export class Http3EventLoop {
7
10
  /** @type {Http3EventLoop | null} */
8
11
  static globalLoop = null
9
12
 
10
13
  /**
11
- * @param {*} [args]
14
+ * @param {{ quicheLogVerbose: any; } | undefined} [args]
12
15
  */
13
16
  constructor(args) {
14
17
  this.eventloopInt = new wtrouter.Http3EventLoop({
@@ -28,13 +31,13 @@ export class Http3EventLoop {
28
31
  * @param {*} [args]
29
32
  */
30
33
  startEventLoop(args) {
31
- console.log('start GlobalEventLoop')
34
+ log('start GlobalEventLoop')
32
35
  this.eventloopInt.startEventLoop(args)
33
36
  this.loopGuardianTimer = setInterval(this.loopGuardian, 5000)
34
37
  }
35
38
 
36
39
  shutdownEventLoop() {
37
- console.log('shutdown GlobalEventLoop')
40
+ log('shutdown GlobalEventLoop')
38
41
  Http3EventLoop.globalLoop = null
39
42
  clearInterval(this.loopGuardianTimer)
40
43
  this.eventloopInt.shutDownEventLoop()
@@ -54,7 +57,7 @@ export class Http3EventLoop {
54
57
  }
55
58
 
56
59
  static callback() {
57
- console.log('final eventloop callback called')
60
+ log('final eventloop callback called')
58
61
  }
59
62
 
60
63
  /**
@@ -65,7 +68,7 @@ export class Http3EventLoop {
65
68
  if (!Http3EventLoop.globalLoop) {
66
69
  Http3EventLoop.globalLoop = new Http3EventLoop()
67
70
  Http3EventLoop.globalLoop.startEventLoop(args)
68
- console.log('createGlobalEventLoop')
71
+ log('createGlobalEventLoop')
69
72
  }
70
73
  return Http3EventLoop.globalLoop
71
74
  }
package/lib/native.js CHANGED
@@ -3,6 +3,9 @@ import { createRequire } from 'module'
3
3
  import * as path from 'path'
4
4
  import * as url from 'url'
5
5
  import { arch, platform } from 'node:process'
6
+ import { logger } from './utils.js'
7
+
8
+ const log = logger(`webtransport:native(${process.pid})`)
6
9
 
7
10
  const binplatform = platform + '_' + arch
8
11
  const require = createRequire(import.meta.url)
@@ -20,6 +23,6 @@ if (
20
23
  wtpath = buildpath + '/Debug/webtransport.node'
21
24
  }
22
25
 
23
- console.log('load webtransport binary:', wtpath)
26
+ log('load webtransport binary:', wtpath)
24
27
 
25
28
  export const wtrouter = require(wtpath)
package/lib/server.js CHANGED
@@ -2,8 +2,9 @@ import { Http3WebTransport } from './transport.js'
2
2
  import { ReadableStream } from 'node:stream/web'
3
3
  import { Http3WTSession } from './session.js'
4
4
  import { isIPv4 } from 'net'
5
- // @ts-ignore
6
- import { defer } from './utils.js'
5
+ import { defer, logger } from './utils.js'
6
+
7
+ const log = logger(`webtransport:http3server(${process.pid})`)
7
8
 
8
9
  /**
9
10
  * @typedef {import('./types').WebTransportSession} WebTransportSession
@@ -47,6 +48,7 @@ export class Http3Server extends Http3WebTransport {
47
48
  }
48
49
 
49
50
  startServer() {
51
+ this.createTransportInt()
50
52
  this.transportInt.startServer()
51
53
  }
52
54
 
@@ -86,7 +88,8 @@ export class Http3Server extends Http3WebTransport {
86
88
 
87
89
  /**
88
90
  * @param {string} path
89
- * @param {any | undefined} [args=undefined]
91
+ * @param {object} [args]
92
+ * @param {boolean} [args.noAutoPaths]
90
93
  * @returns {ReadableStream<WebTransportSession>}
91
94
  */
92
95
  sessionStream(path, args) {
@@ -98,7 +101,9 @@ export class Http3Server extends Http3WebTransport {
98
101
  this.sessionController[path] = controller
99
102
  }
100
103
  })
101
- if (!args || !args.noAutoPaths) this.transportInt.addPath(path)
104
+ if (!args || !args.noAutoPaths) {
105
+ this.transportInt.addPath(path)
106
+ }
102
107
  return this.sessionStreams[path]
103
108
  }
104
109
 
@@ -108,17 +113,19 @@ export class Http3Server extends Http3WebTransport {
108
113
  onSessionRequest(args) {
109
114
  if (args.promise && args.header) {
110
115
  if (!this.requestHandler) throw new Error('Request handler not set')
111
- this.requestHandler({ header: args.header }).then(
112
- (/** @type {any} */ result) => {
113
- console.log('oSR', result)
116
+ this.requestHandler({ header: args.header })
117
+ .then((/** @type {any} */ result) => {
118
+ log('oSR', result)
114
119
  this.transportInt.finishSessionRequest({
115
120
  promise: args.promise,
116
121
  header: args.header,
117
122
  session: args.session,
118
123
  ...result
119
124
  })
120
- }
121
- )
125
+ })
126
+ .catch((/** @type {any} */ err) => {
127
+ log.error(err)
128
+ })
122
129
  } else throw new Error('onSessionRequest')
123
130
  }
124
131
 
@@ -183,7 +190,8 @@ export class Http3Server extends Http3WebTransport {
183
190
  * @param {Http3WTServerSessionVisitorEvent | ServerStatusEvent | ServerSessionRequestEvent} args
184
191
  */
185
192
  customCallback(args) {
186
- // console.log('incoming callback server', args)
193
+ log('callback', args?.purpose)
194
+ log.trace(args)
187
195
  if (args.purpose) {
188
196
  switch (args.purpose) {
189
197
  case 'SessionRequest':