@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,884 @@
1
+ import { PacketType } from '../../../socket.io-parser/build/esm/index.js';
2
+ import { on } from './on.js';
3
+ import { Emitter } from '../../../@socket.io/component-emitter/lib/esm/index.js';
4
+
5
+ /**
6
+ * Internal events.
7
+ * These events can't be emitted by the user.
8
+ */
9
+ const RESERVED_EVENTS = Object.freeze({
10
+ connect: 1,
11
+ connect_error: 1,
12
+ disconnect: 1,
13
+ disconnecting: 1,
14
+ // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
15
+ newListener: 1,
16
+ removeListener: 1,
17
+ });
18
+ /**
19
+ * A Socket is the fundamental class for interacting with the server.
20
+ *
21
+ * A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
22
+ *
23
+ * @example
24
+ * const socket = io();
25
+ *
26
+ * socket.on("connect", () => {
27
+ * console.log("connected");
28
+ * });
29
+ *
30
+ * // send an event to the server
31
+ * socket.emit("foo", "bar");
32
+ *
33
+ * socket.on("foobar", () => {
34
+ * // an event was received from the server
35
+ * });
36
+ *
37
+ * // upon disconnection
38
+ * socket.on("disconnect", (reason) => {
39
+ * console.log(`disconnected due to ${reason}`);
40
+ * });
41
+ */
42
+ class Socket extends Emitter {
43
+ /**
44
+ * `Socket` constructor.
45
+ */
46
+ constructor(io, nsp, opts) {
47
+ super();
48
+ /**
49
+ * Whether the socket is currently connected to the server.
50
+ *
51
+ * @example
52
+ * const socket = io();
53
+ *
54
+ * socket.on("connect", () => {
55
+ * console.log(socket.connected); // true
56
+ * });
57
+ *
58
+ * socket.on("disconnect", () => {
59
+ * console.log(socket.connected); // false
60
+ * });
61
+ */
62
+ this.connected = false;
63
+ /**
64
+ * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
65
+ * be transmitted by the server.
66
+ */
67
+ this.recovered = false;
68
+ /**
69
+ * Buffer for packets received before the CONNECT packet
70
+ */
71
+ this.receiveBuffer = [];
72
+ /**
73
+ * Buffer for packets that will be sent once the socket is connected
74
+ */
75
+ this.sendBuffer = [];
76
+ /**
77
+ * The queue of packets to be sent with retry in case of failure.
78
+ *
79
+ * Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
80
+ * @private
81
+ */
82
+ this._queue = [];
83
+ /**
84
+ * A sequence to generate the ID of the {@link QueuedPacket}.
85
+ * @private
86
+ */
87
+ this._queueSeq = 0;
88
+ this.ids = 0;
89
+ /**
90
+ * A map containing acknowledgement handlers.
91
+ *
92
+ * The `withError` attribute is used to differentiate handlers that accept an error as first argument:
93
+ *
94
+ * - `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
95
+ * - `socket.timeout(5000).emit("test", (err, value) => { ... })`
96
+ * - `const value = await socket.emitWithAck("test")`
97
+ *
98
+ * From those that don't:
99
+ *
100
+ * - `socket.emit("test", (value) => { ... });`
101
+ *
102
+ * In the first case, the handlers will be called with an error when:
103
+ *
104
+ * - the timeout is reached
105
+ * - the socket gets disconnected
106
+ *
107
+ * In the second case, the handlers will be simply discarded upon disconnection, since the client will never receive
108
+ * an acknowledgement from the server.
109
+ *
110
+ * @private
111
+ */
112
+ this.acks = {};
113
+ this.flags = {};
114
+ this.io = io;
115
+ this.nsp = nsp;
116
+ if (opts && opts.auth) {
117
+ this.auth = opts.auth;
118
+ }
119
+ this._opts = Object.assign({}, opts);
120
+ if (this.io._autoConnect)
121
+ this.open();
122
+ }
123
+ /**
124
+ * Whether the socket is currently disconnected
125
+ *
126
+ * @example
127
+ * const socket = io();
128
+ *
129
+ * socket.on("connect", () => {
130
+ * console.log(socket.disconnected); // false
131
+ * });
132
+ *
133
+ * socket.on("disconnect", () => {
134
+ * console.log(socket.disconnected); // true
135
+ * });
136
+ */
137
+ get disconnected() {
138
+ return !this.connected;
139
+ }
140
+ /**
141
+ * Subscribe to open, close and packet events
142
+ *
143
+ * @private
144
+ */
145
+ subEvents() {
146
+ if (this.subs)
147
+ return;
148
+ const io = this.io;
149
+ this.subs = [
150
+ on(io, "open", this.onopen.bind(this)),
151
+ on(io, "packet", this.onpacket.bind(this)),
152
+ on(io, "error", this.onerror.bind(this)),
153
+ on(io, "close", this.onclose.bind(this)),
154
+ ];
155
+ }
156
+ /**
157
+ * Whether the Socket will try to reconnect when its Manager connects or reconnects.
158
+ *
159
+ * @example
160
+ * const socket = io();
161
+ *
162
+ * console.log(socket.active); // true
163
+ *
164
+ * socket.on("disconnect", (reason) => {
165
+ * if (reason === "io server disconnect") {
166
+ * // the disconnection was initiated by the server, you need to manually reconnect
167
+ * console.log(socket.active); // false
168
+ * }
169
+ * // else the socket will automatically try to reconnect
170
+ * console.log(socket.active); // true
171
+ * });
172
+ */
173
+ get active() {
174
+ return !!this.subs;
175
+ }
176
+ /**
177
+ * "Opens" the socket.
178
+ *
179
+ * @example
180
+ * const socket = io({
181
+ * autoConnect: false
182
+ * });
183
+ *
184
+ * socket.connect();
185
+ */
186
+ connect() {
187
+ if (this.connected)
188
+ return this;
189
+ this.subEvents();
190
+ if (!this.io["_reconnecting"])
191
+ this.io.open(); // ensure open
192
+ if ("open" === this.io._readyState)
193
+ this.onopen();
194
+ return this;
195
+ }
196
+ /**
197
+ * Alias for {@link connect()}.
198
+ */
199
+ open() {
200
+ return this.connect();
201
+ }
202
+ /**
203
+ * Sends a `message` event.
204
+ *
205
+ * This method mimics the WebSocket.send() method.
206
+ *
207
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
208
+ *
209
+ * @example
210
+ * socket.send("hello");
211
+ *
212
+ * // this is equivalent to
213
+ * socket.emit("message", "hello");
214
+ *
215
+ * @return self
216
+ */
217
+ send(...args) {
218
+ args.unshift("message");
219
+ this.emit.apply(this, args);
220
+ return this;
221
+ }
222
+ /**
223
+ * Override `emit`.
224
+ * If the event is in `events`, it's emitted normally.
225
+ *
226
+ * @example
227
+ * socket.emit("hello", "world");
228
+ *
229
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
230
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
231
+ *
232
+ * // with an acknowledgement from the server
233
+ * socket.emit("hello", "world", (val) => {
234
+ * // ...
235
+ * });
236
+ *
237
+ * @return self
238
+ */
239
+ emit(ev, ...args) {
240
+ var _a, _b, _c;
241
+ if (RESERVED_EVENTS.hasOwnProperty(ev)) {
242
+ throw new Error('"' + ev.toString() + '" is a reserved event name');
243
+ }
244
+ args.unshift(ev);
245
+ if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
246
+ this._addToQueue(args);
247
+ return this;
248
+ }
249
+ const packet = {
250
+ type: PacketType.EVENT,
251
+ data: args,
252
+ };
253
+ packet.options = {};
254
+ packet.options.compress = this.flags.compress !== false;
255
+ // event ack callback
256
+ if ("function" === typeof args[args.length - 1]) {
257
+ const id = this.ids++;
258
+ const ack = args.pop();
259
+ this._registerAckCallback(id, ack);
260
+ packet.id = id;
261
+ }
262
+ const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
263
+ const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
264
+ const discardPacket = this.flags.volatile && !isTransportWritable;
265
+ if (discardPacket) ;
266
+ else if (isConnected) {
267
+ this.notifyOutgoingListeners(packet);
268
+ this.packet(packet);
269
+ }
270
+ else {
271
+ this.sendBuffer.push(packet);
272
+ }
273
+ this.flags = {};
274
+ return this;
275
+ }
276
+ /**
277
+ * @private
278
+ */
279
+ _registerAckCallback(id, ack) {
280
+ var _a;
281
+ const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
282
+ if (timeout === undefined) {
283
+ this.acks[id] = ack;
284
+ return;
285
+ }
286
+ // @ts-ignore
287
+ const timer = this.io.setTimeoutFn(() => {
288
+ delete this.acks[id];
289
+ for (let i = 0; i < this.sendBuffer.length; i++) {
290
+ if (this.sendBuffer[i].id === id) {
291
+ this.sendBuffer.splice(i, 1);
292
+ }
293
+ }
294
+ ack.call(this, new Error("operation has timed out"));
295
+ }, timeout);
296
+ const fn = (...args) => {
297
+ // @ts-ignore
298
+ this.io.clearTimeoutFn(timer);
299
+ ack.apply(this, args);
300
+ };
301
+ fn.withError = true;
302
+ this.acks[id] = fn;
303
+ }
304
+ /**
305
+ * Emits an event and waits for an acknowledgement
306
+ *
307
+ * @example
308
+ * // without timeout
309
+ * const response = await socket.emitWithAck("hello", "world");
310
+ *
311
+ * // with a specific timeout
312
+ * try {
313
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
314
+ * } catch (err) {
315
+ * // the server did not acknowledge the event in the given delay
316
+ * }
317
+ *
318
+ * @return a Promise that will be fulfilled when the server acknowledges the event
319
+ */
320
+ emitWithAck(ev, ...args) {
321
+ return new Promise((resolve, reject) => {
322
+ const fn = (arg1, arg2) => {
323
+ return arg1 ? reject(arg1) : resolve(arg2);
324
+ };
325
+ fn.withError = true;
326
+ args.push(fn);
327
+ this.emit(ev, ...args);
328
+ });
329
+ }
330
+ /**
331
+ * Add the packet to the queue.
332
+ * @param args
333
+ * @private
334
+ */
335
+ _addToQueue(args) {
336
+ let ack;
337
+ if (typeof args[args.length - 1] === "function") {
338
+ ack = args.pop();
339
+ }
340
+ const packet = {
341
+ id: this._queueSeq++,
342
+ tryCount: 0,
343
+ pending: false,
344
+ args,
345
+ flags: Object.assign({ fromQueue: true }, this.flags),
346
+ };
347
+ args.push((err, ...responseArgs) => {
348
+ if (packet !== this._queue[0]) {
349
+ // the packet has already been acknowledged
350
+ return;
351
+ }
352
+ const hasError = err !== null;
353
+ if (hasError) {
354
+ if (packet.tryCount > this._opts.retries) {
355
+ this._queue.shift();
356
+ if (ack) {
357
+ ack(err);
358
+ }
359
+ }
360
+ }
361
+ else {
362
+ this._queue.shift();
363
+ if (ack) {
364
+ ack(null, ...responseArgs);
365
+ }
366
+ }
367
+ packet.pending = false;
368
+ return this._drainQueue();
369
+ });
370
+ this._queue.push(packet);
371
+ this._drainQueue();
372
+ }
373
+ /**
374
+ * Send the first packet of the queue, and wait for an acknowledgement from the server.
375
+ * @param force - whether to resend a packet that has not been acknowledged yet
376
+ *
377
+ * @private
378
+ */
379
+ _drainQueue(force = false) {
380
+ if (!this.connected || this._queue.length === 0) {
381
+ return;
382
+ }
383
+ const packet = this._queue[0];
384
+ if (packet.pending && !force) {
385
+ return;
386
+ }
387
+ packet.pending = true;
388
+ packet.tryCount++;
389
+ this.flags = packet.flags;
390
+ this.emit.apply(this, packet.args);
391
+ }
392
+ /**
393
+ * Sends a packet.
394
+ *
395
+ * @param packet
396
+ * @private
397
+ */
398
+ packet(packet) {
399
+ packet.nsp = this.nsp;
400
+ this.io._packet(packet);
401
+ }
402
+ /**
403
+ * Called upon engine `open`.
404
+ *
405
+ * @private
406
+ */
407
+ onopen() {
408
+ if (typeof this.auth == "function") {
409
+ this.auth((data) => {
410
+ this._sendConnectPacket(data);
411
+ });
412
+ }
413
+ else {
414
+ this._sendConnectPacket(this.auth);
415
+ }
416
+ }
417
+ /**
418
+ * Sends a CONNECT packet to initiate the Socket.IO session.
419
+ *
420
+ * @param data
421
+ * @private
422
+ */
423
+ _sendConnectPacket(data) {
424
+ this.packet({
425
+ type: PacketType.CONNECT,
426
+ data: this._pid
427
+ ? Object.assign({ pid: this._pid, offset: this._lastOffset }, data)
428
+ : data,
429
+ });
430
+ }
431
+ /**
432
+ * Called upon engine or manager `error`.
433
+ *
434
+ * @param err
435
+ * @private
436
+ */
437
+ onerror(err) {
438
+ if (!this.connected) {
439
+ this.emitReserved("connect_error", err);
440
+ }
441
+ }
442
+ /**
443
+ * Called upon engine `close`.
444
+ *
445
+ * @param reason
446
+ * @param description
447
+ * @private
448
+ */
449
+ onclose(reason, description) {
450
+ this.connected = false;
451
+ delete this.id;
452
+ this.emitReserved("disconnect", reason, description);
453
+ this._clearAcks();
454
+ }
455
+ /**
456
+ * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
457
+ * the server.
458
+ *
459
+ * @private
460
+ */
461
+ _clearAcks() {
462
+ Object.keys(this.acks).forEach((id) => {
463
+ const isBuffered = this.sendBuffer.some((packet) => String(packet.id) === id);
464
+ if (!isBuffered) {
465
+ // note: handlers that do not accept an error as first argument are ignored here
466
+ const ack = this.acks[id];
467
+ delete this.acks[id];
468
+ if (ack.withError) {
469
+ ack.call(this, new Error("socket has been disconnected"));
470
+ }
471
+ }
472
+ });
473
+ }
474
+ /**
475
+ * Called with socket packet.
476
+ *
477
+ * @param packet
478
+ * @private
479
+ */
480
+ onpacket(packet) {
481
+ const sameNamespace = packet.nsp === this.nsp;
482
+ if (!sameNamespace)
483
+ return;
484
+ switch (packet.type) {
485
+ case PacketType.CONNECT:
486
+ if (packet.data && packet.data.sid) {
487
+ this.onconnect(packet.data.sid, packet.data.pid);
488
+ }
489
+ else {
490
+ this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
491
+ }
492
+ break;
493
+ case PacketType.EVENT:
494
+ case PacketType.BINARY_EVENT:
495
+ this.onevent(packet);
496
+ break;
497
+ case PacketType.ACK:
498
+ case PacketType.BINARY_ACK:
499
+ this.onack(packet);
500
+ break;
501
+ case PacketType.DISCONNECT:
502
+ this.ondisconnect();
503
+ break;
504
+ case PacketType.CONNECT_ERROR:
505
+ this.destroy();
506
+ const err = new Error(packet.data.message);
507
+ // @ts-ignore
508
+ err.data = packet.data.data;
509
+ this.emitReserved("connect_error", err);
510
+ break;
511
+ }
512
+ }
513
+ /**
514
+ * Called upon a server event.
515
+ *
516
+ * @param packet
517
+ * @private
518
+ */
519
+ onevent(packet) {
520
+ const args = packet.data || [];
521
+ if (null != packet.id) {
522
+ args.push(this.ack(packet.id));
523
+ }
524
+ if (this.connected) {
525
+ this.emitEvent(args);
526
+ }
527
+ else {
528
+ this.receiveBuffer.push(Object.freeze(args));
529
+ }
530
+ }
531
+ emitEvent(args) {
532
+ if (this._anyListeners && this._anyListeners.length) {
533
+ const listeners = this._anyListeners.slice();
534
+ for (const listener of listeners) {
535
+ listener.apply(this, args);
536
+ }
537
+ }
538
+ super.emit.apply(this, args);
539
+ if (this._pid && args.length && typeof args[args.length - 1] === "string") {
540
+ this._lastOffset = args[args.length - 1];
541
+ }
542
+ }
543
+ /**
544
+ * Produces an ack callback to emit with an event.
545
+ *
546
+ * @private
547
+ */
548
+ ack(id) {
549
+ const self = this;
550
+ let sent = false;
551
+ return function (...args) {
552
+ // prevent double callbacks
553
+ if (sent)
554
+ return;
555
+ sent = true;
556
+ self.packet({
557
+ type: PacketType.ACK,
558
+ id: id,
559
+ data: args,
560
+ });
561
+ };
562
+ }
563
+ /**
564
+ * Called upon a server acknowledgement.
565
+ *
566
+ * @param packet
567
+ * @private
568
+ */
569
+ onack(packet) {
570
+ const ack = this.acks[packet.id];
571
+ if (typeof ack !== "function") {
572
+ return;
573
+ }
574
+ delete this.acks[packet.id];
575
+ // @ts-ignore FIXME ack is incorrectly inferred as 'never'
576
+ if (ack.withError) {
577
+ packet.data.unshift(null);
578
+ }
579
+ // @ts-ignore
580
+ ack.apply(this, packet.data);
581
+ }
582
+ /**
583
+ * Called upon server connect.
584
+ *
585
+ * @private
586
+ */
587
+ onconnect(id, pid) {
588
+ this.id = id;
589
+ this.recovered = pid && this._pid === pid;
590
+ this._pid = pid; // defined only if connection state recovery is enabled
591
+ this.connected = true;
592
+ this.emitBuffered();
593
+ this.emitReserved("connect");
594
+ this._drainQueue(true);
595
+ }
596
+ /**
597
+ * Emit buffered events (received and emitted).
598
+ *
599
+ * @private
600
+ */
601
+ emitBuffered() {
602
+ this.receiveBuffer.forEach((args) => this.emitEvent(args));
603
+ this.receiveBuffer = [];
604
+ this.sendBuffer.forEach((packet) => {
605
+ this.notifyOutgoingListeners(packet);
606
+ this.packet(packet);
607
+ });
608
+ this.sendBuffer = [];
609
+ }
610
+ /**
611
+ * Called upon server disconnect.
612
+ *
613
+ * @private
614
+ */
615
+ ondisconnect() {
616
+ this.destroy();
617
+ this.onclose("io server disconnect");
618
+ }
619
+ /**
620
+ * Called upon forced client/server side disconnections,
621
+ * this method ensures the manager stops tracking us and
622
+ * that reconnections don't get triggered for this.
623
+ *
624
+ * @private
625
+ */
626
+ destroy() {
627
+ if (this.subs) {
628
+ // clean subscriptions to avoid reconnections
629
+ this.subs.forEach((subDestroy) => subDestroy());
630
+ this.subs = undefined;
631
+ }
632
+ this.io["_destroy"](this);
633
+ }
634
+ /**
635
+ * Disconnects the socket manually. In that case, the socket will not try to reconnect.
636
+ *
637
+ * If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
638
+ *
639
+ * @example
640
+ * const socket = io();
641
+ *
642
+ * socket.on("disconnect", (reason) => {
643
+ * // console.log(reason); prints "io client disconnect"
644
+ * });
645
+ *
646
+ * socket.disconnect();
647
+ *
648
+ * @return self
649
+ */
650
+ disconnect() {
651
+ if (this.connected) {
652
+ this.packet({ type: PacketType.DISCONNECT });
653
+ }
654
+ // remove socket from pool
655
+ this.destroy();
656
+ if (this.connected) {
657
+ // fire events
658
+ this.onclose("io client disconnect");
659
+ }
660
+ return this;
661
+ }
662
+ /**
663
+ * Alias for {@link disconnect()}.
664
+ *
665
+ * @return self
666
+ */
667
+ close() {
668
+ return this.disconnect();
669
+ }
670
+ /**
671
+ * Sets the compress flag.
672
+ *
673
+ * @example
674
+ * socket.compress(false).emit("hello");
675
+ *
676
+ * @param compress - if `true`, compresses the sending data
677
+ * @return self
678
+ */
679
+ compress(compress) {
680
+ this.flags.compress = compress;
681
+ return this;
682
+ }
683
+ /**
684
+ * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
685
+ * ready to send messages.
686
+ *
687
+ * @example
688
+ * socket.volatile.emit("hello"); // the server may or may not receive it
689
+ *
690
+ * @returns self
691
+ */
692
+ get volatile() {
693
+ this.flags.volatile = true;
694
+ return this;
695
+ }
696
+ /**
697
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
698
+ * given number of milliseconds have elapsed without an acknowledgement from the server:
699
+ *
700
+ * @example
701
+ * socket.timeout(5000).emit("my-event", (err) => {
702
+ * if (err) {
703
+ * // the server did not acknowledge the event in the given delay
704
+ * }
705
+ * });
706
+ *
707
+ * @returns self
708
+ */
709
+ timeout(timeout) {
710
+ this.flags.timeout = timeout;
711
+ return this;
712
+ }
713
+ /**
714
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
715
+ * callback.
716
+ *
717
+ * @example
718
+ * socket.onAny((event, ...args) => {
719
+ * console.log(`got ${event}`);
720
+ * });
721
+ *
722
+ * @param listener
723
+ */
724
+ onAny(listener) {
725
+ this._anyListeners = this._anyListeners || [];
726
+ this._anyListeners.push(listener);
727
+ return this;
728
+ }
729
+ /**
730
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
731
+ * callback. The listener is added to the beginning of the listeners array.
732
+ *
733
+ * @example
734
+ * socket.prependAny((event, ...args) => {
735
+ * console.log(`got event ${event}`);
736
+ * });
737
+ *
738
+ * @param listener
739
+ */
740
+ prependAny(listener) {
741
+ this._anyListeners = this._anyListeners || [];
742
+ this._anyListeners.unshift(listener);
743
+ return this;
744
+ }
745
+ /**
746
+ * Removes the listener that will be fired when any event is emitted.
747
+ *
748
+ * @example
749
+ * const catchAllListener = (event, ...args) => {
750
+ * console.log(`got event ${event}`);
751
+ * }
752
+ *
753
+ * socket.onAny(catchAllListener);
754
+ *
755
+ * // remove a specific listener
756
+ * socket.offAny(catchAllListener);
757
+ *
758
+ * // or remove all listeners
759
+ * socket.offAny();
760
+ *
761
+ * @param listener
762
+ */
763
+ offAny(listener) {
764
+ if (!this._anyListeners) {
765
+ return this;
766
+ }
767
+ if (listener) {
768
+ const listeners = this._anyListeners;
769
+ for (let i = 0; i < listeners.length; i++) {
770
+ if (listener === listeners[i]) {
771
+ listeners.splice(i, 1);
772
+ return this;
773
+ }
774
+ }
775
+ }
776
+ else {
777
+ this._anyListeners = [];
778
+ }
779
+ return this;
780
+ }
781
+ /**
782
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
783
+ * e.g. to remove listeners.
784
+ */
785
+ listenersAny() {
786
+ return this._anyListeners || [];
787
+ }
788
+ /**
789
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
790
+ * callback.
791
+ *
792
+ * Note: acknowledgements sent to the server are not included.
793
+ *
794
+ * @example
795
+ * socket.onAnyOutgoing((event, ...args) => {
796
+ * console.log(`sent event ${event}`);
797
+ * });
798
+ *
799
+ * @param listener
800
+ */
801
+ onAnyOutgoing(listener) {
802
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
803
+ this._anyOutgoingListeners.push(listener);
804
+ return this;
805
+ }
806
+ /**
807
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
808
+ * callback. The listener is added to the beginning of the listeners array.
809
+ *
810
+ * Note: acknowledgements sent to the server are not included.
811
+ *
812
+ * @example
813
+ * socket.prependAnyOutgoing((event, ...args) => {
814
+ * console.log(`sent event ${event}`);
815
+ * });
816
+ *
817
+ * @param listener
818
+ */
819
+ prependAnyOutgoing(listener) {
820
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
821
+ this._anyOutgoingListeners.unshift(listener);
822
+ return this;
823
+ }
824
+ /**
825
+ * Removes the listener that will be fired when any event is emitted.
826
+ *
827
+ * @example
828
+ * const catchAllListener = (event, ...args) => {
829
+ * console.log(`sent event ${event}`);
830
+ * }
831
+ *
832
+ * socket.onAnyOutgoing(catchAllListener);
833
+ *
834
+ * // remove a specific listener
835
+ * socket.offAnyOutgoing(catchAllListener);
836
+ *
837
+ * // or remove all listeners
838
+ * socket.offAnyOutgoing();
839
+ *
840
+ * @param [listener] - the catch-all listener (optional)
841
+ */
842
+ offAnyOutgoing(listener) {
843
+ if (!this._anyOutgoingListeners) {
844
+ return this;
845
+ }
846
+ if (listener) {
847
+ const listeners = this._anyOutgoingListeners;
848
+ for (let i = 0; i < listeners.length; i++) {
849
+ if (listener === listeners[i]) {
850
+ listeners.splice(i, 1);
851
+ return this;
852
+ }
853
+ }
854
+ }
855
+ else {
856
+ this._anyOutgoingListeners = [];
857
+ }
858
+ return this;
859
+ }
860
+ /**
861
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
862
+ * e.g. to remove listeners.
863
+ */
864
+ listenersAnyOutgoing() {
865
+ return this._anyOutgoingListeners || [];
866
+ }
867
+ /**
868
+ * Notify the listeners for each packet sent
869
+ *
870
+ * @param packet
871
+ *
872
+ * @private
873
+ */
874
+ notifyOutgoingListeners(packet) {
875
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
876
+ const listeners = this._anyOutgoingListeners.slice();
877
+ for (const listener of listeners) {
878
+ listener.apply(this, packet.data);
879
+ }
880
+ }
881
+ }
882
+ }
883
+
884
+ export { Socket };