sfml.js 1.0.0-rc.2 → 1.1.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 (314) hide show
  1. package/README.ja.md +16 -11
  2. package/README.ko.md +16 -11
  3. package/README.md +16 -11
  4. package/README.zh-CN.md +16 -11
  5. package/assets/breakout.png +0 -0
  6. package/binding.gyp +23 -16
  7. package/dist/audio/effect-processor.js +9 -3
  8. package/dist/audio/input-sound-file.js +41 -15
  9. package/dist/audio/listener.js +33 -11
  10. package/dist/audio/music.js +41 -18
  11. package/dist/audio/output-sound-file.js +4 -2
  12. package/dist/audio/playback-device.js +11 -3
  13. package/dist/audio/sound-buffer-recorder.js +8 -5
  14. package/dist/audio/sound-buffer.js +40 -17
  15. package/dist/audio/sound-file-factory.js +21 -9
  16. package/dist/audio/sound-file-reader.js +21 -7
  17. package/dist/audio/sound-recorder.js +36 -15
  18. package/dist/audio/sound-source.js +117 -40
  19. package/dist/audio/sound-stream.js +14 -5
  20. package/dist/audio/sound.js +9 -4
  21. package/dist/audio/value.js +42 -16
  22. package/dist/graphics/blend-mode.js +2 -1
  23. package/dist/graphics/boolean-vector.d.ts +1 -2
  24. package/dist/graphics/boolean-vector.js +19 -9
  25. package/dist/graphics/color.js +2 -1
  26. package/dist/graphics/convex-shape.js +7 -3
  27. package/dist/graphics/font.js +52 -23
  28. package/dist/graphics/glsl-matrix.js +8 -3
  29. package/dist/graphics/glsl.js +47 -16
  30. package/dist/graphics/glyph.js +27 -10
  31. package/dist/graphics/image.js +30 -14
  32. package/dist/graphics/rect.js +15 -8
  33. package/dist/graphics/render-states.js +18 -9
  34. package/dist/graphics/render-target.js +49 -23
  35. package/dist/graphics/render-texture.js +24 -12
  36. package/dist/graphics/render-window.js +6 -3
  37. package/dist/graphics/shader.js +67 -32
  38. package/dist/graphics/shape.js +25 -13
  39. package/dist/graphics/sprite.js +19 -9
  40. package/dist/graphics/stencil-mode.js +10 -6
  41. package/dist/graphics/swap.js +2 -1
  42. package/dist/graphics/text.js +123 -48
  43. package/dist/graphics/texture.js +48 -24
  44. package/dist/graphics/transform.js +29 -13
  45. package/dist/graphics/transformable.js +2 -1
  46. package/dist/graphics/vertex-array.js +40 -18
  47. package/dist/graphics/vertex-buffer.js +39 -19
  48. package/dist/graphics/vertex.js +6 -3
  49. package/dist/graphics/view.js +30 -14
  50. package/dist/index.d.ts +4 -4
  51. package/dist/internal/audio-codec-registry.js +12 -6
  52. package/dist/internal/audio-input-stream.js +2 -1
  53. package/dist/internal/audio-music-pump.js +58 -24
  54. package/dist/internal/audio-recorder-session.js +17 -7
  55. package/dist/internal/audio-worker-session.js +28 -10
  56. package/dist/internal/audio-worker.js +40 -21
  57. package/dist/internal/glsl-value.d.ts +3 -1
  58. package/dist/internal/glsl-value.js +18 -8
  59. package/dist/internal/graphics-state.js +29 -15
  60. package/dist/internal/input-stream.d.ts +3 -1
  61. package/dist/internal/input-stream.js +16 -7
  62. package/dist/internal/numeric-properties.js +2 -1
  63. package/dist/internal/render-states.js +2 -1
  64. package/dist/internal/scalar.js +22 -13
  65. package/dist/internal/shaped-glyph.d.ts +3 -1
  66. package/dist/internal/shaped-glyph.js +12 -4
  67. package/dist/internal/struct-view.d.ts +3 -1
  68. package/dist/internal/struct-view.js +3 -1
  69. package/dist/internal/transformable.js +2 -1
  70. package/dist/network/common.js +23 -11
  71. package/dist/network/dns.js +25 -17
  72. package/dist/network/ftp.js +43 -18
  73. package/dist/network/http.js +126 -56
  74. package/dist/network/ip-address.js +50 -25
  75. package/dist/network/packet.js +63 -25
  76. package/dist/network/sftp.js +175 -74
  77. package/dist/network/socket-selector.js +28 -14
  78. package/dist/network/socket.js +71 -30
  79. package/dist/network/tcp-listener.js +42 -19
  80. package/dist/network/tcp-socket.js +111 -53
  81. package/dist/network/tls-material.js +2 -1
  82. package/dist/network/udp-socket.js +68 -33
  83. package/dist/system/angle.js +2 -1
  84. package/dist/system/clock.js +4 -2
  85. package/dist/system/err.js +5 -2
  86. package/dist/system/file-input-stream.js +8 -4
  87. package/dist/system/input-stream.js +6 -3
  88. package/dist/system/operators.d.ts +1 -1
  89. package/dist/system/operators.js +90 -50
  90. package/dist/system/sleep.js +4 -2
  91. package/dist/system/time.js +12 -6
  92. package/dist/system/vector2.js +6 -7
  93. package/dist/system/vector3.js +11 -6
  94. package/dist/window/clipboard.js +2 -1
  95. package/dist/window/context.js +10 -5
  96. package/dist/window/cursor.js +2 -1
  97. package/dist/window/event.js +9 -5
  98. package/dist/window/mouse.js +4 -2
  99. package/dist/window/video-mode.js +2 -1
  100. package/dist/window/window.js +19 -12
  101. package/native/addon.cc +25 -12
  102. package/native/audio-binding.cc +266 -126
  103. package/native/audio-codec-binding.cc +147 -77
  104. package/native/audio-device-binding.cc +76 -49
  105. package/native/audio-file-binding.cc +116 -67
  106. package/native/audio-recorder-binding.cc +147 -98
  107. package/native/audio-recorder.h +1 -1
  108. package/native/audio-state.h +53 -30
  109. package/native/audio-stream-binding.cc +148 -94
  110. package/native/audio-stream.h +5 -4
  111. package/native/audio-worker-binding.cc +163 -81
  112. package/native/audio-worker.h +35 -19
  113. package/native/batch-drawable.cc +29 -16
  114. package/native/batch-drawable.h +11 -8
  115. package/native/context-binding.cc +40 -27
  116. package/native/context-settings.h +15 -8
  117. package/native/deferred-delete.cc +9 -6
  118. package/native/deferred-delete.h +7 -8
  119. package/native/error-stream-binding.cc +42 -28
  120. package/native/font-binding.cc +89 -48
  121. package/native/graphics-binding.cc +122 -72
  122. package/native/graphics-state.h +50 -36
  123. package/native/image-binding.cc +38 -24
  124. package/native/image-state.h +26 -18
  125. package/native/input-binding.cc +42 -27
  126. package/native/render-window-binding.cc +38 -23
  127. package/native/shader-binding.cc +115 -50
  128. package/native/shape-binding.cc +94 -49
  129. package/native/shape-state.h +18 -9
  130. package/native/shaped-glyph-storage.h +9 -5
  131. package/native/stream-binding.cc +143 -117
  132. package/native/system-binding.cc +17 -12
  133. package/native/text-binding.cc +68 -35
  134. package/native/text-state.h +25 -18
  135. package/native/texture-binding.cc +42 -33
  136. package/native/texture-resource.h +20 -12
  137. package/native/time-value.h +3 -1
  138. package/native/transformable-binding.cc +12 -6
  139. package/native/transformable-state.h +6 -6
  140. package/native/value-binding.h +46 -28
  141. package/native/value-layout.h +10 -10
  142. package/native/values-binding.cc +29 -23
  143. package/native/vertex-binding.cc +18 -12
  144. package/native/vertex-buffer-binding.cc +38 -24
  145. package/native/vertex-storage.h +2 -2
  146. package/native/view-data.h +4 -3
  147. package/native/window-binding.cc +75 -45
  148. package/native/window-event.h +20 -11
  149. package/native/window-owner.h +15 -12
  150. package/package.json +43 -50
  151. package/src/audio/effect-processor.ts +9 -3
  152. package/src/audio/input-sound-file.ts +108 -36
  153. package/src/audio/listener.ts +39 -13
  154. package/src/audio/music.ts +112 -47
  155. package/src/audio/output-sound-file.ts +40 -11
  156. package/src/audio/playback-device.ts +23 -8
  157. package/src/audio/sound-buffer-recorder.ts +35 -13
  158. package/src/audio/sound-buffer.ts +166 -58
  159. package/src/audio/sound-file-factory.ts +127 -49
  160. package/src/audio/sound-file-reader.ts +49 -15
  161. package/src/audio/sound-recorder.ts +100 -34
  162. package/src/audio/sound-source.ts +142 -45
  163. package/src/audio/sound-stream.ts +15 -5
  164. package/src/audio/sound.ts +12 -4
  165. package/src/audio/value.ts +89 -26
  166. package/src/graphics/blend-mode.ts +3 -1
  167. package/src/graphics/boolean-vector.ts +56 -26
  168. package/src/graphics/color.ts +3 -1
  169. package/src/graphics/convex-shape.ts +10 -3
  170. package/src/graphics/font.ts +171 -50
  171. package/src/graphics/glsl-matrix.ts +9 -3
  172. package/src/graphics/glsl.ts +81 -35
  173. package/src/graphics/glyph.ts +67 -26
  174. package/src/graphics/image.ts +119 -45
  175. package/src/graphics/rect.ts +56 -24
  176. package/src/graphics/render-states.ts +31 -14
  177. package/src/graphics/render-target.ts +197 -81
  178. package/src/graphics/render-texture.ts +36 -12
  179. package/src/graphics/render-window.ts +9 -3
  180. package/src/graphics/shader.ts +186 -61
  181. package/src/graphics/shape.ts +93 -35
  182. package/src/graphics/sprite.ts +64 -25
  183. package/src/graphics/stencil-mode.ts +12 -6
  184. package/src/graphics/swap.ts +3 -2
  185. package/src/graphics/text.ts +229 -74
  186. package/src/graphics/texture.ts +180 -61
  187. package/src/graphics/transform.ts +132 -47
  188. package/src/graphics/transformable.ts +3 -1
  189. package/src/graphics/vertex-array.ts +87 -35
  190. package/src/graphics/vertex-buffer.ts +97 -33
  191. package/src/graphics/vertex.ts +9 -3
  192. package/src/graphics/view.ts +59 -21
  193. package/src/index.ts +101 -23
  194. package/src/internal/audio-codec-registry.ts +18 -6
  195. package/src/internal/audio-input-stream.ts +6 -2
  196. package/src/internal/audio-music-pump.ts +116 -41
  197. package/src/internal/audio-native.ts +249 -96
  198. package/src/internal/audio-recorder-session.ts +68 -24
  199. package/src/internal/audio-worker-session.ts +65 -21
  200. package/src/internal/audio-worker.ts +85 -41
  201. package/src/internal/glsl-value.ts +26 -11
  202. package/src/internal/graphics-state.ts +57 -20
  203. package/src/internal/input-stream.ts +23 -10
  204. package/src/internal/native.ts +252 -99
  205. package/src/internal/numeric-properties.ts +2 -1
  206. package/src/internal/render-states.ts +3 -1
  207. package/src/internal/scalar.ts +33 -14
  208. package/src/internal/shaped-glyph.ts +25 -12
  209. package/src/internal/struct-view.ts +40 -13
  210. package/src/internal/transformable.ts +3 -1
  211. package/src/network/common.ts +35 -11
  212. package/src/network/dns.ts +95 -38
  213. package/src/network/ftp.ts +129 -47
  214. package/src/network/http.ts +232 -77
  215. package/src/network/ip-address.ts +118 -48
  216. package/src/network/packet.ts +161 -54
  217. package/src/network/sftp.ts +498 -168
  218. package/src/network/socket-selector.ts +66 -26
  219. package/src/network/socket.ts +133 -46
  220. package/src/network/tcp-listener.ts +78 -29
  221. package/src/network/tcp-socket.ts +240 -95
  222. package/src/network/tls-material.ts +6 -2
  223. package/src/network/udp-socket.ts +147 -53
  224. package/src/system/angle.ts +3 -1
  225. package/src/system/clock.ts +12 -4
  226. package/src/system/err.ts +5 -2
  227. package/src/system/file-input-stream.ts +12 -4
  228. package/src/system/input-stream.ts +9 -3
  229. package/src/system/operators.ts +290 -115
  230. package/src/system/sleep.ts +6 -2
  231. package/src/system/time.ts +18 -6
  232. package/src/system/timeout-with-predicate.ts +19 -8
  233. package/src/system/vector2.ts +101 -49
  234. package/src/system/vector3.ts +85 -36
  235. package/src/window/clipboard.ts +3 -1
  236. package/src/window/context.ts +15 -5
  237. package/src/window/cursor.ts +3 -1
  238. package/src/window/event.ts +26 -12
  239. package/src/window/mouse.ts +6 -2
  240. package/src/window/video-mode.ts +3 -1
  241. package/src/window/window.ts +119 -37
  242. package/test/native/audio-probes.cc +74 -36
  243. package/test/native/deferred-delete-probes.cc +17 -11
  244. package/test/native/drawable-probes.cc +70 -36
  245. package/test/native/exception-probes.cc +14 -9
  246. package/test/native/image-probes.cc +20 -10
  247. package/test/native/matrix-probes.cc +8 -4
  248. package/test/native/network-oracle.cc +17 -11
  249. package/test/native/render-texture-probes.cc +33 -24
  250. package/test/native/shader-probes.cc +9 -9
  251. package/test/native/shape-probes.cc +37 -23
  252. package/test/native/sprite-probes.cc +41 -25
  253. package/test/native/system-probes.cc +58 -35
  254. package/test/native/text-probes.cc +77 -44
  255. package/test/native/texture-probes.cc +43 -26
  256. package/test/native/time-probes.cc +18 -12
  257. package/test/native/transform-probes.cc +15 -10
  258. package/test/native/transformable-probes.cc +23 -17
  259. package/test/native/value-oracle.h +9 -4
  260. package/test/native/value-probes.cc +31 -23
  261. package/test/native/vertex-array-probes.cc +22 -14
  262. package/test/native/vertex-buffer-probes.cc +28 -17
  263. package/test/native/view-probes.cc +29 -17
  264. package/test/native/window-probes.cc +66 -33
  265. package/tools/ensure-sfml.cjs +9 -0
  266. package/tools/generate-network-constants.cjs +11 -6
  267. package/tools/generate-window-constants.cjs +31 -12
  268. package/docs/README.ja.md +0 -30
  269. package/docs/README.ko.md +0 -30
  270. package/docs/README.md +0 -30
  271. package/docs/README.zh-CN.md +0 -30
  272. package/docs/api.ja.md +0 -84
  273. package/docs/api.ko.md +0 -84
  274. package/docs/api.md +0 -81
  275. package/docs/api.zh-CN.md +0 -81
  276. package/docs/audio.ja.md +0 -249
  277. package/docs/audio.ko.md +0 -251
  278. package/docs/audio.md +0 -252
  279. package/docs/audio.zh-CN.md +0 -252
  280. package/docs/concepts.ja.md +0 -130
  281. package/docs/concepts.ko.md +0 -130
  282. package/docs/concepts.md +0 -131
  283. package/docs/concepts.zh-CN.md +0 -131
  284. package/docs/development.ja.md +0 -148
  285. package/docs/development.ko.md +0 -148
  286. package/docs/development.md +0 -150
  287. package/docs/development.zh-CN.md +0 -150
  288. package/docs/getting-started.ja.md +0 -154
  289. package/docs/getting-started.ko.md +0 -154
  290. package/docs/getting-started.md +0 -156
  291. package/docs/getting-started.zh-CN.md +0 -156
  292. package/docs/graphics.ja.md +0 -256
  293. package/docs/graphics.ko.md +0 -254
  294. package/docs/graphics.md +0 -255
  295. package/docs/graphics.zh-CN.md +0 -257
  296. package/docs/network.ja.md +0 -214
  297. package/docs/network.ko.md +0 -216
  298. package/docs/network.md +0 -218
  299. package/docs/network.zh-CN.md +0 -218
  300. package/docs/system.ja.md +0 -169
  301. package/docs/system.ko.md +0 -171
  302. package/docs/system.md +0 -173
  303. package/docs/system.zh-CN.md +0 -173
  304. package/docs/window.ja.md +0 -138
  305. package/docs/window.ko.md +0 -140
  306. package/docs/window.md +0 -141
  307. package/docs/window.zh-CN.md +0 -141
  308. package/native/exception-boundary.h +0 -97
  309. package/native/numeric-fields.h +0 -96
  310. package/native/shared-handle.h +0 -69
  311. package/test/tsconfig.json +0 -8
  312. package/tools/configure-lsp.cjs +0 -23
  313. package/tools/lib_downloader.cjs +0 -92
  314. package/tools/lib_downloader_urls.cjs +0 -23
