uwebsockets 1.0.0 → 2.0.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 (118) hide show
  1. package/LICENSE +201 -0
  2. package/{docs/index.d.ts → index.d.ts} +69 -102
  3. package/package.json +3 -10
  4. package/source_commit +1 -0
  5. package/{src/uws.js → uws.js} +2 -2
  6. package/uws_darwin_arm64_102.node +0 -0
  7. package/uws_darwin_arm64_83.node +0 -0
  8. package/uws_darwin_arm64_88.node +0 -0
  9. package/uws_darwin_arm64_93.node +0 -0
  10. package/uws_darwin_x64_102.node +0 -0
  11. package/uws_darwin_x64_83.node +0 -0
  12. package/uws_darwin_x64_88.node +0 -0
  13. package/uws_darwin_x64_93.node +0 -0
  14. package/uws_linux_arm64_102.node +0 -0
  15. package/uws_linux_arm64_83.node +0 -0
  16. package/uws_linux_arm64_88.node +0 -0
  17. package/uws_linux_arm64_93.node +0 -0
  18. package/uws_linux_x64_102.node +0 -0
  19. package/uws_linux_x64_83.node +0 -0
  20. package/uws_linux_x64_88.node +0 -0
  21. package/uws_linux_x64_93.node +0 -0
  22. package/uws_win32_x64_102.node +0 -0
  23. package/uws_win32_x64_83.node +0 -0
  24. package/uws_win32_x64_88.node +0 -0
  25. package/uws_win32_x64_93.node +0 -0
  26. package/.gitattributes +0 -3
  27. package/.gitmodules +0 -3
  28. package/Makefile +0 -11
  29. package/build.c +0 -185
  30. package/docs/Makefile +0 -2
  31. package/docs/generated/.nojekyll +0 -1
  32. package/docs/generated/assets/highlight.css +0 -22
  33. package/docs/generated/assets/main.js +0 -4
  34. package/docs/generated/assets/search.js +0 -1
  35. package/docs/generated/assets/style.css +0 -1280
  36. package/docs/generated/enums/ListenOptions.html +0 -70
  37. package/docs/generated/functions/App.html +0 -94
  38. package/docs/generated/functions/SSLApp.html +0 -93
  39. package/docs/generated/functions/getParts.html +0 -95
  40. package/docs/generated/functions/us_listen_socket_close.html +0 -93
  41. package/docs/generated/functions/us_socket_local_port.html +0 -93
  42. package/docs/generated/index.html +0 -131
  43. package/docs/generated/interfaces/AppOptions.html +0 -115
  44. package/docs/generated/interfaces/HttpRequest.html +0 -204
  45. package/docs/generated/interfaces/HttpResponse.html +0 -400
  46. package/docs/generated/interfaces/MultipartField.html +0 -88
  47. package/docs/generated/interfaces/TemplatedApp.html +0 -595
  48. package/docs/generated/interfaces/WebSocket.html +0 -303
  49. package/docs/generated/interfaces/WebSocketBehavior.html +0 -331
  50. package/docs/generated/interfaces/us_listen_socket.html +0 -89
  51. package/docs/generated/interfaces/us_socket.html +0 -89
  52. package/docs/generated/interfaces/us_socket_context_t.html +0 -89
  53. package/docs/generated/types/CompressOptions.html +0 -84
  54. package/docs/generated/types/RecognizedString.html +0 -89
  55. package/docs/generated/variables/DEDICATED_COMPRESSOR_128KB.html +0 -84
  56. package/docs/generated/variables/DEDICATED_COMPRESSOR_16KB.html +0 -84
  57. package/docs/generated/variables/DEDICATED_COMPRESSOR_256KB.html +0 -84
  58. package/docs/generated/variables/DEDICATED_COMPRESSOR_32KB.html +0 -84
  59. package/docs/generated/variables/DEDICATED_COMPRESSOR_3KB.html +0 -84
  60. package/docs/generated/variables/DEDICATED_COMPRESSOR_4KB.html +0 -84
  61. package/docs/generated/variables/DEDICATED_COMPRESSOR_64KB.html +0 -84
  62. package/docs/generated/variables/DEDICATED_COMPRESSOR_8KB.html +0 -84
  63. package/docs/generated/variables/DEDICATED_DECOMPRESSOR.html +0 -84
  64. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_16KB.html +0 -84
  65. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_1KB.html +0 -84
  66. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_2KB.html +0 -84
  67. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_32KB.html +0 -84
  68. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_4KB.html +0 -84
  69. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_512B.html +0 -84
  70. package/docs/generated/variables/DEDICATED_DECOMPRESSOR_8KB.html +0 -84
  71. package/docs/generated/variables/DISABLED.html +0 -84
  72. package/docs/generated/variables/SHARED_COMPRESSOR.html +0 -84
  73. package/docs/generated/variables/SHARED_DECOMPRESSOR.html +0 -84
  74. package/docs/report.pdf +0 -0
  75. package/docs/tsconfig.json +0 -11
  76. package/examples/AsyncFunction.js +0 -43
  77. package/examples/AutomaticPortSelection.js +0 -20
  78. package/examples/Backpressure.js +0 -75
  79. package/examples/Broadcast.js +0 -39
  80. package/examples/GracefulShutdown.js +0 -39
  81. package/examples/H3lloWorld.js +0 -23
  82. package/examples/Headers.js +0 -31
  83. package/examples/HelloWorld.js +0 -18
  84. package/examples/JsonPost.js +0 -72
  85. package/examples/ProxyProtocol.js +0 -25
  86. package/examples/PubSub.js +0 -57
  87. package/examples/RateLimit.js +0 -69
  88. package/examples/Router.js +0 -30
  89. package/examples/ServerName.js +0 -34
  90. package/examples/ServerSentEvents.js +0 -48
  91. package/examples/SlowReceiver.js +0 -53
  92. package/examples/Upgrade.js +0 -51
  93. package/examples/UpgradeAsync.js +0 -80
  94. package/examples/Upload.js +0 -36
  95. package/examples/VideoStreamer.js +0 -115
  96. package/examples/VideoStreamerSync.js +0 -42
  97. package/examples/WebSockets.js +0 -37
  98. package/examples/WorkerThreads.js +0 -33
  99. package/misc/Manycast latency comparison [lower is better].png +0 -0
  100. package/misc/addon.pro +0 -24
  101. package/misc/cert.pem +0 -21
  102. package/misc/chart.png +0 -0
  103. package/misc/features_strip.png +0 -0
  104. package/misc/host.pro +0 -31
  105. package/misc/key.pem +0 -28
  106. package/misc/logo.svg +0 -1
  107. package/misc/streaming.png +0 -0
  108. package/src/AppWrapper.h +0 -734
  109. package/src/HttpRequestWrapper.h +0 -196
  110. package/src/HttpResponseWrapper.h +0 -463
  111. package/src/Utilities.h +0 -172
  112. package/src/WebSocketWrapper.h +0 -348
  113. package/src/addon.cpp +0 -437
  114. package/src/host.cpp +0 -115
  115. package/tests/Autobahn.js +0 -102
  116. package/tests/Hammer.js +0 -203
  117. package/tests/Makefile +0 -2
  118. package/tests/fuzzingclient.json +0 -28
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -47,12 +47,13 @@ export type RecognizedString = string | ArrayBuffer | Uint8Array | Int8Array | U
47
47
  /** A WebSocket connection that is valid from open to close event.
48
48
  * Read more about this in the user manual.
49
49
  */
