@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,993 @@
1
+ import { __exports as socket } from '../../../_virtual/socket.js';
2
+ import { __require as requireCjs } from '../../socket.io-parser/build/cjs/index.js';
3
+ import { __require as requireSrc } from '../node_modules/debug/src/index.js';
4
+ import { __require as requireTypedEvents } from './typed-events.js';
5
+ import { __require as requireBase64id } from '../../base64id/lib/base64id.js';
6
+ import { __require as requireBroadcastOperator } from './broadcast-operator.js';
7
+ import { __require as requireSocketTypes } from './socket-types.js';
8
+
9
+ var hasRequiredSocket;
10
+
11
+ function requireSocket () {
12
+ if (hasRequiredSocket) return socket;
13
+ hasRequiredSocket = 1;
14
+ var __importDefault = (socket && socket.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(socket, "__esModule", { value: true });
18
+ socket.Socket = void 0;
19
+ const socket_io_parser_1 = requireCjs();
20
+ const debug_1 = __importDefault(requireSrc());
21
+ const typed_events_1 = requireTypedEvents();
22
+ const base64id_1 = __importDefault(requireBase64id());
23
+ const broadcast_operator_1 = requireBroadcastOperator();
24
+ const socket_types_1 = requireSocketTypes();
25
+ const debug = (0, debug_1.default)("socket.io:socket");
26
+ const RECOVERABLE_DISCONNECT_REASONS = new Set([
27
+ "transport error",
28
+ "transport close",
29
+ "forced close",
30
+ "ping timeout",
31
+ "server shutting down",
32
+ "forced server close",
33
+ ]);
34
+ function noop() { }
35
+ /**
36
+ * This is the main object for interacting with a client.
37
+ *
38
+ * A Socket belongs to a given {@link Namespace} and uses an underlying {@link Client} to communicate.
39
+ *
40
+ * Within each {@link Namespace}, you can also define arbitrary channels (called "rooms") that the {@link Socket} can
41
+ * join and leave. That provides a convenient way to broadcast to a group of socket instances.
42
+ *
43
+ * @example
44
+ * io.on("connection", (socket) => {
45
+ * console.log(`socket ${socket.id} connected`);
46
+ *
47
+ * // send an event to the client
48
+ * socket.emit("foo", "bar");
49
+ *
50
+ * socket.on("foobar", () => {
51
+ * // an event was received from the client
52
+ * });
53
+ *
54
+ * // join the room named "room1"
55
+ * socket.join("room1");
56
+ *
57
+ * // broadcast to everyone in the room named "room1"
58
+ * io.to("room1").emit("hello");
59
+ *
60
+ * // upon disconnection
61
+ * socket.on("disconnect", (reason) => {
62
+ * console.log(`socket ${socket.id} disconnected due to ${reason}`);
63
+ * });
64
+ * });
65
+ */
66
+ class Socket extends typed_events_1.StrictEventEmitter {
67
+ /**
68
+ * Interface to a `Client` for a given `Namespace`.
69
+ *
70
+ * @param {Namespace} nsp
71
+ * @param {Client} client
72
+ * @param {Object} auth
73
+ * @package
74
+ */
75
+ constructor(nsp, client, auth, previousSession) {
76
+ super();
77
+ this.nsp = nsp;
78
+ this.client = client;
79
+ /**
80
+ * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
81
+ * be transmitted to the client, the data attribute and the rooms will be restored.
82
+ */
83
+ this.recovered = false;
84
+ /**
85
+ * Additional information that can be attached to the Socket instance and which will be used in the
86
+ * {@link Server.fetchSockets()} method.
87
+ */
88
+ this.data = {};
89
+ /**
90
+ * Whether the socket is currently connected or not.
91
+ *
92
+ * @example
93
+ * io.use((socket, next) => {
94
+ * console.log(socket.connected); // false
95
+ * next();
96
+ * });
97
+ *
98
+ * io.on("connection", (socket) => {
99
+ * console.log(socket.connected); // true
100
+ * });
101
+ */
102
+ this.connected = false;
103
+ this.acks = new Map();
104
+ this.fns = [];
105
+ this.flags = {};
106
+ this.server = nsp.server;
107
+ this.adapter = this.nsp.adapter;
108
+ if (previousSession) {
109
+ this.id = previousSession.sid;
110
+ this.pid = previousSession.pid;
111
+ previousSession.rooms.forEach((room) => this.join(room));
112
+ this.data = previousSession.data;
113
+ previousSession.missedPackets.forEach((packet) => {
114
+ this.packet({
115
+ type: socket_io_parser_1.PacketType.EVENT,
116
+ data: packet,
117
+ });
118
+ });
119
+ this.recovered = true;
120
+ }
121
+ else {
122
+ if (client.conn.protocol === 3) {
123
+ // @ts-ignore
124
+ this.id = nsp.name !== "/" ? nsp.name + "#" + client.id : client.id;
125
+ }
126
+ else {
127
+ this.id = base64id_1.default.generateId(); // don't reuse the Engine.IO id because it's sensitive information
128
+ }
129
+ if (this.server._opts.connectionStateRecovery) {
130
+ this.pid = base64id_1.default.generateId();
131
+ }
132
+ }
133
+ this.handshake = this.buildHandshake(auth);
134
+ // prevents crash when the socket receives an "error" event without listener
135
+ this.on("error", noop);
136
+ }
137
+ /**
138
+ * Builds the `handshake` BC object
139
+ *
140
+ * @private
141
+ */
142
+ buildHandshake(auth) {
143
+ var _a, _b, _c, _d;
144
+ return {
145
+ headers: ((_a = this.request) === null || _a === void 0 ? void 0 : _a.headers) || {},
146
+ time: new Date() + "",
147
+ address: this.conn.remoteAddress,
148
+ xdomain: !!((_b = this.request) === null || _b === void 0 ? void 0 : _b.headers.origin),
149
+ // @ts-ignore
150
+ secure: !this.request || !!this.request.connection.encrypted,
151
+ issued: +new Date(),
152
+ url: (_c = this.request) === null || _c === void 0 ? void 0 : _c.url,
153
+ // @ts-ignore
154
+ query: ((_d = this.request) === null || _d === void 0 ? void 0 : _d._query) || {},
155
+ auth,
156
+ };
157
+ }
158
+ /**
159
+ * Emits to this client.
160
+ *
161
+ * @example
162
+ * io.on("connection", (socket) => {
163
+ * socket.emit("hello", "world");
164
+ *
165
+ * // all serializable datastructures are supported (no need to call JSON.stringify)
166
+ * socket.emit("hello", 1, "2", { 3: ["4"], 5: Buffer.from([6]) });
167
+ *
168
+ * // with an acknowledgement from the client
169
+ * socket.emit("hello", "world", (val) => {
170
+ * // ...
171
+ * });
172
+ * });
173
+ *
174
+ * @return Always returns `true`.
175
+ */
176
+ emit(ev, ...args) {
177
+ if (socket_types_1.RESERVED_EVENTS.has(ev)) {
178
+ throw new Error(`"${String(ev)}" is a reserved event name`);
179
+ }
180
+ const data = [ev, ...args];
181
+ const packet = {
182
+ type: socket_io_parser_1.PacketType.EVENT,
183
+ data: data,
184
+ };
185
+ // access last argument to see if it's an ACK callback
186
+ if (typeof data[data.length - 1] === "function") {
187
+ const id = this.nsp._ids++;
188
+ debug("emitting packet with ack id %d", id);
189
+ this.registerAckCallback(id, data.pop());
190
+ packet.id = id;
191
+ }
192
+ const flags = Object.assign({}, this.flags);
193
+ this.flags = {};
194
+ // @ts-ignore
195
+ if (this.nsp.server.opts.connectionStateRecovery) {
196
+ // this ensures the packet is stored and can be transmitted upon reconnection
197
+ this.adapter.broadcast(packet, {
198
+ rooms: new Set([this.id]),
199
+ except: new Set(),
200
+ flags,
201
+ });
202
+ }
203
+ else {
204
+ this.notifyOutgoingListeners(packet);
205
+ this.packet(packet, flags);
206
+ }
207
+ return true;
208
+ }
209
+ /**
210
+ * Emits an event and waits for an acknowledgement
211
+ *
212
+ * @example
213
+ * io.on("connection", async (socket) => {
214
+ * // without timeout
215
+ * const response = await socket.emitWithAck("hello", "world");
216
+ *
217
+ * // with a specific timeout
218
+ * try {
219
+ * const response = await socket.timeout(1000).emitWithAck("hello", "world");
220
+ * } catch (err) {
221
+ * // the client did not acknowledge the event in the given delay
222
+ * }
223
+ * });
224
+ *
225
+ * @return a Promise that will be fulfilled when the client acknowledges the event
226
+ */
227
+ emitWithAck(ev, ...args) {
228
+ // the timeout flag is optional
229
+ const withErr = this.flags.timeout !== undefined;
230
+ return new Promise((resolve, reject) => {
231
+ args.push((arg1, arg2) => {
232
+ if (withErr) {
233
+ return arg1 ? reject(arg1) : resolve(arg2);
234
+ }
235
+ else {
236
+ return resolve(arg1);
237
+ }
238
+ });
239
+ this.emit(ev, ...args);
240
+ });
241
+ }
242
+ /**
243
+ * @private
244
+ */
245
+ registerAckCallback(id, ack) {
246
+ const timeout = this.flags.timeout;
247
+ if (timeout === undefined) {
248
+ this.acks.set(id, ack);
249
+ return;
250
+ }
251
+ const timer = setTimeout(() => {
252
+ debug("event with ack id %d has timed out after %d ms", id, timeout);
253
+ this.acks.delete(id);
254
+ ack.call(this, new Error("operation has timed out"));
255
+ }, timeout);
256
+ this.acks.set(id, (...args) => {
257
+ clearTimeout(timer);
258
+ ack.apply(this, [null, ...args]);
259
+ });
260
+ }
261
+ /**
262
+ * Targets a room when broadcasting.
263
+ *
264
+ * @example
265
+ * io.on("connection", (socket) => {
266
+ * // the “foo” event will be broadcast to all connected clients in the “room-101” room, except this socket
267
+ * socket.to("room-101").emit("foo", "bar");
268
+ *
269
+ * // the code above is equivalent to:
270
+ * io.to("room-101").except(socket.id).emit("foo", "bar");
271
+ *
272
+ * // with an array of rooms (a client will be notified at most once)
273
+ * socket.to(["room-101", "room-102"]).emit("foo", "bar");
274
+ *
275
+ * // with multiple chained calls
276
+ * socket.to("room-101").to("room-102").emit("foo", "bar");
277
+ * });
278
+ *
279
+ * @param room - a room, or an array of rooms
280
+ * @return a new {@link BroadcastOperator} instance for chaining
281
+ */
282
+ to(room) {
283
+ return this.newBroadcastOperator().to(room);
284
+ }
285
+ /**
286
+ * Targets a room when broadcasting. Similar to `to()`, but might feel clearer in some cases:
287
+ *
288
+ * @example
289
+ * io.on("connection", (socket) => {
290
+ * // disconnect all clients in the "room-101" room, except this socket
291
+ * socket.in("room-101").disconnectSockets();
292
+ * });
293
+ *
294
+ * @param room - a room, or an array of rooms
295
+ * @return a new {@link BroadcastOperator} instance for chaining
296
+ */
297
+ in(room) {
298
+ return this.newBroadcastOperator().in(room);
299
+ }
300
+ /**
301
+ * Excludes a room when broadcasting.
302
+ *
303
+ * @example
304
+ * io.on("connection", (socket) => {
305
+ * // the "foo" event will be broadcast to all connected clients, except the ones that are in the "room-101" room
306
+ * // and this socket
307
+ * socket.except("room-101").emit("foo", "bar");
308
+ *
309
+ * // with an array of rooms
310
+ * socket.except(["room-101", "room-102"]).emit("foo", "bar");
311
+ *
312
+ * // with multiple chained calls
313
+ * socket.except("room-101").except("room-102").emit("foo", "bar");
314
+ * });
315
+ *
316
+ * @param room - a room, or an array of rooms
317
+ * @return a new {@link BroadcastOperator} instance for chaining
318
+ */
319
+ except(room) {
320
+ return this.newBroadcastOperator().except(room);
321
+ }
322
+ /**
323
+ * Sends a `message` event.
324
+ *
325
+ * This method mimics the WebSocket.send() method.
326
+ *
327
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
328
+ *
329
+ * @example
330
+ * io.on("connection", (socket) => {
331
+ * socket.send("hello");
332
+ *
333
+ * // this is equivalent to
334
+ * socket.emit("message", "hello");
335
+ * });
336
+ *
337
+ * @return self
338
+ */
339
+ send(...args) {
340
+ this.emit("message", ...args);
341
+ return this;
342
+ }
343
+ /**
344
+ * Sends a `message` event. Alias of {@link send}.
345
+ *
346
+ * @return self
347
+ */
348
+ write(...args) {
349
+ this.emit("message", ...args);
350
+ return this;
351
+ }
352
+ /**
353
+ * Writes a packet.
354
+ *
355
+ * @param {Object} packet - packet object
356
+ * @param {Object} opts - options
357
+ * @private
358
+ */
359
+ packet(packet, opts = {}) {
360
+ packet.nsp = this.nsp.name;
361
+ opts.compress = false !== opts.compress;
362
+ this.client._packet(packet, opts);
363
+ }
364
+ /**
365
+ * Joins a room.
366
+ *
367
+ * @example
368
+ * io.on("connection", (socket) => {
369
+ * // join a single room
370
+ * socket.join("room1");
371
+ *
372
+ * // join multiple rooms
373
+ * socket.join(["room1", "room2"]);
374
+ * });
375
+ *
376
+ * @param {String|Array} rooms - room or array of rooms
377
+ * @return a Promise or nothing, depending on the adapter
378
+ */
379
+ join(rooms) {
380
+ debug("join room %s", rooms);
381
+ return this.adapter.addAll(this.id, new Set(Array.isArray(rooms) ? rooms : [rooms]));
382
+ }
383
+ /**
384
+ * Leaves a room.
385
+ *
386
+ * @example
387
+ * io.on("connection", (socket) => {
388
+ * // leave a single room
389
+ * socket.leave("room1");
390
+ *
391
+ * // leave multiple rooms
392
+ * socket.leave("room1").leave("room2");
393
+ * });
394
+ *
395
+ * @param {String} room
396
+ * @return a Promise or nothing, depending on the adapter
397
+ */
398
+ leave(room) {
399
+ debug("leave room %s", room);
400
+ return this.adapter.del(this.id, room);
401
+ }
402
+ /**
403
+ * Leave all rooms.
404
+ *
405
+ * @private
406
+ */
407
+ leaveAll() {
408
+ this.adapter.delAll(this.id);
409
+ }
410
+ /**
411
+ * Called by `Namespace` upon successful
412
+ * middleware execution (ie: authorization).
413
+ * Socket is added to namespace array before
414
+ * call to join, so adapters can access it.
415
+ *
416
+ * @private
417
+ */
418
+ _onconnect() {
419
+ debug("socket connected - writing packet");
420
+ this.connected = true;
421
+ this.join(this.id);
422
+ if (this.conn.protocol === 3) {
423
+ this.packet({ type: socket_io_parser_1.PacketType.CONNECT });
424
+ }
425
+ else {
426
+ this.packet({
427
+ type: socket_io_parser_1.PacketType.CONNECT,
428
+ data: { sid: this.id, pid: this.pid },
429
+ });
430
+ }
431
+ }
432
+ /**
433
+ * Called with each packet. Called by `Client`.
434
+ *
435
+ * @param {Object} packet
436
+ * @private
437
+ */
438
+ _onpacket(packet) {
439
+ debug("got packet %j", packet);
440
+ switch (packet.type) {
441
+ case socket_io_parser_1.PacketType.EVENT:
442
+ this.onevent(packet);
443
+ break;
444
+ case socket_io_parser_1.PacketType.BINARY_EVENT:
445
+ this.onevent(packet);
446
+ break;
447
+ case socket_io_parser_1.PacketType.ACK:
448
+ this.onack(packet);
449
+ break;
450
+ case socket_io_parser_1.PacketType.BINARY_ACK:
451
+ this.onack(packet);
452
+ break;
453
+ case socket_io_parser_1.PacketType.DISCONNECT:
454
+ this.ondisconnect();
455
+ break;
456
+ }
457
+ }
458
+ /**
459
+ * Called upon event packet.
460
+ *
461
+ * @param {Packet} packet - packet object
462
+ * @private
463
+ */
464
+ onevent(packet) {
465
+ const args = packet.data || [];
466
+ debug("emitting event %j", args);
467
+ if (null != packet.id) {
468
+ debug("attaching ack callback to event");
469
+ args.push(this.ack(packet.id));
470
+ }
471
+ if (this._anyListeners && this._anyListeners.length) {
472
+ const listeners = this._anyListeners.slice();
473
+ for (const listener of listeners) {
474
+ listener.apply(this, args);
475
+ }
476
+ }
477
+ this.dispatch(args);
478
+ }
479
+ /**
480
+ * Produces an ack callback to emit with an event.
481
+ *
482
+ * @param {Number} id - packet id
483
+ * @private
484
+ */
485
+ ack(id) {
486
+ const self = this;
487
+ let sent = false;
488
+ return function () {
489
+ // prevent double callbacks
490
+ if (sent)
491
+ return;
492
+ const args = Array.prototype.slice.call(arguments);
493
+ debug("sending ack %j", args);
494
+ self.packet({
495
+ id: id,
496
+ type: socket_io_parser_1.PacketType.ACK,
497
+ data: args,
498
+ });
499
+ sent = true;
500
+ };
501
+ }
502
+ /**
503
+ * Called upon ack packet.
504
+ *
505
+ * @private
506
+ */
507
+ onack(packet) {
508
+ const ack = this.acks.get(packet.id);
509
+ if ("function" == typeof ack) {
510
+ debug("calling ack %s with %j", packet.id, packet.data);
511
+ ack.apply(this, packet.data);
512
+ this.acks.delete(packet.id);
513
+ }
514
+ else {
515
+ debug("bad ack %s", packet.id);
516
+ }
517
+ }
518
+ /**
519
+ * Called upon client disconnect packet.
520
+ *
521
+ * @private
522
+ */
523
+ ondisconnect() {
524
+ debug("got disconnect packet");
525
+ this._onclose("client namespace disconnect");
526
+ }
527
+ /**
528
+ * Handles a client error.
529
+ *
530
+ * @private
531
+ */
532
+ _onerror(err) {
533
+ // FIXME the meaning of the "error" event is overloaded:
534
+ // - it can be sent by the client (`socket.emit("error")`)
535
+ // - it can be emitted when the connection encounters an error (an invalid packet for example)
536
+ // - it can be emitted when a packet is rejected in a middleware (`socket.use()`)
537
+ this.emitReserved("error", err);
538
+ }
539
+ /**
540
+ * Called upon closing. Called by `Client`.
541
+ *
542
+ * @param {String} reason
543
+ * @param description
544
+ * @throw {Error} optional error object
545
+ *
546
+ * @private
547
+ */
548
+ _onclose(reason, description) {
549
+ if (!this.connected)
550
+ return this;
551
+ debug("closing socket - reason %s", reason);
552
+ this.emitReserved("disconnecting", reason, description);
553
+ if (this.server._opts.connectionStateRecovery &&
554
+ RECOVERABLE_DISCONNECT_REASONS.has(reason)) {
555
+ debug("connection state recovery is enabled for sid %s", this.id);
556
+ this.adapter.persistSession({
557
+ sid: this.id,
558
+ pid: this.pid,
559
+ rooms: [...this.rooms],
560
+ data: this.data,
561
+ });
562
+ }
563
+ this._cleanup();
564
+ this.client._remove(this);
565
+ this.connected = false;
566
+ this.emitReserved("disconnect", reason, description);
567
+ return;
568
+ }
569
+ /**
570
+ * Makes the socket leave all the rooms it was part of and prevents it from joining any other room
571
+ *
572
+ * @private
573
+ */
574
+ _cleanup() {
575
+ this.leaveAll();
576
+ this.nsp._remove(this);
577
+ this.join = noop;
578
+ }
579
+ /**
580
+ * Produces an `error` packet.
581
+ *
582
+ * @param {Object} err - error object
583
+ *
584
+ * @private
585
+ */
586
+ _error(err) {
587
+ this.packet({ type: socket_io_parser_1.PacketType.CONNECT_ERROR, data: err });
588
+ }
589
+ /**
590
+ * Disconnects this client.
591
+ *
592
+ * @example
593
+ * io.on("connection", (socket) => {
594
+ * // disconnect this socket (the connection might be kept alive for other namespaces)
595
+ * socket.disconnect();
596
+ *
597
+ * // disconnect this socket and close the underlying connection
598
+ * socket.disconnect(true);
599
+ * })
600
+ *
601
+ * @param {Boolean} close - if `true`, closes the underlying connection
602
+ * @return self
603
+ */
604
+ disconnect(close = false) {
605
+ if (!this.connected)
606
+ return this;
607
+ if (close) {
608
+ this.client._disconnect();
609
+ }
610
+ else {
611
+ this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
612
+ this._onclose("server namespace disconnect");
613
+ }
614
+ return this;
615
+ }
616
+ /**
617
+ * Sets the compress flag.
618
+ *
619
+ * @example
620
+ * io.on("connection", (socket) => {
621
+ * socket.compress(false).emit("hello");
622
+ * });
623
+ *
624
+ * @param {Boolean} compress - if `true`, compresses the sending data
625
+ * @return {Socket} self
626
+ */
627
+ compress(compress) {
628
+ this.flags.compress = compress;
629
+ return this;
630
+ }
631
+ /**
632
+ * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
633
+ * receive messages (because of network slowness or other issues, or because they’re connected through long polling
634
+ * and is in the middle of a request-response cycle).
635
+ *
636
+ * @example
637
+ * io.on("connection", (socket) => {
638
+ * socket.volatile.emit("hello"); // the client may or may not receive it
639
+ * });
640
+ *
641
+ * @return {Socket} self
642
+ */
643
+ get volatile() {
644
+ this.flags.volatile = true;
645
+ return this;
646
+ }
647
+ /**
648
+ * Sets a modifier for a subsequent event emission that the event data will only be broadcast to every sockets but the
649
+ * sender.
650
+ *
651
+ * @example
652
+ * io.on("connection", (socket) => {
653
+ * // the “foo” event will be broadcast to all connected clients, except this socket
654
+ * socket.broadcast.emit("foo", "bar");
655
+ * });
656
+ *
657
+ * @return a new {@link BroadcastOperator} instance for chaining
658
+ */
659
+ get broadcast() {
660
+ return this.newBroadcastOperator();
661
+ }
662
+ /**
663
+ * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
664
+ *
665
+ * @example
666
+ * io.on("connection", (socket) => {
667
+ * // the “foo” event will be broadcast to all connected clients on this node, except this socket
668
+ * socket.local.emit("foo", "bar");
669
+ * });
670
+ *
671
+ * @return a new {@link BroadcastOperator} instance for chaining
672
+ */
673
+ get local() {
674
+ return this.newBroadcastOperator().local;
675
+ }
676
+ /**
677
+ * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
678
+ * given number of milliseconds have elapsed without an acknowledgement from the client:
679
+ *
680
+ * @example
681
+ * io.on("connection", (socket) => {
682
+ * socket.timeout(5000).emit("my-event", (err) => {
683
+ * if (err) {
684
+ * // the client did not acknowledge the event in the given delay
685
+ * }
686
+ * });
687
+ * });
688
+ *
689
+ * @returns self
690
+ */
691
+ timeout(timeout) {
692
+ this.flags.timeout = timeout;
693
+ return this;
694
+ }
695
+ /**
696
+ * Dispatch incoming event to socket listeners.
697
+ *
698
+ * @param {Array} event - event that will get emitted
699
+ * @private
700
+ */
701
+ dispatch(event) {
702
+ debug("dispatching an event %j", event);
703
+ this.run(event, (err) => {
704
+ process.nextTick(() => {
705
+ if (err) {
706
+ return this._onerror(err);
707
+ }
708
+ if (this.connected) {
709
+ super.emitUntyped.apply(this, event);
710
+ }
711
+ else {
712
+ debug("ignore packet received after disconnection");
713
+ }
714
+ });
715
+ });
716
+ }
717
+ /**
718
+ * Sets up socket middleware.
719
+ *
720
+ * @example
721
+ * io.on("connection", (socket) => {
722
+ * socket.use(([event, ...args], next) => {
723
+ * if (isUnauthorized(event)) {
724
+ * return next(new Error("unauthorized event"));
725
+ * }
726
+ * // do not forget to call next
727
+ * next();
728
+ * });
729
+ *
730
+ * socket.on("error", (err) => {
731
+ * if (err && err.message === "unauthorized event") {
732
+ * socket.disconnect();
733
+ * }
734
+ * });
735
+ * });
736
+ *
737
+ * @param {Function} fn - middleware function (event, next)
738
+ * @return {Socket} self
739
+ */
740
+ use(fn) {
741
+ this.fns.push(fn);
742
+ return this;
743
+ }
744
+ /**
745
+ * Executes the middleware for an incoming event.
746
+ *
747
+ * @param {Array} event - event that will get emitted
748
+ * @param {Function} fn - last fn call in the middleware
749
+ * @private
750
+ */
751
+ run(event, fn) {
752
+ if (!this.fns.length)
753
+ return fn();
754
+ const fns = this.fns.slice(0);
755
+ function run(i) {
756
+ fns[i](event, (err) => {
757
+ // upon error, short-circuit
758
+ if (err)
759
+ return fn(err);
760
+ // if no middleware left, summon callback
761
+ if (!fns[i + 1])
762
+ return fn();
763
+ // go on to next
764
+ run(i + 1);
765
+ });
766
+ }
767
+ run(0);
768
+ }
769
+ /**
770
+ * Whether the socket is currently disconnected
771
+ */
772
+ get disconnected() {
773
+ return !this.connected;
774
+ }
775
+ /**
776
+ * A reference to the request that originated the underlying Engine.IO Socket.
777
+ */
778
+ get request() {
779
+ return this.client.request;
780
+ }
781
+ /**
782
+ * A reference to the underlying Client transport connection (Engine.IO Socket object).
783
+ *
784
+ * @example
785
+ * io.on("connection", (socket) => {
786
+ * console.log(socket.conn.transport.name); // prints "polling" or "websocket"
787
+ *
788
+ * socket.conn.once("upgrade", () => {
789
+ * console.log(socket.conn.transport.name); // prints "websocket"
790
+ * });
791
+ * });
792
+ */
793
+ get conn() {
794
+ return this.client.conn;
795
+ }
796
+ /**
797
+ * Returns the rooms the socket is currently in.
798
+ *
799
+ * @example
800
+ * io.on("connection", (socket) => {
801
+ * console.log(socket.rooms); // Set { <socket.id> }
802
+ *
803
+ * socket.join("room1");
804
+ *
805
+ * console.log(socket.rooms); // Set { <socket.id>, "room1" }
806
+ * });
807
+ */
808
+ get rooms() {
809
+ return this.adapter.socketRooms(this.id) || new Set();
810
+ }
811
+ /**
812
+ * Adds a listener that will be fired when any event is received. The event name is passed as the first argument to
813
+ * the callback.
814
+ *
815
+ * @example
816
+ * io.on("connection", (socket) => {
817
+ * socket.onAny((event, ...args) => {
818
+ * console.log(`got event ${event}`);
819
+ * });
820
+ * });
821
+ *
822
+ * @param listener
823
+ */
824
+ onAny(listener) {
825
+ this._anyListeners = this._anyListeners || [];
826
+ this._anyListeners.push(listener);
827
+ return this;
828
+ }
829
+ /**
830
+ * Adds a listener that will be fired when any event is received. The event name is passed as the first argument to
831
+ * the callback. The listener is added to the beginning of the listeners array.
832
+ *
833
+ * @param listener
834
+ */
835
+ prependAny(listener) {
836
+ this._anyListeners = this._anyListeners || [];
837
+ this._anyListeners.unshift(listener);
838
+ return this;
839
+ }
840
+ /**
841
+ * Removes the listener that will be fired when any event is received.
842
+ *
843
+ * @example
844
+ * io.on("connection", (socket) => {
845
+ * const catchAllListener = (event, ...args) => {
846
+ * console.log(`got event ${event}`);
847
+ * }
848
+ *
849
+ * socket.onAny(catchAllListener);
850
+ *
851
+ * // remove a specific listener
852
+ * socket.offAny(catchAllListener);
853
+ *
854
+ * // or remove all listeners
855
+ * socket.offAny();
856
+ * });
857
+ *
858
+ * @param listener
859
+ */
860
+ offAny(listener) {
861
+ if (!this._anyListeners) {
862
+ return this;
863
+ }
864
+ if (listener) {
865
+ const listeners = this._anyListeners;
866
+ for (let i = 0; i < listeners.length; i++) {
867
+ if (listener === listeners[i]) {
868
+ listeners.splice(i, 1);
869
+ return this;
870
+ }
871
+ }
872
+ }
873
+ else {
874
+ this._anyListeners = [];
875
+ }
876
+ return this;
877
+ }
878
+ /**
879
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
880
+ * e.g. to remove listeners.
881
+ */
882
+ listenersAny() {
883
+ return this._anyListeners || [];
884
+ }
885
+ /**
886
+ * Adds a listener that will be fired when any event is sent. The event name is passed as the first argument to
887
+ * the callback.
888
+ *
889
+ * Note: acknowledgements sent to the client are not included.
890
+ *
891
+ * @example
892
+ * io.on("connection", (socket) => {
893
+ * socket.onAnyOutgoing((event, ...args) => {
894
+ * console.log(`sent event ${event}`);
895
+ * });
896
+ * });
897
+ *
898
+ * @param listener
899
+ */
900
+ onAnyOutgoing(listener) {
901
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
902
+ this._anyOutgoingListeners.push(listener);
903
+ return this;
904
+ }
905
+ /**
906
+ * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
907
+ * callback. The listener is added to the beginning of the listeners array.
908
+ *
909
+ * @example
910
+ * io.on("connection", (socket) => {
911
+ * socket.prependAnyOutgoing((event, ...args) => {
912
+ * console.log(`sent event ${event}`);
913
+ * });
914
+ * });
915
+ *
916
+ * @param listener
917
+ */
918
+ prependAnyOutgoing(listener) {
919
+ this._anyOutgoingListeners = this._anyOutgoingListeners || [];
920
+ this._anyOutgoingListeners.unshift(listener);
921
+ return this;
922
+ }
923
+ /**
924
+ * Removes the listener that will be fired when any event is sent.
925
+ *
926
+ * @example
927
+ * io.on("connection", (socket) => {
928
+ * const catchAllListener = (event, ...args) => {
929
+ * console.log(`sent event ${event}`);
930
+ * }
931
+ *
932
+ * socket.onAnyOutgoing(catchAllListener);
933
+ *
934
+ * // remove a specific listener
935
+ * socket.offAnyOutgoing(catchAllListener);
936
+ *
937
+ * // or remove all listeners
938
+ * socket.offAnyOutgoing();
939
+ * });
940
+ *
941
+ * @param listener - the catch-all listener
942
+ */
943
+ offAnyOutgoing(listener) {
944
+ if (!this._anyOutgoingListeners) {
945
+ return this;
946
+ }
947
+ if (listener) {
948
+ const listeners = this._anyOutgoingListeners;
949
+ for (let i = 0; i < listeners.length; i++) {
950
+ if (listener === listeners[i]) {
951
+ listeners.splice(i, 1);
952
+ return this;
953
+ }
954
+ }
955
+ }
956
+ else {
957
+ this._anyOutgoingListeners = [];
958
+ }
959
+ return this;
960
+ }
961
+ /**
962
+ * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
963
+ * e.g. to remove listeners.
964
+ */
965
+ listenersAnyOutgoing() {
966
+ return this._anyOutgoingListeners || [];
967
+ }
968
+ /**
969
+ * Notify the listeners for each packet sent (emit or broadcast)
970
+ *
971
+ * @param packet
972
+ *
973
+ * @private
974
+ */
975
+ notifyOutgoingListeners(packet) {
976
+ if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
977
+ const listeners = this._anyOutgoingListeners.slice();
978
+ for (const listener of listeners) {
979
+ listener.apply(this, packet.data);
980
+ }
981
+ }
982
+ }
983
+ newBroadcastOperator() {
984
+ const flags = Object.assign({}, this.flags);
985
+ this.flags = {};
986
+ return new broadcast_operator_1.BroadcastOperator(this.adapter, new Set(), new Set([this.id]), flags);
987
+ }
988
+ }
989
+ socket.Socket = Socket;
990
+ return socket;
991
+ }
992
+
993
+ export { requireSocket as __require };