@wabot-dev/framework 0.0.14 → 0.0.17

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 (370) hide show
  1. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +108 -0
  2. package/dist/src/channels/cmd/@cmd.js +1 -1
  3. package/dist/src/channels/cmd/CmdChannel.js +1 -1
  4. package/dist/src/channels/socket-io/@socket.js +24 -0
  5. package/dist/src/channels/socket-io/SocketChannel.js +78 -0
  6. package/dist/src/channels/socket-io/SocketChannelConfig.js +15 -0
  7. package/dist/src/channels/telegram/@telegram.js +1 -1
  8. package/dist/src/channels/telegram/TelegramChannel.js +1 -1
  9. package/dist/src/channels/whatsapp/@whatsapp.js +1 -1
  10. package/dist/src/channels/whatsapp/WhatsAppChannel.js +1 -1
  11. package/dist/src/channels/whatsapp/WhatsAppConnection.js +1 -1
  12. package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +11 -3
  13. package/dist/src/channels/whatsapp/{whatsAppDevSocketContracts.js → WhatsAppDevSocketContracts.js} +1 -0
  14. package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +4 -1
  15. package/dist/src/channels/whatsapp/WhatsAppSender.js +23 -0
  16. package/dist/src/controller/socket.io/SocketIO.js +1 -1
  17. package/dist/src/index.d.ts +82 -9
  18. package/dist/src/index.js +9 -1
  19. package/dist/src/logger/Logger.js +1 -1
  20. package/dist/src/mindset/MindsetOperator.js +1 -1
  21. package/dist/src/server/runChannel.js +1 -1
  22. package/dist/src/server/runServer.js +4 -4
  23. package/package.json +2 -1
  24. package/dist/src/_virtual/XMLHttpRequest.js +0 -7
  25. package/dist/src/_virtual/_commonjsHelpers.js +0 -32
  26. package/dist/src/_virtual/base64id.js +0 -3
  27. package/dist/src/_virtual/binary.js +0 -3
  28. package/dist/src/_virtual/bom-handling.js +0 -3
  29. package/dist/src/_virtual/broadcast-operator.js +0 -3
  30. package/dist/src/_virtual/browser.js +0 -3
  31. package/dist/src/_virtual/browser2.js +0 -3
  32. package/dist/src/_virtual/browser3.js +0 -3
  33. package/dist/src/_virtual/browser4.js +0 -3
  34. package/dist/src/_virtual/browser5.js +0 -3
  35. package/dist/src/_virtual/buffer-util.js +0 -3
  36. package/dist/src/_virtual/buffer-util2.js +0 -3
  37. package/dist/src/_virtual/buffer-util3.js +0 -3
  38. package/dist/src/_virtual/charset.js +0 -3
  39. package/dist/src/_virtual/charset2.js +0 -3
  40. package/dist/src/_virtual/client.js +0 -3
  41. package/dist/src/_virtual/cluster-adapter.js +0 -3
  42. package/dist/src/_virtual/commons.js +0 -3
  43. package/dist/src/_virtual/dbcs-codec.js +0 -3
  44. package/dist/src/_virtual/decodePacket.js +0 -3
  45. package/dist/src/_virtual/encodePacket.js +0 -3
  46. package/dist/src/_virtual/encoding.js +0 -3
  47. package/dist/src/_virtual/encoding2.js +0 -3
  48. package/dist/src/_virtual/engine.io.js +0 -3
  49. package/dist/src/_virtual/in-memory-adapter.js +0 -3
  50. package/dist/src/_virtual/index.js +0 -7
  51. package/dist/src/_virtual/index10.js +0 -3
  52. package/dist/src/_virtual/index11.js +0 -3
  53. package/dist/src/_virtual/index12.js +0 -3
  54. package/dist/src/_virtual/index13.js +0 -3
  55. package/dist/src/_virtual/index14.js +0 -3
  56. package/dist/src/_virtual/index15.js +0 -3
  57. package/dist/src/_virtual/index16.js +0 -3
  58. package/dist/src/_virtual/index17.js +0 -3
  59. package/dist/src/_virtual/index18.js +0 -3
  60. package/dist/src/_virtual/index19.js +0 -3
  61. package/dist/src/_virtual/index2.js +0 -7
  62. package/dist/src/_virtual/index20.js +0 -3
  63. package/dist/src/_virtual/index21.js +0 -3
  64. package/dist/src/_virtual/index22.js +0 -3
  65. package/dist/src/_virtual/index23.js +0 -3
  66. package/dist/src/_virtual/index24.js +0 -3
  67. package/dist/src/_virtual/index25.js +0 -3
  68. package/dist/src/_virtual/index26.js +0 -3
  69. package/dist/src/_virtual/index27.js +0 -3
  70. package/dist/src/_virtual/index28.js +0 -3
  71. package/dist/src/_virtual/index29.js +0 -3
  72. package/dist/src/_virtual/index3.js +0 -7
  73. package/dist/src/_virtual/index30.js +0 -3
  74. package/dist/src/_virtual/index31.js +0 -3
  75. package/dist/src/_virtual/index32.js +0 -3
  76. package/dist/src/_virtual/index33.js +0 -3
  77. package/dist/src/_virtual/index4.js +0 -3
  78. package/dist/src/_virtual/index5.js +0 -3
  79. package/dist/src/_virtual/index6.js +0 -3
  80. package/dist/src/_virtual/index7.js +0 -3
  81. package/dist/src/_virtual/index8.js +0 -6
  82. package/dist/src/_virtual/index9.js +0 -3
  83. package/dist/src/_virtual/inherits.js +0 -3
  84. package/dist/src/_virtual/inherits_browser.js +0 -3
  85. package/dist/src/_virtual/is-binary.js +0 -3
  86. package/dist/src/_virtual/language.js +0 -3
  87. package/dist/src/_virtual/language2.js +0 -3
  88. package/dist/src/_virtual/mediaType.js +0 -3
  89. package/dist/src/_virtual/mediaType2.js +0 -3
  90. package/dist/src/_virtual/namespace.js +0 -3
  91. package/dist/src/_virtual/node.js +0 -3
  92. package/dist/src/_virtual/node2.js +0 -3
  93. package/dist/src/_virtual/node3.js +0 -3
  94. package/dist/src/_virtual/node4.js +0 -3
  95. package/dist/src/_virtual/node5.js +0 -3
  96. package/dist/src/_virtual/parent-namespace.js +0 -3
  97. package/dist/src/_virtual/polling-jsonp.js +0 -3
  98. package/dist/src/_virtual/polling.js +0 -3
  99. package/dist/src/_virtual/polling2.js +0 -3
  100. package/dist/src/_virtual/receiver.js +0 -3
  101. package/dist/src/_virtual/sbcs-codec.js +0 -3
  102. package/dist/src/_virtual/sender.js +0 -3
  103. package/dist/src/_virtual/server.js +0 -3
  104. package/dist/src/_virtual/socket-types.js +0 -3
  105. package/dist/src/_virtual/socket.js +0 -3
  106. package/dist/src/_virtual/socket2.js +0 -3
  107. package/dist/src/_virtual/stream.js +0 -3
  108. package/dist/src/_virtual/transport.js +0 -3
  109. package/dist/src/_virtual/typed-events.js +0 -3
  110. package/dist/src/_virtual/userver.js +0 -3
  111. package/dist/src/_virtual/utf16.js +0 -3
  112. package/dist/src/_virtual/utf32.js +0 -3
  113. package/dist/src/_virtual/utf7.js +0 -3
  114. package/dist/src/_virtual/uws.js +0 -3
  115. package/dist/src/_virtual/validation.js +0 -3
  116. package/dist/src/_virtual/validation2.js +0 -3
  117. package/dist/src/_virtual/validation3.js +0 -3
  118. package/dist/src/_virtual/websocket-server.js +0 -3
  119. package/dist/src/_virtual/websocket.js +0 -7
  120. package/dist/src/_virtual/websocket2.js +0 -3
  121. package/dist/src/_virtual/websocket3.js +0 -3
  122. package/dist/src/_virtual/webtransport.js +0 -3
  123. package/dist/src/_virtual/yeast.js +0 -3
  124. package/dist/src/node_modules/@socket.io/component-emitter/lib/esm/index.js +0 -171
  125. package/dist/src/node_modules/base64id/lib/base64id.js +0 -117
  126. package/dist/src/node_modules/body-parser/index.js +0 -96
  127. package/dist/src/node_modules/body-parser/lib/read.js +0 -225
  128. package/dist/src/node_modules/body-parser/lib/types/json.js +0 -222
  129. package/dist/src/node_modules/body-parser/lib/types/raw.js +0 -90
  130. package/dist/src/node_modules/body-parser/lib/types/text.js +0 -95
  131. package/dist/src/node_modules/body-parser/lib/types/urlencoded.js +0 -194
  132. package/dist/src/node_modules/body-parser/lib/utils.js +0 -96
  133. package/dist/src/node_modules/bytes/index.js +0 -180
  134. package/dist/src/node_modules/call-bind-apply-helpers/actualApply.js +0 -24
  135. package/dist/src/node_modules/call-bind-apply-helpers/functionApply.js +0 -13
  136. package/dist/src/node_modules/call-bind-apply-helpers/functionCall.js +0 -13
  137. package/dist/src/node_modules/call-bind-apply-helpers/index.js +0 -29
  138. package/dist/src/node_modules/call-bind-apply-helpers/reflectApply.js +0 -13
  139. package/dist/src/node_modules/call-bound/index.js +0 -31
  140. package/dist/src/node_modules/content-type/index.js +0 -235
  141. package/dist/src/node_modules/cookie/index.js +0 -345
  142. package/dist/src/node_modules/cors/lib/index.js +0 -249
  143. package/dist/src/node_modules/debug/src/browser.js +0 -286
  144. package/dist/src/node_modules/debug/src/common.js +0 -303
  145. package/dist/src/node_modules/debug/src/index.js +0 -23
  146. package/dist/src/node_modules/debug/src/node.js +0 -279
  147. package/dist/src/node_modules/depd/index.js +0 -550
  148. package/dist/src/node_modules/dunder-proto/get.js +0 -42
  149. package/dist/src/node_modules/ee-first/index.js +0 -104
  150. package/dist/src/node_modules/engine.io/build/engine.io.js +0 -73
  151. package/dist/src/node_modules/engine.io/build/parser-v3/index.js +0 -429
  152. package/dist/src/node_modules/engine.io/build/parser-v3/utf8.js +0 -198
  153. package/dist/src/node_modules/engine.io/build/server.js +0 -808
  154. package/dist/src/node_modules/engine.io/build/socket.js +0 -469
  155. package/dist/src/node_modules/engine.io/build/transport.js +0 -131
  156. package/dist/src/node_modules/engine.io/build/transports/index.js +0 -37
  157. package/dist/src/node_modules/engine.io/build/transports/polling-jsonp.js +0 -53
  158. package/dist/src/node_modules/engine.io/build/transports/polling.js +0 -346
  159. package/dist/src/node_modules/engine.io/build/transports/websocket.js +0 -106
  160. package/dist/src/node_modules/engine.io/build/transports/webtransport.js +0 -76
  161. package/dist/src/node_modules/engine.io/build/transports-uws/index.js +0 -20
  162. package/dist/src/node_modules/engine.io/build/transports-uws/polling.js +0 -378
  163. package/dist/src/node_modules/engine.io/build/transports-uws/websocket.js +0 -85
  164. package/dist/src/node_modules/engine.io/build/userver.js +0 -292
  165. package/dist/src/node_modules/engine.io/node_modules/accepts/index.js +0 -250
  166. package/dist/src/node_modules/engine.io/node_modules/debug/src/browser.js +0 -285
  167. package/dist/src/node_modules/engine.io/node_modules/debug/src/common.js +0 -285
  168. package/dist/src/node_modules/engine.io/node_modules/debug/src/index.js +0 -23
  169. package/dist/src/node_modules/engine.io/node_modules/debug/src/node.js +0 -279
  170. package/dist/src/node_modules/engine.io/node_modules/mime-db/db.json.js +0 -10704
  171. package/dist/src/node_modules/engine.io/node_modules/mime-db/index.js +0 -24
  172. package/dist/src/node_modules/engine.io/node_modules/mime-types/index.js +0 -202
  173. package/dist/src/node_modules/engine.io/node_modules/negotiator/index.js +0 -96
  174. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/charset.js +0 -179
  175. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/encoding.js +0 -193
  176. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/language.js +0 -188
  177. package/dist/src/node_modules/engine.io/node_modules/negotiator/lib/mediaType.js +0 -304
  178. package/dist/src/node_modules/engine.io/node_modules/ws/index.js +0 -28
  179. package/dist/src/node_modules/engine.io/node_modules/ws/lib/buffer-util.js +0 -142
  180. package/dist/src/node_modules/engine.io/node_modules/ws/lib/constants.js +0 -21
  181. package/dist/src/node_modules/engine.io/node_modules/ws/lib/event-target.js +0 -303
  182. package/dist/src/node_modules/engine.io/node_modules/ws/lib/extension.js +0 -214
  183. package/dist/src/node_modules/engine.io/node_modules/ws/lib/limiter.js +0 -64
  184. package/dist/src/node_modules/engine.io/node_modules/ws/lib/permessage-deflate.js +0 -528
  185. package/dist/src/node_modules/engine.io/node_modules/ws/lib/receiver.js +0 -719
  186. package/dist/src/node_modules/engine.io/node_modules/ws/lib/sender.js +0 -513
  187. package/dist/src/node_modules/engine.io/node_modules/ws/lib/stream.js +0 -170
  188. package/dist/src/node_modules/engine.io/node_modules/ws/lib/subprotocol.js +0 -73
  189. package/dist/src/node_modules/engine.io/node_modules/ws/lib/validation.js +0 -141
  190. package/dist/src/node_modules/engine.io/node_modules/ws/lib/websocket-server.js +0 -559
  191. package/dist/src/node_modules/engine.io/node_modules/ws/lib/websocket.js +0 -1363
  192. package/dist/src/node_modules/engine.io-client/build/esm/contrib/has-cors.js +0 -13
  193. package/dist/src/node_modules/engine.io-client/build/esm/contrib/parseqs.js +0 -36
  194. package/dist/src/node_modules/engine.io-client/build/esm/contrib/parseuri.js +0 -66
  195. package/dist/src/node_modules/engine.io-client/build/esm/globals.node.js +0 -92
  196. package/dist/src/node_modules/engine.io-client/build/esm/index.js +0 -17
  197. package/dist/src/node_modules/engine.io-client/build/esm/socket.js +0 -728
  198. package/dist/src/node_modules/engine.io-client/build/esm/transport.js +0 -143
  199. package/dist/src/node_modules/engine.io-client/build/esm/transports/index.js +0 -11
  200. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +0 -256
  201. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +0 -21
  202. package/dist/src/node_modules/engine.io-client/build/esm/transports/polling.js +0 -146
  203. package/dist/src/node_modules/engine.io-client/build/esm/transports/websocket.js +0 -107
  204. package/dist/src/node_modules/engine.io-client/build/esm/transports/websocket.node.js +0 -48
  205. package/dist/src/node_modules/engine.io-client/build/esm/transports/webtransport.js +0 -83
  206. package/dist/src/node_modules/engine.io-client/build/esm/util.js +0 -62
  207. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js +0 -142
  208. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/constants.js +0 -21
  209. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/event-target.js +0 -303
  210. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/extension.js +0 -214
  211. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/limiter.js +0 -64
  212. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js +0 -528
  213. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/receiver.js +0 -719
  214. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/sender.js +0 -513
  215. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/stream.js +0 -170
  216. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js +0 -73
  217. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/validation.js +0 -141
  218. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js +0 -559
  219. package/dist/src/node_modules/engine.io-client/node_modules/ws/lib/websocket.js +0 -1363
  220. package/dist/src/node_modules/engine.io-parser/build/cjs/commons.js +0 -29
  221. package/dist/src/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -70
  222. package/dist/src/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -51
  223. package/dist/src/node_modules/engine.io-parser/build/cjs/index.js +0 -179
  224. package/dist/src/node_modules/engine.io-parser/build/esm/commons.js +0 -15
  225. package/dist/src/node_modules/engine.io-parser/build/esm/decodePacket.js +0 -58
  226. package/dist/src/node_modules/engine.io-parser/build/esm/encodePacket.js +0 -36
  227. package/dist/src/node_modules/engine.io-parser/build/esm/index.js +0 -158
  228. package/dist/src/node_modules/es-define-property/index.js +0 -23
  229. package/dist/src/node_modules/es-errors/eval.js +0 -13
  230. package/dist/src/node_modules/es-errors/index.js +0 -13
  231. package/dist/src/node_modules/es-errors/range.js +0 -13
  232. package/dist/src/node_modules/es-errors/ref.js +0 -13
  233. package/dist/src/node_modules/es-errors/syntax.js +0 -13
  234. package/dist/src/node_modules/es-errors/type.js +0 -13
  235. package/dist/src/node_modules/es-errors/uri.js +0 -13
  236. package/dist/src/node_modules/es-object-atoms/index.js +0 -13
  237. package/dist/src/node_modules/function-bind/implementation.js +0 -93
  238. package/dist/src/node_modules/function-bind/index.js +0 -16
  239. package/dist/src/node_modules/get-intrinsic/index.js +0 -413
  240. package/dist/src/node_modules/get-proto/Object.getPrototypeOf.js +0 -17
  241. package/dist/src/node_modules/get-proto/Reflect.getPrototypeOf.js +0 -13
  242. package/dist/src/node_modules/get-proto/index.js +0 -40
  243. package/dist/src/node_modules/gopd/gOPD.js +0 -13
  244. package/dist/src/node_modules/gopd/index.js +0 -26
  245. package/dist/src/node_modules/has-symbols/index.js +0 -25
  246. package/dist/src/node_modules/has-symbols/shams.js +0 -54
  247. package/dist/src/node_modules/hasown/index.js +0 -19
  248. package/dist/src/node_modules/http-errors/index.js +0 -306
  249. package/dist/src/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -598
  250. package/dist/src/node_modules/iconv-lite/encodings/dbcs-data.js +0 -206
  251. package/dist/src/node_modules/iconv-lite/encodings/index.js +0 -44
  252. package/dist/src/node_modules/iconv-lite/encodings/internal.js +0 -210
  253. package/dist/src/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -83
  254. package/dist/src/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -460
  255. package/dist/src/node_modules/iconv-lite/encodings/sbcs-data.js +0 -187
  256. package/dist/src/node_modules/iconv-lite/encodings/tables/big5-added.json.js +0 -506
  257. package/dist/src/node_modules/iconv-lite/encodings/tables/cp936.json.js +0 -2621
  258. package/dist/src/node_modules/iconv-lite/encodings/tables/cp949.json.js +0 -2380
  259. package/dist/src/node_modules/iconv-lite/encodings/tables/cp950.json.js +0 -729
  260. package/dist/src/node_modules/iconv-lite/encodings/tables/eucjp.json.js +0 -822
  261. package/dist/src/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json.js +0 -424
  262. package/dist/src/node_modules/iconv-lite/encodings/tables/gbk-added.json.js +0 -264
  263. package/dist/src/node_modules/iconv-lite/encodings/tables/shiftjis.json.js +0 -548
  264. package/dist/src/node_modules/iconv-lite/encodings/utf16.js +0 -206
  265. package/dist/src/node_modules/iconv-lite/encodings/utf32.js +0 -329
  266. package/dist/src/node_modules/iconv-lite/encodings/utf7.js +0 -297
  267. package/dist/src/node_modules/iconv-lite/lib/bom-handling.js +0 -61
  268. package/dist/src/node_modules/iconv-lite/lib/index.js +0 -192
  269. package/dist/src/node_modules/iconv-lite/lib/streams.js +0 -120
  270. package/dist/src/node_modules/inherits/inherits.js +0 -21
  271. package/dist/src/node_modules/inherits/inherits_browser.js +0 -38
  272. package/dist/src/node_modules/math-intrinsics/abs.js +0 -13
  273. package/dist/src/node_modules/math-intrinsics/floor.js +0 -13
  274. package/dist/src/node_modules/math-intrinsics/isNaN.js +0 -15
  275. package/dist/src/node_modules/math-intrinsics/max.js +0 -13
  276. package/dist/src/node_modules/math-intrinsics/min.js +0 -13
  277. package/dist/src/node_modules/math-intrinsics/pow.js +0 -13
  278. package/dist/src/node_modules/math-intrinsics/round.js +0 -13
  279. package/dist/src/node_modules/math-intrinsics/sign.js +0 -22
  280. package/dist/src/node_modules/media-typer/index.js +0 -153
  281. package/dist/src/node_modules/mime-db/db.json.js +0 -11656
  282. package/dist/src/node_modules/mime-db/index.js +0 -24
  283. package/dist/src/node_modules/mime-types/index.js +0 -226
  284. package/dist/src/node_modules/mime-types/mimeScore.js +0 -62
  285. package/dist/src/node_modules/ms/index.js +0 -172
  286. package/dist/src/node_modules/object-assign/index.js +0 -99
  287. package/dist/src/node_modules/object-inspect/index.js +0 -557
  288. package/dist/src/node_modules/object-inspect/util.inspect.js +0 -13
  289. package/dist/src/node_modules/on-finished/index.js +0 -245
  290. package/dist/src/node_modules/qs/lib/formats.js +0 -32
  291. package/dist/src/node_modules/qs/lib/index.js +0 -24
  292. package/dist/src/node_modules/qs/lib/parse.js +0 -339
  293. package/dist/src/node_modules/qs/lib/stringify.js +0 -369
  294. package/dist/src/node_modules/qs/lib/utils.js +0 -279
  295. package/dist/src/node_modules/raw-body/index.js +0 -351
  296. package/dist/src/node_modules/safer-buffer/safer.js +0 -88
  297. package/dist/src/node_modules/setprototypeof/index.js +0 -26
  298. package/dist/src/node_modules/side-channel/index.js +0 -58
  299. package/dist/src/node_modules/side-channel-list/index.js +0 -125
  300. package/dist/src/node_modules/side-channel-map/index.js +0 -82
  301. package/dist/src/node_modules/side-channel-weakmap/index.js +0 -99
  302. package/dist/src/node_modules/socket.io/dist/broadcast-operator.js +0 -448
  303. package/dist/src/node_modules/socket.io/dist/client.js +0 -281
  304. package/dist/src/node_modules/socket.io/dist/index.js +0 -837
  305. package/dist/src/node_modules/socket.io/dist/namespace.js +0 -597
  306. package/dist/src/node_modules/socket.io/dist/parent-namespace.js +0 -101
  307. package/dist/src/node_modules/socket.io/dist/socket-types.js +0 -21
  308. package/dist/src/node_modules/socket.io/dist/socket.js +0 -993
  309. package/dist/src/node_modules/socket.io/dist/typed-events.js +0 -92
  310. package/dist/src/node_modules/socket.io/dist/uws.js +0 -149
  311. package/dist/src/node_modules/socket.io/node_modules/accepts/index.js +0 -250
  312. package/dist/src/node_modules/socket.io/node_modules/debug/src/browser.js +0 -285
  313. package/dist/src/node_modules/socket.io/node_modules/debug/src/common.js +0 -285
  314. package/dist/src/node_modules/socket.io/node_modules/debug/src/index.js +0 -23
  315. package/dist/src/node_modules/socket.io/node_modules/debug/src/node.js +0 -279
  316. package/dist/src/node_modules/socket.io/node_modules/mime-db/db.json.js +0 -10704
  317. package/dist/src/node_modules/socket.io/node_modules/mime-db/index.js +0 -24
  318. package/dist/src/node_modules/socket.io/node_modules/mime-types/index.js +0 -202
  319. package/dist/src/node_modules/socket.io/node_modules/negotiator/index.js +0 -96
  320. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/charset.js +0 -179
  321. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/encoding.js +0 -193
  322. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/language.js +0 -188
  323. package/dist/src/node_modules/socket.io/node_modules/negotiator/lib/mediaType.js +0 -304
  324. package/dist/src/node_modules/socket.io/package.json.js +0 -5
  325. package/dist/src/node_modules/socket.io/wrapper.js +0 -5
  326. package/dist/src/node_modules/socket.io-adapter/dist/cluster-adapter.js +0 -689
  327. package/dist/src/node_modules/socket.io-adapter/dist/contrib/yeast.js +0 -64
  328. package/dist/src/node_modules/socket.io-adapter/dist/in-memory-adapter.js +0 -407
  329. package/dist/src/node_modules/socket.io-adapter/dist/index.js +0 -24
  330. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/browser.js +0 -285
  331. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/common.js +0 -285
  332. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/index.js +0 -23
  333. package/dist/src/node_modules/socket.io-adapter/node_modules/debug/src/node.js +0 -279
  334. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/index.js +0 -28
  335. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/buffer-util.js +0 -142
  336. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/constants.js +0 -21
  337. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/event-target.js +0 -303
  338. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/extension.js +0 -214
  339. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/limiter.js +0 -64
  340. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/permessage-deflate.js +0 -528
  341. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/receiver.js +0 -719
  342. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/sender.js +0 -513
  343. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/stream.js +0 -170
  344. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/subprotocol.js +0 -73
  345. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/validation.js +0 -141
  346. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/websocket-server.js +0 -559
  347. package/dist/src/node_modules/socket.io-adapter/node_modules/ws/lib/websocket.js +0 -1363
  348. package/dist/src/node_modules/socket.io-client/build/esm/contrib/backo2.js +0 -68
  349. package/dist/src/node_modules/socket.io-client/build/esm/index.js +0 -50
  350. package/dist/src/node_modules/socket.io-client/build/esm/manager.js +0 -373
  351. package/dist/src/node_modules/socket.io-client/build/esm/on.js +0 -8
  352. package/dist/src/node_modules/socket.io-client/build/esm/socket.js +0 -884
  353. package/dist/src/node_modules/socket.io-client/build/esm/url.js +0 -63
  354. package/dist/src/node_modules/socket.io-parser/build/cjs/binary.js +0 -99
  355. package/dist/src/node_modules/socket.io-parser/build/cjs/index.js +0 -337
  356. package/dist/src/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -65
  357. package/dist/src/node_modules/socket.io-parser/build/esm/binary.js +0 -86
  358. package/dist/src/node_modules/socket.io-parser/build/esm/index.js +0 -314
  359. package/dist/src/node_modules/socket.io-parser/build/esm/is-binary.js +0 -52
  360. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/browser.js +0 -285
  361. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/common.js +0 -285
  362. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/index.js +0 -23
  363. package/dist/src/node_modules/socket.io-parser/node_modules/debug/src/node.js +0 -279
  364. package/dist/src/node_modules/statuses/codes.json.js +0 -67
  365. package/dist/src/node_modules/statuses/index.js +0 -157
  366. package/dist/src/node_modules/toidentifier/index.js +0 -41
  367. package/dist/src/node_modules/type-is/index.js +0 -263
  368. package/dist/src/node_modules/unpipe/index.js +0 -78
  369. package/dist/src/node_modules/vary/index.js +0 -159
  370. package/dist/src/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +0 -702
@@ -1,993 +0,0 @@
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 };