@fails-components/webtransport 0.0.8 → 0.1.0-macarmbuild.5

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/CMakeLists.txt CHANGED
@@ -18,6 +18,26 @@ set(BUILD_TESTING OFF)
18
18
 
19
19
  set(protobuf_BUILD_PROTOC_BINARIES ON)
20
20
 
21
+
22
+ IF( NOT WIN32)
23
+ IF(APPLE)
24
+ IF(DEFINED ENV{LOCALHOMEWBREWICU})
25
+ MESSAGE(STATUS "Local homebrew icu detected")
26
+ MESSAGE(STATUS $ENV{LOCALHOMEWBREWICU})
27
+ SET(ICU_ROOT $ENV{LOCALHOMEWBREWICU})
28
+ ELSE()
29
+ IF(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
30
+ MESSAGE(STATUS "set icu root local")
31
+ SET(ICU_ROOT "/usr/local/opt/icu4c")
32
+ ELSE()
33
+ MESSAGE(STATUS "set icu root homebrew")
34
+ SET(ICU_ROOT "/opt/homebrew/icu4c")
35
+ ENDIF()
36
+ ENDIF()
37
+ ENDIF(APPLE)
38
+ find_package(ICU COMPONENTS uc i18n REQUIRED)
39
+ ENDIF(NOT WIN32)
40
+
21
41
  IF (WIN32)
22
42
  add_compile_definitions(NOMINMAX)
23
43
  ENDIF(WIN32)
@@ -35,6 +55,9 @@ add_subdirectory(third_party/libevent EXCLUDE_FROM_ALL)
35
55
  SET(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")
36
56
  SET(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
37
57
  add_subdirectory(third_party/protobuf EXCLUDE_FROM_ALL)
58
+ IF(APPLE)
59
+ set_target_properties(protoc libprotoc libprotobuf PROPERTIES OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Build architectures for Mac OS X" FORCE )
60
+ ENDIF(APPLE)
38
61
 
39
62
  IF (WIN32)
40
63
  add_compile_definitions(WIN32_LEAN_AND_MEAN NOGDI)
@@ -68,74 +91,78 @@ endif(COMMAND cmake_policy)
68
91
 
69
92
  add_compile_definitions(QUICHE_ENABLE_LIBEVENT)
70
93
 
94
+
95
+ IF (WIN32)
96
+
71
97
  add_library(icu STATIC
72
98
  #icu
73
- third_party/icu/icu4c/source/common/appendable.cpp
74
- third_party/icu/icu4c/source/common/bytestream.cpp
75
- third_party/icu/icu4c/source/common/bytesinkutil.cpp
76
- third_party/icu/icu4c/source/common/bytestrie.cpp
77
- third_party/icu/icu4c/source/common/bmpset.cpp
78
- third_party/icu/icu4c/source/common/charstr.cpp
79
- third_party/icu/icu4c/source/common/cmemory.cpp
80
- third_party/icu/icu4c/source/common/cstring.cpp
81
- third_party/icu/icu4c/source/common/edits.cpp
82
- third_party/icu/icu4c/source/common/locavailable.cpp
83
- third_party/icu/icu4c/source/common/localebuilder.cpp
84
- third_party/icu/icu4c/source/common/locid.cpp
85
- third_party/icu/icu4c/source/common/locmap.cpp
86
- third_party/icu/icu4c/source/common/loclikely.cpp
87
- third_party/icu/icu4c/source/common/loadednormalizer2impl.cpp
88
- third_party/icu/icu4c/source/common/normalizer2.cpp
89
- third_party/icu/icu4c/source/common/normalizer2impl.cpp
90
- third_party/icu/icu4c/source/common/patternprops.cpp
91
- third_party/icu/icu4c/source/common/propname.cpp
92
- third_party/icu/icu4c/source/common/punycode.cpp
93
- third_party/icu/icu4c/source/common/resource.cpp
94
- third_party/icu/icu4c/source/common/stringpiece.cpp
95
- third_party/icu/icu4c/source/common/uarrsort.cpp
96
- third_party/icu/icu4c/source/common/ubidi_props.cpp
97
- third_party/icu/icu4c/source/common/uchar.cpp
98
- third_party/icu/icu4c/source/common/ucmndata.cpp
99
- third_party/icu/icu4c/source/common/ucln_cmn.cpp
100
- third_party/icu/icu4c/source/common/ucptrie.cpp
101
- third_party/icu/icu4c/source/common/ucol_swp.cpp
102
- third_party/icu/icu4c/source/common/udata.cpp
103
- third_party/icu/icu4c/source/common/udatamem.cpp
104
- third_party/icu/icu4c/source/common/udataswp.cpp
105
- third_party/icu/icu4c/source/common/uenum.cpp
106
- third_party/icu/icu4c/source/common/uhash.cpp
107
- third_party/icu/icu4c/source/common/uloc.cpp
108
- third_party/icu/icu4c/source/common/uloc_tag.cpp
109
- third_party/icu/icu4c/source/common/uloc_keytype.cpp
110
- third_party/icu/icu4c/source/common/umapfile.cpp
111
- third_party/icu/icu4c/source/common/umath.cpp
112
- third_party/icu/icu4c/source/common/umutablecptrie.cpp
113
- third_party/icu/icu4c/source/common/umutex.cpp
114
- third_party/icu/icu4c/source/common/unistr.cpp
115
- third_party/icu/icu4c/source/common/unifilt.cpp
116
- third_party/icu/icu4c/source/common/unifunct.cpp
117
- third_party/icu/icu4c/source/common/unisetspan.cpp
118
- third_party/icu/icu4c/source/common/ustring.cpp
119
- third_party/icu/icu4c/source/common/ustrtrns.cpp
120
- third_party/icu/icu4c/source/common/ustrenum.cpp
121
- third_party/icu/icu4c/source/common/uscript_props.cpp
122
- third_party/icu/icu4c/source/common/util.cpp
123
- third_party/icu/icu4c/source/common/uts46.cpp
124
- third_party/icu/icu4c/source/common/uobject.cpp
125
- third_party/icu/icu4c/source/common/uinvchar.cpp
126
- third_party/icu/icu4c/source/common/uresbund.cpp
127
- third_party/icu/icu4c/source/common/uresdata.cpp
128
- third_party/icu/icu4c/source/common/uniset.cpp
129
- third_party/icu/icu4c/source/common/utf_impl.cpp
130
- third_party/icu/icu4c/source/common/utrace.cpp
131
- third_party/icu/icu4c/source/common/utrie2.cpp
132
- third_party/icu/icu4c/source/common/utrie_swap.cpp
133
- third_party/icu/icu4c/source/common/utypes.cpp
134
- third_party/icu/icu4c/source/common/uvector.cpp
135
- third_party/icu/icu4c/source/common/putil.cpp
136
- )
137
- target_include_directories(icu PUBLIC third_party/icu/icu4c/source/common)
138
- IF (WIN32)
99
+ third_party/icu/icu4c/source/common/appendable.cpp
100
+ third_party/icu/icu4c/source/common/bytestream.cpp
101
+ third_party/icu/icu4c/source/common/bytesinkutil.cpp
102
+ third_party/icu/icu4c/source/common/bytestrie.cpp
103
+ third_party/icu/icu4c/source/common/bmpset.cpp
104
+ third_party/icu/icu4c/source/common/charstr.cpp
105
+ third_party/icu/icu4c/source/common/cmemory.cpp
106
+ third_party/icu/icu4c/source/common/cstring.cpp
107
+ third_party/icu/icu4c/source/common/edits.cpp
108
+ third_party/icu/icu4c/source/common/locavailable.cpp
109
+ third_party/icu/icu4c/source/common/localebuilder.cpp
110
+ third_party/icu/icu4c/source/common/locid.cpp
111
+ third_party/icu/icu4c/source/common/locmap.cpp
112
+ third_party/icu/icu4c/source/common/loclikely.cpp
113
+ third_party/icu/icu4c/source/common/loadednormalizer2impl.cpp
114
+ third_party/icu/icu4c/source/common/normalizer2.cpp
115
+ third_party/icu/icu4c/source/common/normalizer2impl.cpp
116
+ third_party/icu/icu4c/source/common/patternprops.cpp
117
+ third_party/icu/icu4c/source/common/propname.cpp
118
+ third_party/icu/icu4c/source/common/punycode.cpp
119
+ third_party/icu/icu4c/source/common/resource.cpp
120
+ third_party/icu/icu4c/source/common/stringpiece.cpp
121
+ third_party/icu/icu4c/source/common/uarrsort.cpp
122
+ third_party/icu/icu4c/source/common/ubidi_props.cpp
123
+ third_party/icu/icu4c/source/common/uchar.cpp
124
+ third_party/icu/icu4c/source/common/ucmndata.cpp
125
+ third_party/icu/icu4c/source/common/ucln_cmn.cpp
126
+ third_party/icu/icu4c/source/common/ucptrie.cpp
127
+ third_party/icu/icu4c/source/common/ucol_swp.cpp
128
+ third_party/icu/icu4c/source/common/udata.cpp
129
+ third_party/icu/icu4c/source/common/udatamem.cpp
130
+ third_party/icu/icu4c/source/common/udataswp.cpp
131
+ third_party/icu/icu4c/source/common/uenum.cpp
132
+ third_party/icu/icu4c/source/common/uhash.cpp
133
+ third_party/icu/icu4c/source/common/uloc.cpp
134
+ third_party/icu/icu4c/source/common/uloc_tag.cpp
135
+ third_party/icu/icu4c/source/common/uloc_keytype.cpp
136
+ third_party/icu/icu4c/source/common/umapfile.cpp
137
+ third_party/icu/icu4c/source/common/umath.cpp
138
+ third_party/icu/icu4c/source/common/umutablecptrie.cpp
139
+ third_party/icu/icu4c/source/common/umutex.cpp
140
+ third_party/icu/icu4c/source/common/unistr.cpp
141
+ third_party/icu/icu4c/source/common/unifilt.cpp
142
+ third_party/icu/icu4c/source/common/unifunct.cpp
143
+ third_party/icu/icu4c/source/common/unisetspan.cpp
144
+ third_party/icu/icu4c/source/common/ustring.cpp
145
+ third_party/icu/icu4c/source/common/ustrtrns.cpp
146
+ third_party/icu/icu4c/source/common/ustrenum.cpp
147
+ third_party/icu/icu4c/source/common/uscript_props.cpp
148
+ third_party/icu/icu4c/source/common/util.cpp
149
+ third_party/icu/icu4c/source/common/uts46.cpp
150
+ third_party/icu/icu4c/source/common/uobject.cpp
151
+ third_party/icu/icu4c/source/common/uinvchar.cpp
152
+ third_party/icu/icu4c/source/common/uresbund.cpp
153
+ third_party/icu/icu4c/source/common/uresdata.cpp
154
+ third_party/icu/icu4c/source/common/uniset.cpp
155
+ third_party/icu/icu4c/source/common/utf_impl.cpp
156
+ third_party/icu/icu4c/source/common/utrace.cpp
157
+ third_party/icu/icu4c/source/common/utrie2.cpp
158
+ third_party/icu/icu4c/source/common/utrie_swap.cpp
159
+ third_party/icu/icu4c/source/common/utypes.cpp
160
+ third_party/icu/icu4c/source/common/uvector.cpp
161
+ third_party/icu/icu4c/source/common/putil.cpp
162
+ )
163
+ target_include_directories(icu
164
+ PUBLIC third_party/icu/icu4c/source/common
165
+ )
139
166
  target_sources(icu PRIVATE
140
167
  third_party/icu/icu4c/source/common/wintz.cpp
141
168
  )
@@ -143,13 +170,14 @@ IF (WIN32)
143
170
  #hack since this function is not currently used
144
171
  ICU_DATA_DIR_WINDOWS=""
145
172
  )
146
- ENDIF(WIN32)
147
173
 
148
- target_compile_definitions(icu
149
- PRIVATE U_DEFINE_FALSE_AND_TRUE=1
150
- U_STATIC_IMPLEMENTATION
151
- U_COMMON_IMPLEMENTATION
152
- )
174
+ target_compile_definitions(icu
175
+ PRIVATE U_DEFINE_FALSE_AND_TRUE=1
176
+ U_STATIC_IMPLEMENTATION
177
+ U_COMMON_IMPLEMENTATION
178
+ )
179
+
180
+ ENDIF(WIN32)
153
181
 
154
182
  add_library(gquiche STATIC
155
183
  #plattform impl
@@ -740,8 +768,6 @@ third_party/quiche/quiche/quic/core/quic_idle_network_detector.h
740
768
  third_party/quiche/quiche/quic/core/quic_interval.h
741
769
  third_party/quiche/quiche/quic/core/quic_interval_deque.h
742
770
  third_party/quiche/quiche/quic/core/quic_interval_set.h
743
- third_party/quiche/quiche/quic/core/quic_legacy_version_encapsulator.cc
744
- third_party/quiche/quiche/quic/core/quic_legacy_version_encapsulator.h
745
771
  third_party/quiche/quiche/quic/core/quic_lru_cache.h
746
772
  third_party/quiche/quiche/quic/core/quic_mtu_discovery.cc
747
773
  third_party/quiche/quiche/quic/core/quic_mtu_discovery.h
@@ -898,6 +924,7 @@ ELSE(WIN32)
898
924
  )
899
925
  ENDIF(WIN32)
900
926
 
927
+
901
928
  add_custom_command(
902
929
  OUTPUT
903
930
  ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/cached_network_parameters.pb.h
@@ -954,13 +981,20 @@ PUBLIC third_party/boringssl/src/include
954
981
  PUBLIC third_party/abseil-cpp
955
982
  PUBLIC third_party/googleurl
956
983
  PUBLIC third_party/libevent/include
957
- PUBLIC third_party/icu/icu4c/source/common
958
984
  PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/third_party/libevent/include
959
985
  PUBLIC .
960
986
  PUBLIC ${Protobuf_INCLUDE_DIRS}
961
987
  PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
962
988
  PUBLIC ${CMAKE_JS_INC}
963
989
  )
990
+
991
+ IF (WIN32)
992
+ target_include_directories(gquiche PUBLIC third_party/icu/icu4c/source/common)
993
+ ELSE(WIN32)
994
+ include_directories(gquiche PUBLIC ${ICU_INCLUDE_DIRS})
995
+ target_link_libraries(gquiche ICU::uc ICU::i18n)
996
+ ENDIF(WIN32)
997
+
964
998
  target_link_libraries(gquiche
965
999
  absl::base
966
1000
  absl::int128
package/build.js CHANGED
@@ -157,6 +157,23 @@ const prebuildInstall = async (args) => {
157
157
  })
158
158
  }
159
159
 
160
+ const buildTypes = async () => {
161
+ return new Promise((resolve, reject) => {
162
+ const tsc = 'tsc'
163
+ const proc = spawn(tsc, {
164
+ cwd: process.cwd(),
165
+ stdio: [null, 'inherit', 'inherit'],
166
+ shell: true
167
+ })
168
+
169
+ proc.on('close', (code) => {
170
+ if (code === 0) resolve(code)
171
+ else reject(code)
172
+ console.log(`child process exited with code ${code}`)
173
+ })
174
+ })
175
+ }
176
+
160
177
  const execbuild = async (args) => {
161
178
  return new Promise((resolve, reject) => {
162
179
  const cmakejs = 'cmake-js'
@@ -184,14 +201,18 @@ if (argv.length > 2) {
184
201
  ]
185
202
  if (platform === 'win32') platformargs.push('-t', 'ClangCL')
186
203
  const pbargs = []
187
- if (platform === 'win32') pbargs.push('-t', 'ClangCL')
188
204
  const pbargspre = []
189
- if (env.BUILDARCH) pbargspre.push('--arch', env.BUILDARCH)
205
+ if (platform === 'win32') pbargs.push('-t', 'ClangCL')
206
+ if (env.BUILDARCH) {
207
+ pbargspre.push('--arch', env.BUILDARCH)
208
+ platformargs.push('--arch', env.BUILDARCH)
209
+ }
190
210
  if (env.GH_TOKEN) pbargspre.push('--u', env.GH_TOKEN)
211
+
191
212
  switch (argv[2]) {
192
213
  case 'prebuild':
193
214
  try {
194
- prebuild([
215
+ await prebuild([
195
216
  '-t',
196
217
  '6',
197
218
  '-r',
@@ -229,13 +250,13 @@ if (argv.length > 2) {
229
250
  await extractthirdparty()
230
251
  } catch (error) {
231
252
  console.error('Building binary failed: ', error)
232
-
233
253
  }
234
254
  }
235
255
  // eslint-disable-next-line no-fallthrough
236
256
  case 'build':
237
257
  try {
238
- execbuild(['build', ...platformargs])
258
+ await execbuild(['build', ...platformargs])
259
+ await buildTypes()
239
260
  } catch (error) {
240
261
  console.error('Building binary failed: ', error)
241
262
  process.exit(1)
@@ -243,7 +264,8 @@ if (argv.length > 2) {
243
264
  break
244
265
  case 'rebuild':
245
266
  try {
246
- execbuild(['rebuild', ...platformargs])
267
+ await execbuild(['rebuild', ...platformargs])
268
+ await buildTypes()
247
269
  } catch (error) {
248
270
  console.error('ReBuilding binary failed: ', error)
249
271
  process.exit(1)
@@ -251,7 +273,8 @@ if (argv.length > 2) {
251
273
  break
252
274
  case 'build-debug':
253
275
  try {
254
- execbuild(['build', '-D', ...platformargs])
276
+ await execbuild(['build', '-D', ...platformargs])
277
+ await buildTypes()
255
278
  } catch (error) {
256
279
  console.error('Building binary failed: ', error)
257
280
  process.exit(1)
@@ -259,7 +282,8 @@ if (argv.length > 2) {
259
282
  break
260
283
  case 'rebuild-debug':
261
284
  try {
262
- execbuild(['rebuild', '-D', ...platformargs])
285
+ await execbuild(['rebuild', '-D', ...platformargs])
286
+ await buildTypes()
263
287
  } catch (error) {
264
288
  console.error('ReBuilding binary failed: ', error)
265
289
  process.exit(1)
package/lib/client.js ADDED
@@ -0,0 +1,163 @@
1
+ import { Http3WebTransport } from './transport.js'
2
+
3
+ /**
4
+ * @typedef {import('./session').Http3WTSession} Http3WTSession
5
+ *
6
+ * Http3Client events
7
+ * @typedef {import('./types').Http3ClientEventHandler} Http3ClientEventHandler
8
+ * @typedef {import('./types').ClientConnectedEvent} ClientConnectedEvent
9
+ * @typedef {import('./types').ClientWebtransportSupportEvent} ClientWebtransportSupportEvent
10
+ * @typedef {import('./types').Http3WTSessionVisitorEvent} Http3WTSessionVisitorEvent
11
+ */
12
+
13
+ /**
14
+ * @implements {Http3ClientEventHandler}
15
+ */
16
+ export class Http3Client extends Http3WebTransport {
17
+ /**
18
+ * @param {*} args
19
+ */
20
+ constructor(args) {
21
+ super(args, 'client')
22
+
23
+ /** @type {{ resolve: (value?: any) => void, reject: (err?: Error) => void} | null | undefined} */
24
+ this.sessionProm = null
25
+
26
+ /** @type {Promise<void> | undefined} */
27
+ this.sessionobj = new Promise((resolve, reject) => {
28
+ this.sessionProm = { resolve, reject }
29
+ }).catch(() => {}) // add default handler if no one cares
30
+ /** @type {Http3WTSession | null | undefined} */
31
+ this.sessionobjint = null
32
+ this.closeHookSession = this.closeHookSession.bind(this)
33
+
34
+ /** @type {{ resolve: (value?: any) => void, reject: (err?: Error) => void} | null | undefined} */
35
+ this.webtransportProm = null
36
+ /** @type {{ resolve: (value?: any) => void, reject: (err?: Error) => void} | null | undefined} */
37
+ this.quicconnectedProm = null
38
+ }
39
+
40
+ async handleConnection() {
41
+ this.quicconnected = new Promise((resolve, reject) => {
42
+ this.quicconnectedProm = { resolve, reject }
43
+ })
44
+ this.webtransport = new Promise((resolve, reject) => {
45
+ this.webtransportProm = { resolve, reject }
46
+ })
47
+
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
+ }
68
+ }
69
+
70
+ /**
71
+ * @param {Http3WTSession} sessionobj
72
+ * @param {string} path
73
+ * @returns
74
+ */
75
+ 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
+ }
92
+ }
93
+
94
+ closeHookSession() {
95
+ this.transportInt.closeClient()
96
+ this.stopped = true
97
+ }
98
+
99
+ /**
100
+ * @param {ClientConnectedEvent} args
101
+ */
102
+ onClientConnected(args) {
103
+ if (this.quicconnectedProm) {
104
+ if (args.success) this.quicconnectedProm.resolve()
105
+ else
106
+ this.quicconnectedProm.reject(
107
+ new Error('Connecting quic client failed')
108
+ )
109
+ delete this.quicconnectedProm
110
+ } else throw new Error('Client connected with no pending promise')
111
+ }
112
+
113
+ /**
114
+ * @param {ClientWebtransportSupportEvent} args
115
+ */
116
+ onClientWebTransportSupport(args) {
117
+ if (this.webtransportProm) {
118
+ this.webtransportProm.resolve()
119
+ delete this.webtransportProm
120
+ }
121
+ }
122
+
123
+ /**
124
+ * @param {Http3WTSessionVisitorEvent} args
125
+ */
126
+ onHttp3WTSessionVisitor(args) {
127
+ // create Http3 Visitor
128
+ if (args.session && this.sessionProm && this.sessionobjint) {
129
+ this.sessionobjint.setSessionObj(args.session)
130
+ args.session.jsobj.closeHook = this.closeHookSession
131
+ delete this.sessionobjint
132
+ this.sessionProm.resolve(args.session)
133
+ delete this.sessionProm
134
+ } else {
135
+ throw new Error(
136
+ 'Http3WTSessionVisitor no object session or nor sessionprom'
137
+ )
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @param {ClientConnectedEvent | ClientWebtransportSupportEvent | Http3WTSessionVisitorEvent} args
143
+ */
144
+ customCallback(args) {
145
+ // console.log('incoming callback custom client', args)
146
+ if (args.purpose) {
147
+ switch (args.purpose) {
148
+ case 'ClientConnected':
149
+ this.onClientConnected(args)
150
+ break
151
+ case 'ClientWebtransportSupport':
152
+ this.onClientWebTransportSupport(args)
153
+ break
154
+ case 'Http3WTSessionVisitor':
155
+ this.onHttp3WTSessionVisitor(args)
156
+ break
157
+ default: {
158
+ throw new Error('unknown purpose')
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
package/lib/dom.ts ADDED
@@ -0,0 +1,95 @@
1
+ // Types taken from https://www.w3.org/TR/webtransport
2
+ // These can be removed when they are added to the default typescript types
3
+
4
+ export interface WebTransportDatagramStats {
5
+ timestamp: number
6
+ expiredOutgoing: bigint
7
+ droppedIncoming: bigint
8
+ lostOutgoing: bigint
9
+ }
10
+
11
+ export interface WebTransportStats {
12
+ timestamp: number
13
+ bytesSent: bigint
14
+ packetsSent: bigint
15
+ packetsLost: bigint
16
+ numOutgoingStreamsCreated: number
17
+ numIncomingStreamsCreated: number
18
+ bytesReceived: bigint
19
+ packetsReceived: bigint
20
+ smoothedRtt: number
21
+ rttVariation: number
22
+ minRtt: number
23
+ datagrams: WebTransportDatagramStats
24
+ }
25
+
26
+ export interface WebTransportCloseInfo {
27
+ closeCode: number
28
+ reason: string
29
+ }
30
+
31
+ export interface WebTransportDatagramDuplexStream {
32
+ readable: ReadableStream<Uint8Array>
33
+ writable: WritableStream<Uint8Array>
34
+ // readonly maxDatagramSize: number
35
+ // incomingMaxAge?: number
36
+ // outgoingMaxAge?: number
37
+ // incomingHighWaterMark: number
38
+ // outgoingHighWaterMark: number
39
+ }
40
+
41
+ export interface WebTransportBidirectionalStream {
42
+ readonly readable: ReadableStream<Uint8Array>
43
+ readonly writable: WritableStream<Uint8Array>
44
+ }
45
+
46
+ export interface WebTransportSendStreamStats {
47
+ timestamp: number
48
+ bytesWritten: bigint
49
+ bytesSent: bigint
50
+ bytesAcknowledged: bigint
51
+ }
52
+
53
+ export interface WebTransportSendStream extends WritableStream<Uint8Array> {
54
+ getStats: () => Promise<WebTransportSendStreamStats>
55
+ }
56
+
57
+ export interface WebTransportReceiveStreamStats {
58
+ timestamp: number
59
+ bytesReceived: bigint
60
+ bytesRead: bigint
61
+ }
62
+
63
+ export interface WebTransportReceiveStream extends ReadableStream<Uint8Array> {
64
+ getStats: () => Promise<WebTransportReceiveStreamStats>
65
+ }
66
+
67
+ export interface WebTransportHash {
68
+ algorithm: string
69
+ value: BufferSource
70
+ }
71
+
72
+ export interface WebTransportOptions {
73
+ allowPooling?: boolean
74
+ requireUnreliable?: boolean
75
+ serverCertificateHashes?: WebTransportHash[]
76
+ }
77
+
78
+ export interface WebTransport {
79
+ // getStats: () => Promise<WebTransportStats>
80
+ readonly ready: Promise<void>
81
+ // readonly reliability: WebTransportReliabilityMode
82
+ readonly closed: Promise<WebTransportCloseInfo>
83
+ close: (closeInfo?: WebTransportCloseInfo) => void
84
+ readonly datagrams: WebTransportDatagramDuplexStream
85
+
86
+ createBidirectionalStream: () => Promise<WebTransportBidirectionalStream>
87
+ /* a ReadableStream of WebTransportBidirectionalStream objects */
88
+ readonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>
89
+
90
+ createUnidirectionalStream: () => Promise<WebTransportSendStream>
91
+ /* a ReadableStream of WebTransportReceiveStream objects */
92
+ readonly incomingUnidirectionalStreams: ReadableStream<WebTransportReceiveStream>
93
+ }
94
+
95
+ export type WebTransportReliabilityMode = 'pending' | 'reliable-only' | 'supports-unreliable'
@@ -0,0 +1,79 @@
1
+ import { Http3WebTransport } from './transport.js'
2
+ import { Http3WTStream } from './stream.js'
3
+ import { Http3WTSession } from './session.js'
4
+ import { wtrouter } from './native.js'
5
+
6
+ export class Http3EventLoop {
7
+ /** @type {Http3EventLoop | null} */
8
+ static globalLoop = null
9
+
10
+ /**
11
+ * @param {*} [args]
12
+ */
13
+ constructor(args) {
14
+ this.eventloopInt = new wtrouter.Http3EventLoop({
15
+ transportCallback: Http3WebTransport.transportCallback,
16
+ streamCallback: Http3WTStream.callback,
17
+ sessionCallback: Http3WTSession.callback,
18
+ eventloopCallback: Http3EventLoop.callback
19
+ })
20
+ this.eventloopInt.jsobj = this
21
+
22
+ this.refObjects = new Set()
23
+ this.loopGuardian = this.loopGuardian.bind(this)
24
+ }
25
+
26
+ startEventLoop() {
27
+ console.log('start GlobalEventLoop')
28
+ this.eventloopInt.startEventLoop()
29
+ this.loopGuardianTimer = setInterval(this.loopGuardian, 5000)
30
+ }
31
+
32
+ shutdownEventLoop() {
33
+ console.log('shutdown GlobalEventLoop')
34
+ Http3EventLoop.globalLoop = null
35
+ clearInterval(this.loopGuardianTimer)
36
+ this.eventloopInt.shutDownEventLoop()
37
+ }
38
+
39
+ loopGuardian() {
40
+ for (const item of this.refObjects) {
41
+ if (typeof item.deref() === 'undefined' || item.deref()?.stopped)
42
+ this.refObjects.delete(item)
43
+ }
44
+ if (this.refObjects.size === 0) {
45
+ const now = Date.now()
46
+ if (!this.refObjectsEmptyTime) this.refObjectsEmptyTime = now
47
+ else if (now - this.refObjectsEmptyTime > 20 * 1000)
48
+ this.shutdownEventLoop()
49
+ } else if (this.refObjectsEmptyTime) delete this.refObjectsEmptyTime
50
+ }
51
+
52
+ static callback() {
53
+ console.log('final eventloop callback called')
54
+ }
55
+
56
+ /**
57
+ * @returns {Http3EventLoop}
58
+ */
59
+ static createGlobalEventLoop() {
60
+ if (!Http3EventLoop.globalLoop) {
61
+ Http3EventLoop.globalLoop = new Http3EventLoop()
62
+ Http3EventLoop.globalLoop.startEventLoop()
63
+ console.log('createGlobalEventLoop')
64
+ }
65
+ return Http3EventLoop.globalLoop
66
+ }
67
+
68
+ /**
69
+ * @param {any} object
70
+ * @returns {Http3EventLoop}
71
+ */
72
+ static getGlobalEventLoop(object) {
73
+ if (!object) throw new Error('getGlobalEventLoop without reference object')
74
+ const loop =
75
+ Http3EventLoop.globalLoop ?? Http3EventLoop.createGlobalEventLoop()
76
+ loop.refObjects.add(new WeakRef(object))
77
+ return loop
78
+ }
79
+ }