@@ -95,7 +95,9 @@ function closeDatagram(handle) {
95
95
  cleanup();
96
96
  }
97
97
  };
98
- retry = () => { queueMicrotask(close); };
98
+ retry = () => {
99
+ queueMicrotask(close);
100
+ };
99
101
  handle.on('error', retry);
100
102
  handle.once('close', cleanup);
101
103
  close();
@@ -134,8 +136,9 @@ class Socket {
134
136
  * false이면 현재 큐 상태에 따라 NotReady 또는 Partial을 반환합니다.
135
137
  */
136
138
  setBlocking(blocking) {
137
- if (typeof blocking !== 'boolean')
139
+ if (typeof blocking !== 'boolean') {
138
140
  throw new TypeError('Expected a boolean');
141
+ }
139
142
  this.blocking = blocking;
140
143
  this.changed();
141
144
  }
@@ -145,19 +148,24 @@ class Socket {
145
148
  * @ja 非同期待機によるブロッキング動作を使うかどうかを返します。
146
149
  * @ko 비동기 대기를 통한 블로킹 동작을 사용하는지 반환합니다.
147
150
  */
148
- isBlocking() { return this.blocking; }
151
+ isBlocking() {
152
+ return this.blocking;
153
+ }
149
154
  /**
150
155
  * Return the latest underlying error, or undefined if none is recorded.
151
156
  * @zh 返回最近的底层错误;未记录错误时为 undefined。
152
157
  * @ja 最新の下位層のエラーを返し、記録がなければ undefined を返します。
153
158
  * @ko 최근 하위 계층 오류를 반환하며 기록된 오류가 없으면 undefined입니다.
154
159
  */
155
- getLastError() { return this.failure; }
156
- changed() { this[exports.socketEvents].emit('change'); }
160
+ getLastError() {
161
+ return this.failure;
162
+ }
163
+ changed() {
164
+ this[exports.socketEvents].emit('change');
165
+ }
157
166
  async awaitReady(check, generation) {
158
167
  if (!check() && this.blocking && this.epoch === generation) {
159
- await (0, common_1.waitFor)(this[exports.socketEvents], () => check() || !this.blocking ||
160
- this.epoch !== generation);
168
+ await (0, common_1.waitFor)(this[exports.socketEvents], () => check() || !this.blocking || this.epoch !== generation);
161
169
  }
162
170
  return this.epoch === generation && check();
163
171
  }
@@ -167,14 +175,18 @@ class Socket {
167
175
  * @ja サブクラスで上書き可能な準備条件を Selector に公開します。
168
176
  * @ko 하위 클래스에서 재정의할 수 있는 준비 조건을 Selector에 제공합니다.
169
177
  */
170
- [(_a = exports.socketEvents, exports.socketReady)](mask) { return this.getReadiness(mask); }
178
+ [(_a = exports.socketEvents, exports.socketReady)](mask) {
179
+ return this.getReadiness(mask);
180
+ }
171
181
  /**
172
182
  * Expose overridable liveness state to Selector.
173
183
  * @zh 供 Selector 查询子类可覆盖的存活状态。
174
184
  * @ja サブクラスで上書き可能な生存状態を Selector に公開します。
175
185
  * @ko 하위 클래스에서 재정의할 수 있는 활성 상태를 Selector에 제공합니다.
176
186
  */
177
- [exports.socketAlive]() { return this.isAlive(); }
187
+ [exports.socketAlive]() {
188
+ return this.isAlive();
189
+ }
178
190
  /**
179
191
  * Provide subclasses with the underlying Node transport,
180
192
  * or undefined if not yet created.
@@ -184,13 +196,17 @@ class Socket {
184
196
  * @ko 하위 클래스에 기반 Node 전송 객체 접근을 제공합니다.
185
197
  * 아직 생성되지 않았으면 undefined입니다.
186
198
  */
187
- getNativeHandle() { return this.transport; }
199
+ getNativeHandle() {
200
+ return this.transport;
201
+ }
188
202
  create(value = ip_address_1.IpAddressType.IpV4) {
189
203
  const handle = typeof value === 'number'
190
- ? this.allocateHandle((0, common_1.uint)(value, 1)) : value;
204
+ ? this.allocateHandle((0, common_1.uint)(value, 1))
205
+ : value;
191
206
  this.validateHandle(handle);
192
- if (handle === this.transport)
207
+ if (handle === this.transport) {
193
208
  return;
209
+ }
194
210
  this.close();
195
211
  this.failure = undefined;
196
212
  this.transport = handle;
@@ -213,15 +229,17 @@ class Socket {
213
229
  this.detach = undefined;
214
230
  this.transport = undefined;
215
231
  this.onClose();
216
- if (handle instanceof node_dgram_1.Socket)
232
+ if (handle instanceof node_dgram_1.Socket) {
217
233
  closeDatagram(handle);
234
+ }
218
235
  else if (handle) {
219
236
  // 销毁期间可能产生迟到的错误;不再保留捕获当前实例的监听闭包。
220
237
  const ignore = () => { };
221
238
  handle.on('error', ignore);
222
239
  handle.once('close', () => handle.off('error', ignore));
223
- if (handle instanceof node_net_1.Socket)
240
+ if (handle instanceof node_net_1.Socket) {
224
241
  handle.destroy();
242
+ }
225
243
  else {
226
244
  try {
227
245
  handle.close();
@@ -243,7 +261,8 @@ class Socket {
243
261
  * 리스너는 Node Server를 사용하도록 재정의할 수 있습니다.
244
262
  */
245
263
  allocateHandle(addressType) {
246
- return this.type === SocketType.Tcp ? new node_net_1.Socket()
264
+ return this.type === SocketType.Tcp
265
+ ? new node_net_1.Socket()
247
266
  : (0, node_dgram_1.createSocket)(addressType === ip_address_1.IpAddressType.IpV4 ? 'udp4' : 'udp6');
248
267
  }
249
268
  /**
@@ -256,7 +275,8 @@ class Socket {
256
275
  * 전송 객체 타입을 검증합니다.
257
276
  */
258
277
  validateHandle(handle) {
259
- if (this.type === SocketType.Udp ? !(handle instanceof node_dgram_1.Socket)
278
+ if (this.type === SocketType.Udp
279
+ ? !(handle instanceof node_dgram_1.Socket)
260
280
  : !(handle instanceof node_net_1.Socket || handle instanceof node_net_1.Server)) {
261
281
  throw new TypeError('Expected a matching Node socket transport');
262
282
  }
@@ -274,21 +294,34 @@ class Socket {
274
294
  const handle = this.transport;
275
295
  const generation = this.epoch;
276
296
  const current = () => this.epoch === generation && this.transport === handle;
277
- const notify = () => { if (current())
278
- this.changed(); };
297
+ const notify = () => {
298
+ if (current()) {
299
+ this.changed();
300
+ }
301
+ };
279
302
  const error = (error) => {
280
- if (!current())
303
+ if (!current()) {
281
304
  return;
305
+ }
282
306
  this.failure = error;
283
307
  this.changed();
284
308
  };
285
- const events = ['readable', 'drain', 'connect', 'end', 'close', 'listening'];
286
- for (const event of events)
309
+ const events = [
310
+ 'readable',
311
+ 'drain',
312
+ 'connect',
313
+ 'end',
314
+ 'close',
315
+ 'listening',
316
+ ];
317
+ for (const event of events) {
287
318
  handle.on(event, notify);
319
+ }
288
320
  handle.on('error', error);
289
321
  this.detach = () => {
290
- for (const event of events)
322
+ for (const event of events) {
291
323
  handle.off(event, notify);
324
+ }
292
325
  handle.off('error', error);
293
326
  };
294
327
  }
@@ -313,10 +346,12 @@ class Socket {
313
346
  */
314
347
  isAlive() {
315
348
  const handle = this.transport;
316
- if (handle instanceof node_net_1.Socket)
349
+ if (handle instanceof node_net_1.Socket) {
317
350
  return !handle.destroyed;
318
- if (handle instanceof node_net_1.Server)
351
+ }
352
+ if (handle instanceof node_net_1.Server) {
319
353
  return handle.listening;
354
+ }
320
355
  if (handle instanceof node_dgram_1.Socket) {
321
356
  try {
322
357
  handle.address();
@@ -345,15 +380,22 @@ class Socket {
345
380
  const handle = this.transport;
346
381
  let ready = 0;
347
382
  if (handle instanceof node_net_1.Socket) {
348
- if (handle.readableLength || handle.readableEnded || handle.destroyed) {
383
+ if (handle.readableLength ||
384
+ handle.readableEnded ||
385
+ handle.destroyed) {
349
386
  ready += 1;
350
387
  }
351
- if (handle.remoteAddress && !handle.connecting && !handle.destroyed &&
352
- handle.writable && !handle.writableNeedDrain)
388
+ if (handle.remoteAddress &&
389
+ !handle.connecting &&
390
+ !handle.destroyed &&
391
+ handle.writable &&
392
+ !handle.writableNeedDrain) {
353
393
  ready += 2;
394
+ }
354
395
  }
355
- else if (handle instanceof node_dgram_1.Socket && this.isAlive())
396
+ else if (handle instanceof node_dgram_1.Socket && this.isAlive()) {
356
397
  ready = 2;
398
+ }
357
399
  // eslint-disable-next-line no-bitwise
358
400
  return ready & mask;
359
401
  }
@@ -368,8 +410,7 @@ class Socket {
368
410
  */
369
411
  async awaitWrite(completion, generation) {
370
412
  const cancel = new AbortController();
371
- const closed = (0, common_1.waitFor)(this[exports.socketEvents], () => this.epoch !== generation, 0, cancel.signal)
372
- .then(() => SocketStatus.Disconnected);
413
+ const closed = (0, common_1.waitFor)(this[exports.socketEvents], () => this.epoch !== generation, 0, cancel.signal).then(() => SocketStatus.Disconnected);
373
414
  try {
374
415
  return await Promise.race([completion, closed]);
375
416
  }
@@ -46,17 +46,24 @@ class TcpListener extends socket_1.Socket {
46
46
  */
47
47
  async listen(port, address = ip_address_1.IpAddress.Any) {
48
48
  (0, common_1.uint)(port, 65535);
49
- if (!(address instanceof ip_address_1.IpAddress))
49
+ if (!(address instanceof ip_address_1.IpAddress)) {
50
50
  throw new TypeError('Expected IpAddress');
51
+ }
51
52
  this.create(address.getType());
52
53
  const generation = this.epoch;
53
54
  const server = this.transport;
54
- const ready = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.listening ||
55
- !!this.failure || generation !== this.epoch);
56
- server.listen({ host: address.toString(), port, ipv6Only: address.isV6() });
55
+ const ready = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.listening || !!this.failure || generation !== this.epoch);
56
+ server.listen({
57
+ host: address.toString(),
58
+ port,
59
+ ipv6Only: address.isV6(),
60
+ });
57
61
  await ready;
58
- return generation !== this.epoch ? socket_1.SocketStatus.Disconnected
59
- : this.listening ? socket_1.SocketStatus.Done : socket_1.SocketStatus.Error;
62
+ return generation !== this.epoch
63
+ ? socket_1.SocketStatus.Disconnected
64
+ : this.listening
65
+ ? socket_1.SocketStatus.Done
66
+ : socket_1.SocketStatus.Error;
60
67
  }
61
68
  /**
62
69
  * Allocate a Server for the listener without creating a client transport
@@ -77,8 +84,9 @@ class TcpListener extends socket_1.Socket {
77
84
  * @ko 이 리스너는 Node Server만 인수합니다.
78
85
  */
79
86
  validateHandle(handle) {
80
- if (!(handle instanceof node_net_1.Server))
87
+ if (!(handle instanceof node_net_1.Server)) {
81
88
  throw new TypeError('Expected Node Server');
89
+ }
82
90
  }
83
91
  /**
84
92
  * Set up the accept queue and listening state, supporting adoption
@@ -104,30 +112,35 @@ class TcpListener extends socket_1.Socket {
104
112
  this.changed();
105
113
  };
106
114
  const error = (error) => {
107
- if (!current())
115
+ if (!current()) {
108
116
  return;
117
+ }
109
118
  this.failure = error;
110
119
  this.listening = false;
111
120
  this.changed();
112
121
  };
113
122
  const listening = () => {
114
- if (!current())
123
+ if (!current()) {
115
124
  return;
125
+ }
116
126
  this.listening = true;
117
127
  this.changed();
118
128
  };
119
129
  const closed = () => {
120
- if (!current())
130
+ if (!current()) {
121
131
  return;
132
+ }
122
133
  this.listening = false;
123
134
  this.changed();
124
135
  };
125
- server.on('connection', connection)
136
+ server
137
+ .on('connection', connection)
126
138
  .on('error', error)
127
139
  .on('listening', listening)
128
140
  .on('close', closed);
129
141
  this.detach = () => {
130
- server.off('connection', connection)
142
+ server
143
+ .off('connection', connection)
131
144
  .off('error', error)
132
145
  .off('listening', listening)
133
146
  .off('close', closed);
@@ -139,7 +152,9 @@ class TcpListener extends socket_1.Socket {
139
152
  * @ja 待ち受けを停止し、まだ accept されていない接続を閉じます。
140
153
  * @ko 수신 대기를 중지하고 아직 accept하지 않은 연결을 닫습니다.
141
154
  */
142
- close() { super.close(); }
155
+ close() {
156
+ super.close();
157
+ }
143
158
  /**
144
159
  * Clear connections from the previous generation that were not accepted.
145
160
  * @zh 清空旧代际中尚未接受的连接。
@@ -148,8 +163,9 @@ class TcpListener extends socket_1.Socket {
148
163
  */
149
164
  onClose() {
150
165
  this.listening = false;
151
- for (const socket of this.pending)
166
+ for (const socket of this.pending) {
152
167
  socket.destroy();
168
+ }
153
169
  this.pending = [];
154
170
  }
155
171
  /**
@@ -163,16 +179,19 @@ class TcpListener extends socket_1.Socket {
163
179
  * 논블로킹 모드에서 연결이 없으면 NotReady를 반환합니다.
164
180
  */
165
181
  accept(socket) {
166
- if (!(socket instanceof tcp_socket_1.TcpSocket))
182
+ if (!(socket instanceof tcp_socket_1.TcpSocket)) {
167
183
  throw new TypeError('Expected TcpSocket');
184
+ }
168
185
  const generation = this.epoch;
169
186
  return this.accepts.run(async () => {
170
187
  await this.awaitReady(() => this.pending.length > 0 || !this.listening, generation);
171
- if (generation !== this.epoch || !this.listening)
188
+ if (generation !== this.epoch || !this.listening) {
172
189
  return socket_1.SocketStatus.Error;
190
+ }
173
191
  const accepted = this.pending.shift();
174
- if (!accepted)
192
+ if (!accepted) {
175
193
  return socket_1.SocketStatus.NotReady;
194
+ }
176
195
  socket[tcp_socket_1.adoptTcp](accepted);
177
196
  return socket_1.SocketStatus.Done;
178
197
  });
@@ -183,7 +202,9 @@ class TcpListener extends socket_1.Socket {
183
202
  * @ja 待ち受け状態を返します。派生クラスで拡張できます。
184
203
  * @ko 수신 대기 상태를 반환하며 파생 클래스에서 확장할 수 있습니다.
185
204
  */
186
- isAlive() { return this.listening; }
205
+ isAlive() {
206
+ return this.listening;
207
+ }
187
208
  /**
188
209
  * Report receive readiness when the accept queue is not empty.
189
210
  * @zh 接受队列非空时报告接收就绪。
@@ -194,6 +215,8 @@ class TcpListener extends socket_1.Socket {
194
215
  // eslint-disable-next-line no-bitwise
195
216
  return this.pending.length ? mask & 1 : 0;
196
217
  }
197
- getNativeHandle() { return this.transport; }
218
+ getNativeHandle() {
219
+ return this.transport;
220
+ }
198
221
  }
199
222
  exports.TcpListener = TcpListener;