@wabot-dev/framework 0.0.12 → 0.0.14

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 (367) hide show
  1. package/dist/src/_virtual/XMLHttpRequest.js +7 -0
  2. package/dist/src/_virtual/_commonjsHelpers.js +32 -0
  3. package/dist/src/_virtual/base64id.js +3 -0
  4. package/dist/src/_virtual/binary.js +3 -0
  5. package/dist/src/_virtual/bom-handling.js +3 -0
  6. package/dist/src/_virtual/broadcast-operator.js +3 -0
  7. package/dist/src/_virtual/browser.js +3 -0
  8. package/dist/src/_virtual/browser2.js +3 -0
  9. package/dist/src/_virtual/browser3.js +3 -0
  10. package/dist/src/_virtual/browser4.js +3 -0
  11. package/dist/src/_virtual/browser5.js +3 -0
  12. package/dist/src/_virtual/buffer-util.js +3 -0
  13. package/dist/src/_virtual/buffer-util2.js +3 -0
  14. package/dist/src/_virtual/buffer-util3.js +3 -0
  15. package/dist/src/_virtual/charset.js +3 -0
  16. package/dist/src/_virtual/charset2.js +3 -0
  17. package/dist/src/_virtual/client.js +3 -0
  18. package/dist/src/_virtual/cluster-adapter.js +3 -0
  19. package/dist/src/_virtual/commons.js +3 -0
  20. package/dist/src/_virtual/dbcs-codec.js +3 -0
  21. package/dist/src/_virtual/decodePacket.js +3 -0
  22. package/dist/src/_virtual/encodePacket.js +3 -0
  23. package/dist/src/_virtual/encoding.js +3 -0
  24. package/dist/src/_virtual/encoding2.js +3 -0
  25. package/dist/src/_virtual/engine.io.js +3 -0
  26. package/dist/src/_virtual/in-memory-adapter.js +3 -0
  27. package/dist/src/_virtual/index.js +7 -0
  28. package/dist/src/_virtual/index10.js +3 -0
  29. package/dist/src/_virtual/index11.js +3 -0
  30. package/dist/src/_virtual/index12.js +3 -0
  31. package/dist/src/_virtual/index13.js +3 -0
  32. package/dist/src/_virtual/index14.js +3 -0
  33. package/dist/src/_virtual/index15.js +3 -0
  34. package/dist/src/_virtual/index16.js +3 -0
  35. package/dist/src/_virtual/index17.js +3 -0
  36. package/dist/src/_virtual/index18.js +3 -0
  37. package/dist/src/_virtual/index19.js +3 -0
  38. package/dist/src/_virtual/index2.js +7 -0
  39. package/dist/src/_virtual/index20.js +3 -0
  40. package/dist/src/_virtual/index21.js +3 -0
  41. package/dist/src/_virtual/index22.js +3 -0
  42. package/dist/src/_virtual/index23.js +3 -0
  43. package/dist/src/_virtual/index24.js +3 -0
  44. package/dist/src/_virtual/index25.js +3 -0
  45. package/dist/src/_virtual/index26.js +3 -0
  46. package/dist/src/_virtual/index27.js +3 -0
  47. package/dist/src/_virtual/index28.js +3 -0
  48. package/dist/src/_virtual/index29.js +3 -0
  49. package/dist/src/_virtual/index3.js +7 -0
  50. package/dist/src/_virtual/index30.js +3 -0
  51. package/dist/src/_virtual/index31.js +3 -0
  52. package/dist/src/_virtual/index32.js +3 -0
  53. package/dist/src/_virtual/index33.js +3 -0
  54. package/dist/src/_virtual/index4.js +3 -0
  55. package/dist/src/_virtual/index5.js +3 -0
  56. package/dist/src/_virtual/index6.js +3 -0
  57. package/dist/src/_virtual/index7.js +3 -0
  58. package/dist/src/_virtual/index8.js +6 -0
  59. package/dist/src/_virtual/index9.js +3 -0
  60. package/dist/src/_virtual/inherits.js +3 -0
  61. package/dist/src/_virtual/inherits_browser.js +3 -0
  62. package/dist/src/_virtual/is-binary.js +3 -0
  63. package/dist/src/_virtual/language.js +3 -0
  64. package/dist/src/_virtual/language2.js +3 -0
  65. package/dist/src/_virtual/mediaType.js +3 -0
  66. package/dist/src/_virtual/mediaType2.js +3 -0
  67. package/dist/src/_virtual/namespace.js +3 -0
  68. package/dist/src/_virtual/node.js +3 -0
  69. package/dist/src/_virtual/node2.js +3 -0
  70. package/dist/src/_virtual/node3.js +3 -0
  71. package/dist/src/_virtual/node4.js +3 -0
  72. package/dist/src/_virtual/node5.js +3 -0
  73. package/dist/src/_virtual/parent-namespace.js +3 -0
  74. package/dist/src/_virtual/polling-jsonp.js +3 -0
  75. package/dist/src/_virtual/polling.js +3 -0
  76. package/dist/src/_virtual/polling2.js +3 -0
  77. package/dist/src/_virtual/receiver.js +3 -0
  78. package/dist/src/_virtual/sbcs-codec.js +3 -0
  79. package/dist/src/_virtual/sender.js +3 -0
  80. package/dist/src/_virtual/server.js +3 -0
  81. package/dist/src/_virtual/socket-types.js +3 -0
  82. package/dist/src/_virtual/socket.js +3 -0
  83. package/dist/src/_virtual/socket2.js +3 -0
  84. package/dist/src/_virtual/stream.js +3 -0
  85. package/dist/src/_virtual/transport.js +3 -0
  86. package/dist/src/_virtual/typed-events.js +3 -0
  87. package/dist/src/_virtual/userver.js +3 -0
  88. package/dist/src/_virtual/utf16.js +3 -0
  89. package/dist/src/_virtual/utf32.js +3 -0
  90. package/dist/src/_virtual/utf7.js +3 -0
  91. package/dist/src/_virtual/uws.js +3 -0
  92. package/dist/src/_virtual/validation.js +3 -0
  93. package/dist/src/_virtual/validation2.js +3 -0
  94. package/dist/src/_virtual/validation3.js +3 -0
  95. package/dist/src/_virtual/websocket-server.js +3 -0
  96. package/dist/src/_virtual/websocket.js +7 -0
  97. package/dist/src/_virtual/websocket2.js +3 -0
  98. package/dist/src/_virtual/websocket3.js +3 -0
  99. package/dist/src/_virtual/webtransport.js +3 -0
  100. package/dist/src/_virtual/yeast.js +3 -0
  101. package/dist/src/channels/cmd/@cmd.js +2 -0
  102. package/dist/src/channels/cmd/CmdChannel.js +2 -0
  103. package/dist/src/channels/telegram/@telegram.js +2 -0
  104. package/dist/src/channels/telegram/TelegramChannel.js +2 -0
  105. package/dist/src/channels/whatsapp/@whatsapp.js +24 -0
  106. package/dist/src/channels/whatsapp/WhatsAppChannel.js +63 -0
  107. package/dist/src/channels/whatsapp/WhatsAppChannelConfig.js +8 -0
  108. package/dist/src/channels/whatsapp/WhatsAppConnection.js +61 -0
  109. package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +61 -0
  110. package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +36 -0
  111. package/dist/src/channels/whatsapp/whatsAppDevSocketContracts.js +9 -0
  112. package/dist/src/controller/express/Express.js +5 -0
  113. package/dist/src/controller/socket.io/SocketIO.js +5 -0
  114. package/dist/src/env/WabotEnv.js +21 -0
  115. package/dist/src/index.d.ts +168 -1
  116. package/dist/src/index.js +12 -0
  117. package/dist/src/logger/Logger.js +65 -0
  118. package/dist/src/node_modules/@socket.io/component-emitter/lib/esm/index.js +171 -0
  119. package/dist/src/node_modules/base64id/lib/base64id.js +117 -0
  120. package/dist/src/node_modules/body-parser/index.js +96 -0
  121. package/dist/src/node_modules/body-parser/lib/read.js +225 -0
  122. package/dist/src/node_modules/body-parser/lib/types/json.js +222 -0
  123. package/dist/src/node_modules/body-parser/lib/types/raw.js +90 -0
  124. package/dist/src/node_modules/body-parser/lib/types/text.js +95 -0
  125. package/dist/src/node_modules/body-parser/lib/types/urlencoded.js +194 -0
  126. package/dist/src/node_modules/body-parser/lib/utils.js +96 -0
  127. package/dist/src/node_modules/bytes/index.js +180 -0
  128. package/dist/src/node_modules/call-bind-apply-helpers/actualApply.js +24 -0
  129. package/dist/src/node_modules/call-bind-apply-helpers/functionApply.js +13 -0
  130. package/dist/src/node_modules/call-bind-apply-helpers/functionCall.js +13 -0
  131. package/dist/src/node_modules/call-bind-apply-helpers/index.js +29 -0
  132. package/dist/src/node_modules/call-bind-apply-helpers/reflectApply.js +13 -0
  133. package/dist/src/node_modules/call-bound/index.js +31 -0
  134. package/dist/src/node_modules/content-type/index.js +235 -0
  135. package/dist/src/node_modules/cookie/index.js +345 -0
  136. package/dist/src/node_modules/cors/lib/index.js +249 -0
  137. package/dist/src/node_modules/debug/src/browser.js +286 -0
  138. package/dist/src/node_modules/debug/src/common.js +303 -0
  139. package/dist/src/node_modules/debug/src/index.js +23 -0
  140. package/dist/src/node_modules/debug/src/node.js +279 -0
  141. package/dist/src/node_modules/depd/index.js +550 -0
  142. package/dist/src/node_modules/dunder-proto/get.js +42 -0
  143. package/dist/src/node_modules/ee-first/index.js +104 -0
  144. package/dist/src/node_modules/engine.io/build/engine.io.js +73 -0
  145. package/dist/src/node_modules/engine.io/build/parser-v3/index.js +429 -0
  146. package/dist/src/node_modules/engine.io/build/parser-v3/utf8.js +198 -0
  147. package/dist/src/node_modules/engine.io/build/server.js +808 -0
  148. package/dist/src/node_modules/engine.io/build/socket.js +469 -0
  149. package/dist/src/node_modules/engine.io/build/transport.js +131 -0
  150. package/dist/src/node_modules/engine.io/build/transports/index.js +37 -0
  151. package/dist/src/node_modules/engine.io/build/transports/polling-jsonp.js +53 -0
  152. package/dist/src/node_modules/engine.io/build/transports/polling.js +346 -0
  153. package/dist/src/node_modules/engine.io/build/transports/websocket.js +106 -0
  154. package/dist/src/node_modules/engine.io/build/transports/webtransport.js +76 -0
  155. package/dist/src/node_modules/engine.io/build/transports-uws/index.js +20 -0
  156. package/dist/src/node_modules/engine.io/build/transports-uws/polling.js +378 -0
  157. package/dist/src/node_modules/engine.io/build/transports-uws/websocket.js +85 -0
  158. package/dist/src/node_modules/engine.io/build/userver.js +292 -0
  159. package/dist/src/node_modules/engine.io/node_modules/accepts/index.js +250 -0
  160. package/dist/src/node_modules/engine.io/node_modules/debug/src/browser.js +285 -0
  161. package/dist/src/node_modules/engine.io/node_modules/debug/src/common.js +285 -0
  162. package/dist/src/node_modules/engine.io/node_modules/debug/src/index.js +23 -0
  163. package/dist/src/node_modules/engine.io/node_modules/debug/src/node.js +279 -0
  164. package/dist/src/node_modules/engine.io/node_modules/mime-db/db.json.js +10704 -0
  165. package/dist/src/node_modules/engine.io/node_modules/mime-db/index.js +24 -0
  166. package/dist/src/node_modules/engine.io/node_modules/mime-types/index.js +202 -0
  167. package/dist/src/node_modules/engine.io/node_modules/negotiator/index.js +96 -0
  168. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/charset.js +179 -0
  169. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/encoding.js +193 -0
  170. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/language.js +188 -0
  171. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/mediaType.js +304 -0
  172. package/dist/src/node_modules/engine.io/node_modules/ws/index.js +28 -0
  173. package/dist/src/node_modules/engine.io/node_modules/ws/lib/buffer-util.js +142 -0
  174. package/dist/src/node_modules/engine.io/node_modules/ws/lib/constants.js +21 -0
  175. package/dist/src/node_modules/engine.io/node_modules/ws/lib/event-target.js +303 -0
  176. package/dist/src/node_modules/engine.io/node_modules/ws/lib/extension.js +214 -0
  177. package/dist/src/node_modules/engine.io/node_modules/ws/lib/limiter.js +64 -0
  178. package/dist/src/node_modules/engine.io/node_modules/ws/lib/permessage-deflate.js +528 -0
  179. package/dist/src/node_modules/engine.io/node_modules/ws/lib/receiver.js +719 -0
  180. package/dist/src/node_modules/engine.io/node_modules/ws/lib/sender.js +513 -0
  181. package/dist/src/node_modules/engine.io/node_modules/ws/lib/stream.js +170 -0
  182. package/dist/src/node_modules/engine.io/node_modules/ws/lib/subprotocol.js +73 -0
  183. package/dist/src/node_modules/engine.io/node_modules/ws/lib/validation.js +141 -0
  184. package/dist/src/node_modules/engine.io/node_modules/ws/lib/websocket-server.js +559 -0
  185. package/dist/src/node_modules/engine.io/node_modules/ws/lib/websocket.js +1363 -0
  186. package/dist/src/node_modules/engine.io-client/build/esm/contrib/has-cors.js +13 -0
  187. package/dist/src/node_modules/engine.io-client/build/esm/contrib/parseqs.js +36 -0
  188. package/dist/src/node_modules/engine.io-client/build/esm/contrib/parseuri.js +66 -0
  189. package/dist/src/node_modules/engine.io-client/build/esm/globals.node.js +92 -0
  190. package/dist/src/node_modules/engine.io-client/build/esm/index.js +17 -0
  191. package/dist/src/node_modules/engine.io-client/build/esm/socket.js +728 -0
  192. package/dist/src/node_modules/engine.io-client/build/esm/transport.js +143 -0
  193. package/dist/src/node_modules/engine.io-client/build/esm/transports/index.js +11 -0
  194. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +256 -0
  195. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +21 -0
  196. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling.js +146 -0
  197. package/dist/src/node_modules/engine.io-client/build/esm/transports/websocket.js +107 -0
  198. package/dist/src/node_modules/engine.io-client/build/esm/transports/websocket.node.js +48 -0
  199. package/dist/src/node_modules/engine.io-client/build/esm/transports/webtransport.js +83 -0
  200. package/dist/src/node_modules/engine.io-client/build/esm/util.js +62 -0
  201. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js +142 -0
  202. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/constants.js +21 -0
  203. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/event-target.js +303 -0
  204. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/extension.js +214 -0
  205. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/limiter.js +64 -0
  206. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js +528 -0
  207. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/receiver.js +719 -0
  208. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/sender.js +513 -0
  209. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/stream.js +170 -0
  210. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js +73 -0
  211. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/validation.js +141 -0
  212. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js +559 -0
  213. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/websocket.js +1363 -0
  214. package/dist/src/node_modules/engine.io-parser/build/cjs/commons.js +29 -0
  215. package/dist/src/node_modules/engine.io-parser/build/cjs/decodePacket.js +70 -0
  216. package/dist/src/node_modules/engine.io-parser/build/cjs/encodePacket.js +51 -0
  217. package/dist/src/node_modules/engine.io-parser/build/cjs/index.js +179 -0
  218. package/dist/src/node_modules/engine.io-parser/build/esm/commons.js +15 -0
  219. package/dist/src/node_modules/engine.io-parser/build/esm/decodePacket.js +58 -0
  220. package/dist/src/node_modules/engine.io-parser/build/esm/encodePacket.js +36 -0
  221. package/dist/src/node_modules/engine.io-parser/build/esm/index.js +158 -0
  222. package/dist/src/node_modules/es-define-property/index.js +23 -0
  223. package/dist/src/node_modules/es-errors/eval.js +13 -0
  224. package/dist/src/node_modules/es-errors/index.js +13 -0
  225. package/dist/src/node_modules/es-errors/range.js +13 -0
  226. package/dist/src/node_modules/es-errors/ref.js +13 -0
  227. package/dist/src/node_modules/es-errors/syntax.js +13 -0
  228. package/dist/src/node_modules/es-errors/type.js +13 -0
  229. package/dist/src/node_modules/es-errors/uri.js +13 -0
  230. package/dist/src/node_modules/es-object-atoms/index.js +13 -0
  231. package/dist/src/node_modules/function-bind/implementation.js +93 -0
  232. package/dist/src/node_modules/function-bind/index.js +16 -0
  233. package/dist/src/node_modules/get-intrinsic/index.js +413 -0
  234. package/dist/src/node_modules/get-proto/Object.getPrototypeOf.js +17 -0
  235. package/dist/src/node_modules/get-proto/Reflect.getPrototypeOf.js +13 -0
  236. package/dist/src/node_modules/get-proto/index.js +40 -0
  237. package/dist/src/node_modules/gopd/gOPD.js +13 -0
  238. package/dist/src/node_modules/gopd/index.js +26 -0
  239. package/dist/src/node_modules/has-symbols/index.js +25 -0
  240. package/dist/src/node_modules/has-symbols/shams.js +54 -0
  241. package/dist/src/node_modules/hasown/index.js +19 -0
  242. package/dist/src/node_modules/http-errors/index.js +306 -0
  243. package/dist/src/node_modules/iconv-lite/encodings/dbcs-codec.js +598 -0
  244. package/dist/src/node_modules/iconv-lite/encodings/dbcs-data.js +206 -0
  245. package/dist/src/node_modules/iconv-lite/encodings/index.js +44 -0
  246. package/dist/src/node_modules/iconv-lite/encodings/internal.js +210 -0
  247. package/dist/src/node_modules/iconv-lite/encodings/sbcs-codec.js +83 -0
  248. package/dist/src/node_modules/iconv-lite/encodings/sbcs-data-generated.js +460 -0
  249. package/dist/src/node_modules/iconv-lite/encodings/sbcs-data.js +187 -0
  250. package/dist/src/node_modules/iconv-lite/encodings/tables/big5-added.json.js +506 -0
  251. package/dist/src/node_modules/iconv-lite/encodings/tables/cp936.json.js +2621 -0
  252. package/dist/src/node_modules/iconv-lite/encodings/tables/cp949.json.js +2380 -0
  253. package/dist/src/node_modules/iconv-lite/encodings/tables/cp950.json.js +729 -0
  254. package/dist/src/node_modules/iconv-lite/encodings/tables/eucjp.json.js +822 -0
  255. package/dist/src/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json.js +424 -0
  256. package/dist/src/node_modules/iconv-lite/encodings/tables/gbk-added.json.js +264 -0
  257. package/dist/src/node_modules/iconv-lite/encodings/tables/shiftjis.json.js +548 -0
  258. package/dist/src/node_modules/iconv-lite/encodings/utf16.js +206 -0
  259. package/dist/src/node_modules/iconv-lite/encodings/utf32.js +329 -0
  260. package/dist/src/node_modules/iconv-lite/encodings/utf7.js +297 -0
  261. package/dist/src/node_modules/iconv-lite/lib/bom-handling.js +61 -0
  262. package/dist/src/node_modules/iconv-lite/lib/index.js +192 -0
  263. package/dist/src/node_modules/iconv-lite/lib/streams.js +120 -0
  264. package/dist/src/node_modules/inherits/inherits.js +21 -0
  265. package/dist/src/node_modules/inherits/inherits_browser.js +38 -0
  266. package/dist/src/node_modules/math-intrinsics/abs.js +13 -0
  267. package/dist/src/node_modules/math-intrinsics/floor.js +13 -0
  268. package/dist/src/node_modules/math-intrinsics/isNaN.js +15 -0
  269. package/dist/src/node_modules/math-intrinsics/max.js +13 -0
  270. package/dist/src/node_modules/math-intrinsics/min.js +13 -0
  271. package/dist/src/node_modules/math-intrinsics/pow.js +13 -0
  272. package/dist/src/node_modules/math-intrinsics/round.js +13 -0
  273. package/dist/src/node_modules/math-intrinsics/sign.js +22 -0
  274. package/dist/src/node_modules/media-typer/index.js +153 -0
  275. package/dist/src/node_modules/mime-db/db.json.js +11656 -0
  276. package/dist/src/node_modules/mime-db/index.js +24 -0
  277. package/dist/src/node_modules/mime-types/index.js +226 -0
  278. package/dist/src/node_modules/mime-types/mimeScore.js +62 -0
  279. package/dist/src/node_modules/ms/index.js +172 -0
  280. package/dist/src/node_modules/object-assign/index.js +99 -0
  281. package/dist/src/node_modules/object-inspect/index.js +557 -0
  282. package/dist/src/node_modules/object-inspect/util.inspect.js +13 -0
  283. package/dist/src/node_modules/on-finished/index.js +245 -0
  284. package/dist/src/node_modules/qs/lib/formats.js +32 -0
  285. package/dist/src/node_modules/qs/lib/index.js +24 -0
  286. package/dist/src/node_modules/qs/lib/parse.js +339 -0
  287. package/dist/src/node_modules/qs/lib/stringify.js +369 -0
  288. package/dist/src/node_modules/qs/lib/utils.js +279 -0
  289. package/dist/src/node_modules/raw-body/index.js +351 -0
  290. package/dist/src/node_modules/safer-buffer/safer.js +88 -0
  291. package/dist/src/node_modules/setprototypeof/index.js +26 -0
  292. package/dist/src/node_modules/side-channel/index.js +58 -0
  293. package/dist/src/node_modules/side-channel-list/index.js +125 -0
  294. package/dist/src/node_modules/side-channel-map/index.js +82 -0
  295. package/dist/src/node_modules/side-channel-weakmap/index.js +99 -0
  296. package/dist/src/node_modules/socket.io/dist/broadcast-operator.js +448 -0
  297. package/dist/src/node_modules/socket.io/dist/client.js +281 -0
  298. package/dist/src/node_modules/socket.io/dist/index.js +837 -0
  299. package/dist/src/node_modules/socket.io/dist/namespace.js +597 -0
  300. package/dist/src/node_modules/socket.io/dist/parent-namespace.js +101 -0
  301. package/dist/src/node_modules/socket.io/dist/socket-types.js +21 -0
  302. package/dist/src/node_modules/socket.io/dist/socket.js +993 -0
  303. package/dist/src/node_modules/socket.io/dist/typed-events.js +92 -0
  304. package/dist/src/node_modules/socket.io/dist/uws.js +149 -0
  305. package/dist/src/node_modules/socket.io/node_modules/accepts/index.js +250 -0
  306. package/dist/src/node_modules/socket.io/node_modules/debug/src/browser.js +285 -0
  307. package/dist/src/node_modules/socket.io/node_modules/debug/src/common.js +285 -0
  308. package/dist/src/node_modules/socket.io/node_modules/debug/src/index.js +23 -0
  309. package/dist/src/node_modules/socket.io/node_modules/debug/src/node.js +279 -0
  310. package/dist/src/node_modules/socket.io/node_modules/mime-db/db.json.js +10704 -0
  311. package/dist/src/node_modules/socket.io/node_modules/mime-db/index.js +24 -0
  312. package/dist/src/node_modules/socket.io/node_modules/mime-types/index.js +202 -0
  313. package/dist/src/node_modules/socket.io/node_modules/negotiator/index.js +96 -0
  314. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/charset.js +179 -0
  315. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/encoding.js +193 -0
  316. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/language.js +188 -0
  317. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/mediaType.js +304 -0
  318. package/dist/src/node_modules/socket.io/package.json.js +5 -0
  319. package/dist/src/node_modules/socket.io/wrapper.js +5 -0
  320. package/dist/src/node_modules/socket.io-adapter/dist/cluster-adapter.js +689 -0
  321. package/dist/src/node_modules/socket.io-adapter/dist/contrib/yeast.js +64 -0
  322. package/dist/src/node_modules/socket.io-adapter/dist/in-memory-adapter.js +407 -0
  323. package/dist/src/node_modules/socket.io-adapter/dist/index.js +24 -0
  324. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/browser.js +285 -0
  325. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/common.js +285 -0
  326. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/index.js +23 -0
  327. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/node.js +279 -0
  328. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/index.js +28 -0
  329. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/buffer-util.js +142 -0
  330. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/constants.js +21 -0
  331. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/event-target.js +303 -0
  332. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/extension.js +214 -0
  333. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/limiter.js +64 -0
  334. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/permessage-deflate.js +528 -0
  335. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/receiver.js +719 -0
  336. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/sender.js +513 -0
  337. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/stream.js +170 -0
  338. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/subprotocol.js +73 -0
  339. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/validation.js +141 -0
  340. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/websocket-server.js +559 -0
  341. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/websocket.js +1363 -0
  342. package/dist/src/node_modules/socket.io-client/build/esm/contrib/backo2.js +68 -0
  343. package/dist/src/node_modules/socket.io-client/build/esm/index.js +50 -0
  344. package/dist/src/node_modules/socket.io-client/build/esm/manager.js +373 -0
  345. package/dist/src/node_modules/socket.io-client/build/esm/on.js +8 -0
  346. package/dist/src/node_modules/socket.io-client/build/esm/socket.js +884 -0
  347. package/dist/src/node_modules/socket.io-client/build/esm/url.js +63 -0
  348. package/dist/src/node_modules/socket.io-parser/build/cjs/binary.js +99 -0
  349. package/dist/src/node_modules/socket.io-parser/build/cjs/index.js +337 -0
  350. package/dist/src/node_modules/socket.io-parser/build/cjs/is-binary.js +65 -0
  351. package/dist/src/node_modules/socket.io-parser/build/esm/binary.js +86 -0
  352. package/dist/src/node_modules/socket.io-parser/build/esm/index.js +314 -0
  353. package/dist/src/node_modules/socket.io-parser/build/esm/is-binary.js +52 -0
  354. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/browser.js +285 -0
  355. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/common.js +285 -0
  356. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/index.js +23 -0
  357. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/node.js +279 -0
  358. package/dist/src/node_modules/statuses/codes.json.js +67 -0
  359. package/dist/src/node_modules/statuses/index.js +157 -0
  360. package/dist/src/node_modules/toidentifier/index.js +41 -0
  361. package/dist/src/node_modules/type-is/index.js +263 -0
  362. package/dist/src/node_modules/unpipe/index.js +78 -0
  363. package/dist/src/node_modules/vary/index.js +159 -0
  364. package/dist/src/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +702 -0
  365. package/dist/src/server/runChannel.js +8 -8
  366. package/dist/src/server/runServer.js +41 -2
  367. package/package.json +7 -3