50
- export interface WebSocket<UserData> {
51
- /** Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().
50
+ export interface WebSocket {
51
+ /** Sends a message. Make sure to check getBufferedAmount() before sending. Returns true for success, false for built up backpressure that will drain when time is given.
52
+ * Returning false does not mean nothing was sent, it only means backpressure was built up. This you can check by calling getBufferedAmount() afterwards.
52
53
  *
53
54
  * Make sure you properly understand the concept of backpressure. Check the backpressure example file.
54
55
  */
55
- send(message: RecognizedString, isBinary?: boolean, compress?: boolean) : number;
56
+ send(message: RecognizedString, isBinary?: boolean, compress?: boolean) : boolean;
56
57
 
57
58
  /** Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart.
58
59
  * Check backpressure example.
@@ -62,17 +63,23 @@ export interface WebSocket<UserData> {
62
63
  /** Gracefully closes this WebSocket. Immediately calls the close handler.
63
64
  * A WebSocket close message is sent with code and shortMessage.
64
65
  */
65
- end(code?: number, shortMessage?: RecognizedString) : void;
66
+ end(code?: number, shortMessage?: RecognizedString) : WebSocket;
66
67
 
67
68
  /** Forcefully closes this WebSocket. Immediately calls the close handler.
68
69
  * No WebSocket close message is sent.
69
70
  */
70
- close() : void;
71
+ close() : WebSocket;
71
72
 
72
- /** Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++. */
73
- ping(message?: RecognizedString) : number;
73
+ /** Sends a ping control message. Returns true on success in similar ways as WebSocket.send does (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++. */
74
+ ping(message?: RecognizedString) : boolean;
74
75
 
75
- /** Subscribe to a topic. */
76
+ /** Subscribe to a topic in MQTT syntax.
77
+ *
78
+ * MQTT syntax includes things like "root/child/+/grandchild" where "+" is a
79
+ * wildcard and "root/#" where "#" is a terminating wildcard.
80
+ *
81
+ * Read more about MQTT.
82
+ */
76
83
  subscribe(topic: RecognizedString) : boolean;
77
84
 
78
85
  /** Unsubscribe from a topic. Returns true on success, if the WebSocket was subscribed. */
@@ -84,13 +91,20 @@ export interface WebSocket<UserData> {
84
91
  /** Returns a list of topics this websocket is subscribed to. */
85
92
  getTopics() : string[];
86
93
 
87
- /** Publish a message under topic. Backpressure is managed according to maxBackpressure, closeOnBackpressureLimit settings.
88
- * Order is guaranteed since v20.
94
+ /** Publish a message to a topic in MQTT syntax. You cannot publish using wildcards, only fully specified topics. Just like with MQTT.
95
+ *
96
+ * "parent/child" kind of tree is allowed, but not "parent/#" kind of wildcard publishing.
97
+ *
98
+ * The pub/sub system does not guarantee order between what you manually send using WebSocket.send
99
+ * and what you publish using WebSocket.publish. WebSocket messages are perfectly atomic, but the order in which they appear can get scrambled if you mix the two sending functions on the same socket.
100
+ * This shouldn't matter in most applications. Order is guaranteed relative to other calls to WebSocket.publish.
101
+ *
102
+ * Also keep in mind that backpressure will be automatically managed with pub/sub, meaning some outgoing messages may be dropped if backpressure is greater than specified maxBackpressure.
89
103
  */
90
104
  publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean) : boolean;
91
105
 
92
106
  /** See HttpResponse.cork. Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block) */
93
- cork(cb: () => void) : WebSocket<UserData>;
107
+ cork(cb: () => void) : void;
94
108
 
95
109
  /** Returns the remote IP address. Note that the returned IP is binary, not text.
96
110
  *
@@ -104,8 +118,8 @@ export interface WebSocket<UserData> {
104
118
  /** Returns the remote IP address as text. See RecognizedString. */
105
119
  getRemoteAddressAsText() : ArrayBuffer;
106
120
 
107
- /** Returns the UserData object. */
108
- getUserData() : UserData;
121
+ /** Arbitrary user data may be attached to this object. In C++ this is done by using getUserData(). */
122
+ [key: string]: any;
109
123
  }
