uws-react-native 0.0.1-alpha.1

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 (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +84 -0
  3. package/UwsReactNative.podspec +71 -0
  4. package/android/build.gradle.kts +138 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
  7. package/apple/OnLoad.mm +17 -0
  8. package/cpp/CMakeLists.txt +154 -0
  9. package/cpp/UwsReactNativeModule.cpp +191 -0
  10. package/cpp/UwsReactNativeModule.h +30 -0
  11. package/cpp/app/AppHost.h +37 -0
  12. package/cpp/app/AppRunner.h +88 -0
  13. package/cpp/app/CMakeLists.txt +39 -0
  14. package/cpp/app/HttpRequestObject.h +173 -0
  15. package/cpp/app/HttpResponseObject.h +623 -0
  16. package/cpp/app/RecognizedString.h +71 -0
  17. package/cpp/app/TemplatedAppObject.h +472 -0
  18. package/cpp/bridging/ArrayBuffer.h +150 -0
  19. package/cpp/bridging/CMakeLists.txt +34 -0
  20. package/cpp/jsi/Buffer.h +91 -0
  21. package/cpp/jsi/CMakeLists.txt +34 -0
  22. package/cpp/uSockets/bsd.c +767 -0
  23. package/cpp/uSockets/context.c +524 -0
  24. package/cpp/uSockets/crypto/openssl.c +858 -0
  25. package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
  26. package/cpp/uSockets/eventing/asio.cpp +475 -0
  27. package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
  28. package/cpp/uSockets/eventing/gcd.c +278 -0
  29. package/cpp/uSockets/eventing/libuv.c +305 -0
  30. package/cpp/uSockets/internal/eventing/asio.h +45 -0
  31. package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
  32. package/cpp/uSockets/internal/eventing/gcd.h +40 -0
  33. package/cpp/uSockets/internal/eventing/libuv.h +45 -0
  34. package/cpp/uSockets/internal/internal.h +224 -0
  35. package/cpp/uSockets/internal/loop_data.h +38 -0
  36. package/cpp/uSockets/internal/networking/bsd.h +109 -0
  37. package/cpp/uSockets/io_uring/internal.h +98 -0
  38. package/cpp/uSockets/io_uring/io_context.c +302 -0
  39. package/cpp/uSockets/io_uring/io_loop.c +422 -0
  40. package/cpp/uSockets/io_uring/io_socket.c +139 -0
  41. package/cpp/uSockets/libusockets.h +350 -0
  42. package/cpp/uSockets/loop.c +396 -0
  43. package/cpp/uSockets/quic.c +1071 -0
  44. package/cpp/uSockets/quic.h +68 -0
  45. package/cpp/uSockets/socket.c +231 -0
  46. package/cpp/uSockets/udp.c +151 -0
  47. package/cpp/uWebSockets/uWebSockets/App.h +676 -0
  48. package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
  49. package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
  50. package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
  51. package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
  52. package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
  53. package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
  54. package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
  55. package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
  56. package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
  57. package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
  58. package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
  59. package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
  60. package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
  61. package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
  62. package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
  63. package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
  64. package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
  65. package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
  66. package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
  67. package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
  68. package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
  69. package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
  70. package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
  71. package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
  72. package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
  73. package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
  74. package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
  75. package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
  76. package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
  77. package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
  78. package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
  79. package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
  80. package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
  81. package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
  82. package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
  83. package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
  84. package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
  85. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
  86. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  87. package/lib/commonjs/index.js +28 -0
  88. package/lib/commonjs/index.js.map +1 -0
  89. package/lib/commonjs/modules/App.js +17 -0
  90. package/lib/commonjs/modules/App.js.map +1 -0
  91. package/lib/commonjs/modules/CompressOptions.js +103 -0
  92. package/lib/commonjs/modules/CompressOptions.js.map +1 -0
  93. package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
  94. package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
  95. package/lib/commonjs/modules/ListenOptions.js +12 -0
  96. package/lib/commonjs/modules/ListenOptions.js.map +1 -0
  97. package/lib/commonjs/modules/SSLApp.js +15 -0
  98. package/lib/commonjs/modules/SSLApp.js.map +1 -0
  99. package/lib/commonjs/modules/getParts.js +28 -0
  100. package/lib/commonjs/modules/getParts.js.map +1 -0
  101. package/lib/commonjs/modules/index.js +61 -0
  102. package/lib/commonjs/modules/index.js.map +1 -0
  103. package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
  104. package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
  105. package/lib/commonjs/modules/us_socket_local_port.js +22 -0
  106. package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
  107. package/lib/commonjs/package.json +1 -0
  108. package/lib/commonjs/types/AppDescriptor.js +2 -0
  109. package/lib/commonjs/types/AppDescriptor.js.map +1 -0
  110. package/lib/commonjs/types/AppOptions.js +2 -0
  111. package/lib/commonjs/types/AppOptions.js.map +1 -0
  112. package/lib/commonjs/types/HttpRequest.js +6 -0
  113. package/lib/commonjs/types/HttpRequest.js.map +1 -0
  114. package/lib/commonjs/types/HttpResponse.js +6 -0
  115. package/lib/commonjs/types/HttpResponse.js.map +1 -0
  116. package/lib/commonjs/types/HttpRouterOptions.js +2 -0
  117. package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
  118. package/lib/commonjs/types/MultipartField.js +2 -0
  119. package/lib/commonjs/types/MultipartField.js.map +1 -0
  120. package/lib/commonjs/types/RecognizedString.js +2 -0
  121. package/lib/commonjs/types/RecognizedString.js.map +1 -0
  122. package/lib/commonjs/types/TemplatedApp.js +6 -0
  123. package/lib/commonjs/types/TemplatedApp.js.map +1 -0
  124. package/lib/commonjs/types/WebSocket.js +6 -0
  125. package/lib/commonjs/types/WebSocket.js.map +1 -0
  126. package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
  127. package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
  128. package/lib/commonjs/types/index.js +2 -0
  129. package/lib/commonjs/types/index.js.map +1 -0
  130. package/lib/commonjs/types/us_listen_socket.js +2 -0
  131. package/lib/commonjs/types/us_listen_socket.js.map +1 -0
  132. package/lib/commonjs/types/us_socket.js +2 -0
  133. package/lib/commonjs/types/us_socket.js.map +1 -0
  134. package/lib/commonjs/types/us_socket_context_t.js +2 -0
  135. package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
  136. package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
  137. package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  138. package/lib/module/index.js +5 -0
  139. package/lib/module/index.js.map +1 -0
  140. package/lib/module/modules/App.js +12 -0
  141. package/lib/module/modules/App.js.map +1 -0
  142. package/lib/module/modules/CompressOptions.js +103 -0
  143. package/lib/module/modules/CompressOptions.js.map +1 -0
  144. package/lib/module/modules/EnvironmentVariables.js +13 -0
  145. package/lib/module/modules/EnvironmentVariables.js.map +1 -0
  146. package/lib/module/modules/ListenOptions.js +8 -0
  147. package/lib/module/modules/ListenOptions.js.map +1 -0
  148. package/lib/module/modules/SSLApp.js +15 -0
  149. package/lib/module/modules/SSLApp.js.map +1 -0
  150. package/lib/module/modules/getParts.js +23 -0
  151. package/lib/module/modules/getParts.js.map +1 -0
  152. package/lib/module/modules/index.js +11 -0
  153. package/lib/module/modules/index.js.map +1 -0
  154. package/lib/module/modules/us_listen_socket_close.js +17 -0
  155. package/lib/module/modules/us_listen_socket_close.js.map +1 -0
  156. package/lib/module/modules/us_socket_local_port.js +18 -0
  157. package/lib/module/modules/us_socket_local_port.js.map +1 -0
  158. package/lib/module/package.json +1 -0
  159. package/lib/module/types/AppDescriptor.js +2 -0
  160. package/lib/module/types/AppDescriptor.js.map +1 -0
  161. package/lib/module/types/AppOptions.js +2 -0
  162. package/lib/module/types/AppOptions.js.map +1 -0
  163. package/lib/module/types/HttpRequest.js +4 -0
  164. package/lib/module/types/HttpRequest.js.map +1 -0
  165. package/lib/module/types/HttpResponse.js +4 -0
  166. package/lib/module/types/HttpResponse.js.map +1 -0
  167. package/lib/module/types/HttpRouterOptions.js +2 -0
  168. package/lib/module/types/HttpRouterOptions.js.map +1 -0
  169. package/lib/module/types/MultipartField.js +2 -0
  170. package/lib/module/types/MultipartField.js.map +1 -0
  171. package/lib/module/types/RecognizedString.js +2 -0
  172. package/lib/module/types/RecognizedString.js.map +1 -0
  173. package/lib/module/types/TemplatedApp.js +4 -0
  174. package/lib/module/types/TemplatedApp.js.map +1 -0
  175. package/lib/module/types/WebSocket.js +4 -0
  176. package/lib/module/types/WebSocket.js.map +1 -0
  177. package/lib/module/types/WebSocketBehaviour.js +139 -0
  178. package/lib/module/types/WebSocketBehaviour.js.map +1 -0
  179. package/lib/module/types/index.js +2 -0
  180. package/lib/module/types/index.js.map +1 -0
  181. package/lib/module/types/us_listen_socket.js +2 -0
  182. package/lib/module/types/us_listen_socket.js.map +1 -0
  183. package/lib/module/types/us_socket.js +2 -0
  184. package/lib/module/types/us_socket.js.map +1 -0
  185. package/lib/module/types/us_socket_context_t.js +2 -0
  186. package/lib/module/types/us_socket_context_t.js.map +1 -0
  187. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  188. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/index.d.ts +3 -0
  190. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/modules/App.d.ts +7 -0
  192. package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
  194. package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
  196. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
  198. package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
  200. package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
  202. package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/modules/index.d.ts +6 -0
  204. package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
  206. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
  208. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
  209. package/lib/typescript/commonjs/package.json +1 -0
  210. package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
  211. package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
  212. package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
  213. package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
  215. package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
  217. package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
  219. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
  221. package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
  222. package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
  223. package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
  224. package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
  225. package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
  226. package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
  227. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
  228. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
  229. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
  230. package/lib/typescript/commonjs/types/index.d.ts +6 -0
  231. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  232. package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
  233. package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
  234. package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
  235. package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
  236. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
  237. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
  238. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  239. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  240. package/lib/typescript/module/index.d.ts +3 -0
  241. package/lib/typescript/module/index.d.ts.map +1 -0
  242. package/lib/typescript/module/modules/App.d.ts +7 -0
  243. package/lib/typescript/module/modules/App.d.ts.map +1 -0
  244. package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
  245. package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
  246. package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
  247. package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
  248. package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
  249. package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
  250. package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
  251. package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
  252. package/lib/typescript/module/modules/getParts.d.ts +6 -0
  253. package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
  254. package/lib/typescript/module/modules/index.d.ts +6 -0
  255. package/lib/typescript/module/modules/index.d.ts.map +1 -0
  256. package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
  257. package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
  258. package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
  259. package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
  260. package/lib/typescript/module/package.json +1 -0
  261. package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
  262. package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
  263. package/lib/typescript/module/types/AppOptions.d.ts +17 -0
  264. package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
  265. package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
  266. package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
  267. package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
  268. package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
  269. package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
  270. package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
  271. package/lib/typescript/module/types/MultipartField.d.ts +7 -0
  272. package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
  273. package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
  274. package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
  275. package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
  276. package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
  277. package/lib/typescript/module/types/WebSocket.d.ts +96 -0
  278. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
  279. package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
  280. package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
  281. package/lib/typescript/module/types/index.d.ts +6 -0
  282. package/lib/typescript/module/types/index.d.ts.map +1 -0
  283. package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
  284. package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
  285. package/lib/typescript/module/types/us_socket.d.ts +7 -0
  286. package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
  287. package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
  288. package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
  289. package/lib/typescript/tsconfig.tsbuildinfo +1 -0
  290. package/package.json +62 -0
  291. package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
  292. package/src/index.ts +2 -0
  293. package/src/modules/App.ts +14 -0
  294. package/src/modules/CompressOptions.ts +101 -0
  295. package/src/modules/EnvironmentVariables.ts +16 -0
  296. package/src/modules/ListenOptions.ts +4 -0
  297. package/src/modules/SSLApp.ts +13 -0
  298. package/src/modules/getParts.ts +29 -0
  299. package/src/modules/index.ts +8 -0
  300. package/src/modules/us_listen_socket_close.ts +15 -0
  301. package/src/modules/us_socket_local_port.ts +16 -0
  302. package/src/types/AppDescriptor.ts +7 -0
  303. package/src/types/AppOptions.ts +22 -0
  304. package/src/types/HttpRequest.ts +74 -0
  305. package/src/types/HttpResponse.ts +309 -0
  306. package/src/types/HttpRouterOptions.ts +24 -0
  307. package/src/types/MultipartField.ts +6 -0
  308. package/src/types/RecognizedString.ts +11 -0
  309. package/src/types/TemplatedApp.ts +285 -0
  310. package/src/types/WebSocket.ts +147 -0
  311. package/src/types/WebSocketBehaviour.ts +137 -0
  312. package/src/types/index.ts +12 -0
  313. package/src/types/us_listen_socket.ts +6 -0
  314. package/src/types/us_socket.ts +6 -0
  315. package/src/types/us_socket_context_t.ts +6 -0
@@ -0,0 +1,154 @@
1
+ # Currently, this CMake is only used by Android for React Native C++ static autolinking
2
+ # We need to adjust this build if this is getting used by other platforms
3
+ # or to build Shared Object file.
4
+
5
+ project("uws_react_native")
6
+ cmake_minimum_required(VERSION 3.14.0)
7
+
8
+ # include(FetchContent)
9
+
10
+ set(CMAKE_VERBOSE_MAKEFILE ON)
11
+ set(CMAKE_CXX_STANDARD 20)
12
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
13
+ # set(CMAKE_ANDROID_STL_TYPE "c++_static")
14
+ set(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES ON)
15
+
16
+ set(LIB_ANDROID_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../android")
17
+ set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
18
+ set(LIB_CODEGEN_SPEC_NAME "UwsReactNativeSpecs")
19
+
20
+ if(CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a" OR CMAKE_ANDROID_ARCH_ABI STREQUAL "x86_64")
21
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
22
+ endif()
23
+
24
+ find_package(ReactAndroid REQUIRED CONFIG)
25
+ find_package(fbjni REQUIRED CONFIG)
26
+ find_package(ZLIB REQUIRED)
27
+
28
+ file(
29
+ GLOB_RECURSE
30
+ LIB_SHARED_SRCS
31
+ RELATIVE
32
+ ${CMAKE_CURRENT_SOURCE_DIR}
33
+ "./*.cpp"
34
+ )
35
+
36
+ # It's useful later to call cpp to Java/Kotlin
37
+ # file(GLOB_RECURSE LIB_ANDROID_SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/main/cpp/*.cpp")
38
+ file(
39
+ GLOB
40
+ LIB_ANDROID_SRCS
41
+ RELATIVE
42
+ ${LIB_ANDROID_DIR}
43
+ "src/main/cpp/*.cpp"
44
+ )
45
+
46
+ # Codegen source files
47
+ file(
48
+ GLOB_RECURSE
49
+ LIB_CODEGEN_SRCS
50
+ CONFIGURE_DEPENDS
51
+ ${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp
52
+ ${LIB_ANDROID_GENERATED_JNI_DIR}/**/*.cpp
53
+ )
54
+
55
+ add_library(
56
+ ${PROJECT_NAME}
57
+ STATIC
58
+ ${LIB_SHARED_SRCS}
59
+ ${LIB_ANDROID_SRCS}
60
+ ${LIB_CODEGEN_SRCS}
61
+ )
62
+
63
+ # Add headers search paths
64
+ target_include_directories(
65
+ ${PROJECT_NAME}
66
+ PUBLIC
67
+ "."
68
+ ${LIB_ANDROID_SRCS}
69
+ ${LIB_ANDROID_GENERATED_JNI_DIR}
70
+ "${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_CODEGEN_SPEC_NAME}"
71
+ )
72
+
73
+ # uSockets & uWebSockets setup
74
+ # Thanks to https://github.com/tony-go/cmake-uwebsockets/blob/main/CMakeLists.txt
75
+
76
+ # The "uSockets" and "uWebSockets" files
77
+ # are generated by /uws-react-native/package-builder/scripts/_uws-mod.mjs.
78
+ # If you are library user and see this note from your /node_modules,
79
+ # the "uws-mod.mjs" is not part of the library file.
80
+ # Visit our repository https://github.com/RakaDoank/uws-react-native
81
+
82
+ # +++++ uSockets +++++
83
+ file(
84
+ GLOB_RECURSE
85
+ USOCKETS_SRCS
86
+ CONFIGURE_DEPENDS
87
+ "./uSockets/*.c"
88
+ )
89
+
90
+ add_library(
91
+ uSockets
92
+ ${USOCKETS_SRCS}
93
+ )
94
+
95
+ # We make the uSockets headers flatten path without its directory name
96
+ # because uWebSockets include the uSockets header internally without its directory name.
97
+ # So whoever want to use uSockets including the uWebSockets
98
+ # They just need to write like ` #include "libusockets.h" `.
99
+ target_include_directories(
100
+ uSockets
101
+ PUBLIC
102
+ "./uSockets"
103
+ )
104
+
105
+ target_compile_definitions(
106
+ uSockets
107
+ PRIVATE
108
+ LIBUS_NO_SSL
109
+ )
110
+ # ----- uSockets -----
111
+
112
+ # +++++ uWebSockets +++++
113
+ add_library(
114
+ uWebSockets
115
+ INTERFACE
116
+ )
117
+
118
+ # Notice that `uWebSockets` directory has another directory inside with the same name `uWebSockets`.
119
+ # So, to include uWebSockets headers, the directory name has to be included.
120
+ # ` #include "uWebSockets/App.h" `
121
+ target_include_directories(
122
+ uWebSockets
123
+ INTERFACE
124
+ "./uWebSockets"
125
+ )
126
+
127
+ target_link_libraries(
128
+ uWebSockets
129
+ INTERFACE
130
+ uSockets
131
+ ${ZLIB_LIBRARIES}
132
+ )
133
+
134
+ target_compile_options(uWebSockets INTERFACE -Wno-deprecated-declarations)
135
+ # ----- uWebSockets -----
136
+
137
+ add_subdirectory(app)
138
+ add_subdirectory(bridging)
139
+ add_subdirectory(jsi)
140
+
141
+ # Link Libraries
142
+ target_link_libraries(
143
+ ${PROJECT_NAME}
144
+ ReactAndroid::reactnative
145
+ ReactAndroid::jsi
146
+ fbjni::fbjni
147
+ react_codegen_UwsReactNativeSpecs
148
+ uWebSockets
149
+ android
150
+ log
151
+ uws_react_native::app
152
+ uws_react_native::bridging
153
+ uws_react_native::jsi
154
+ )
@@ -0,0 +1,191 @@
1
+ #include "UwsReactNativeModule.h"
2
+ #include <memory>
3
+ #include <vector>
4
+ #include <jsi/jsi.h>
5
+ #include "app/AppHost.h"
6
+ #include "app/TemplatedAppObject.h"
7
+ #include "jsi/Buffer.h"
8
+ #include "uWebSockets/HttpContextData.h"
9
+ #include "uWebSockets/HttpResponse.h"
10
+ #include "uWebSockets/Multipart.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ namespace {
15
+
16
+ std::vector<std::shared_ptr<uws_react_native::AppHost>> appHosts;
17
+
18
+ } // namespace
19
+
20
+ UwsReactNativeModule::UwsReactNativeModule(std::shared_ptr<CallInvoker> jsInvoker)
21
+ : NativeUwsReactNativeCxxSpec(std::move(jsInvoker)) {}
22
+
23
+ uws_react_native::TemplatedAppObject UwsReactNativeModule::App(facebook::jsi::Runtime &rt,
24
+ std::optional<facebook::jsi::Object> appOptions) {
25
+ auto assignedIndex = appHosts.size();
26
+
27
+ auto appHost = std::make_shared<uws_react_native::AppHost>([assignedIndex]() {
28
+ if(assignedIndex < appHosts.size()) {
29
+ appHosts.erase(appHosts.begin() + assignedIndex);
30
+ }
31
+ });
32
+ appHosts.emplace_back(appHost);
33
+
34
+ /// Be aware!
35
+ /// We pass increased number of the assignedIndex to the appHost->getTemplatedAppObject().
36
+ /// When users use the listen method (app.listen)
37
+ /// they got 1..n number, not zero at first.
38
+ /// It will passes 0 (zero) if the listen method is failed
39
+ /// that has been done internally in `app/TemplatedAppObject.h`.
40
+
41
+ /// This is intentional to get similar behaviour from uWebSockets.js.
42
+ /// And this is also for future usage kind of thing.
43
+ /// When we actually start to pass the `us_socket_t` or `us_listen_socket_t` to the listen method in JS,
44
+ /// we don't break users code space and they don't need to do anything at all.
45
+
46
+ /// User often uses the app.listen like this below
47
+
48
+ /// app.listen(5000, token => {
49
+ /// if(token) {
50
+ /// console.log("Listening to port 5000");
51
+ /// } else {
52
+ /// console.log("Failed to listen to port 5000");
53
+ /// }
54
+ /// });
55
+ return appHost->getTemplatedAppObject(rt, this->jsInvoker_, assignedIndex + 1);
56
+ }
57
+
58
+ /// Ported of uWebSockets.js `getParts`
59
+ /// See https://github.com/uNetworking/uWebSockets.js/blob/master/src/addon.cpp#L45
60
+ facebook::jsi::Object UwsReactNativeModule::getParts(facebook::jsi::Runtime &rt,
61
+ facebook::jsi::Object body,
62
+ facebook::jsi::String contentType) {
63
+ /// Sucks
64
+ /// Codegen maps `unknown` type to JSI Object.
65
+ /// We can't return Array | Undefined
66
+ /// If an empty object, it indicates undefined.
67
+ /// Empty object needs to be remapped to undefined.
68
+ /// See /uws-react-native/package/src/modules/getParts.ts
69
+
70
+ if(!body.isArrayBuffer(rt)) {
71
+ /// undefined
72
+ return facebook::jsi::Object(rt);
73
+ }
74
+
75
+ auto arrayBuffer = body.getArrayBuffer(rt);
76
+
77
+ auto mp = uWS::MultipartParser(contentType.utf8(rt));
78
+ if(mp.isValid()) {
79
+ mp.setBody(std::string_view(reinterpret_cast<char *>(arrayBuffer.data(rt)),
80
+ arrayBuffer.size(rt)));
81
+
82
+ std::pair<std::string_view, std::string_view> headers[10];
83
+
84
+ auto parts = std::vector<facebook::jsi::Object>();
85
+
86
+ while(true) {
87
+ std::optional<std::string_view> optionalPart = mp.getNextPart(headers);
88
+ if(!optionalPart.has_value()) {
89
+ break;
90
+ }
91
+
92
+ std::string_view part = optionalPart.value();
93
+ auto partObj = facebook::jsi::Object(rt);
94
+
95
+ partObj.setProperty(rt,
96
+ "data",
97
+ facebook::jsi::ArrayBuffer(rt, std::make_shared<uws_react_native::StringViewMutableBuffer>(part)));
98
+
99
+ for(int i = 0; headers[i].first.length(); i++) {
100
+ if(headers[i].first == "content-type") {
101
+ partObj.setProperty(rt,
102
+ "type",
103
+ std::string(headers[i].second));
104
+ } else if(headers[i].first == "content-disposition") {
105
+ /* Parse the parameters */
106
+ uWS::ParameterParser pp(headers[i].second);
107
+ while(true) {
108
+ auto [key, value] = pp.getKeyValue();
109
+ if(!key.length()) {
110
+ break;
111
+ }
112
+
113
+ if(key == "name" || key == "filename") {
114
+ partObj.setProperty(rt,
115
+ facebook::jsi::PropNameID::forUtf8(rt, std::string(key)),
116
+ std::string(value));
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ parts.emplace_back(std::move(partObj));
123
+ }
124
+
125
+ auto multipartField = facebook::jsi::Array(rt, parts.size());
126
+
127
+ std::for_each(parts.begin(), parts.end(), [&rt, &multipartField, i = 0](auto &part) mutable {
128
+ multipartField.setValueAtIndex(rt, i, part);
129
+ i++;
130
+ });
131
+
132
+ return multipartField;
133
+ }
134
+
135
+ /// undefined
136
+ return facebook::jsi::Object(rt);
137
+ }
138
+
139
+ /// It's better to have different name than this.
140
+ /// It doesn't use us_listen_socket_close from uSockets directly in this function
141
+ void UwsReactNativeModule::_us_listen_socket_close(facebook::jsi::Runtime &rt,
142
+ double id
143
+ /*facebook::jsi::Object listenSocket*/) {
144
+ if(id < 1) {
145
+ return;
146
+ }
147
+
148
+ /// Decreased one number. See notes above at UwsReactNativeModule::App
149
+ auto assignedIndex = id - 1;
150
+
151
+ auto appHost = appHosts.at(assignedIndex);
152
+
153
+ if(!appHost) {
154
+ return;
155
+ }
156
+
157
+ appHost->appRunner.close([assignedIndex]() {
158
+ if(assignedIndex < appHosts.size()) {
159
+ appHosts.erase(appHosts.begin() + assignedIndex);
160
+ }
161
+ });
162
+ }
163
+
164
+ /// It's better to have different name than this.
165
+ /// JS side doesn't pass the actual us_socket_t or us_listen_socket_t to this function.
166
+ double UwsReactNativeModule::_us_socket_local_port(facebook::jsi::Runtime &rt,
167
+ double id
168
+ /*facebook::jsi::Object socket*/) {
169
+ if(id < 1) {
170
+ return -1;
171
+ }
172
+
173
+ /// Decreased one number. See notes above at UwsReactNativeModule::App
174
+ auto assignedIndex = id - 1;
175
+
176
+ auto appHost = appHosts.at(assignedIndex);
177
+
178
+ if(!appHost) {
179
+ return -1;
180
+ }
181
+
182
+ auto *listenSocket = appHost->appRunner.listenSocket;
183
+
184
+ if(!listenSocket) {
185
+ return -1;
186
+ }
187
+
188
+ return us_socket_local_port(0, (struct us_socket_t *)listenSocket);
189
+ }
190
+
191
+ } // namespace facebook::react
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include <UwsReactNativeSpecsJSI.h>
4
+ #include "app/TemplatedAppObject.h"
5
+
6
+ namespace facebook::react {
7
+
8
+ class UwsReactNativeModule : public NativeUwsReactNativeCxxSpec<UwsReactNativeModule> {
9
+
10
+ public:
11
+ UwsReactNativeModule(std::shared_ptr<CallInvoker> jsInvoker);
12
+
13
+ uws_react_native::TemplatedAppObject App(facebook::jsi::Runtime &rt,
14
+ std::optional<facebook::jsi::Object> appOptions);
15
+
16
+ facebook::jsi::Object getParts(facebook::jsi::Runtime &rt,
17
+ facebook::jsi::Object body,
18
+ facebook::jsi::String contentType);
19
+
20
+ void _us_listen_socket_close(facebook::jsi::Runtime &rt,
21
+ double id
22
+ /*facebook::jsi::Object listenSocket*/);
23
+
24
+ double _us_socket_local_port(facebook::jsi::Runtime &rt,
25
+ double id
26
+ /*facebook::jsi::Object socket*/);
27
+
28
+ };
29
+
30
+ }
@@ -0,0 +1,37 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include "AppRunner.h"
6
+ #include "TemplatedAppObject.h"
7
+
8
+ namespace uws_react_native {
9
+
10
+ class AppHost {
11
+
12
+ private:
13
+ std::function<void ()> closeHandler;
14
+
15
+ public:
16
+ AppRunner appRunner = {};
17
+
18
+ AppHost(std::function<void ()> &&closeHandler) {
19
+ // TODO Implement the uWS::App ssl options
20
+ // this->appRunner = std::make_shared<AppRunner>();
21
+
22
+ this->closeHandler = closeHandler;
23
+ }
24
+
25
+ TemplatedAppObject getTemplatedAppObject(facebook::jsi::Runtime &rt,
26
+ std::shared_ptr<facebook::react::CallInvoker> &jsInvoker,
27
+ unsigned short id) {
28
+ return {this->appRunner, rt, jsInvoker, id, [this]() {
29
+ this->appRunner.close([this]() {
30
+ this->closeHandler();
31
+ });
32
+ }};
33
+ }
34
+
35
+ };
36
+
37
+ }
@@ -0,0 +1,88 @@
1
+ #pragma once
2
+
3
+ #include <optional>
4
+ #include <mutex>
5
+ #include <thread>
6
+ #include "uWebSockets/App.h"
7
+
8
+ namespace uws_react_native {
9
+
10
+ /**
11
+ * This simple wrapper helps consumer to run the uWebSockets server in an another thread.
12
+ * UI Thread and JavaScript thread must not be blocked by the app run.
13
+ */
14
+ class AppRunner {
15
+
16
+ private:
17
+ std::thread serverThread;
18
+
19
+ /**
20
+ * The main loop of the uWebSockets.
21
+ * Useful to wake the uWS Loop immediately to execute queued tasks.
22
+ */
23
+ uWS::Loop *serverLoop = nullptr;
24
+
25
+ // +++++ for socket closing +++++
26
+ std::mutex listenSocketMutex;
27
+ // ----- for socket closing -----
28
+
29
+ public:
30
+ /**
31
+ * Be careful. Once the `listen` method from this class instance has been invoked,
32
+ * this member has moved into another rvalue.
33
+ *
34
+ * Do not run the uWebSockets server manually from this instance.
35
+ * If you do, you don't need this class.
36
+ */
37
+ uWS::App app;
38
+
39
+ us_listen_socket_t *listenSocket = nullptr;
40
+
41
+ void listen(const std::optional<std::string> &host,
42
+ const int port,
43
+ const std::optional<int> options,
44
+ std::function<void (us_listen_socket_t *listenedSocket)> &&handler) {
45
+ // To prevent the UI thread is getting blocked,
46
+ // run the server from another thread
47
+ // https://github.com/uNetworking/uWebSockets/issues/1858#issuecomment-2907728248
48
+ this->serverThread = std::thread([this, host, options, port, handler]{
49
+ uWS::App internalApp = uWS::App(std::move(this->app));
50
+ this->serverLoop = internalApp.getLoop();
51
+
52
+ std::function<void (us_listen_socket_t *listenedSocket)> listenHandler = [this, handler](auto *listenedSocket) {
53
+ this->listenSocket = listenedSocket;
54
+ handler(this->listenSocket);
55
+ };
56
+
57
+ if(host.has_value()) {
58
+ if(options.has_value()) {
59
+ internalApp.listen(host.value(), port, options.value(), std::move(listenHandler));
60
+ } else {
61
+ internalApp.listen(host.value(), port, std::move(listenHandler));
62
+ }
63
+ } else {
64
+ internalApp.listen(port, std::move(listenHandler));
65
+ }
66
+
67
+ this->serverLoop->run();
68
+ });
69
+
70
+ this->serverThread.detach();
71
+ };
72
+
73
+ void close(std::function<void ()> &&onClose) {
74
+ if(this->serverLoop) {
75
+ this->serverLoop->defer([this, onClose]() {
76
+ std::lock_guard<std::mutex> lock(this->listenSocketMutex);
77
+ if(this->listenSocket) {
78
+ us_listen_socket_close(0, this->listenSocket);
79
+ this->listenSocket = nullptr;
80
+ onClose();
81
+ }
82
+ });
83
+ }
84
+ };
85
+
86
+ };
87
+
88
+ } // namespace
@@ -0,0 +1,39 @@
1
+ project("uws_react_native__app")
2
+
3
+ file(
4
+ GLOB_RECURSE
5
+ LIB_HEADER_SRCS
6
+ RELATIVE
7
+ ${CMAKE_CURRENT_SOURCE_DIR}
8
+ "./*.h"
9
+ )
10
+
11
+ add_library(
12
+ ${PROJECT_NAME}
13
+ INTERFACE
14
+ ${LIB_HEADER_SRCS}
15
+ )
16
+
17
+ add_library(
18
+ "uws_react_native::app"
19
+ ALIAS
20
+ ${PROJECT_NAME}
21
+ )
22
+
23
+ target_include_directories(
24
+ ${PROJECT_NAME}
25
+ INTERFACE
26
+ "."
27
+ )
28
+
29
+ target_link_libraries(
30
+ ${PROJECT_NAME}
31
+ INTERFACE
32
+ reactnative
33
+ jsi
34
+ uWebSockets
35
+ android
36
+ log
37
+ uws_react_native::bridging
38
+ uws_react_native::jsi
39
+ )