@@ -0,0 +1,728 @@
1
+ import { transports } from './transports/index.js';
2
+ import { installTimerFunctions, byteLength } from './util.js';
3
+ import { decode } from './contrib/parseqs.js';
4
+ import { parse } from './contrib/parseuri.js';
5
+ import { Emitter } from '../../../@socket.io/component-emitter/lib/esm/index.js';
6
+ import { protocol } from '../../../engine.io-parser/build/esm/index.js';
7
+ import { defaultBinaryType, createCookieJar, nextTick } from './globals.node.js';
8
+
9
+ const withEventListeners = typeof addEventListener === "function" &&
10
+ typeof removeEventListener === "function";
11
+ const OFFLINE_EVENT_LISTENERS = [];
12
+ if (withEventListeners) {
13
+ // within a ServiceWorker, any event handler for the 'offline' event must be added on the initial evaluation of the
14
+ // script, so we create one single event listener here which will forward the event to the socket instances
15
+ addEventListener("offline", () => {
16
+ OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
17
+ }, false);
18
+ }
19
+ /**
20
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
21
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
22
+ *
23
+ * This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
24
+ * successfully establishes the connection.
25
+ *
26
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
27
+ *
28
+ * @example
29
+ * import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
30
+ *
31
+ * const socket = new SocketWithoutUpgrade({
32
+ * transports: [WebSocket]
33
+ * });
34
+ *
35
+ * socket.on("open", () => {
36
+ * socket.send("hello");
37
+ * });
38
+ *
39
+ * @see SocketWithUpgrade
40
+ * @see Socket
41
+ */
42
+ class SocketWithoutUpgrade extends Emitter {
43
+ /**
44
+ * Socket constructor.
45
+ *
46
+ * @param {String|Object} uri - uri or options
47
+ * @param {Object} opts - options
48
+ */
49
+ constructor(uri, opts) {
50
+ super();
51
+ this.binaryType = defaultBinaryType;
52
+ this.writeBuffer = [];
53
+ this._prevBufferLen = 0;
54
+ this._pingInterval = -1;
55
+ this._pingTimeout = -1;
56
+ this._maxPayload = -1;
57
+ /**
58
+ * The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
59
+ * callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
60
+ */
61
+ this._pingTimeoutTime = Infinity;
62
+ if (uri && "object" === typeof uri) {
63
+ opts = uri;
64
+ uri = null;
65
+ }
66
+ if (uri) {
67
+ const parsedUri = parse(uri);
68
+ opts.hostname = parsedUri.host;
69
+ opts.secure =
70
+ parsedUri.protocol === "https" || parsedUri.protocol === "wss";
71
+ opts.port = parsedUri.port;
72
+ if (parsedUri.query)
73
+ opts.query = parsedUri.query;
74
+ }
75
+ else if (opts.host) {
76
+ opts.hostname = parse(opts.host).host;
77
+ }
78
+ installTimerFunctions(this, opts);
79
+ this.secure =
80
+ null != opts.secure
81
+ ? opts.secure
82
+ : typeof location !== "undefined" && "https:" === location.protocol;
83
+ if (opts.hostname && !opts.port) {
84
+ // if no port is specified manually, use the protocol default
85
+ opts.port = this.secure ? "443" : "80";
86
+ }
87
+ this.hostname =
88
+ opts.hostname ||
89
+ (typeof location !== "undefined" ? location.hostname : "localhost");
90
+ this.port =
91
+ opts.port ||
92
+ (typeof location !== "undefined" && location.port
93
+ ? location.port
94
+ : this.secure
95
+ ? "443"
96
+ : "80");
97
+ this.transports = [];
98
+ this._transportsByName = {};
99
+ opts.transports.forEach((t) => {
100
+ const transportName = t.prototype.name;
101
+ this.transports.push(transportName);
102
+ this._transportsByName[transportName] = t;
103
+ });
104
+ this.opts = Object.assign({
105
+ path: "/engine.io",
106
+ agent: false,
107
+ withCredentials: false,
108
+ upgrade: true,
109
+ timestampParam: "t",
110
+ rememberUpgrade: false,
111
+ addTrailingSlash: true,
112
+ rejectUnauthorized: true,
113
+ perMessageDeflate: {
114
+ threshold: 1024,
115
+ },
116
+ transportOptions: {},
117
+ closeOnBeforeunload: false,
118
+ }, opts);
119
+ this.opts.path =
120
+ this.opts.path.replace(/\/$/, "") +
121
+ (this.opts.addTrailingSlash ? "/" : "");
122
+ if (typeof this.opts.query === "string") {
123
+ this.opts.query = decode(this.opts.query);
124
+ }
125
+ if (withEventListeners) {
126
+ if (this.opts.closeOnBeforeunload) {
127
+ // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
128
+ // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
129
+ // closed/reloaded)
130
+ this._beforeunloadEventListener = () => {
131
+ if (this.transport) {
132
+ // silently close the transport
133
+ this.transport.removeAllListeners();
134
+ this.transport.close();
135
+ }
136
+ };
137
+ addEventListener("beforeunload", this._beforeunloadEventListener, false);
138
+ }
139
+ if (this.hostname !== "localhost") {
140
+ this._offlineEventListener = () => {
141
+ this._onClose("transport close", {
142
+ description: "network connection lost",
143
+ });
144
+ };
145
+ OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
146
+ }
147
+ }
148
+ if (this.opts.withCredentials) {
149
+ this._cookieJar = createCookieJar();
150
+ }
151
+ this._open();
152
+ }
153
+ /**
154
+ * Creates transport of the given type.
155
+ *
156
+ * @param {String} name - transport name
157
+ * @return {Transport}
158
+ * @private
159
+ */
160
+ createTransport(name) {
161
+ const query = Object.assign({}, this.opts.query);
162
+ // append engine.io protocol identifier
163
+ query.EIO = protocol;
164
+ // transport name
165
+ query.transport = name;
166
+ // session id if we already have one
167
+ if (this.id)
168
+ query.sid = this.id;
169
+ const opts = Object.assign({}, this.opts, {
170
+ query,
171
+ socket: this,
172
+ hostname: this.hostname,
173
+ secure: this.secure,
174
+ port: this.port,
175
+ }, this.opts.transportOptions[name]);
176
+ return new this._transportsByName[name](opts);
177
+ }
178
+ /**
179
+ * Initializes transport to use and starts probe.
180
+ *
181
+ * @private
182
+ */
183
+ _open() {
184
+ if (this.transports.length === 0) {
185
+ // Emit error on next tick so it can be listened to
186
+ this.setTimeoutFn(() => {
187
+ this.emitReserved("error", "No transports available");
188
+ }, 0);
189
+ return;
190
+ }
191
+ const transportName = this.opts.rememberUpgrade &&
192
+ SocketWithoutUpgrade.priorWebsocketSuccess &&
193
+ this.transports.indexOf("websocket") !== -1
194
+ ? "websocket"
195
+ : this.transports[0];
196
+ this.readyState = "opening";
197
+ const transport = this.createTransport(transportName);
198
+ transport.open();
199
+ this.setTransport(transport);
200
+ }
201
+ /**
202
+ * Sets the current transport. Disables the existing one (if any).
203
+ *
204
+ * @private
205
+ */
206
+ setTransport(transport) {
207
+ if (this.transport) {
208
+ this.transport.removeAllListeners();
209
+ }
210
+ // set up transport
211
+ this.transport = transport;
212
+ // set up transport listeners
213
+ transport
214
+ .on("drain", this._onDrain.bind(this))
215
+ .on("packet", this._onPacket.bind(this))
216
+ .on("error", this._onError.bind(this))
217
+ .on("close", (reason) => this._onClose("transport close", reason));
218
+ }
219
+ /**
220
+ * Called when connection is deemed open.
221
+ *
222
+ * @private
223
+ */
224
+ onOpen() {
225
+ this.readyState = "open";
226
+ SocketWithoutUpgrade.priorWebsocketSuccess =
227
+ "websocket" === this.transport.name;
228
+ this.emitReserved("open");
229
+ this.flush();
230
+ }
231
+ /**
232
+ * Handles a packet.
233
+ *
234
+ * @private
235
+ */
236
+ _onPacket(packet) {
237
+ if ("opening" === this.readyState ||
238
+ "open" === this.readyState ||
239
+ "closing" === this.readyState) {
240
+ this.emitReserved("packet", packet);
241
+ // Socket is live - any packet counts
242
+ this.emitReserved("heartbeat");
243
+ switch (packet.type) {
244
+ case "open":
245
+ this.onHandshake(JSON.parse(packet.data));
246
+ break;
247
+ case "ping":
248
+ this._sendPacket("pong");
249
+ this.emitReserved("ping");
250
+ this.emitReserved("pong");
251
+ this._resetPingTimeout();
252
+ break;
253
+ case "error":
254
+ const err = new Error("server error");
255
+ // @ts-ignore
256
+ err.code = packet.data;
257
+ this._onError(err);
258
+ break;
259
+ case "message":
260
+ this.emitReserved("data", packet.data);
261
+ this.emitReserved("message", packet.data);
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ /**
267
+ * Called upon handshake completion.
268
+ *
269
+ * @param {Object} data - handshake obj
270
+ * @private
271
+ */
272
+ onHandshake(data) {
273
+ this.emitReserved("handshake", data);
274
+ this.id = data.sid;
275
+ this.transport.query.sid = data.sid;
276
+ this._pingInterval = data.pingInterval;
277
+ this._pingTimeout = data.pingTimeout;
278
+ this._maxPayload = data.maxPayload;
279
+ this.onOpen();
280
+ // In case open handler closes socket
281
+ if ("closed" === this.readyState)
282
+ return;
283
+ this._resetPingTimeout();
284
+ }
285
+ /**
286
+ * Sets and resets ping timeout timer based on server pings.
287
+ *
288
+ * @private
289
+ */
290
+ _resetPingTimeout() {
291
+ this.clearTimeoutFn(this._pingTimeoutTimer);
292
+ const delay = this._pingInterval + this._pingTimeout;
293
+ this._pingTimeoutTime = Date.now() + delay;
294
+ this._pingTimeoutTimer = this.setTimeoutFn(() => {
295
+ this._onClose("ping timeout");
296
+ }, delay);
297
+ if (this.opts.autoUnref) {
298
+ this._pingTimeoutTimer.unref();
299
+ }
300
+ }
301
+ /**
302
+ * Called on `drain` event
303
+ *
304
+ * @private
305
+ */
306
+ _onDrain() {
307
+ this.writeBuffer.splice(0, this._prevBufferLen);
308
+ // setting prevBufferLen = 0 is very important
309
+ // for example, when upgrading, upgrade packet is sent over,
310
+ // and a nonzero prevBufferLen could cause problems on `drain`
311
+ this._prevBufferLen = 0;
312
+ if (0 === this.writeBuffer.length) {
313
+ this.emitReserved("drain");
314
+ }
315
+ else {
316
+ this.flush();
317
+ }
318
+ }
319
+ /**
320
+ * Flush write buffers.
321
+ *
322
+ * @private
323
+ */
324
+ flush() {
325
+ if ("closed" !== this.readyState &&
326
+ this.transport.writable &&
327
+ !this.upgrading &&
328
+ this.writeBuffer.length) {
329
+ const packets = this._getWritablePackets();
330
+ this.transport.send(packets);
331
+ // keep track of current length of writeBuffer
332
+ // splice writeBuffer and callbackBuffer on `drain`
333
+ this._prevBufferLen = packets.length;
334
+ this.emitReserved("flush");
335
+ }
336
+ }
337
+ /**
338
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
339
+ * long-polling)
340
+ *
341
+ * @private
342
+ */
343
+ _getWritablePackets() {
344
+ const shouldCheckPayloadSize = this._maxPayload &&
345
+ this.transport.name === "polling" &&
346
+ this.writeBuffer.length > 1;
347
+ if (!shouldCheckPayloadSize) {
348
+ return this.writeBuffer;
349
+ }
350
+ let payloadSize = 1; // first packet type
351
+ for (let i = 0; i < this.writeBuffer.length; i++) {
352
+ const data = this.writeBuffer[i].data;
353
+ if (data) {
354
+ payloadSize += byteLength(data);
355
+ }
356
+ if (i > 0 && payloadSize > this._maxPayload) {
357
+ return this.writeBuffer.slice(0, i);
358
+ }
359
+ payloadSize += 2; // separator + packet type
360
+ }
361
+ return this.writeBuffer;
362
+ }
363
+ /**
364
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
365
+ *
366
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
367
+ * `write()` method then the message would not be buffered by the Socket.IO client.
368
+ *
369
+ * @return {boolean}
370
+ * @private
371
+ */
372
+ /* private */ _hasPingExpired() {
373
+ if (!this._pingTimeoutTime)
374
+ return true;
375
+ const hasExpired = Date.now() > this._pingTimeoutTime;
376
+ if (hasExpired) {
377
+ this._pingTimeoutTime = 0;
378
+ nextTick(() => {
379
+ this._onClose("ping timeout");
380
+ }, this.setTimeoutFn);
381
+ }
382
+ return hasExpired;
383
+ }
384
+ /**
385
+ * Sends a message.
386
+ *
387
+ * @param {String} msg - message.
388
+ * @param {Object} options.
389
+ * @param {Function} fn - callback function.
390
+ * @return {Socket} for chaining.
391
+ */
392
+ write(msg, options, fn) {
393
+ this._sendPacket("message", msg, options, fn);
394
+ return this;
395
+ }
396
+ /**
397
+ * Sends a message. Alias of {@link Socket#write}.
398
+ *
399
+ * @param {String} msg - message.
400
+ * @param {Object} options.
401
+ * @param {Function} fn - callback function.
402
+ * @return {Socket} for chaining.
403
+ */
404
+ send(msg, options, fn) {
405
+ this._sendPacket("message", msg, options, fn);
406
+ return this;
407
+ }
408
+ /**
409
+ * Sends a packet.
410
+ *
411
+ * @param {String} type: packet type.
412
+ * @param {String} data.
413
+ * @param {Object} options.
414
+ * @param {Function} fn - callback function.
415
+ * @private
416
+ */
417
+ _sendPacket(type, data, options, fn) {
418
+ if ("function" === typeof data) {
419
+ fn = data;
420
+ data = undefined;
421
+ }
422
+ if ("function" === typeof options) {
423
+ fn = options;
424
+ options = null;
425
+ }
426
+ if ("closing" === this.readyState || "closed" === this.readyState) {
427
+ return;
428
+ }
429
+ options = options || {};
430
+ options.compress = false !== options.compress;
431
+ const packet = {
432
+ type: type,
433
+ data: data,
434
+ options: options,
435
+ };
436
+ this.emitReserved("packetCreate", packet);
437
+ this.writeBuffer.push(packet);
438
+ if (fn)
439
+ this.once("flush", fn);
440
+ this.flush();
441
+ }
442
+ /**
443
+ * Closes the connection.
444
+ */
445
+ close() {
446
+ const close = () => {
447
+ this._onClose("forced close");
448
+ this.transport.close();
449
+ };
450
+ const cleanupAndClose = () => {
451
+ this.off("upgrade", cleanupAndClose);
452
+ this.off("upgradeError", cleanupAndClose);
453
+ close();
454
+ };
455
+ const waitForUpgrade = () => {
456
+ // wait for upgrade to finish since we can't send packets while pausing a transport
457
+ this.once("upgrade", cleanupAndClose);
458
+ this.once("upgradeError", cleanupAndClose);
459
+ };
460
+ if ("opening" === this.readyState || "open" === this.readyState) {
461
+ this.readyState = "closing";
462
+ if (this.writeBuffer.length) {
463
+ this.once("drain", () => {
464
+ if (this.upgrading) {
465
+ waitForUpgrade();
466
+ }
467
+ else {
468
+ close();
469
+ }
470
+ });
471
+ }
472
+ else if (this.upgrading) {
473
+ waitForUpgrade();
474
+ }
475
+ else {
476
+ close();
477
+ }
478
+ }
479
+ return this;
480
+ }
481
+ /**
482
+ * Called upon transport error
483
+ *
484
+ * @private
485
+ */
486
+ _onError(err) {
487
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
488
+ if (this.opts.tryAllTransports &&
489
+ this.transports.length > 1 &&
490
+ this.readyState === "opening") {
491
+ this.transports.shift();
492
+ return this._open();
493
+ }
494
+ this.emitReserved("error", err);
495
+ this._onClose("transport error", err);
496
+ }
497
+ /**
498
+ * Called upon transport close.
499
+ *
500
+ * @private
501
+ */
502
+ _onClose(reason, description) {
503
+ if ("opening" === this.readyState ||
504
+ "open" === this.readyState ||
505
+ "closing" === this.readyState) {
506
+ // clear timers
507
+ this.clearTimeoutFn(this._pingTimeoutTimer);
508
+ // stop event from firing again for transport
509
+ this.transport.removeAllListeners("close");
510
+ // ensure transport won't stay open
511
+ this.transport.close();
512
+ // ignore further transport communication
513
+ this.transport.removeAllListeners();
514
+ if (withEventListeners) {
515
+ if (this._beforeunloadEventListener) {
516
+ removeEventListener("beforeunload", this._beforeunloadEventListener, false);
517
+ }
518
+ if (this._offlineEventListener) {
519
+ const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
520
+ if (i !== -1) {
521
+ OFFLINE_EVENT_LISTENERS.splice(i, 1);
522
+ }
523
+ }
524
+ }
525
+ // set ready state
526
+ this.readyState = "closed";
527
+ // clear session id
528
+ this.id = null;
529
+ // emit close event
530
+ this.emitReserved("close", reason, description);
531
+ // clean buffers after, so users can still
532
+ // grab the buffers on `close` event
533
+ this.writeBuffer = [];
534
+ this._prevBufferLen = 0;
535
+ }
536
+ }
537
+ }
538
+ SocketWithoutUpgrade.protocol = protocol;
539
+ /**
540
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
541
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
542
+ *
543
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
544
+ * low-level transport, it will try to upgrade to a better transport.
545
+ *
546
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
547
+ *
548
+ * @example
549
+ * import { SocketWithUpgrade, WebSocket } from "engine.io-client";
550
+ *
551
+ * const socket = new SocketWithUpgrade({
552
+ * transports: [WebSocket]
553
+ * });
554
+ *
555
+ * socket.on("open", () => {
556
+ * socket.send("hello");
557
+ * });
558
+ *
559
+ * @see SocketWithoutUpgrade
560
+ * @see Socket
561
+ */
562
+ class SocketWithUpgrade extends SocketWithoutUpgrade {
563
+ constructor() {
564
+ super(...arguments);
565
+ this._upgrades = [];
566
+ }
567
+ onOpen() {
568
+ super.onOpen();
569
+ if ("open" === this.readyState && this.opts.upgrade) {
570
+ for (let i = 0; i < this._upgrades.length; i++) {
571
+ this._probe(this._upgrades[i]);
572
+ }
573
+ }
574
+ }
575
+ /**
576
+ * Probes a transport.
577
+ *
578
+ * @param {String} name - transport name
579
+ * @private
580
+ */
581
+ _probe(name) {
582
+ let transport = this.createTransport(name);
583
+ let failed = false;
584
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
585
+ const onTransportOpen = () => {
586
+ if (failed)
587
+ return;
588
+ transport.send([{ type: "ping", data: "probe" }]);
589
+ transport.once("packet", (msg) => {
590
+ if (failed)
591
+ return;
592
+ if ("pong" === msg.type && "probe" === msg.data) {
593
+ this.upgrading = true;
594
+ this.emitReserved("upgrading", transport);
595
+ if (!transport)
596
+ return;
597
+ SocketWithoutUpgrade.priorWebsocketSuccess =
598
+ "websocket" === transport.name;
599
+ this.transport.pause(() => {
600
+ if (failed)
601
+ return;
602
+ if ("closed" === this.readyState)
603
+ return;
604
+ cleanup();
605
+ this.setTransport(transport);
606
+ transport.send([{ type: "upgrade" }]);
607
+ this.emitReserved("upgrade", transport);
608
+ transport = null;
609
+ this.upgrading = false;
610
+ this.flush();
611
+ });
612
+ }
613
+ else {
614
+ const err = new Error("probe error");
615
+ // @ts-ignore
616
+ err.transport = transport.name;
617
+ this.emitReserved("upgradeError", err);
618
+ }
619
+ });
620
+ };
621
+ function freezeTransport() {
622
+ if (failed)
623
+ return;
624
+ // Any callback called by transport should be ignored since now
625
+ failed = true;
626
+ cleanup();
627
+ transport.close();
628
+ transport = null;
629
+ }
630
+ // Handle any error that happens while probing
631
+ const onerror = (err) => {
632
+ const error = new Error("probe error: " + err);
633
+ // @ts-ignore
634
+ error.transport = transport.name;
635
+ freezeTransport();
636
+ this.emitReserved("upgradeError", error);
637
+ };
638
+ function onTransportClose() {
639
+ onerror("transport closed");
640
+ }
641
+ // When the socket is closed while we're probing
642
+ function onclose() {
643
+ onerror("socket closed");
644
+ }
645
+ // When the socket is upgraded while we're probing
646
+ function onupgrade(to) {
647
+ if (transport && to.name !== transport.name) {
648
+ freezeTransport();
649
+ }
650
+ }
651
+ // Remove all listeners on the transport and on self
652
+ const cleanup = () => {
653
+ transport.removeListener("open", onTransportOpen);
654
+ transport.removeListener("error", onerror);
655
+ transport.removeListener("close", onTransportClose);
656
+ this.off("close", onclose);
657
+ this.off("upgrading", onupgrade);
658
+ };
659
+ transport.once("open", onTransportOpen);
660
+ transport.once("error", onerror);
661
+ transport.once("close", onTransportClose);
662
+ this.once("close", onclose);
663
+ this.once("upgrading", onupgrade);
664
+ if (this._upgrades.indexOf("webtransport") !== -1 &&
665
+ name !== "webtransport") {
666
+ // favor WebTransport
667
+ this.setTimeoutFn(() => {
668
+ if (!failed) {
669
+ transport.open();
670
+ }
671
+ }, 200);
672
+ }
673
+ else {
674
+ transport.open();
675
+ }
676
+ }
677
+ onHandshake(data) {
678
+ this._upgrades = this._filterUpgrades(data.upgrades);
679
+ super.onHandshake(data);
680
+ }
681
+ /**
682
+ * Filters upgrades, returning only those matching client transports.
683
+ *
684
+ * @param {Array} upgrades - server upgrades
685
+ * @private
686
+ */
687
+ _filterUpgrades(upgrades) {
688
+ const filteredUpgrades = [];
689
+ for (let i = 0; i < upgrades.length; i++) {
690
+ if (~this.transports.indexOf(upgrades[i]))
691
+ filteredUpgrades.push(upgrades[i]);
692
+ }
693
+ return filteredUpgrades;
694
+ }
695
+ }
696
+ /**
697
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
698
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
699
+ *
700
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
701
+ * low-level transport, it will try to upgrade to a better transport.
702
+ *
703
+ * @example
704
+ * import { Socket } from "engine.io-client";
705
+ *
706
+ * const socket = new Socket();
707
+ *
708
+ * socket.on("open", () => {
709
+ * socket.send("hello");
710
+ * });
711
+ *
712
+ * @see SocketWithoutUpgrade
713
+ * @see SocketWithUpgrade
714
+ */
715
+ class Socket extends SocketWithUpgrade {
716
+ constructor(uri, opts = {}) {
717
+ const o = typeof uri === "object" ? uri : opts;
718
+ if (!o.transports ||
719
+ (o.transports && typeof o.transports[0] === "string")) {
720
+ o.transports = (o.transports || ["polling", "websocket", "webtransport"])
721
+ .map((transportName) => transports[transportName])
722
+ .filter((t) => !!t);
723
+ }
724
+ super(uri, o);
725
+ }
726
+ }
727
+
728
+ export { Socket, SocketWithUpgrade, SocketWithoutUpgrade };