110
124
 
111
125
  /** An HttpResponse is valid until either onAborted callback or any of the .end/.tryEnd calls succeed. You may attach user data to this object. */
@@ -124,24 +138,15 @@ export interface HttpResponse {
124
138
  * buffer, not in a hash table. You can read about this in
125
139
  * the user manual under "corking".
126
140
  */
127
-
128
- /** Pause http body streaming (throttle) */
129
- pause() : void;
130
-
131
- /** Resume http body streaming (unthrottle) */
132
- resume() : void;
133
-
134
141
  writeStatus(status: RecognizedString) : HttpResponse;
135
142
  /** Writes key and value to HTTP response.
136
143
  * See writeStatus and corking.
137
144
  */
138
145
  writeHeader(key: RecognizedString, value: RecognizedString) : HttpResponse;
139
- /** Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. Returns true if no backpressure was added. */
140
- write(chunk: RecognizedString) : boolean;
146
+ /** Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. */
147
+ write(chunk: RecognizedString) : HttpResponse;
141
148
  /** Ends this response by copying the contents of body. */
142
149
  end(body?: RecognizedString, closeConnection?: boolean) : HttpResponse;
143
- /** Ends this response without a body. */
144
- endWithoutBody(reportedContentLength?: number, closeConnection?: boolean) : HttpResponse;
145
150
  /** Ends this response, or tries to, by streaming appropriately sized chunks of body. Use in conjunction with onWritable. Returns tuple [ok, hasResponded].*/
146
151
  tryEnd(fullBodyOrChunk: RecognizedString, totalSize: number) : [boolean, boolean];
147
152
 
@@ -159,7 +164,7 @@ export interface HttpResponse {
159
164
 
160
165
  /** Every HttpResponse MUST have an attached abort handler IF you do not respond
161
166
  * to it immediately inside of the callback. Returning from an Http request handler
162
- * without attaching (by calling onAborted) an abort handler is ill-use and will terminate.
167
+ * without attaching (by calling onAborted) an abort handler is ill-use and will termiante.
163
168
  * When this event emits, the response has been aborted and may not be used. */
164
169
  onAborted(handler: () => void) : HttpResponse;
165
170
 
@@ -187,16 +192,14 @@ export interface HttpResponse {
187
192
  *
188
193
  * Example usage:
189
194
  *
190
- * ```
191
195
  * res.cork(() => {
192
196
  * res.writeStatus("200 OK").writeHeader("Some", "Value").write("Hello world!");
193
197
  * });
194
- * ```
195
198
  */
196
- cork(cb: () => void) : HttpResponse;
199
+ cork(cb: () => void) : void;
197
200
 
198
201
  /** Upgrades a HttpResponse to a WebSocket. See UpgradeAsync, UpgradeSync example files. */
199
- upgrade<UserData>(userData : UserData, secWebSocketKey: RecognizedString, secWebSocketProtocol: RecognizedString, secWebSocketExtensions: RecognizedString, context: us_socket_context_t) : void;
202
+ upgrade<T>(userData : T, secWebSocketKey: RecognizedString, secWebSocketProtocol: RecognizedString, secWebSocketExtensions: RecognizedString, context: us_socket_context_t) : void;
200
203
 
201
204
  /** Arbitrary user data may be attached to this object */
202
205
  [key: string]: any;
@@ -210,56 +213,46 @@ export interface HttpRequest {
210
213
  getParameter(index: number) : string;
211
214
  /** Returns the URL including initial /slash */
212
215
  getUrl() : string;
213
- /** Returns the lowercased HTTP method, useful for "any" routes. */
216
+ /** Returns the HTTP method, useful for "any" routes. */
214
217
  getMethod() : string;
215
- /** Returns the HTTP method as-is. */
216
- getCaseSensitiveMethod() : string;
217
218
  /** Returns the raw querystring (the part of URL after ? sign) or empty string. */
218
219
  getQuery() : string;
219
- /** Returns a decoded query parameter value or undefined. */
220
- getQuery(key: string) : string | undefined;
220
+ /** Returns a decoded query parameter value or empty string. */
221
+ getQuery(key: string) : string;
221
222
  /** Loops over all headers. */
222
223
  forEach(cb: (key: string, value: string) => void) : void;
223
224
  /** Setting yield to true is to say that this route handler did not handle the route, causing the router to continue looking for a matching route handler, or fail. */
224
- setYield(_yield: boolean) : HttpRequest;
225
+ setYield(yield: boolean) : HttpRequest;
225
226
  }
226
227
 
227
228
  /** A structure holding settings and handlers for a WebSocket URL route handler. */
228
- export interface WebSocketBehavior<UserData> {
229
+ export interface WebSocketBehavior {
229
230
  /** Maximum length of received message. If a client tries to send you a message larger than this, the connection is immediately closed. Defaults to 16 * 1024. */
230
231
  maxPayloadLength?: number;
231
- /** Whether or not we should automatically close the socket when a message is dropped due to backpressure. Defaults to false. */
232
- closeOnBackpressureLimit?: number;
233
- /** Maximum number of minutes a WebSocket may be connected before being closed by the server. 0 disables the feature. */
234
- maxLifetime?: number;
235
232
  /** Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes. Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest.
236
233
  * Disable by using 0. Defaults to 120.
237
234
  */
238
235
  idleTimeout?: number;
239
236
  /** What permessage-deflate compression to use. uWS.DISABLED, uWS.SHARED_COMPRESSOR or any of the uWS.DEDICATED_COMPRESSOR_xxxKB. Defaults to uWS.DISABLED. */
240
237
  compression?: CompressOptions;
241
- /** Maximum length of allowed backpressure per socket when publishing or sending messages. Slow receivers with too high backpressure will be skipped until they catch up or timeout. Defaults to 64 * 1024. */
238
+ /** Maximum length of allowed backpressure per socket when publishing or sending messages. Slow receivers with too high backpressure will be skipped until they catch up or timeout. Defaults to 1024 * 1024. */
242
239
  maxBackpressure?: number;
243
- /** Whether or not we should automatically send pings to uphold a stable connection given whatever idleTimeout. */
244
- sendPingsAutomatically?: boolean;
245
240
  /** Upgrade handler used to intercept HTTP upgrade requests and potentially upgrade to WebSocket.
246
241
  * See UpgradeAsync and UpgradeSync example files.
247
242
  */
248
- upgrade?: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => void | Promise<void>;
243
+ upgrade?: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => void;
249
244
  /** Handler for new WebSocket connection. WebSocket is valid from open to close, no errors. */
250
- open?: (ws: WebSocket<UserData>) => void | Promise<void>;
245
+ open?: (ws: WebSocket) => void;
251
246
  /** Handler for a WebSocket message. Messages are given as ArrayBuffer no matter if they are binary or not. Given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered. */
252
- message?: (ws: WebSocket<UserData>, message: ArrayBuffer, isBinary: boolean) => void | Promise<void>;
247
+ message?: (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => void;
253
248
  /** Handler for when WebSocket backpressure drains. Check ws.getBufferedAmount(). Use this to guide / drive your backpressure throttling. */
254
- drain?: (ws: WebSocket<UserData>) => void;
249
+ drain?: (ws: WebSocket) => void;
255
250
  /** Handler for close event, no matter if error, timeout or graceful close. You may not use WebSocket after this event. Do not send on this WebSocket from within here, it is closed. */
256
- close?: (ws: WebSocket<UserData>, code: number, message: ArrayBuffer) => void;
251
+ close?: (ws: WebSocket, code: number, message: ArrayBuffer) => void;
257
252
  /** Handler for received ping control message. You do not need to handle this, pong messages are automatically sent as per the standard. */
258
- ping?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void;
253
+ ping?: (ws: WebSocket, message: ArrayBuffer) => void;
259
254
  /** Handler for received pong control message. */
260
- pong?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void;
261
- /** Handler for subscription changes. */
262
- subscription?: (ws: WebSocket<UserData>, topic: ArrayBuffer, newCount: number, oldCount: number) => void;
255
+ pong?: (ws: WebSocket, message: ArrayBuffer) => void;
263
256
  }
264
257
 
265
258
  /** Options used when constructing an app. Especially for SSLApp.
@@ -268,10 +261,8 @@ export interface WebSocketBehavior<UserData> {
268
261
  export interface AppOptions {
269
262
  key_file_name?: RecognizedString;
270
263
  cert_file_name?: RecognizedString;
271
- ca_file_name?: RecognizedString;
272
264
  passphrase?: RecognizedString;
273
265
  dh_params_file_name?: RecognizedString;
274
- ssl_ciphers?: RecognizedString;
275
266
  /** This translates to SSL_MODE_RELEASE_BUFFERS */
276
267
  ssl_prefer_low_memory_usage?: boolean;
277
268
  }
@@ -284,64 +275,58 @@ export enum ListenOptions {
284
275
  /** TemplatedApp is either an SSL or non-SSL app. See App for more info, read user manual. */
285
276
  export interface TemplatedApp {
286
277
  /** Listens to hostname & port. Callback hands either false or a listen socket. */
287
- listen(host: RecognizedString, port: number, cb: (listenSocket: us_listen_socket | false) => void | Promise<void>) : TemplatedApp;
278
+ listen(host: RecognizedString, port: number, cb: (listenSocket: us_listen_socket) => void): TemplatedApp;
288
279
  /** Listens to port. Callback hands either false or a listen socket. */
289
- listen(port: number, cb: (listenSocket: us_listen_socket | false) => void | Promise<void>) : TemplatedApp;
280
+ listen(port: number, cb: (listenSocket: any) => void): TemplatedApp;
290
281
  /** Listens to port and sets Listen Options. Callback hands either false or a listen socket. */
291
- listen(port: number, options: ListenOptions, cb: (listenSocket: us_listen_socket | false) => void | Promise<void>) : TemplatedApp;
292
- /** Listens to unix socket. Callback hands either false or a listen socket. */
293
- listen_unix(cb: (listenSocket: us_listen_socket) => void | Promise<void>, path: RecognizedString) : TemplatedApp;
282
+ listen(port: number, options: ListenOptions, cb: (listenSocket: us_listen_socket | false) => void): TemplatedApp;
294
283
  /** Registers an HTTP GET handler matching specified URL pattern. */
295
- get(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
284
+ get(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
296
285
  /** Registers an HTTP POST handler matching specified URL pattern. */
297
- post(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
286
+ post(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
298
287
  /** Registers an HTTP OPTIONS handler matching specified URL pattern. */
299
- options(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
288
+ options(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
300
289
  /** Registers an HTTP DELETE handler matching specified URL pattern. */
301
- del(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
290
+ del(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
302
291
  /** Registers an HTTP PATCH handler matching specified URL pattern. */
303
- patch(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
292
+ patch(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
304
293
  /** Registers an HTTP PUT handler matching specified URL pattern. */
305
- put(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
294
+ put(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
306
295
  /** Registers an HTTP HEAD handler matching specified URL pattern. */
307
- head(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
296
+ head(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
308
297
  /** Registers an HTTP CONNECT handler matching specified URL pattern. */
309
- connect(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
298
+ connect(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
310
299
  /** Registers an HTTP TRACE handler matching specified URL pattern. */
311
- trace(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
300
+ trace(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
312
301
  /** Registers an HTTP handler matching specified URL pattern on any HTTP method. */
313
- any(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void | Promise<void>) : TemplatedApp;
302
+ any(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp;
314
303
  /** Registers a handler matching specified URL pattern where WebSocket upgrade requests are caught. */
315
- ws<UserData>(pattern: RecognizedString, behavior: WebSocketBehavior<UserData>) : TemplatedApp;
304
+ ws(pattern: RecognizedString, behavior: WebSocketBehavior) : TemplatedApp;
316
305
  /** Publishes a message under topic, for all WebSockets under this app. See WebSocket.publish. */
317
306
  publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean) : boolean;
318
307
  /** Returns number of subscribers for this topic. */
319
308
  numSubscribers(topic: RecognizedString) : number;
320
309
  /** Adds a server name. */
321
- addServerName(hostname: string, options: AppOptions) : TemplatedApp;
322
- /** Browse to SNI domain. Used together with .get, .post and similar to attach routes under SNI domains. */
323
- domain(domain: string) : TemplatedApp;
310
+ addServerName(hostname: string, options: AppOptions): TemplatedApp;
324
311
  /** Removes a server name. */
325
- removeServerName(hostname: string) : TemplatedApp;
312
+ removeServerName(hostname: string): TemplatedApp;
326
313
  /** Registers a synchronous callback on missing server names. See /examples/ServerName.js. */
327
- missingServerName(cb: (hostname: string) => void) : TemplatedApp;
328
- /** Closes all sockets including listen sockets. This will forcefully terminate all connections. */
329
- close() : TemplatedApp;
314
+ missingServerName(cb: (hostname: string) => void): TemplatedApp;
330
315
  }
331
316
 
332
317
  /** Constructs a non-SSL app. An app is your starting point where you attach behavior to URL routes.
333
318
  * This is also where you listen and run your app, set any SSL options (in case of SSLApp) and the like.
334
319
  */
335
- export function App(options?: AppOptions) : TemplatedApp;
320
+ export function App(options?: AppOptions): TemplatedApp;
336
321
 
337
322
  /** Constructs an SSL app. See App. */
338
- export function SSLApp(options: AppOptions) : TemplatedApp;
323
+ export function SSLApp(options: AppOptions): TemplatedApp;
339
324
 
340
325
  /** Closes a uSockets listen socket. */
341
- export function us_listen_socket_close(listenSocket: us_listen_socket) : void;
326
+ export function us_listen_socket_close(listenSocket: us_listen_socket): void;
342
327
 
343
328
  /** Gets local port of socket (or listenSocket) or -1. */
344
- export function us_socket_local_port(socket: us_socket) : number;
329
+ export function us_socket_local_port(socket: us_socket): number;
345
330
 
346
331
  export interface MultipartField {
347
332
  data: ArrayBuffer;
@@ -351,16 +336,14 @@ export interface MultipartField {
351
336
  }
352
337
 
353
338
  /** Takes a POSTed body and contentType, and returns an array of parts if the request is a multipart request */
354
- export function getParts(body: RecognizedString, contentType: RecognizedString) : MultipartField[] | undefined;
339
+ export function getParts(body: RecognizedString, contentType: RecognizedString): MultipartField[] | undefined;
355
340
 
356
- /** WebSocket compression options. Combine any compressor with any decompressor using bitwise OR. */
341
+ /** WebSocket compression options */
357
342
  export type CompressOptions = number;
358
343
  /** No compression (always a good idea if you operate using an efficient binary protocol) */
359
344
  export var DISABLED: CompressOptions;
360
- /** Zero memory overhead compression. */
345
+ /** Zero memory overhead compression (recommended for pub/sub where same message is sent to many receivers) */
361
346
  export var SHARED_COMPRESSOR: CompressOptions;
362
- /** Zero memory overhead decompression. */
363
- export var SHARED_DECOMPRESSOR: CompressOptions;
364
347
  /** Sliding dedicated compress window, requires 3KB of memory per socket */
365
348
  export var DEDICATED_COMPRESSOR_3KB: CompressOptions;
366
349
  /** Sliding dedicated compress window, requires 4KB of memory per socket */
@@ -377,19 +360,3 @@ export var DEDICATED_COMPRESSOR_64KB: CompressOptions;
377
360
  export var DEDICATED_COMPRESSOR_128KB: CompressOptions;
378
361
  /** Sliding dedicated compress window, requires 256KB of memory per socket */
379
362
  export var DEDICATED_COMPRESSOR_256KB: CompressOptions;
380
- /** Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB) */
381
- export var DEDICATED_DECOMPRESSOR_32KB: CompressOptions;
382
- /** Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB) */
383
- export var DEDICATED_DECOMPRESSOR_16KB: CompressOptions;
384
- /** Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB) */
385
- export var DEDICATED_DECOMPRESSOR_8KB: CompressOptions;
386
- /** Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB) */
387
- export var DEDICATED_DECOMPRESSOR_4KB: CompressOptions;
388
- /** Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB) */
389
- export var DEDICATED_DECOMPRESSOR_2KB: CompressOptions;
390
- /** Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB) */
391
- export var DEDICATED_DECOMPRESSOR_1KB: CompressOptions;
392
- /** Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB) */
393
- export var DEDICATED_DECOMPRESSOR_512B: CompressOptions;
394
- /** Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB) */
395
- export var DEDICATED_DECOMPRESSOR: CompressOptions;
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "uwebsockets",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "µWebSockets.js is a web server bypass for Node.js that reimplements eventing, networking, encryption, web protocols, routing and pub/sub in highly optimized C++. As such, µWebSockets.js delivers web serving for Node.js, 8.5x that of Fastify and at least 10x that of Socket.IO. It is also the built-in web server of Bun.",
5
- "main": "index.js",
6
- "directories": {
7
- "doc": "docs",
8
- "example": "examples",
9
- "test": "tests"
10
- },
11
- "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1"
13
- },
5
+ "main": "uws.js",
6
+ "types": "./index.d.ts",
14
7
  "repository": {
15
8
  "type": "git",
16
9
  "url": "git+https://github.com/NPM-Package-Jaykumar/uWebSockets.git"
package/source_commit ADDED
@@ -0,0 +1 @@
1
+ c70d2e6d2d923183885e991c6cb4189419b521a5
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Authored by Alex Hultman, 2018-2022.
2
+ * Authored by Alex Hultman, 2018-2021.
3
3
  * Intellectual property of third-party.
4
4
 
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,6 @@ module.exports = (() => {
19
19
  try {
20
20
  return require('./uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node');
21
21
  } catch (e) {
22
- throw new Error('This version of uWS.js supports only Node.js LTS versions 16, 18 and 20 on (glibc) Linux, macOS and Windows, on Tier 1 platforms (https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list).\n\n' + e.toString());
22
+ throw new Error('This version of µWS is not compatible with your Node.js build:\n\n' + e.toString());
23
23
  }
24
24
  })();
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/.gitattributes DELETED
@@ -1,3 +0,0 @@
1
- *.js linguist-vendored
2
- *.pro linguist-vendored
3
- src/* linguist-vendored=false