@pllla/openclaw-plugin 0.1.0

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 (283) hide show
  1. package/dist/accounts.js +66 -0
  2. package/dist/bridges.js +110 -0
  3. package/dist/index.js +215 -0
  4. package/dist/lane.js +158 -0
  5. package/dist/pairing.js +36 -0
  6. package/dist/stateStore.js +88 -0
  7. package/node_modules/@socket.io/component-emitter/LICENSE +24 -0
  8. package/node_modules/@socket.io/component-emitter/Readme.md +79 -0
  9. package/node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts +179 -0
  10. package/node_modules/@socket.io/component-emitter/lib/cjs/index.js +176 -0
  11. package/node_modules/@socket.io/component-emitter/lib/cjs/package.json +4 -0
  12. package/node_modules/@socket.io/component-emitter/lib/esm/index.d.ts +179 -0
  13. package/node_modules/@socket.io/component-emitter/lib/esm/index.js +169 -0
  14. package/node_modules/@socket.io/component-emitter/lib/esm/package.json +4 -0
  15. package/node_modules/@socket.io/component-emitter/package.json +28 -0
  16. package/node_modules/debug/LICENSE +20 -0
  17. package/node_modules/debug/README.md +481 -0
  18. package/node_modules/debug/package.json +64 -0
  19. package/node_modules/debug/src/browser.js +272 -0
  20. package/node_modules/debug/src/common.js +292 -0
  21. package/node_modules/debug/src/index.js +10 -0
  22. package/node_modules/debug/src/node.js +263 -0
  23. package/node_modules/engine.io-client/LICENSE +22 -0
  24. package/node_modules/engine.io-client/README.md +331 -0
  25. package/node_modules/engine.io-client/build/cjs/browser-entrypoint.d.ts +3 -0
  26. package/node_modules/engine.io-client/build/cjs/browser-entrypoint.js +4 -0
  27. package/node_modules/engine.io-client/build/cjs/contrib/has-cors.d.ts +1 -0
  28. package/node_modules/engine.io-client/build/cjs/contrib/has-cors.js +14 -0
  29. package/node_modules/engine.io-client/build/cjs/contrib/parseqs.d.ts +15 -0
  30. package/node_modules/engine.io-client/build/cjs/contrib/parseqs.js +38 -0
  31. package/node_modules/engine.io-client/build/cjs/contrib/parseuri.d.ts +1 -0
  32. package/node_modules/engine.io-client/build/cjs/contrib/parseuri.js +67 -0
  33. package/node_modules/engine.io-client/build/cjs/globals.d.ts +4 -0
  34. package/node_modules/engine.io-client/build/cjs/globals.js +26 -0
  35. package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +21 -0
  36. package/node_modules/engine.io-client/build/cjs/globals.node.js +97 -0
  37. package/node_modules/engine.io-client/build/cjs/index.d.ts +15 -0
  38. package/node_modules/engine.io-client/build/cjs/index.js +32 -0
  39. package/node_modules/engine.io-client/build/cjs/package.json +10 -0
  40. package/node_modules/engine.io-client/build/cjs/socket.d.ts +482 -0
  41. package/node_modules/engine.io-client/build/cjs/socket.js +766 -0
  42. package/node_modules/engine.io-client/build/cjs/transport.d.ts +106 -0
  43. package/node_modules/engine.io-client/build/cjs/transport.js +153 -0
  44. package/node_modules/engine.io-client/build/cjs/transports/index.d.ts +8 -0
  45. package/node_modules/engine.io-client/build/cjs/transports/index.js +11 -0
  46. package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts +15 -0
  47. package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.js +60 -0
  48. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +108 -0
  49. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +285 -0
  50. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts +11 -0
  51. package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +44 -0
  52. package/node_modules/engine.io-client/build/cjs/transports/polling.d.ts +52 -0
  53. package/node_modules/engine.io-client/build/cjs/transports/polling.js +165 -0
  54. package/node_modules/engine.io-client/build/cjs/transports/websocket.d.ts +36 -0
  55. package/node_modules/engine.io-client/build/cjs/transports/websocket.js +136 -0
  56. package/node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts +14 -0
  57. package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +68 -0
  58. package/node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts +18 -0
  59. package/node_modules/engine.io-client/build/cjs/transports/webtransport.js +94 -0
  60. package/node_modules/engine.io-client/build/cjs/util.d.ts +7 -0
  61. package/node_modules/engine.io-client/build/cjs/util.js +65 -0
  62. package/node_modules/engine.io-client/build/esm/browser-entrypoint.d.ts +3 -0
  63. package/node_modules/engine.io-client/build/esm/browser-entrypoint.js +2 -0
  64. package/node_modules/engine.io-client/build/esm/contrib/has-cors.d.ts +1 -0
  65. package/node_modules/engine.io-client/build/esm/contrib/has-cors.js +11 -0
  66. package/node_modules/engine.io-client/build/esm/contrib/parseqs.d.ts +15 -0
  67. package/node_modules/engine.io-client/build/esm/contrib/parseqs.js +34 -0
  68. package/node_modules/engine.io-client/build/esm/contrib/parseuri.d.ts +1 -0
  69. package/node_modules/engine.io-client/build/esm/contrib/parseuri.js +64 -0
  70. package/node_modules/engine.io-client/build/esm/globals.d.ts +4 -0
  71. package/node_modules/engine.io-client/build/esm/globals.js +22 -0
  72. package/node_modules/engine.io-client/build/esm/globals.node.d.ts +21 -0
  73. package/node_modules/engine.io-client/build/esm/globals.node.js +91 -0
  74. package/node_modules/engine.io-client/build/esm/index.d.ts +15 -0
  75. package/node_modules/engine.io-client/build/esm/index.js +15 -0
  76. package/node_modules/engine.io-client/build/esm/package.json +10 -0
  77. package/node_modules/engine.io-client/build/esm/socket.d.ts +482 -0
  78. package/node_modules/engine.io-client/build/esm/socket.js +728 -0
  79. package/node_modules/engine.io-client/build/esm/transport.d.ts +106 -0
  80. package/node_modules/engine.io-client/build/esm/transport.js +142 -0
  81. package/node_modules/engine.io-client/build/esm/transports/index.d.ts +8 -0
  82. package/node_modules/engine.io-client/build/esm/transports/index.js +8 -0
  83. package/node_modules/engine.io-client/build/esm/transports/polling-fetch.d.ts +15 -0
  84. package/node_modules/engine.io-client/build/esm/transports/polling-fetch.js +56 -0
  85. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +108 -0
  86. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +271 -0
  87. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.d.ts +11 -0
  88. package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +17 -0
  89. package/node_modules/engine.io-client/build/esm/transports/polling.d.ts +52 -0
  90. package/node_modules/engine.io-client/build/esm/transports/polling.js +145 -0
  91. package/node_modules/engine.io-client/build/esm/transports/websocket.d.ts +36 -0
  92. package/node_modules/engine.io-client/build/esm/transports/websocket.js +125 -0
  93. package/node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts +14 -0
  94. package/node_modules/engine.io-client/build/esm/transports/websocket.node.js +41 -0
  95. package/node_modules/engine.io-client/build/esm/transports/webtransport.d.ts +18 -0
  96. package/node_modules/engine.io-client/build/esm/transports/webtransport.js +80 -0
  97. package/node_modules/engine.io-client/build/esm/util.d.ts +7 -0
  98. package/node_modules/engine.io-client/build/esm/util.js +59 -0
  99. package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.d.ts +3 -0
  100. package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.js +2 -0
  101. package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.d.ts +1 -0
  102. package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js +11 -0
  103. package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.d.ts +15 -0
  104. package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js +34 -0
  105. package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.d.ts +1 -0
  106. package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js +64 -0
  107. package/node_modules/engine.io-client/build/esm-debug/globals.d.ts +4 -0
  108. package/node_modules/engine.io-client/build/esm-debug/globals.js +22 -0
  109. package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +21 -0
  110. package/node_modules/engine.io-client/build/esm-debug/globals.node.js +91 -0
  111. package/node_modules/engine.io-client/build/esm-debug/index.d.ts +15 -0
  112. package/node_modules/engine.io-client/build/esm-debug/index.js +15 -0
  113. package/node_modules/engine.io-client/build/esm-debug/package.json +10 -0
  114. package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +482 -0
  115. package/node_modules/engine.io-client/build/esm-debug/socket.js +757 -0
  116. package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +106 -0
  117. package/node_modules/engine.io-client/build/esm-debug/transport.js +145 -0
  118. package/node_modules/engine.io-client/build/esm-debug/transports/index.d.ts +8 -0
  119. package/node_modules/engine.io-client/build/esm-debug/transports/index.js +8 -0
  120. package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.d.ts +15 -0
  121. package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.js +56 -0
  122. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +108 -0
  123. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +276 -0
  124. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.d.ts +11 -0
  125. package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js +17 -0
  126. package/node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts +52 -0
  127. package/node_modules/engine.io-client/build/esm-debug/transports/polling.js +158 -0
  128. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts +36 -0
  129. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.js +128 -0
  130. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.d.ts +14 -0
  131. package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js +41 -0
  132. package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.d.ts +18 -0
  133. package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.js +87 -0
  134. package/node_modules/engine.io-client/build/esm-debug/util.d.ts +7 -0
  135. package/node_modules/engine.io-client/build/esm-debug/util.js +59 -0
  136. package/node_modules/engine.io-client/dist/engine.io.esm.min.js +7 -0
  137. package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +1 -0
  138. package/node_modules/engine.io-client/dist/engine.io.js +3094 -0
  139. package/node_modules/engine.io-client/dist/engine.io.js.map +1 -0
  140. package/node_modules/engine.io-client/dist/engine.io.min.js +7 -0
  141. package/node_modules/engine.io-client/dist/engine.io.min.js.map +1 -0
  142. package/node_modules/engine.io-client/package.json +95 -0
  143. package/node_modules/engine.io-parser/LICENSE +22 -0
  144. package/node_modules/engine.io-parser/Readme.md +158 -0
  145. package/node_modules/engine.io-parser/build/cjs/commons.d.ts +14 -0
  146. package/node_modules/engine.io-parser/build/cjs/commons.js +19 -0
  147. package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.d.ts +2 -0
  148. package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.js +48 -0
  149. package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.d.ts +2 -0
  150. package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.js +66 -0
  151. package/node_modules/engine.io-parser/build/cjs/decodePacket.d.ts +2 -0
  152. package/node_modules/engine.io-parser/build/cjs/decodePacket.js +59 -0
  153. package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.d.ts +4 -0
  154. package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.js +72 -0
  155. package/node_modules/engine.io-parser/build/cjs/encodePacket.d.ts +3 -0
  156. package/node_modules/engine.io-parser/build/cjs/encodePacket.js +38 -0
  157. package/node_modules/engine.io-parser/build/cjs/index.d.ts +9 -0
  158. package/node_modules/engine.io-parser/build/cjs/index.js +164 -0
  159. package/node_modules/engine.io-parser/build/cjs/package.json +8 -0
  160. package/node_modules/engine.io-parser/build/esm/commons.d.ts +14 -0
  161. package/node_modules/engine.io-parser/build/esm/commons.js +14 -0
  162. package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.d.ts +2 -0
  163. package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js +43 -0
  164. package/node_modules/engine.io-parser/build/esm/decodePacket.browser.d.ts +2 -0
  165. package/node_modules/engine.io-parser/build/esm/decodePacket.browser.js +62 -0
  166. package/node_modules/engine.io-parser/build/esm/decodePacket.d.ts +2 -0
  167. package/node_modules/engine.io-parser/build/esm/decodePacket.js +55 -0
  168. package/node_modules/engine.io-parser/build/esm/encodePacket.browser.d.ts +4 -0
  169. package/node_modules/engine.io-parser/build/esm/encodePacket.browser.js +68 -0
  170. package/node_modules/engine.io-parser/build/esm/encodePacket.d.ts +3 -0
  171. package/node_modules/engine.io-parser/build/esm/encodePacket.js +33 -0
  172. package/node_modules/engine.io-parser/build/esm/index.d.ts +9 -0
  173. package/node_modules/engine.io-parser/build/esm/index.js +156 -0
  174. package/node_modules/engine.io-parser/build/esm/package.json +8 -0
  175. package/node_modules/engine.io-parser/package.json +46 -0
  176. package/node_modules/ms/index.js +162 -0
  177. package/node_modules/ms/license.md +21 -0
  178. package/node_modules/ms/package.json +38 -0
  179. package/node_modules/ms/readme.md +59 -0
  180. package/node_modules/socket.io-client/LICENSE +21 -0
  181. package/node_modules/socket.io-client/README.md +29 -0
  182. package/node_modules/socket.io-client/build/cjs/browser-entrypoint.d.ts +2 -0
  183. package/node_modules/socket.io-client/build/cjs/browser-entrypoint.js +4 -0
  184. package/node_modules/socket.io-client/build/cjs/contrib/backo2.d.ts +12 -0
  185. package/node_modules/socket.io-client/build/cjs/contrib/backo2.js +69 -0
  186. package/node_modules/socket.io-client/build/cjs/index.d.ts +29 -0
  187. package/node_modules/socket.io-client/build/cjs/index.js +76 -0
  188. package/node_modules/socket.io-client/build/cjs/manager.d.ts +295 -0
  189. package/node_modules/socket.io-client/build/cjs/manager.js +416 -0
  190. package/node_modules/socket.io-client/build/cjs/on.d.ts +2 -0
  191. package/node_modules/socket.io-client/build/cjs/on.js +9 -0
  192. package/node_modules/socket.io-client/build/cjs/socket.d.ts +593 -0
  193. package/node_modules/socket.io-client/build/cjs/socket.js +909 -0
  194. package/node_modules/socket.io-client/build/cjs/url.d.ts +33 -0
  195. package/node_modules/socket.io-client/build/cjs/url.js +69 -0
  196. package/node_modules/socket.io-client/build/esm/browser-entrypoint.d.ts +2 -0
  197. package/node_modules/socket.io-client/build/esm/browser-entrypoint.js +2 -0
  198. package/node_modules/socket.io-client/build/esm/contrib/backo2.d.ts +12 -0
  199. package/node_modules/socket.io-client/build/esm/contrib/backo2.js +66 -0
  200. package/node_modules/socket.io-client/build/esm/index.d.ts +29 -0
  201. package/node_modules/socket.io-client/build/esm/index.js +58 -0
  202. package/node_modules/socket.io-client/build/esm/manager.d.ts +295 -0
  203. package/node_modules/socket.io-client/build/esm/manager.js +367 -0
  204. package/node_modules/socket.io-client/build/esm/on.d.ts +2 -0
  205. package/node_modules/socket.io-client/build/esm/on.js +6 -0
  206. package/node_modules/socket.io-client/build/esm/package.json +5 -0
  207. package/node_modules/socket.io-client/build/esm/socket.d.ts +593 -0
  208. package/node_modules/socket.io-client/build/esm/socket.js +880 -0
  209. package/node_modules/socket.io-client/build/esm/url.d.ts +33 -0
  210. package/node_modules/socket.io-client/build/esm/url.js +59 -0
  211. package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.d.ts +2 -0
  212. package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.js +2 -0
  213. package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.d.ts +12 -0
  214. package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.js +66 -0
  215. package/node_modules/socket.io-client/build/esm-debug/index.d.ts +29 -0
  216. package/node_modules/socket.io-client/build/esm-debug/index.js +62 -0
  217. package/node_modules/socket.io-client/build/esm-debug/manager.d.ts +295 -0
  218. package/node_modules/socket.io-client/build/esm-debug/manager.js +386 -0
  219. package/node_modules/socket.io-client/build/esm-debug/on.d.ts +2 -0
  220. package/node_modules/socket.io-client/build/esm-debug/on.js +6 -0
  221. package/node_modules/socket.io-client/build/esm-debug/package.json +5 -0
  222. package/node_modules/socket.io-client/build/esm-debug/socket.d.ts +593 -0
  223. package/node_modules/socket.io-client/build/esm-debug/socket.js +902 -0
  224. package/node_modules/socket.io-client/build/esm-debug/url.d.ts +33 -0
  225. package/node_modules/socket.io-client/build/esm-debug/url.js +63 -0
  226. package/node_modules/socket.io-client/dist/socket.io.esm.min.js +7 -0
  227. package/node_modules/socket.io-client/dist/socket.io.esm.min.js.map +1 -0
  228. package/node_modules/socket.io-client/dist/socket.io.js +4955 -0
  229. package/node_modules/socket.io-client/dist/socket.io.js.map +1 -0
  230. package/node_modules/socket.io-client/dist/socket.io.min.js +7 -0
  231. package/node_modules/socket.io-client/dist/socket.io.min.js.map +1 -0
  232. package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js +7 -0
  233. package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js.map +1 -0
  234. package/node_modules/socket.io-client/package.json +101 -0
  235. package/node_modules/socket.io-parser/LICENSE +20 -0
  236. package/node_modules/socket.io-parser/Readme.md +81 -0
  237. package/node_modules/socket.io-parser/build/cjs/binary.d.ts +20 -0
  238. package/node_modules/socket.io-parser/build/cjs/binary.js +90 -0
  239. package/node_modules/socket.io-parser/build/cjs/index.d.ts +101 -0
  240. package/node_modules/socket.io-parser/build/cjs/index.js +366 -0
  241. package/node_modules/socket.io-parser/build/cjs/is-binary.d.ts +7 -0
  242. package/node_modules/socket.io-parser/build/cjs/is-binary.js +54 -0
  243. package/node_modules/socket.io-parser/build/cjs/package.json +3 -0
  244. package/node_modules/socket.io-parser/build/esm/binary.d.ts +20 -0
  245. package/node_modules/socket.io-parser/build/esm/binary.js +86 -0
  246. package/node_modules/socket.io-parser/build/esm/index.d.ts +101 -0
  247. package/node_modules/socket.io-parser/build/esm/index.js +352 -0
  248. package/node_modules/socket.io-parser/build/esm/is-binary.d.ts +7 -0
  249. package/node_modules/socket.io-parser/build/esm/is-binary.js +50 -0
  250. package/node_modules/socket.io-parser/build/esm/package.json +3 -0
  251. package/node_modules/socket.io-parser/build/esm-debug/binary.d.ts +20 -0
  252. package/node_modules/socket.io-parser/build/esm-debug/binary.js +86 -0
  253. package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +101 -0
  254. package/node_modules/socket.io-parser/build/esm-debug/index.js +357 -0
  255. package/node_modules/socket.io-parser/build/esm-debug/is-binary.d.ts +7 -0
  256. package/node_modules/socket.io-parser/build/esm-debug/is-binary.js +50 -0
  257. package/node_modules/socket.io-parser/build/esm-debug/package.json +3 -0
  258. package/node_modules/socket.io-parser/package.json +44 -0
  259. package/node_modules/ws/LICENSE +20 -0
  260. package/node_modules/ws/README.md +548 -0
  261. package/node_modules/ws/browser.js +8 -0
  262. package/node_modules/ws/index.js +22 -0
  263. package/node_modules/ws/lib/buffer-util.js +131 -0
  264. package/node_modules/ws/lib/constants.js +19 -0
  265. package/node_modules/ws/lib/event-target.js +292 -0
  266. package/node_modules/ws/lib/extension.js +203 -0
  267. package/node_modules/ws/lib/limiter.js +55 -0
  268. package/node_modules/ws/lib/permessage-deflate.js +530 -0
  269. package/node_modules/ws/lib/receiver.js +743 -0
  270. package/node_modules/ws/lib/sender.js +607 -0
  271. package/node_modules/ws/lib/stream.js +161 -0
  272. package/node_modules/ws/lib/subprotocol.js +62 -0
  273. package/node_modules/ws/lib/validation.js +152 -0
  274. package/node_modules/ws/lib/websocket-server.js +562 -0
  275. package/node_modules/ws/lib/websocket.js +1407 -0
  276. package/node_modules/ws/package.json +74 -0
  277. package/node_modules/ws/wrapper.mjs +21 -0
  278. package/node_modules/xmlhttprequest-ssl/LICENSE +22 -0
  279. package/node_modules/xmlhttprequest-ssl/README.md +67 -0
  280. package/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +689 -0
  281. package/node_modules/xmlhttprequest-ssl/package.json +40 -0
  282. package/openclaw.plugin.json +60 -0
  283. package/package.json +48 -0
@@ -0,0 +1,3094 @@
1
+ /*!
2
+ * Engine.IO v6.6.6
3
+ * (c) 2014-2026 Guillermo Rauch
4
+ * Released under the MIT License.
5
+ */
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.eio = factory());
10
+ })(this, (function () { 'use strict';
11
+
12
+ function _arrayLikeToArray(r, a) {
13
+ (null == a || a > r.length) && (a = r.length);
14
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
15
+ return n;
16
+ }
17
+ function _arrayWithoutHoles(r) {
18
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
19
+ }
20
+ function _construct(t, e, r) {
21
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
22
+ var o = [null];
23
+ o.push.apply(o, e);
24
+ var p = new (t.bind.apply(t, o))();
25
+ return r && _setPrototypeOf(p, r.prototype), p;
26
+ }
27
+ function _defineProperties(e, r) {
28
+ for (var t = 0; t < r.length; t++) {
29
+ var o = r[t];
30
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
31
+ }
32
+ }
33
+ function _createClass(e, r, t) {
34
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
35
+ writable: !1
36
+ }), e;
37
+ }
38
+ function _createForOfIteratorHelper(r, e) {
39
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
40
+ if (!t) {
41
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
42
+ t && (r = t);
43
+ var n = 0,
44
+ F = function () {};
45
+ return {
46
+ s: F,
47
+ n: function () {
48
+ return n >= r.length ? {
49
+ done: !0
50
+ } : {
51
+ done: !1,
52
+ value: r[n++]
53
+ };
54
+ },
55
+ e: function (r) {
56
+ throw r;
57
+ },
58
+ f: F
59
+ };
60
+ }
61
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ }
63
+ var o,
64
+ a = !0,
65
+ u = !1;
66
+ return {
67
+ s: function () {
68
+ t = t.call(r);
69
+ },
70
+ n: function () {
71
+ var r = t.next();
72
+ return a = r.done, r;
73
+ },
74
+ e: function (r) {
75
+ u = !0, o = r;
76
+ },
77
+ f: function () {
78
+ try {
79
+ a || null == t.return || t.return();
80
+ } finally {
81
+ if (u) throw o;
82
+ }
83
+ }
84
+ };
85
+ }
86
+ function _defineProperty(e, r, t) {
87
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
88
+ value: t,
89
+ enumerable: !0,
90
+ configurable: !0,
91
+ writable: !0
92
+ }) : e[r] = t, e;
93
+ }
94
+ function _extends() {
95
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
96
+ for (var e = 1; e < arguments.length; e++) {
97
+ var t = arguments[e];
98
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
99
+ }
100
+ return n;
101
+ }, _extends.apply(null, arguments);
102
+ }
103
+ function _getPrototypeOf(t) {
104
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
105
+ return t.__proto__ || Object.getPrototypeOf(t);
106
+ }, _getPrototypeOf(t);
107
+ }
108
+ function _inheritsLoose(t, o) {
109
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
110
+ }
111
+ function _isNativeFunction(t) {
112
+ try {
113
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
114
+ } catch (n) {
115
+ return "function" == typeof t;
116
+ }
117
+ }
118
+ function _isNativeReflectConstruct() {
119
+ try {
120
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
121
+ } catch (t) {}
122
+ return (_isNativeReflectConstruct = function () {
123
+ return !!t;
124
+ })();
125
+ }
126
+ function _iterableToArray(r) {
127
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
128
+ }
129
+ function _nonIterableSpread() {
130
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
131
+ }
132
+ function ownKeys(e, r) {
133
+ var t = Object.keys(e);
134
+ if (Object.getOwnPropertySymbols) {
135
+ var o = Object.getOwnPropertySymbols(e);
136
+ r && (o = o.filter(function (r) {
137
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
138
+ })), t.push.apply(t, o);
139
+ }
140
+ return t;
141
+ }
142
+ function _objectSpread2(e) {
143
+ for (var r = 1; r < arguments.length; r++) {
144
+ var t = null != arguments[r] ? arguments[r] : {};
145
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
146
+ _defineProperty(e, r, t[r]);
147
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
148
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
149
+ });
150
+ }
151
+ return e;
152
+ }
153
+ function _setPrototypeOf(t, e) {
154
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
155
+ return t.__proto__ = e, t;
156
+ }, _setPrototypeOf(t, e);
157
+ }
158
+ function _toConsumableArray(r) {
159
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
160
+ }
161
+ function _toPrimitive(t, r) {
162
+ if ("object" != typeof t || !t) return t;
163
+ var e = t[Symbol.toPrimitive];
164
+ if (void 0 !== e) {
165
+ var i = e.call(t, r || "default");
166
+ if ("object" != typeof i) return i;
167
+ throw new TypeError("@@toPrimitive must return a primitive value.");
168
+ }
169
+ return ("string" === r ? String : Number)(t);
170
+ }
171
+ function _toPropertyKey(t) {
172
+ var i = _toPrimitive(t, "string");
173
+ return "symbol" == typeof i ? i : i + "";
174
+ }
175
+ function _typeof(o) {
176
+ "@babel/helpers - typeof";
177
+
178
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
179
+ return typeof o;
180
+ } : function (o) {
181
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
182
+ }, _typeof(o);
183
+ }
184
+ function _unsupportedIterableToArray(r, a) {
185
+ if (r) {
186
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
187
+ var t = {}.toString.call(r).slice(8, -1);
188
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
189
+ }
190
+ }
191
+ function _wrapNativeSuper(t) {
192
+ var r = "function" == typeof Map ? new Map() : void 0;
193
+ return _wrapNativeSuper = function (t) {
194
+ if (null === t || !_isNativeFunction(t)) return t;
195
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
196
+ if (void 0 !== r) {
197
+ if (r.has(t)) return r.get(t);
198
+ r.set(t, Wrapper);
199
+ }
200
+ function Wrapper() {
201
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
202
+ }
203
+ return Wrapper.prototype = Object.create(t.prototype, {
204
+ constructor: {
205
+ value: Wrapper,
206
+ enumerable: !1,
207
+ writable: !0,
208
+ configurable: !0
209
+ }
210
+ }), _setPrototypeOf(Wrapper, t);
211
+ }, _wrapNativeSuper(t);
212
+ }
213
+
214
+ var PACKET_TYPES = Object.create(null); // no Map = no polyfill
215
+ PACKET_TYPES["open"] = "0";
216
+ PACKET_TYPES["close"] = "1";
217
+ PACKET_TYPES["ping"] = "2";
218
+ PACKET_TYPES["pong"] = "3";
219
+ PACKET_TYPES["message"] = "4";
220
+ PACKET_TYPES["upgrade"] = "5";
221
+ PACKET_TYPES["noop"] = "6";
222
+ var PACKET_TYPES_REVERSE = Object.create(null);
223
+ Object.keys(PACKET_TYPES).forEach(function (key) {
224
+ PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
225
+ });
226
+ var ERROR_PACKET = {
227
+ type: "error",
228
+ data: "parser error"
229
+ };
230
+
231
+ var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
232
+ var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
233
+ // ArrayBuffer.isView method is not defined in IE10
234
+ var isView = function isView(obj) {
235
+ return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
236
+ };
237
+ var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
238
+ var type = _ref.type,
239
+ data = _ref.data;
240
+ if (withNativeBlob && data instanceof Blob) {
241
+ if (supportsBinary) {
242
+ return callback(data);
243
+ } else {
244
+ return encodeBlobAsBase64(data, callback);
245
+ }
246
+ } else if (withNativeArrayBuffer$1 && (data instanceof ArrayBuffer || isView(data))) {
247
+ if (supportsBinary) {
248
+ return callback(data);
249
+ } else {
250
+ return encodeBlobAsBase64(new Blob([data]), callback);
251
+ }
252
+ }
253
+ // plain string
254
+ return callback(PACKET_TYPES[type] + (data || ""));
255
+ };
256
+ var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
257
+ var fileReader = new FileReader();
258
+ fileReader.onload = function () {
259
+ var content = fileReader.result.split(",")[1];
260
+ callback("b" + (content || ""));
261
+ };
262
+ return fileReader.readAsDataURL(data);
263
+ };
264
+ function toArray(data) {
265
+ if (data instanceof Uint8Array) {
266
+ return data;
267
+ } else if (data instanceof ArrayBuffer) {
268
+ return new Uint8Array(data);
269
+ } else {
270
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
271
+ }
272
+ }
273
+ var TEXT_ENCODER;
274
+ function encodePacketToBinary(packet, callback) {
275
+ if (withNativeBlob && packet.data instanceof Blob) {
276
+ return packet.data.arrayBuffer().then(toArray).then(callback);
277
+ } else if (withNativeArrayBuffer$1 && (packet.data instanceof ArrayBuffer || isView(packet.data))) {
278
+ return callback(toArray(packet.data));
279
+ }
280
+ encodePacket(packet, false, function (encoded) {
281
+ if (!TEXT_ENCODER) {
282
+ TEXT_ENCODER = new TextEncoder();
283
+ }
284
+ callback(TEXT_ENCODER.encode(encoded));
285
+ });
286
+ }
287
+
288
+ // imported from https://github.com/socketio/base64-arraybuffer
289
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
290
+ // Use a lookup table to find the index.
291
+ var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
292
+ for (var i = 0; i < chars.length; i++) {
293
+ lookup[chars.charCodeAt(i)] = i;
294
+ }
295
+ var decode$1 = function decode(base64) {
296
+ var bufferLength = base64.length * 0.75,
297
+ len = base64.length,
298
+ i,
299
+ p = 0,
300
+ encoded1,
301
+ encoded2,
302
+ encoded3,
303
+ encoded4;
304
+ if (base64[base64.length - 1] === '=') {
305
+ bufferLength--;
306
+ if (base64[base64.length - 2] === '=') {
307
+ bufferLength--;
308
+ }
309
+ }
310
+ var arraybuffer = new ArrayBuffer(bufferLength),
311
+ bytes = new Uint8Array(arraybuffer);
312
+ for (i = 0; i < len; i += 4) {
313
+ encoded1 = lookup[base64.charCodeAt(i)];
314
+ encoded2 = lookup[base64.charCodeAt(i + 1)];
315
+ encoded3 = lookup[base64.charCodeAt(i + 2)];
316
+ encoded4 = lookup[base64.charCodeAt(i + 3)];
317
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
318
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
319
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
320
+ }
321
+ return arraybuffer;
322
+ };
323
+
324
+ var withNativeArrayBuffer = typeof ArrayBuffer === "function";
325
+ var decodePacket = function decodePacket(encodedPacket, binaryType) {
326
+ if (typeof encodedPacket !== "string") {
327
+ return {
328
+ type: "message",
329
+ data: mapBinary(encodedPacket, binaryType)
330
+ };
331
+ }
332
+ var type = encodedPacket.charAt(0);
333
+ if (type === "b") {
334
+ return {
335
+ type: "message",
336
+ data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
337
+ };
338
+ }
339
+ var packetType = PACKET_TYPES_REVERSE[type];
340
+ if (!packetType) {
341
+ return ERROR_PACKET;
342
+ }
343
+ return encodedPacket.length > 1 ? {
344
+ type: PACKET_TYPES_REVERSE[type],
345
+ data: encodedPacket.substring(1)
346
+ } : {
347
+ type: PACKET_TYPES_REVERSE[type]
348
+ };
349
+ };
350
+ var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
351
+ if (withNativeArrayBuffer) {
352
+ var decoded = decode$1(data);
353
+ return mapBinary(decoded, binaryType);
354
+ } else {
355
+ return {
356
+ base64: true,
357
+ data: data
358
+ }; // fallback for old browsers
359
+ }
360
+ };
361
+ var mapBinary = function mapBinary(data, binaryType) {
362
+ switch (binaryType) {
363
+ case "blob":
364
+ if (data instanceof Blob) {
365
+ // from WebSocket + binaryType "blob"
366
+ return data;
367
+ } else {
368
+ // from HTTP long-polling or WebTransport
369
+ return new Blob([data]);
370
+ }
371
+ case "arraybuffer":
372
+ default:
373
+ if (data instanceof ArrayBuffer) {
374
+ // from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
375
+ return data;
376
+ } else {
377
+ // from WebTransport (Uint8Array)
378
+ return data.buffer;
379
+ }
380
+ }
381
+ };
382
+
383
+ var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
384
+ var encodePayload = function encodePayload(packets, callback) {
385
+ // some packets may be added to the array while encoding, so the initial length must be saved
386
+ var length = packets.length;
387
+ var encodedPackets = new Array(length);
388
+ var count = 0;
389
+ packets.forEach(function (packet, i) {
390
+ // force base64 encoding for binary packets
391
+ encodePacket(packet, false, function (encodedPacket) {
392
+ encodedPackets[i] = encodedPacket;
393
+ if (++count === length) {
394
+ callback(encodedPackets.join(SEPARATOR));
395
+ }
396
+ });
397
+ });
398
+ };
399
+ var decodePayload = function decodePayload(encodedPayload, binaryType) {
400
+ var encodedPackets = encodedPayload.split(SEPARATOR);
401
+ var packets = [];
402
+ for (var i = 0; i < encodedPackets.length; i++) {
403
+ var decodedPacket = decodePacket(encodedPackets[i], binaryType);
404
+ packets.push(decodedPacket);
405
+ if (decodedPacket.type === "error") {
406
+ break;
407
+ }
408
+ }
409
+ return packets;
410
+ };
411
+ function createPacketEncoderStream() {
412
+ return new TransformStream({
413
+ transform: function transform(packet, controller) {
414
+ encodePacketToBinary(packet, function (encodedPacket) {
415
+ var payloadLength = encodedPacket.length;
416
+ var header;
417
+ // inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
418
+ if (payloadLength < 126) {
419
+ header = new Uint8Array(1);
420
+ new DataView(header.buffer).setUint8(0, payloadLength);
421
+ } else if (payloadLength < 65536) {
422
+ header = new Uint8Array(3);
423
+ var view = new DataView(header.buffer);
424
+ view.setUint8(0, 126);
425
+ view.setUint16(1, payloadLength);
426
+ } else {
427
+ header = new Uint8Array(9);
428
+ var _view = new DataView(header.buffer);
429
+ _view.setUint8(0, 127);
430
+ _view.setBigUint64(1, BigInt(payloadLength));
431
+ }
432
+ // first bit indicates whether the payload is plain text (0) or binary (1)
433
+ if (packet.data && typeof packet.data !== "string") {
434
+ header[0] |= 0x80;
435
+ }
436
+ controller.enqueue(header);
437
+ controller.enqueue(encodedPacket);
438
+ });
439
+ }
440
+ });
441
+ }
442
+ var TEXT_DECODER;
443
+ function totalLength(chunks) {
444
+ return chunks.reduce(function (acc, chunk) {
445
+ return acc + chunk.length;
446
+ }, 0);
447
+ }
448
+ function concatChunks(chunks, size) {
449
+ if (chunks[0].length === size) {
450
+ return chunks.shift();
451
+ }
452
+ var buffer = new Uint8Array(size);
453
+ var j = 0;
454
+ for (var i = 0; i < size; i++) {
455
+ buffer[i] = chunks[0][j++];
456
+ if (j === chunks[0].length) {
457
+ chunks.shift();
458
+ j = 0;
459
+ }
460
+ }
461
+ if (chunks.length && j < chunks[0].length) {
462
+ chunks[0] = chunks[0].slice(j);
463
+ }
464
+ return buffer;
465
+ }
466
+ function createPacketDecoderStream(maxPayload, binaryType) {
467
+ if (!TEXT_DECODER) {
468
+ TEXT_DECODER = new TextDecoder();
469
+ }
470
+ var chunks = [];
471
+ var state = 0 /* State.READ_HEADER */;
472
+ var expectedLength = -1;
473
+ var isBinary = false;
474
+ return new TransformStream({
475
+ transform: function transform(chunk, controller) {
476
+ chunks.push(chunk);
477
+ while (true) {
478
+ if (state === 0 /* State.READ_HEADER */) {
479
+ if (totalLength(chunks) < 1) {
480
+ break;
481
+ }
482
+ var header = concatChunks(chunks, 1);
483
+ isBinary = (header[0] & 0x80) === 0x80;
484
+ expectedLength = header[0] & 0x7f;
485
+ if (expectedLength < 126) {
486
+ state = 3 /* State.READ_PAYLOAD */;
487
+ } else if (expectedLength === 126) {
488
+ state = 1 /* State.READ_EXTENDED_LENGTH_16 */;
489
+ } else {
490
+ state = 2 /* State.READ_EXTENDED_LENGTH_64 */;
491
+ }
492
+ } else if (state === 1 /* State.READ_EXTENDED_LENGTH_16 */) {
493
+ if (totalLength(chunks) < 2) {
494
+ break;
495
+ }
496
+ var headerArray = concatChunks(chunks, 2);
497
+ expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
498
+ state = 3 /* State.READ_PAYLOAD */;
499
+ } else if (state === 2 /* State.READ_EXTENDED_LENGTH_64 */) {
500
+ if (totalLength(chunks) < 8) {
501
+ break;
502
+ }
503
+ var _headerArray = concatChunks(chunks, 8);
504
+ var view = new DataView(_headerArray.buffer, _headerArray.byteOffset, _headerArray.length);
505
+ var n = view.getUint32(0);
506
+ if (n > Math.pow(2, 53 - 32) - 1) {
507
+ // the maximum safe integer in JavaScript is 2^53 - 1
508
+ controller.enqueue(ERROR_PACKET);
509
+ break;
510
+ }
511
+ expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
512
+ state = 3 /* State.READ_PAYLOAD */;
513
+ } else {
514
+ if (totalLength(chunks) < expectedLength) {
515
+ break;
516
+ }
517
+ var data = concatChunks(chunks, expectedLength);
518
+ controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
519
+ state = 0 /* State.READ_HEADER */;
520
+ }
521
+ if (expectedLength === 0 || expectedLength > maxPayload) {
522
+ controller.enqueue(ERROR_PACKET);
523
+ break;
524
+ }
525
+ }
526
+ }
527
+ });
528
+ }
529
+ var protocol = 4;
530
+
531
+ /**
532
+ * Initialize a new `Emitter`.
533
+ *
534
+ * @api public
535
+ */
536
+
537
+ function Emitter(obj) {
538
+ if (obj) return mixin(obj);
539
+ }
540
+
541
+ /**
542
+ * Mixin the emitter properties.
543
+ *
544
+ * @param {Object} obj
545
+ * @return {Object}
546
+ * @api private
547
+ */
548
+
549
+ function mixin(obj) {
550
+ for (var key in Emitter.prototype) {
551
+ obj[key] = Emitter.prototype[key];
552
+ }
553
+ return obj;
554
+ }
555
+
556
+ /**
557
+ * Listen on the given `event` with `fn`.
558
+ *
559
+ * @param {String} event
560
+ * @param {Function} fn
561
+ * @return {Emitter}
562
+ * @api public
563
+ */
564
+
565
+ Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
566
+ this._callbacks = this._callbacks || {};
567
+ (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
568
+ return this;
569
+ };
570
+
571
+ /**
572
+ * Adds an `event` listener that will be invoked a single
573
+ * time then automatically removed.
574
+ *
575
+ * @param {String} event
576
+ * @param {Function} fn
577
+ * @return {Emitter}
578
+ * @api public
579
+ */
580
+
581
+ Emitter.prototype.once = function (event, fn) {
582
+ function on() {
583
+ this.off(event, on);
584
+ fn.apply(this, arguments);
585
+ }
586
+ on.fn = fn;
587
+ this.on(event, on);
588
+ return this;
589
+ };
590
+
591
+ /**
592
+ * Remove the given callback for `event` or all
593
+ * registered callbacks.
594
+ *
595
+ * @param {String} event
596
+ * @param {Function} fn
597
+ * @return {Emitter}
598
+ * @api public
599
+ */
600
+
601
+ Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
602
+ this._callbacks = this._callbacks || {};
603
+
604
+ // all
605
+ if (0 == arguments.length) {
606
+ this._callbacks = {};
607
+ return this;
608
+ }
609
+
610
+ // specific event
611
+ var callbacks = this._callbacks['$' + event];
612
+ if (!callbacks) return this;
613
+
614
+ // remove all handlers
615
+ if (1 == arguments.length) {
616
+ delete this._callbacks['$' + event];
617
+ return this;
618
+ }
619
+
620
+ // remove specific handler
621
+ var cb;
622
+ for (var i = 0; i < callbacks.length; i++) {
623
+ cb = callbacks[i];
624
+ if (cb === fn || cb.fn === fn) {
625
+ callbacks.splice(i, 1);
626
+ break;
627
+ }
628
+ }
629
+
630
+ // Remove event specific arrays for event types that no
631
+ // one is subscribed for to avoid memory leak.
632
+ if (callbacks.length === 0) {
633
+ delete this._callbacks['$' + event];
634
+ }
635
+ return this;
636
+ };
637
+
638
+ /**
639
+ * Emit `event` with the given args.
640
+ *
641
+ * @param {String} event
642
+ * @param {Mixed} ...
643
+ * @return {Emitter}
644
+ */
645
+
646
+ Emitter.prototype.emit = function (event) {
647
+ this._callbacks = this._callbacks || {};
648
+ var args = new Array(arguments.length - 1),
649
+ callbacks = this._callbacks['$' + event];
650
+ for (var i = 1; i < arguments.length; i++) {
651
+ args[i - 1] = arguments[i];
652
+ }
653
+ if (callbacks) {
654
+ callbacks = callbacks.slice(0);
655
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
656
+ callbacks[i].apply(this, args);
657
+ }
658
+ }
659
+ return this;
660
+ };
661
+
662
+ // alias used for reserved events (protected method)
663
+ Emitter.prototype.emitReserved = Emitter.prototype.emit;
664
+
665
+ /**
666
+ * Return array of callbacks for `event`.
667
+ *
668
+ * @param {String} event
669
+ * @return {Array}
670
+ * @api public
671
+ */
672
+
673
+ Emitter.prototype.listeners = function (event) {
674
+ this._callbacks = this._callbacks || {};
675
+ return this._callbacks['$' + event] || [];
676
+ };
677
+
678
+ /**
679
+ * Check if this emitter has `event` handlers.
680
+ *
681
+ * @param {String} event
682
+ * @return {Boolean}
683
+ * @api public
684
+ */
685
+
686
+ Emitter.prototype.hasListeners = function (event) {
687
+ return !!this.listeners(event).length;
688
+ };
689
+
690
+ var nextTick = function () {
691
+ var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
692
+ if (isPromiseAvailable) {
693
+ return function (cb) {
694
+ return Promise.resolve().then(cb);
695
+ };
696
+ } else {
697
+ return function (cb, setTimeoutFn) {
698
+ return setTimeoutFn(cb, 0);
699
+ };
700
+ }
701
+ }();
702
+ var globalThisShim = function () {
703
+ if (typeof self !== "undefined") {
704
+ return self;
705
+ } else if (typeof window !== "undefined") {
706
+ return window;
707
+ } else {
708
+ return Function("return this")();
709
+ }
710
+ }();
711
+ var defaultBinaryType = "arraybuffer";
712
+ function createCookieJar() {}
713
+
714
+ function pick(obj) {
715
+ for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
716
+ attr[_key - 1] = arguments[_key];
717
+ }
718
+ return attr.reduce(function (acc, k) {
719
+ if (obj.hasOwnProperty(k)) {
720
+ acc[k] = obj[k];
721
+ }
722
+ return acc;
723
+ }, {});
724
+ }
725
+ // Keep a reference to the real timeout functions so they can be used when overridden
726
+ var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
727
+ var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
728
+ function installTimerFunctions(obj, opts) {
729
+ if (opts.useNativeTimers) {
730
+ obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
731
+ obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
732
+ } else {
733
+ obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
734
+ obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
735
+ }
736
+ }
737
+ // base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
738
+ var BASE64_OVERHEAD = 1.33;
739
+ // we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
740
+ function byteLength(obj) {
741
+ if (typeof obj === "string") {
742
+ return utf8Length(obj);
743
+ }
744
+ // arraybuffer or blob
745
+ return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
746
+ }
747
+ function utf8Length(str) {
748
+ var c = 0,
749
+ length = 0;
750
+ for (var i = 0, l = str.length; i < l; i++) {
751
+ c = str.charCodeAt(i);
752
+ if (c < 0x80) {
753
+ length += 1;
754
+ } else if (c < 0x800) {
755
+ length += 2;
756
+ } else if (c < 0xd800 || c >= 0xe000) {
757
+ length += 3;
758
+ } else {
759
+ i++;
760
+ length += 4;
761
+ }
762
+ }
763
+ return length;
764
+ }
765
+ /**
766
+ * Generates a random 8-characters string.
767
+ */
768
+ function randomString() {
769
+ return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
770
+ }
771
+
772
+ // imported from https://github.com/galkn/querystring
773
+ /**
774
+ * Compiles a querystring
775
+ * Returns string representation of the object
776
+ *
777
+ * @param {Object}
778
+ * @api private
779
+ */
780
+ function encode(obj) {
781
+ var str = '';
782
+ for (var i in obj) {
783
+ if (obj.hasOwnProperty(i)) {
784
+ if (str.length) str += '&';
785
+ str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
786
+ }
787
+ }
788
+ return str;
789
+ }
790
+ /**
791
+ * Parses a simple querystring into an object
792
+ *
793
+ * @param {String} qs
794
+ * @api private
795
+ */
796
+ function decode(qs) {
797
+ var qry = {};
798
+ var pairs = qs.split('&');
799
+ for (var i = 0, l = pairs.length; i < l; i++) {
800
+ var pair = pairs[i].split('=');
801
+ qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
802
+ }
803
+ return qry;
804
+ }
805
+
806
+ function getDefaultExportFromCjs (x) {
807
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
808
+ }
809
+
810
+ var browser = {exports: {}};
811
+
812
+ var ms;
813
+ var hasRequiredMs;
814
+ function requireMs() {
815
+ if (hasRequiredMs) return ms;
816
+ hasRequiredMs = 1;
817
+ var s = 1000;
818
+ var m = s * 60;
819
+ var h = m * 60;
820
+ var d = h * 24;
821
+ var w = d * 7;
822
+ var y = d * 365.25;
823
+
824
+ /**
825
+ * Parse or format the given `val`.
826
+ *
827
+ * Options:
828
+ *
829
+ * - `long` verbose formatting [false]
830
+ *
831
+ * @param {String|Number} val
832
+ * @param {Object} [options]
833
+ * @throws {Error} throw an error if val is not a non-empty string or a number
834
+ * @return {String|Number}
835
+ * @api public
836
+ */
837
+
838
+ ms = function ms(val, options) {
839
+ options = options || {};
840
+ var type = _typeof(val);
841
+ if (type === 'string' && val.length > 0) {
842
+ return parse(val);
843
+ } else if (type === 'number' && isFinite(val)) {
844
+ return options["long"] ? fmtLong(val) : fmtShort(val);
845
+ }
846
+ throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
847
+ };
848
+
849
+ /**
850
+ * Parse the given `str` and return milliseconds.
851
+ *
852
+ * @param {String} str
853
+ * @return {Number}
854
+ * @api private
855
+ */
856
+
857
+ function parse(str) {
858
+ str = String(str);
859
+ if (str.length > 100) {
860
+ return;
861
+ }
862
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
863
+ if (!match) {
864
+ return;
865
+ }
866
+ var n = parseFloat(match[1]);
867
+ var type = (match[2] || 'ms').toLowerCase();
868
+ switch (type) {
869
+ case 'years':
870
+ case 'year':
871
+ case 'yrs':
872
+ case 'yr':
873
+ case 'y':
874
+ return n * y;
875
+ case 'weeks':
876
+ case 'week':
877
+ case 'w':
878
+ return n * w;
879
+ case 'days':
880
+ case 'day':
881
+ case 'd':
882
+ return n * d;
883
+ case 'hours':
884
+ case 'hour':
885
+ case 'hrs':
886
+ case 'hr':
887
+ case 'h':
888
+ return n * h;
889
+ case 'minutes':
890
+ case 'minute':
891
+ case 'mins':
892
+ case 'min':
893
+ case 'm':
894
+ return n * m;
895
+ case 'seconds':
896
+ case 'second':
897
+ case 'secs':
898
+ case 'sec':
899
+ case 's':
900
+ return n * s;
901
+ case 'milliseconds':
902
+ case 'millisecond':
903
+ case 'msecs':
904
+ case 'msec':
905
+ case 'ms':
906
+ return n;
907
+ default:
908
+ return undefined;
909
+ }
910
+ }
911
+
912
+ /**
913
+ * Short format for `ms`.
914
+ *
915
+ * @param {Number} ms
916
+ * @return {String}
917
+ * @api private
918
+ */
919
+
920
+ function fmtShort(ms) {
921
+ var msAbs = Math.abs(ms);
922
+ if (msAbs >= d) {
923
+ return Math.round(ms / d) + 'd';
924
+ }
925
+ if (msAbs >= h) {
926
+ return Math.round(ms / h) + 'h';
927
+ }
928
+ if (msAbs >= m) {
929
+ return Math.round(ms / m) + 'm';
930
+ }
931
+ if (msAbs >= s) {
932
+ return Math.round(ms / s) + 's';
933
+ }
934
+ return ms + 'ms';
935
+ }
936
+
937
+ /**
938
+ * Long format for `ms`.
939
+ *
940
+ * @param {Number} ms
941
+ * @return {String}
942
+ * @api private
943
+ */
944
+
945
+ function fmtLong(ms) {
946
+ var msAbs = Math.abs(ms);
947
+ if (msAbs >= d) {
948
+ return plural(ms, msAbs, d, 'day');
949
+ }
950
+ if (msAbs >= h) {
951
+ return plural(ms, msAbs, h, 'hour');
952
+ }
953
+ if (msAbs >= m) {
954
+ return plural(ms, msAbs, m, 'minute');
955
+ }
956
+ if (msAbs >= s) {
957
+ return plural(ms, msAbs, s, 'second');
958
+ }
959
+ return ms + ' ms';
960
+ }
961
+
962
+ /**
963
+ * Pluralization helper.
964
+ */
965
+
966
+ function plural(ms, msAbs, n, name) {
967
+ var isPlural = msAbs >= n * 1.5;
968
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
969
+ }
970
+ return ms;
971
+ }
972
+
973
+ /**
974
+ * This is the common logic for both the Node.js and web browser
975
+ * implementations of `debug()`.
976
+ */
977
+
978
+ function setup(env) {
979
+ createDebug.debug = createDebug;
980
+ createDebug["default"] = createDebug;
981
+ createDebug.coerce = coerce;
982
+ createDebug.disable = disable;
983
+ createDebug.enable = enable;
984
+ createDebug.enabled = enabled;
985
+ createDebug.humanize = requireMs();
986
+ createDebug.destroy = destroy;
987
+ Object.keys(env).forEach(function (key) {
988
+ createDebug[key] = env[key];
989
+ });
990
+
991
+ /**
992
+ * The currently active debug mode names, and names to skip.
993
+ */
994
+
995
+ createDebug.names = [];
996
+ createDebug.skips = [];
997
+
998
+ /**
999
+ * Map of special "%n" handling functions, for the debug "format" argument.
1000
+ *
1001
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
1002
+ */
1003
+ createDebug.formatters = {};
1004
+
1005
+ /**
1006
+ * Selects a color for a debug namespace
1007
+ * @param {String} namespace The namespace string for the debug instance to be colored
1008
+ * @return {Number|String} An ANSI color code for the given namespace
1009
+ * @api private
1010
+ */
1011
+ function selectColor(namespace) {
1012
+ var hash = 0;
1013
+ for (var i = 0; i < namespace.length; i++) {
1014
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
1015
+ hash |= 0; // Convert to 32bit integer
1016
+ }
1017
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
1018
+ }
1019
+ createDebug.selectColor = selectColor;
1020
+
1021
+ /**
1022
+ * Create a debugger with the given `namespace`.
1023
+ *
1024
+ * @param {String} namespace
1025
+ * @return {Function}
1026
+ * @api public
1027
+ */
1028
+ function createDebug(namespace) {
1029
+ var prevTime;
1030
+ var enableOverride = null;
1031
+ var namespacesCache;
1032
+ var enabledCache;
1033
+ function debug() {
1034
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1035
+ args[_key] = arguments[_key];
1036
+ }
1037
+ // Disabled?
1038
+ if (!debug.enabled) {
1039
+ return;
1040
+ }
1041
+ var self = debug;
1042
+
1043
+ // Set `diff` timestamp
1044
+ var curr = Number(new Date());
1045
+ var ms = curr - (prevTime || curr);
1046
+ self.diff = ms;
1047
+ self.prev = prevTime;
1048
+ self.curr = curr;
1049
+ prevTime = curr;
1050
+ args[0] = createDebug.coerce(args[0]);
1051
+ if (typeof args[0] !== 'string') {
1052
+ // Anything else let's inspect with %O
1053
+ args.unshift('%O');
1054
+ }
1055
+
1056
+ // Apply any `formatters` transformations
1057
+ var index = 0;
1058
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
1059
+ // If we encounter an escaped % then don't increase the array index
1060
+ if (match === '%%') {
1061
+ return '%';
1062
+ }
1063
+ index++;
1064
+ var formatter = createDebug.formatters[format];
1065
+ if (typeof formatter === 'function') {
1066
+ var val = args[index];
1067
+ match = formatter.call(self, val);
1068
+
1069
+ // Now we need to remove `args[index]` since it's inlined in the `format`
1070
+ args.splice(index, 1);
1071
+ index--;
1072
+ }
1073
+ return match;
1074
+ });
1075
+
1076
+ // Apply env-specific formatting (colors, etc.)
1077
+ createDebug.formatArgs.call(self, args);
1078
+ var logFn = self.log || createDebug.log;
1079
+ logFn.apply(self, args);
1080
+ }
1081
+ debug.namespace = namespace;
1082
+ debug.useColors = createDebug.useColors();
1083
+ debug.color = createDebug.selectColor(namespace);
1084
+ debug.extend = extend;
1085
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
1086
+
1087
+ Object.defineProperty(debug, 'enabled', {
1088
+ enumerable: true,
1089
+ configurable: false,
1090
+ get: function get() {
1091
+ if (enableOverride !== null) {
1092
+ return enableOverride;
1093
+ }
1094
+ if (namespacesCache !== createDebug.namespaces) {
1095
+ namespacesCache = createDebug.namespaces;
1096
+ enabledCache = createDebug.enabled(namespace);
1097
+ }
1098
+ return enabledCache;
1099
+ },
1100
+ set: function set(v) {
1101
+ enableOverride = v;
1102
+ }
1103
+ });
1104
+
1105
+ // Env-specific initialization logic for debug instances
1106
+ if (typeof createDebug.init === 'function') {
1107
+ createDebug.init(debug);
1108
+ }
1109
+ return debug;
1110
+ }
1111
+ function extend(namespace, delimiter) {
1112
+ var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
1113
+ newDebug.log = this.log;
1114
+ return newDebug;
1115
+ }
1116
+
1117
+ /**
1118
+ * Enables a debug mode by namespaces. This can include modes
1119
+ * separated by a colon and wildcards.
1120
+ *
1121
+ * @param {String} namespaces
1122
+ * @api public
1123
+ */
1124
+ function enable(namespaces) {
1125
+ createDebug.save(namespaces);
1126
+ createDebug.namespaces = namespaces;
1127
+ createDebug.names = [];
1128
+ createDebug.skips = [];
1129
+ var split = (typeof namespaces === 'string' ? namespaces : '').trim().replace(/\s+/g, ',').split(',').filter(Boolean);
1130
+ var _iterator = _createForOfIteratorHelper(split),
1131
+ _step;
1132
+ try {
1133
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1134
+ var ns = _step.value;
1135
+ if (ns[0] === '-') {
1136
+ createDebug.skips.push(ns.slice(1));
1137
+ } else {
1138
+ createDebug.names.push(ns);
1139
+ }
1140
+ }
1141
+ } catch (err) {
1142
+ _iterator.e(err);
1143
+ } finally {
1144
+ _iterator.f();
1145
+ }
1146
+ }
1147
+
1148
+ /**
1149
+ * Checks if the given string matches a namespace template, honoring
1150
+ * asterisks as wildcards.
1151
+ *
1152
+ * @param {String} search
1153
+ * @param {String} template
1154
+ * @return {Boolean}
1155
+ */
1156
+ function matchesTemplate(search, template) {
1157
+ var searchIndex = 0;
1158
+ var templateIndex = 0;
1159
+ var starIndex = -1;
1160
+ var matchIndex = 0;
1161
+ while (searchIndex < search.length) {
1162
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
1163
+ // Match character or proceed with wildcard
1164
+ if (template[templateIndex] === '*') {
1165
+ starIndex = templateIndex;
1166
+ matchIndex = searchIndex;
1167
+ templateIndex++; // Skip the '*'
1168
+ } else {
1169
+ searchIndex++;
1170
+ templateIndex++;
1171
+ }
1172
+ } else if (starIndex !== -1) {
1173
+ // eslint-disable-line no-negated-condition
1174
+ // Backtrack to the last '*' and try to match more characters
1175
+ templateIndex = starIndex + 1;
1176
+ matchIndex++;
1177
+ searchIndex = matchIndex;
1178
+ } else {
1179
+ return false; // No match
1180
+ }
1181
+ }
1182
+
1183
+ // Handle trailing '*' in template
1184
+ while (templateIndex < template.length && template[templateIndex] === '*') {
1185
+ templateIndex++;
1186
+ }
1187
+ return templateIndex === template.length;
1188
+ }
1189
+
1190
+ /**
1191
+ * Disable debug output.
1192
+ *
1193
+ * @return {String} namespaces
1194
+ * @api public
1195
+ */
1196
+ function disable() {
1197
+ var namespaces = [].concat(_toConsumableArray(createDebug.names), _toConsumableArray(createDebug.skips.map(function (namespace) {
1198
+ return '-' + namespace;
1199
+ }))).join(',');
1200
+ createDebug.enable('');
1201
+ return namespaces;
1202
+ }
1203
+
1204
+ /**
1205
+ * Returns true if the given mode name is enabled, false otherwise.
1206
+ *
1207
+ * @param {String} name
1208
+ * @return {Boolean}
1209
+ * @api public
1210
+ */
1211
+ function enabled(name) {
1212
+ var _iterator2 = _createForOfIteratorHelper(createDebug.skips),
1213
+ _step2;
1214
+ try {
1215
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1216
+ var skip = _step2.value;
1217
+ if (matchesTemplate(name, skip)) {
1218
+ return false;
1219
+ }
1220
+ }
1221
+ } catch (err) {
1222
+ _iterator2.e(err);
1223
+ } finally {
1224
+ _iterator2.f();
1225
+ }
1226
+ var _iterator3 = _createForOfIteratorHelper(createDebug.names),
1227
+ _step3;
1228
+ try {
1229
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1230
+ var ns = _step3.value;
1231
+ if (matchesTemplate(name, ns)) {
1232
+ return true;
1233
+ }
1234
+ }
1235
+ } catch (err) {
1236
+ _iterator3.e(err);
1237
+ } finally {
1238
+ _iterator3.f();
1239
+ }
1240
+ return false;
1241
+ }
1242
+
1243
+ /**
1244
+ * Coerce `val`.
1245
+ *
1246
+ * @param {Mixed} val
1247
+ * @return {Mixed}
1248
+ * @api private
1249
+ */
1250
+ function coerce(val) {
1251
+ if (val instanceof Error) {
1252
+ return val.stack || val.message;
1253
+ }
1254
+ return val;
1255
+ }
1256
+
1257
+ /**
1258
+ * XXX DO NOT USE. This is a temporary stub function.
1259
+ * XXX It WILL be removed in the next major release.
1260
+ */
1261
+ function destroy() {
1262
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1263
+ }
1264
+ createDebug.enable(createDebug.load());
1265
+ return createDebug;
1266
+ }
1267
+ var common = setup;
1268
+
1269
+ /* eslint-env browser */
1270
+ browser.exports;
1271
+ (function (module, exports) {
1272
+ /**
1273
+ * This is the web browser implementation of `debug()`.
1274
+ */
1275
+
1276
+ exports.formatArgs = formatArgs;
1277
+ exports.save = save;
1278
+ exports.load = load;
1279
+ exports.useColors = useColors;
1280
+ exports.storage = localstorage();
1281
+ exports.destroy = function () {
1282
+ var warned = false;
1283
+ return function () {
1284
+ if (!warned) {
1285
+ warned = true;
1286
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1287
+ }
1288
+ };
1289
+ }();
1290
+
1291
+ /**
1292
+ * Colors.
1293
+ */
1294
+
1295
+ exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
1296
+
1297
+ /**
1298
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
1299
+ * and the Firebug extension (any Firefox version) are known
1300
+ * to support "%c" CSS customizations.
1301
+ *
1302
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
1303
+ */
1304
+
1305
+ // eslint-disable-next-line complexity
1306
+ function useColors() {
1307
+ // NB: In an Electron preload script, document will be defined but not fully
1308
+ // initialized. Since we know we're in Chrome, we'll just detect this case
1309
+ // explicitly
1310
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
1311
+ return true;
1312
+ }
1313
+
1314
+ // Internet Explorer and Edge do not support colors.
1315
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1316
+ return false;
1317
+ }
1318
+ var m;
1319
+
1320
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
1321
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
1322
+ // eslint-disable-next-line no-return-assign
1323
+ return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
1324
+ // Is firebug? http://stackoverflow.com/a/398120/376773
1325
+ typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
1326
+ // Is firefox >= v31?
1327
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1328
+ typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 ||
1329
+ // Double check webkit in userAgent just in case we are in a worker
1330
+ typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
1331
+ }
1332
+
1333
+ /**
1334
+ * Colorize log arguments if enabled.
1335
+ *
1336
+ * @api public
1337
+ */
1338
+
1339
+ function formatArgs(args) {
1340
+ args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
1341
+ if (!this.useColors) {
1342
+ return;
1343
+ }
1344
+ var c = 'color: ' + this.color;
1345
+ args.splice(1, 0, c, 'color: inherit');
1346
+
1347
+ // The final "%c" is somewhat tricky, because there could be other
1348
+ // arguments passed either before or after the %c, so we need to
1349
+ // figure out the correct index to insert the CSS into
1350
+ var index = 0;
1351
+ var lastC = 0;
1352
+ args[0].replace(/%[a-zA-Z%]/g, function (match) {
1353
+ if (match === '%%') {
1354
+ return;
1355
+ }
1356
+ index++;
1357
+ if (match === '%c') {
1358
+ // We only are interested in the *last* %c
1359
+ // (the user may have provided their own)
1360
+ lastC = index;
1361
+ }
1362
+ });
1363
+ args.splice(lastC, 0, c);
1364
+ }
1365
+
1366
+ /**
1367
+ * Invokes `console.debug()` when available.
1368
+ * No-op when `console.debug` is not a "function".
1369
+ * If `console.debug` is not available, falls back
1370
+ * to `console.log`.
1371
+ *
1372
+ * @api public
1373
+ */
1374
+ exports.log = console.debug || console.log || function () {};
1375
+
1376
+ /**
1377
+ * Save `namespaces`.
1378
+ *
1379
+ * @param {String} namespaces
1380
+ * @api private
1381
+ */
1382
+ function save(namespaces) {
1383
+ try {
1384
+ if (namespaces) {
1385
+ exports.storage.setItem('debug', namespaces);
1386
+ } else {
1387
+ exports.storage.removeItem('debug');
1388
+ }
1389
+ } catch (error) {
1390
+ // Swallow
1391
+ // XXX (@Qix-) should we be logging these?
1392
+ }
1393
+ }
1394
+
1395
+ /**
1396
+ * Load `namespaces`.
1397
+ *
1398
+ * @return {String} returns the previously persisted debug modes
1399
+ * @api private
1400
+ */
1401
+ function load() {
1402
+ var r;
1403
+ try {
1404
+ r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG');
1405
+ } catch (error) {
1406
+ // Swallow
1407
+ // XXX (@Qix-) should we be logging these?
1408
+ }
1409
+
1410
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
1411
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
1412
+ r = process.env.DEBUG;
1413
+ }
1414
+ return r;
1415
+ }
1416
+
1417
+ /**
1418
+ * Localstorage attempts to return the localstorage.
1419
+ *
1420
+ * This is necessary because safari throws
1421
+ * when a user disables cookies/localstorage
1422
+ * and you attempt to access it.
1423
+ *
1424
+ * @return {LocalStorage}
1425
+ * @api private
1426
+ */
1427
+
1428
+ function localstorage() {
1429
+ try {
1430
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
1431
+ // The Browser also has localStorage in the global context.
1432
+ return localStorage;
1433
+ } catch (error) {
1434
+ // Swallow
1435
+ // XXX (@Qix-) should we be logging these?
1436
+ }
1437
+ }
1438
+ module.exports = common(exports);
1439
+ var formatters = module.exports.formatters;
1440
+
1441
+ /**
1442
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
1443
+ */
1444
+
1445
+ formatters.j = function (v) {
1446
+ try {
1447
+ return JSON.stringify(v);
1448
+ } catch (error) {
1449
+ return '[UnexpectedJSONParseError]: ' + error.message;
1450
+ }
1451
+ };
1452
+ })(browser, browser.exports);
1453
+ var browserExports = browser.exports;
1454
+ var debugModule = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
1455
+
1456
+ var debug$5 = debugModule("engine.io-client:transport"); // debug()
1457
+ var TransportError = /*#__PURE__*/function (_Error) {
1458
+ function TransportError(reason, description, context) {
1459
+ var _this;
1460
+ _this = _Error.call(this, reason) || this;
1461
+ _this.description = description;
1462
+ _this.context = context;
1463
+ _this.type = "TransportError";
1464
+ return _this;
1465
+ }
1466
+ _inheritsLoose(TransportError, _Error);
1467
+ return TransportError;
1468
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
1469
+ var Transport = /*#__PURE__*/function (_Emitter) {
1470
+ /**
1471
+ * Transport abstract constructor.
1472
+ *
1473
+ * @param {Object} opts - options
1474
+ * @protected
1475
+ */
1476
+ function Transport(opts) {
1477
+ var _this2;
1478
+ _this2 = _Emitter.call(this) || this;
1479
+ _this2.writable = false;
1480
+ installTimerFunctions(_this2, opts);
1481
+ _this2.opts = opts;
1482
+ _this2.query = opts.query;
1483
+ _this2.socket = opts.socket;
1484
+ _this2.supportsBinary = !opts.forceBase64;
1485
+ return _this2;
1486
+ }
1487
+ /**
1488
+ * Emits an error.
1489
+ *
1490
+ * @param {String} reason
1491
+ * @param description
1492
+ * @param context - the error context
1493
+ * @return {Transport} for chaining
1494
+ * @protected
1495
+ */
1496
+ _inheritsLoose(Transport, _Emitter);
1497
+ var _proto = Transport.prototype;
1498
+ _proto.onError = function onError(reason, description, context) {
1499
+ _Emitter.prototype.emitReserved.call(this, "error", new TransportError(reason, description, context));
1500
+ return this;
1501
+ }
1502
+ /**
1503
+ * Opens the transport.
1504
+ */;
1505
+ _proto.open = function open() {
1506
+ this.readyState = "opening";
1507
+ this.doOpen();
1508
+ return this;
1509
+ }
1510
+ /**
1511
+ * Closes the transport.
1512
+ */;
1513
+ _proto.close = function close() {
1514
+ if (this.readyState === "opening" || this.readyState === "open") {
1515
+ this.doClose();
1516
+ this.onClose();
1517
+ }
1518
+ return this;
1519
+ }
1520
+ /**
1521
+ * Sends multiple packets.
1522
+ *
1523
+ * @param {Array} packets
1524
+ */;
1525
+ _proto.send = function send(packets) {
1526
+ if (this.readyState === "open") {
1527
+ this.write(packets);
1528
+ } else {
1529
+ // this might happen if the transport was silently closed in the beforeunload event handler
1530
+ debug$5("transport is not open, discarding packets");
1531
+ }
1532
+ }
1533
+ /**
1534
+ * Called upon open
1535
+ *
1536
+ * @protected
1537
+ */;
1538
+ _proto.onOpen = function onOpen() {
1539
+ this.readyState = "open";
1540
+ this.writable = true;
1541
+ _Emitter.prototype.emitReserved.call(this, "open");
1542
+ }
1543
+ /**
1544
+ * Called with data.
1545
+ *
1546
+ * @param {String} data
1547
+ * @protected
1548
+ */;
1549
+ _proto.onData = function onData(data) {
1550
+ var packet = decodePacket(data, this.socket.binaryType);
1551
+ this.onPacket(packet);
1552
+ }
1553
+ /**
1554
+ * Called with a decoded packet.
1555
+ *
1556
+ * @protected
1557
+ */;
1558
+ _proto.onPacket = function onPacket(packet) {
1559
+ _Emitter.prototype.emitReserved.call(this, "packet", packet);
1560
+ }
1561
+ /**
1562
+ * Called upon close.
1563
+ *
1564
+ * @protected
1565
+ */;
1566
+ _proto.onClose = function onClose(details) {
1567
+ this.readyState = "closed";
1568
+ _Emitter.prototype.emitReserved.call(this, "close", details);
1569
+ }
1570
+ /**
1571
+ * Pauses the transport, in order not to lose packets during an upgrade.
1572
+ *
1573
+ * @param onPause
1574
+ */;
1575
+ _proto.pause = function pause(onPause) {};
1576
+ _proto.createUri = function createUri(schema) {
1577
+ var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1578
+ return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
1579
+ };
1580
+ _proto._hostname = function _hostname() {
1581
+ var hostname = this.opts.hostname;
1582
+ return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
1583
+ };
1584
+ _proto._port = function _port() {
1585
+ if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
1586
+ return ":" + this.opts.port;
1587
+ } else {
1588
+ return "";
1589
+ }
1590
+ };
1591
+ _proto._query = function _query(query) {
1592
+ var encodedQuery = encode(query);
1593
+ return encodedQuery.length ? "?" + encodedQuery : "";
1594
+ };
1595
+ return Transport;
1596
+ }(Emitter);
1597
+
1598
+ var debug$4 = debugModule("engine.io-client:polling"); // debug()
1599
+ var Polling = /*#__PURE__*/function (_Transport) {
1600
+ function Polling() {
1601
+ var _this;
1602
+ _this = _Transport.apply(this, arguments) || this;
1603
+ _this._polling = false;
1604
+ return _this;
1605
+ }
1606
+ _inheritsLoose(Polling, _Transport);
1607
+ var _proto = Polling.prototype;
1608
+ /**
1609
+ * Opens the socket (triggers polling). We write a PING message to determine
1610
+ * when the transport is open.
1611
+ *
1612
+ * @protected
1613
+ */
1614
+ _proto.doOpen = function doOpen() {
1615
+ this._poll();
1616
+ }
1617
+ /**
1618
+ * Pauses polling.
1619
+ *
1620
+ * @param {Function} onPause - callback upon buffers are flushed and transport is paused
1621
+ * @package
1622
+ */;
1623
+ _proto.pause = function pause(onPause) {
1624
+ var _this2 = this;
1625
+ this.readyState = "pausing";
1626
+ var pause = function pause() {
1627
+ debug$4("paused");
1628
+ _this2.readyState = "paused";
1629
+ onPause();
1630
+ };
1631
+ if (this._polling || !this.writable) {
1632
+ var total = 0;
1633
+ if (this._polling) {
1634
+ debug$4("we are currently polling - waiting to pause");
1635
+ total++;
1636
+ this.once("pollComplete", function () {
1637
+ debug$4("pre-pause polling complete");
1638
+ --total || pause();
1639
+ });
1640
+ }
1641
+ if (!this.writable) {
1642
+ debug$4("we are currently writing - waiting to pause");
1643
+ total++;
1644
+ this.once("drain", function () {
1645
+ debug$4("pre-pause writing complete");
1646
+ --total || pause();
1647
+ });
1648
+ }
1649
+ } else {
1650
+ pause();
1651
+ }
1652
+ }
1653
+ /**
1654
+ * Starts polling cycle.
1655
+ *
1656
+ * @private
1657
+ */;
1658
+ _proto._poll = function _poll() {
1659
+ debug$4("polling");
1660
+ this._polling = true;
1661
+ this.doPoll();
1662
+ this.emitReserved("poll");
1663
+ }
1664
+ /**
1665
+ * Overloads onData to detect payloads.
1666
+ *
1667
+ * @protected
1668
+ */;
1669
+ _proto.onData = function onData(data) {
1670
+ var _this3 = this;
1671
+ debug$4("polling got data %s", data);
1672
+ var callback = function callback(packet) {
1673
+ // if its the first message we consider the transport open
1674
+ if ("opening" === _this3.readyState && packet.type === "open") {
1675
+ _this3.onOpen();
1676
+ }
1677
+ // if its a close packet, we close the ongoing requests
1678
+ if ("close" === packet.type) {
1679
+ _this3.onClose({
1680
+ description: "transport closed by the server"
1681
+ });
1682
+ return false;
1683
+ }
1684
+ // otherwise bypass onData and handle the message
1685
+ _this3.onPacket(packet);
1686
+ };
1687
+ // decode payload
1688
+ decodePayload(data, this.socket.binaryType).forEach(callback);
1689
+ // if an event did not trigger closing
1690
+ if ("closed" !== this.readyState) {
1691
+ // if we got data we're not polling
1692
+ this._polling = false;
1693
+ this.emitReserved("pollComplete");
1694
+ if ("open" === this.readyState) {
1695
+ this._poll();
1696
+ } else {
1697
+ debug$4('ignoring poll - transport state "%s"', this.readyState);
1698
+ }
1699
+ }
1700
+ }
1701
+ /**
1702
+ * For polling, send a close packet.
1703
+ *
1704
+ * @protected
1705
+ */;
1706
+ _proto.doClose = function doClose() {
1707
+ var _this4 = this;
1708
+ var close = function close() {
1709
+ debug$4("writing close packet");
1710
+ _this4.write([{
1711
+ type: "close"
1712
+ }]);
1713
+ };
1714
+ if ("open" === this.readyState) {
1715
+ debug$4("transport open - closing");
1716
+ close();
1717
+ } else {
1718
+ // in case we're trying to close while
1719
+ // handshaking is in progress (GH-164)
1720
+ debug$4("transport not open - deferring close");
1721
+ this.once("open", close);
1722
+ }
1723
+ }
1724
+ /**
1725
+ * Writes a packets payload.
1726
+ *
1727
+ * @param {Array} packets - data packets
1728
+ * @protected
1729
+ */;
1730
+ _proto.write = function write(packets) {
1731
+ var _this5 = this;
1732
+ this.writable = false;
1733
+ encodePayload(packets, function (data) {
1734
+ _this5.doWrite(data, function () {
1735
+ _this5.writable = true;
1736
+ _this5.emitReserved("drain");
1737
+ });
1738
+ });
1739
+ }
1740
+ /**
1741
+ * Generates uri for connection.
1742
+ *
1743
+ * @private
1744
+ */;
1745
+ _proto.uri = function uri() {
1746
+ var schema = this.opts.secure ? "https" : "http";
1747
+ var query = this.query || {};
1748
+ // cache busting is forced
1749
+ if (false !== this.opts.timestampRequests) {
1750
+ query[this.opts.timestampParam] = randomString();
1751
+ }
1752
+ if (!this.supportsBinary && !query.sid) {
1753
+ query.b64 = 1;
1754
+ }
1755
+ return this.createUri(schema, query);
1756
+ };
1757
+ return _createClass(Polling, [{
1758
+ key: "name",
1759
+ get: function get() {
1760
+ return "polling";
1761
+ }
1762
+ }]);
1763
+ }(Transport);
1764
+
1765
+ // imported from https://github.com/component/has-cors
1766
+ var value = false;
1767
+ try {
1768
+ value = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
1769
+ } catch (err) {
1770
+ // if XMLHttp support is disabled in IE then it will throw
1771
+ // when trying to create
1772
+ }
1773
+ var hasCORS = value;
1774
+
1775
+ var debug$3 = debugModule("engine.io-client:polling"); // debug()
1776
+ function empty() {}
1777
+ var BaseXHR = /*#__PURE__*/function (_Polling) {
1778
+ /**
1779
+ * XHR Polling constructor.
1780
+ *
1781
+ * @param {Object} opts
1782
+ * @package
1783
+ */
1784
+ function BaseXHR(opts) {
1785
+ var _this;
1786
+ _this = _Polling.call(this, opts) || this;
1787
+ if (typeof location !== "undefined") {
1788
+ var isSSL = "https:" === location.protocol;
1789
+ var port = location.port;
1790
+ // some user agents have empty `location.port`
1791
+ if (!port) {
1792
+ port = isSSL ? "443" : "80";
1793
+ }
1794
+ _this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
1795
+ }
1796
+ return _this;
1797
+ }
1798
+ /**
1799
+ * Sends data.
1800
+ *
1801
+ * @param {String} data - data to send.
1802
+ * @param {Function} fn - called upon flush.
1803
+ * @private
1804
+ */
1805
+ _inheritsLoose(BaseXHR, _Polling);
1806
+ var _proto = BaseXHR.prototype;
1807
+ _proto.doWrite = function doWrite(data, fn) {
1808
+ var _this2 = this;
1809
+ var req = this.request({
1810
+ method: "POST",
1811
+ data: data
1812
+ });
1813
+ req.on("success", fn);
1814
+ req.on("error", function (xhrStatus, context) {
1815
+ _this2.onError("xhr post error", xhrStatus, context);
1816
+ });
1817
+ }
1818
+ /**
1819
+ * Starts a poll cycle.
1820
+ *
1821
+ * @private
1822
+ */;
1823
+ _proto.doPoll = function doPoll() {
1824
+ var _this3 = this;
1825
+ debug$3("xhr poll");
1826
+ var req = this.request();
1827
+ req.on("data", this.onData.bind(this));
1828
+ req.on("error", function (xhrStatus, context) {
1829
+ _this3.onError("xhr poll error", xhrStatus, context);
1830
+ });
1831
+ this.pollXhr = req;
1832
+ };
1833
+ return BaseXHR;
1834
+ }(Polling);
1835
+ var Request = /*#__PURE__*/function (_Emitter) {
1836
+ /**
1837
+ * Request constructor
1838
+ *
1839
+ * @param {Object} options
1840
+ * @package
1841
+ */
1842
+ function Request(createRequest, uri, opts) {
1843
+ var _this4;
1844
+ _this4 = _Emitter.call(this) || this;
1845
+ _this4.createRequest = createRequest;
1846
+ installTimerFunctions(_this4, opts);
1847
+ _this4._opts = opts;
1848
+ _this4._method = opts.method || "GET";
1849
+ _this4._uri = uri;
1850
+ _this4._data = undefined !== opts.data ? opts.data : null;
1851
+ _this4._create();
1852
+ return _this4;
1853
+ }
1854
+ /**
1855
+ * Creates the XHR object and sends the request.
1856
+ *
1857
+ * @private
1858
+ */
1859
+ _inheritsLoose(Request, _Emitter);
1860
+ var _proto2 = Request.prototype;
1861
+ _proto2._create = function _create() {
1862
+ var _this5 = this;
1863
+ var _a;
1864
+ var opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
1865
+ opts.xdomain = !!this._opts.xd;
1866
+ var xhr = this._xhr = this.createRequest(opts);
1867
+ try {
1868
+ debug$3("xhr open %s: %s", this._method, this._uri);
1869
+ xhr.open(this._method, this._uri, true);
1870
+ try {
1871
+ if (this._opts.extraHeaders) {
1872
+ // @ts-ignore
1873
+ xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
1874
+ for (var i in this._opts.extraHeaders) {
1875
+ if (this._opts.extraHeaders.hasOwnProperty(i)) {
1876
+ xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
1877
+ }
1878
+ }
1879
+ }
1880
+ } catch (e) {}
1881
+ if ("POST" === this._method) {
1882
+ try {
1883
+ xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
1884
+ } catch (e) {}
1885
+ }
1886
+ try {
1887
+ xhr.setRequestHeader("Accept", "*/*");
1888
+ } catch (e) {}
1889
+ (_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
1890
+ // ie6 check
1891
+ if ("withCredentials" in xhr) {
1892
+ xhr.withCredentials = this._opts.withCredentials;
1893
+ }
1894
+ if (this._opts.requestTimeout) {
1895
+ xhr.timeout = this._opts.requestTimeout;
1896
+ }
1897
+ xhr.onreadystatechange = function () {
1898
+ var _a;
1899
+ if (xhr.readyState === 3) {
1900
+ (_a = _this5._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(
1901
+ // @ts-ignore
1902
+ xhr.getResponseHeader("set-cookie"));
1903
+ }
1904
+ if (4 !== xhr.readyState) return;
1905
+ if (200 === xhr.status || 1223 === xhr.status) {
1906
+ _this5._onLoad();
1907
+ } else {
1908
+ // make sure the `error` event handler that's user-set
1909
+ // does not throw in the same tick and gets caught here
1910
+ _this5.setTimeoutFn(function () {
1911
+ _this5._onError(typeof xhr.status === "number" ? xhr.status : 0);
1912
+ }, 0);
1913
+ }
1914
+ };
1915
+ debug$3("xhr data %s", this._data);
1916
+ xhr.send(this._data);
1917
+ } catch (e) {
1918
+ // Need to defer since .create() is called directly from the constructor
1919
+ // and thus the 'error' event can only be only bound *after* this exception
1920
+ // occurs. Therefore, also, we cannot throw here at all.
1921
+ this.setTimeoutFn(function () {
1922
+ _this5._onError(e);
1923
+ }, 0);
1924
+ return;
1925
+ }
1926
+ if (typeof document !== "undefined") {
1927
+ this._index = Request.requestsCount++;
1928
+ Request.requests[this._index] = this;
1929
+ }
1930
+ }
1931
+ /**
1932
+ * Called upon error.
1933
+ *
1934
+ * @private
1935
+ */;
1936
+ _proto2._onError = function _onError(err) {
1937
+ this.emitReserved("error", err, this._xhr);
1938
+ this._cleanup(true);
1939
+ }
1940
+ /**
1941
+ * Cleans up house.
1942
+ *
1943
+ * @private
1944
+ */;
1945
+ _proto2._cleanup = function _cleanup(fromError) {
1946
+ if ("undefined" === typeof this._xhr || null === this._xhr) {
1947
+ return;
1948
+ }
1949
+ this._xhr.onreadystatechange = empty;
1950
+ if (fromError) {
1951
+ try {
1952
+ this._xhr.abort();
1953
+ } catch (e) {}
1954
+ }
1955
+ if (typeof document !== "undefined") {
1956
+ delete Request.requests[this._index];
1957
+ }
1958
+ this._xhr = null;
1959
+ }
1960
+ /**
1961
+ * Called upon load.
1962
+ *
1963
+ * @private
1964
+ */;
1965
+ _proto2._onLoad = function _onLoad() {
1966
+ var data = this._xhr.responseText;
1967
+ if (data !== null) {
1968
+ this.emitReserved("data", data);
1969
+ this.emitReserved("success");
1970
+ this._cleanup();
1971
+ }
1972
+ }
1973
+ /**
1974
+ * Aborts the request.
1975
+ *
1976
+ * @package
1977
+ */;
1978
+ _proto2.abort = function abort() {
1979
+ this._cleanup();
1980
+ };
1981
+ return Request;
1982
+ }(Emitter);
1983
+ Request.requestsCount = 0;
1984
+ Request.requests = {};
1985
+ /**
1986
+ * Aborts pending requests when unloading the window. This is needed to prevent
1987
+ * memory leaks (e.g. when using IE) and to ensure that no spurious error is
1988
+ * emitted.
1989
+ */
1990
+ if (typeof document !== "undefined") {
1991
+ // @ts-ignore
1992
+ if (typeof attachEvent === "function") {
1993
+ // @ts-ignore
1994
+ attachEvent("onunload", unloadHandler);
1995
+ } else if (typeof addEventListener === "function") {
1996
+ var terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
1997
+ addEventListener(terminationEvent, unloadHandler, false);
1998
+ }
1999
+ }
2000
+ function unloadHandler() {
2001
+ for (var i in Request.requests) {
2002
+ if (Request.requests.hasOwnProperty(i)) {
2003
+ Request.requests[i].abort();
2004
+ }
2005
+ }
2006
+ }
2007
+ var hasXHR2 = function () {
2008
+ var xhr = newRequest({
2009
+ xdomain: false
2010
+ });
2011
+ return xhr && xhr.responseType !== null;
2012
+ }();
2013
+ /**
2014
+ * HTTP long-polling based on the built-in `XMLHttpRequest` object.
2015
+ *
2016
+ * Usage: browser
2017
+ *
2018
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
2019
+ */
2020
+ var XHR = /*#__PURE__*/function (_BaseXHR) {
2021
+ function XHR(opts) {
2022
+ var _this6;
2023
+ _this6 = _BaseXHR.call(this, opts) || this;
2024
+ var forceBase64 = opts && opts.forceBase64;
2025
+ _this6.supportsBinary = hasXHR2 && !forceBase64;
2026
+ return _this6;
2027
+ }
2028
+ _inheritsLoose(XHR, _BaseXHR);
2029
+ var _proto3 = XHR.prototype;
2030
+ _proto3.request = function request() {
2031
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2032
+ _extends(opts, {
2033
+ xd: this.xd
2034
+ }, this.opts);
2035
+ return new Request(newRequest, this.uri(), opts);
2036
+ };
2037
+ return XHR;
2038
+ }(BaseXHR);
2039
+ function newRequest(opts) {
2040
+ var xdomain = opts.xdomain;
2041
+ // XMLHttpRequest can be disabled on IE
2042
+ try {
2043
+ if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
2044
+ return new XMLHttpRequest();
2045
+ }
2046
+ } catch (e) {}
2047
+ if (!xdomain) {
2048
+ try {
2049
+ return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
2050
+ } catch (e) {}
2051
+ }
2052
+ }
2053
+
2054
+ var debug$2 = debugModule("engine.io-client:websocket"); // debug()
2055
+ // detect ReactNative environment
2056
+ var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
2057
+ var BaseWS = /*#__PURE__*/function (_Transport) {
2058
+ function BaseWS() {
2059
+ return _Transport.apply(this, arguments) || this;
2060
+ }
2061
+ _inheritsLoose(BaseWS, _Transport);
2062
+ var _proto = BaseWS.prototype;
2063
+ _proto.doOpen = function doOpen() {
2064
+ var uri = this.uri();
2065
+ var protocols = this.opts.protocols;
2066
+ // React Native only supports the 'headers' option, and will print a warning if anything else is passed
2067
+ var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
2068
+ if (this.opts.extraHeaders) {
2069
+ opts.headers = this.opts.extraHeaders;
2070
+ }
2071
+ try {
2072
+ this.ws = this.createSocket(uri, protocols, opts);
2073
+ } catch (err) {
2074
+ return this.emitReserved("error", err);
2075
+ }
2076
+ this.ws.binaryType = this.socket.binaryType;
2077
+ this.addEventListeners();
2078
+ }
2079
+ /**
2080
+ * Adds event listeners to the socket
2081
+ *
2082
+ * @private
2083
+ */;
2084
+ _proto.addEventListeners = function addEventListeners() {
2085
+ var _this = this;
2086
+ this.ws.onopen = function () {
2087
+ if (_this.opts.autoUnref) {
2088
+ _this.ws._socket.unref();
2089
+ }
2090
+ _this.onOpen();
2091
+ };
2092
+ this.ws.onclose = function (closeEvent) {
2093
+ return _this.onClose({
2094
+ description: "websocket connection closed",
2095
+ context: closeEvent
2096
+ });
2097
+ };
2098
+ this.ws.onmessage = function (ev) {
2099
+ return _this.onData(ev.data);
2100
+ };
2101
+ this.ws.onerror = function (e) {
2102
+ return _this.onError("websocket error", e);
2103
+ };
2104
+ };
2105
+ _proto.write = function write(packets) {
2106
+ var _this2 = this;
2107
+ this.writable = false;
2108
+ // encodePacket efficient as it uses WS framing
2109
+ // no need for encodePayload
2110
+ var _loop = function _loop() {
2111
+ var packet = packets[i];
2112
+ var lastPacket = i === packets.length - 1;
2113
+ encodePacket(packet, _this2.supportsBinary, function (data) {
2114
+ // Sometimes the websocket has already been closed but the browser didn't
2115
+ // have a chance of informing us about it yet, in that case send will
2116
+ // throw an error
2117
+ try {
2118
+ _this2.doWrite(packet, data);
2119
+ } catch (e) {
2120
+ debug$2("websocket closed before onclose event");
2121
+ }
2122
+ if (lastPacket) {
2123
+ // fake drain
2124
+ // defer to next tick to allow Socket to clear writeBuffer
2125
+ nextTick(function () {
2126
+ _this2.writable = true;
2127
+ _this2.emitReserved("drain");
2128
+ }, _this2.setTimeoutFn);
2129
+ }
2130
+ });
2131
+ };
2132
+ for (var i = 0; i < packets.length; i++) {
2133
+ _loop();
2134
+ }
2135
+ };
2136
+ _proto.doClose = function doClose() {
2137
+ if (typeof this.ws !== "undefined") {
2138
+ this.ws.onerror = function () {};
2139
+ this.ws.close();
2140
+ this.ws = null;
2141
+ }
2142
+ }
2143
+ /**
2144
+ * Generates uri for connection.
2145
+ *
2146
+ * @private
2147
+ */;
2148
+ _proto.uri = function uri() {
2149
+ var schema = this.opts.secure ? "wss" : "ws";
2150
+ var query = this.query || {};
2151
+ // append timestamp to URI
2152
+ if (this.opts.timestampRequests) {
2153
+ query[this.opts.timestampParam] = randomString();
2154
+ }
2155
+ // communicate binary support capabilities
2156
+ if (!this.supportsBinary) {
2157
+ query.b64 = 1;
2158
+ }
2159
+ return this.createUri(schema, query);
2160
+ };
2161
+ return _createClass(BaseWS, [{
2162
+ key: "name",
2163
+ get: function get() {
2164
+ return "websocket";
2165
+ }
2166
+ }]);
2167
+ }(Transport);
2168
+ var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
2169
+ /**
2170
+ * WebSocket transport based on the built-in `WebSocket` object.
2171
+ *
2172
+ * Usage: browser, Node.js (since v21), Deno, Bun
2173
+ *
2174
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
2175
+ * @see https://caniuse.com/mdn-api_websocket
2176
+ * @see https://nodejs.org/api/globals.html#websocket
2177
+ */
2178
+ var WS = /*#__PURE__*/function (_BaseWS) {
2179
+ function WS() {
2180
+ return _BaseWS.apply(this, arguments) || this;
2181
+ }
2182
+ _inheritsLoose(WS, _BaseWS);
2183
+ var _proto2 = WS.prototype;
2184
+ _proto2.createSocket = function createSocket(uri, protocols, opts) {
2185
+ return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts);
2186
+ };
2187
+ _proto2.doWrite = function doWrite(_packet, data) {
2188
+ this.ws.send(data);
2189
+ };
2190
+ return WS;
2191
+ }(BaseWS);
2192
+
2193
+ var debug$1 = debugModule("engine.io-client:webtransport"); // debug()
2194
+ /**
2195
+ * WebTransport transport based on the built-in `WebTransport` object.
2196
+ *
2197
+ * Usage: browser, Node.js (with the `@fails-components/webtransport` package)
2198
+ *
2199
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
2200
+ * @see https://caniuse.com/webtransport
2201
+ */
2202
+ var WT = /*#__PURE__*/function (_Transport) {
2203
+ function WT() {
2204
+ return _Transport.apply(this, arguments) || this;
2205
+ }
2206
+ _inheritsLoose(WT, _Transport);
2207
+ var _proto = WT.prototype;
2208
+ _proto.doOpen = function doOpen() {
2209
+ var _this = this;
2210
+ try {
2211
+ // @ts-ignore
2212
+ this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
2213
+ } catch (err) {
2214
+ return this.emitReserved("error", err);
2215
+ }
2216
+ this._transport.closed.then(function () {
2217
+ debug$1("transport closed gracefully");
2218
+ _this.onClose();
2219
+ })["catch"](function (err) {
2220
+ debug$1("transport closed due to %s", err);
2221
+ _this.onError("webtransport error", err);
2222
+ });
2223
+ // note: we could have used async/await, but that would require some additional polyfills
2224
+ this._transport.ready.then(function () {
2225
+ _this._transport.createBidirectionalStream().then(function (stream) {
2226
+ var decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, _this.socket.binaryType);
2227
+ var reader = stream.readable.pipeThrough(decoderStream).getReader();
2228
+ var encoderStream = createPacketEncoderStream();
2229
+ encoderStream.readable.pipeTo(stream.writable);
2230
+ _this._writer = encoderStream.writable.getWriter();
2231
+ var read = function read() {
2232
+ reader.read().then(function (_ref) {
2233
+ var done = _ref.done,
2234
+ value = _ref.value;
2235
+ if (done) {
2236
+ debug$1("session is closed");
2237
+ return;
2238
+ }
2239
+ debug$1("received chunk: %o", value);
2240
+ _this.onPacket(value);
2241
+ read();
2242
+ })["catch"](function (err) {
2243
+ debug$1("an error occurred while reading: %s", err);
2244
+ });
2245
+ };
2246
+ read();
2247
+ var packet = {
2248
+ type: "open"
2249
+ };
2250
+ if (_this.query.sid) {
2251
+ packet.data = "{\"sid\":\"".concat(_this.query.sid, "\"}");
2252
+ }
2253
+ _this._writer.write(packet).then(function () {
2254
+ return _this.onOpen();
2255
+ });
2256
+ });
2257
+ });
2258
+ };
2259
+ _proto.write = function write(packets) {
2260
+ var _this2 = this;
2261
+ this.writable = false;
2262
+ var _loop = function _loop() {
2263
+ var packet = packets[i];
2264
+ var lastPacket = i === packets.length - 1;
2265
+ _this2._writer.write(packet).then(function () {
2266
+ if (lastPacket) {
2267
+ nextTick(function () {
2268
+ _this2.writable = true;
2269
+ _this2.emitReserved("drain");
2270
+ }, _this2.setTimeoutFn);
2271
+ }
2272
+ });
2273
+ };
2274
+ for (var i = 0; i < packets.length; i++) {
2275
+ _loop();
2276
+ }
2277
+ };
2278
+ _proto.doClose = function doClose() {
2279
+ var _a;
2280
+ (_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
2281
+ };
2282
+ return _createClass(WT, [{
2283
+ key: "name",
2284
+ get: function get() {
2285
+ return "webtransport";
2286
+ }
2287
+ }]);
2288
+ }(Transport);
2289
+
2290
+ var transports = {
2291
+ websocket: WS,
2292
+ webtransport: WT,
2293
+ polling: XHR
2294
+ };
2295
+
2296
+ // imported from https://github.com/galkn/parseuri
2297
+ /**
2298
+ * Parses a URI
2299
+ *
2300
+ * Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
2301
+ *
2302
+ * See:
2303
+ * - https://developer.mozilla.org/en-US/docs/Web/API/URL
2304
+ * - https://caniuse.com/url
2305
+ * - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
2306
+ *
2307
+ * History of the parse() method:
2308
+ * - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
2309
+ * - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
2310
+ * - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
2311
+ *
2312
+ * @author Steven Levithan <stevenlevithan.com> (MIT license)
2313
+ * @api private
2314
+ */
2315
+ var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
2316
+ var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
2317
+ function parse(str) {
2318
+ if (str.length > 8000) {
2319
+ throw "URI too long";
2320
+ }
2321
+ var src = str,
2322
+ b = str.indexOf('['),
2323
+ e = str.indexOf(']');
2324
+ if (b != -1 && e != -1) {
2325
+ str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
2326
+ }
2327
+ var m = re.exec(str || ''),
2328
+ uri = {},
2329
+ i = 14;
2330
+ while (i--) {
2331
+ uri[parts[i]] = m[i] || '';
2332
+ }
2333
+ if (b != -1 && e != -1) {
2334
+ uri.source = src;
2335
+ uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
2336
+ uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
2337
+ uri.ipv6uri = true;
2338
+ }
2339
+ uri.pathNames = pathNames(uri, uri['path']);
2340
+ uri.queryKey = queryKey(uri, uri['query']);
2341
+ return uri;
2342
+ }
2343
+ function pathNames(obj, path) {
2344
+ var regx = /\/{2,9}/g,
2345
+ names = path.replace(regx, "/").split("/");
2346
+ if (path.slice(0, 1) == '/' || path.length === 0) {
2347
+ names.splice(0, 1);
2348
+ }
2349
+ if (path.slice(-1) == '/') {
2350
+ names.splice(names.length - 1, 1);
2351
+ }
2352
+ return names;
2353
+ }
2354
+ function queryKey(uri, query) {
2355
+ var data = {};
2356
+ query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
2357
+ if ($1) {
2358
+ data[$1] = $2;
2359
+ }
2360
+ });
2361
+ return data;
2362
+ }
2363
+
2364
+ var debug = debugModule("engine.io-client:socket"); // debug()
2365
+ var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
2366
+ var OFFLINE_EVENT_LISTENERS = [];
2367
+ if (withEventListeners) {
2368
+ // within a ServiceWorker, any event handler for the 'offline' event must be added on the initial evaluation of the
2369
+ // script, so we create one single event listener here which will forward the event to the socket instances
2370
+ addEventListener("offline", function () {
2371
+ debug("closing %d connection(s) because the network was lost", OFFLINE_EVENT_LISTENERS.length);
2372
+ OFFLINE_EVENT_LISTENERS.forEach(function (listener) {
2373
+ return listener();
2374
+ });
2375
+ }, false);
2376
+ }
2377
+ /**
2378
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
2379
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
2380
+ *
2381
+ * This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
2382
+ * successfully establishes the connection.
2383
+ *
2384
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
2385
+ *
2386
+ * @example
2387
+ * import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
2388
+ *
2389
+ * const socket = new SocketWithoutUpgrade({
2390
+ * transports: [WebSocket]
2391
+ * });
2392
+ *
2393
+ * socket.on("open", () => {
2394
+ * socket.send("hello");
2395
+ * });
2396
+ *
2397
+ * @see SocketWithUpgrade
2398
+ * @see Socket
2399
+ */
2400
+ var SocketWithoutUpgrade = /*#__PURE__*/function (_Emitter) {
2401
+ /**
2402
+ * Socket constructor.
2403
+ *
2404
+ * @param {String|Object} uri - uri or options
2405
+ * @param {Object} opts - options
2406
+ */
2407
+ function SocketWithoutUpgrade(uri, opts) {
2408
+ var _this;
2409
+ _this = _Emitter.call(this) || this;
2410
+ _this.binaryType = defaultBinaryType;
2411
+ _this.writeBuffer = [];
2412
+ _this._prevBufferLen = 0;
2413
+ _this._pingInterval = -1;
2414
+ _this._pingTimeout = -1;
2415
+ _this._maxPayload = -1;
2416
+ /**
2417
+ * The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
2418
+ * callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
2419
+ */
2420
+ _this._pingTimeoutTime = Infinity;
2421
+ if (uri && "object" === _typeof(uri)) {
2422
+ opts = uri;
2423
+ uri = null;
2424
+ }
2425
+ if (uri) {
2426
+ var parsedUri = parse(uri);
2427
+ opts.hostname = parsedUri.host;
2428
+ opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
2429
+ opts.port = parsedUri.port;
2430
+ if (parsedUri.query) opts.query = parsedUri.query;
2431
+ } else if (opts.host) {
2432
+ opts.hostname = parse(opts.host).host;
2433
+ }
2434
+ installTimerFunctions(_this, opts);
2435
+ _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
2436
+ if (opts.hostname && !opts.port) {
2437
+ // if no port is specified manually, use the protocol default
2438
+ opts.port = _this.secure ? "443" : "80";
2439
+ }
2440
+ _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
2441
+ _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
2442
+ _this.transports = [];
2443
+ _this._transportsByName = {};
2444
+ opts.transports.forEach(function (t) {
2445
+ var transportName = t.prototype.name;
2446
+ _this.transports.push(transportName);
2447
+ _this._transportsByName[transportName] = t;
2448
+ });
2449
+ _this.opts = _extends({
2450
+ path: "/engine.io",
2451
+ agent: false,
2452
+ withCredentials: false,
2453
+ upgrade: true,
2454
+ timestampParam: "t",
2455
+ rememberUpgrade: false,
2456
+ addTrailingSlash: true,
2457
+ rejectUnauthorized: true,
2458
+ perMessageDeflate: {
2459
+ threshold: 1024
2460
+ },
2461
+ transportOptions: {},
2462
+ closeOnBeforeunload: false
2463
+ }, opts);
2464
+ _this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : "");
2465
+ if (typeof _this.opts.query === "string") {
2466
+ _this.opts.query = decode(_this.opts.query);
2467
+ }
2468
+ if (withEventListeners) {
2469
+ if (_this.opts.closeOnBeforeunload) {
2470
+ // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
2471
+ // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
2472
+ // closed/reloaded)
2473
+ _this._beforeunloadEventListener = function () {
2474
+ if (_this.transport) {
2475
+ // silently close the transport
2476
+ _this.transport.removeAllListeners();
2477
+ _this.transport.close();
2478
+ }
2479
+ };
2480
+ addEventListener("beforeunload", _this._beforeunloadEventListener, false);
2481
+ }
2482
+ if (_this.hostname !== "localhost") {
2483
+ debug("adding listener for the 'offline' event");
2484
+ _this._offlineEventListener = function () {
2485
+ _this._onClose("transport close", {
2486
+ description: "network connection lost"
2487
+ });
2488
+ };
2489
+ OFFLINE_EVENT_LISTENERS.push(_this._offlineEventListener);
2490
+ }
2491
+ }
2492
+ if (_this.opts.withCredentials) {
2493
+ _this._cookieJar = createCookieJar();
2494
+ }
2495
+ _this._open();
2496
+ return _this;
2497
+ }
2498
+ /**
2499
+ * Creates transport of the given type.
2500
+ *
2501
+ * @param {String} name - transport name
2502
+ * @return {Transport}
2503
+ * @private
2504
+ */
2505
+ _inheritsLoose(SocketWithoutUpgrade, _Emitter);
2506
+ var _proto = SocketWithoutUpgrade.prototype;
2507
+ _proto.createTransport = function createTransport(name) {
2508
+ debug('creating transport "%s"', name);
2509
+ var query = _extends({}, this.opts.query);
2510
+ // append engine.io protocol identifier
2511
+ query.EIO = protocol;
2512
+ // transport name
2513
+ query.transport = name;
2514
+ // session id if we already have one
2515
+ if (this.id) query.sid = this.id;
2516
+ var opts = _extends({}, this.opts, {
2517
+ query: query,
2518
+ socket: this,
2519
+ hostname: this.hostname,
2520
+ secure: this.secure,
2521
+ port: this.port
2522
+ }, this.opts.transportOptions[name]);
2523
+ debug("options: %j", opts);
2524
+ return new this._transportsByName[name](opts);
2525
+ }
2526
+ /**
2527
+ * Initializes transport to use and starts probe.
2528
+ *
2529
+ * @private
2530
+ */;
2531
+ _proto._open = function _open() {
2532
+ var _this2 = this;
2533
+ if (this.transports.length === 0) {
2534
+ // Emit error on next tick so it can be listened to
2535
+ this.setTimeoutFn(function () {
2536
+ _this2.emitReserved("error", "No transports available");
2537
+ }, 0);
2538
+ return;
2539
+ }
2540
+ var transportName = this.opts.rememberUpgrade && SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
2541
+ this.readyState = "opening";
2542
+ var transport = this.createTransport(transportName);
2543
+ transport.open();
2544
+ this.setTransport(transport);
2545
+ }
2546
+ /**
2547
+ * Sets the current transport. Disables the existing one (if any).
2548
+ *
2549
+ * @private
2550
+ */;
2551
+ _proto.setTransport = function setTransport(transport) {
2552
+ var _this3 = this;
2553
+ debug("setting transport %s", transport.name);
2554
+ if (this.transport) {
2555
+ debug("clearing existing transport %s", this.transport.name);
2556
+ this.transport.removeAllListeners();
2557
+ }
2558
+ // set up transport
2559
+ this.transport = transport;
2560
+ // set up transport listeners
2561
+ transport.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", function (reason) {
2562
+ return _this3._onClose("transport close", reason);
2563
+ });
2564
+ }
2565
+ /**
2566
+ * Called when connection is deemed open.
2567
+ *
2568
+ * @private
2569
+ */;
2570
+ _proto.onOpen = function onOpen() {
2571
+ debug("socket open");
2572
+ this.readyState = "open";
2573
+ SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name;
2574
+ this.emitReserved("open");
2575
+ this.flush();
2576
+ }
2577
+ /**
2578
+ * Handles a packet.
2579
+ *
2580
+ * @private
2581
+ */;
2582
+ _proto._onPacket = function _onPacket(packet) {
2583
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2584
+ debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
2585
+ this.emitReserved("packet", packet);
2586
+ // Socket is live - any packet counts
2587
+ this.emitReserved("heartbeat");
2588
+ switch (packet.type) {
2589
+ case "open":
2590
+ this.onHandshake(JSON.parse(packet.data));
2591
+ break;
2592
+ case "ping":
2593
+ this._sendPacket("pong");
2594
+ this.emitReserved("ping");
2595
+ this.emitReserved("pong");
2596
+ this._resetPingTimeout();
2597
+ break;
2598
+ case "error":
2599
+ var err = new Error("server error");
2600
+ // @ts-ignore
2601
+ err.code = packet.data;
2602
+ this._onError(err);
2603
+ break;
2604
+ case "message":
2605
+ this.emitReserved("data", packet.data);
2606
+ this.emitReserved("message", packet.data);
2607
+ break;
2608
+ }
2609
+ } else {
2610
+ debug('packet received with socket readyState "%s"', this.readyState);
2611
+ }
2612
+ }
2613
+ /**
2614
+ * Called upon handshake completion.
2615
+ *
2616
+ * @param {Object} data - handshake obj
2617
+ * @private
2618
+ */;
2619
+ _proto.onHandshake = function onHandshake(data) {
2620
+ this.emitReserved("handshake", data);
2621
+ this.id = data.sid;
2622
+ this.transport.query.sid = data.sid;
2623
+ this._pingInterval = data.pingInterval;
2624
+ this._pingTimeout = data.pingTimeout;
2625
+ this._maxPayload = data.maxPayload;
2626
+ this.onOpen();
2627
+ // In case open handler closes socket
2628
+ if ("closed" === this.readyState) return;
2629
+ this._resetPingTimeout();
2630
+ }
2631
+ /**
2632
+ * Sets and resets ping timeout timer based on server pings.
2633
+ *
2634
+ * @private
2635
+ */;
2636
+ _proto._resetPingTimeout = function _resetPingTimeout() {
2637
+ var _this4 = this;
2638
+ this.clearTimeoutFn(this._pingTimeoutTimer);
2639
+ var delay = this._pingInterval + this._pingTimeout;
2640
+ this._pingTimeoutTime = Date.now() + delay;
2641
+ this._pingTimeoutTimer = this.setTimeoutFn(function () {
2642
+ _this4._onClose("ping timeout");
2643
+ }, delay);
2644
+ if (this.opts.autoUnref) {
2645
+ this._pingTimeoutTimer.unref();
2646
+ }
2647
+ }
2648
+ /**
2649
+ * Called on `drain` event
2650
+ *
2651
+ * @private
2652
+ */;
2653
+ _proto._onDrain = function _onDrain() {
2654
+ this.writeBuffer.splice(0, this._prevBufferLen);
2655
+ // setting prevBufferLen = 0 is very important
2656
+ // for example, when upgrading, upgrade packet is sent over,
2657
+ // and a nonzero prevBufferLen could cause problems on `drain`
2658
+ this._prevBufferLen = 0;
2659
+ if (0 === this.writeBuffer.length) {
2660
+ this.emitReserved("drain");
2661
+ } else {
2662
+ this.flush();
2663
+ }
2664
+ }
2665
+ /**
2666
+ * Flush write buffers.
2667
+ *
2668
+ * @private
2669
+ */;
2670
+ _proto.flush = function flush() {
2671
+ if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
2672
+ var packets = this._getWritablePackets();
2673
+ debug("flushing %d packets in socket", packets.length);
2674
+ this.transport.send(packets);
2675
+ // keep track of current length of writeBuffer
2676
+ // splice writeBuffer and callbackBuffer on `drain`
2677
+ this._prevBufferLen = packets.length;
2678
+ this.emitReserved("flush");
2679
+ }
2680
+ }
2681
+ /**
2682
+ * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
2683
+ * long-polling)
2684
+ *
2685
+ * @private
2686
+ */;
2687
+ _proto._getWritablePackets = function _getWritablePackets() {
2688
+ var shouldCheckPayloadSize = this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
2689
+ if (!shouldCheckPayloadSize) {
2690
+ return this.writeBuffer;
2691
+ }
2692
+ var payloadSize = 1; // first packet type
2693
+ for (var i = 0; i < this.writeBuffer.length; i++) {
2694
+ var data = this.writeBuffer[i].data;
2695
+ if (data) {
2696
+ payloadSize += byteLength(data);
2697
+ }
2698
+ if (i > 0 && payloadSize > this._maxPayload) {
2699
+ debug("only send %d out of %d packets", i, this.writeBuffer.length);
2700
+ return this.writeBuffer.slice(0, i);
2701
+ }
2702
+ payloadSize += 2; // separator + packet type
2703
+ }
2704
+ debug("payload size is %d (max: %d)", payloadSize, this._maxPayload);
2705
+ return this.writeBuffer;
2706
+ }
2707
+ /**
2708
+ * Checks whether the heartbeat timer has expired but the socket has not yet been notified.
2709
+ *
2710
+ * Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
2711
+ * `write()` method then the message would not be buffered by the Socket.IO client.
2712
+ *
2713
+ * @return {boolean}
2714
+ * @private
2715
+ */
2716
+ /* private */;
2717
+ _proto._hasPingExpired = function _hasPingExpired() {
2718
+ var _this5 = this;
2719
+ if (!this._pingTimeoutTime) return true;
2720
+ var hasExpired = Date.now() > this._pingTimeoutTime;
2721
+ if (hasExpired) {
2722
+ debug("throttled timer detected, scheduling connection close");
2723
+ this._pingTimeoutTime = 0;
2724
+ nextTick(function () {
2725
+ _this5._onClose("ping timeout");
2726
+ }, this.setTimeoutFn);
2727
+ }
2728
+ return hasExpired;
2729
+ }
2730
+ /**
2731
+ * Sends a message.
2732
+ *
2733
+ * @param {String} msg - message.
2734
+ * @param {Object} options.
2735
+ * @param {Function} fn - callback function.
2736
+ * @return {Socket} for chaining.
2737
+ */;
2738
+ _proto.write = function write(msg, options, fn) {
2739
+ this._sendPacket("message", msg, options, fn);
2740
+ return this;
2741
+ }
2742
+ /**
2743
+ * Sends a message. Alias of {@link Socket#write}.
2744
+ *
2745
+ * @param {String} msg - message.
2746
+ * @param {Object} options.
2747
+ * @param {Function} fn - callback function.
2748
+ * @return {Socket} for chaining.
2749
+ */;
2750
+ _proto.send = function send(msg, options, fn) {
2751
+ this._sendPacket("message", msg, options, fn);
2752
+ return this;
2753
+ }
2754
+ /**
2755
+ * Sends a packet.
2756
+ *
2757
+ * @param {String} type - packet type.
2758
+ * @param {String} data.
2759
+ * @param {Object} options.
2760
+ * @param {Function} fn - callback function.
2761
+ * @private
2762
+ */;
2763
+ _proto._sendPacket = function _sendPacket(type, data, options, fn) {
2764
+ if ("function" === typeof data) {
2765
+ fn = data;
2766
+ data = undefined;
2767
+ }
2768
+ if ("function" === typeof options) {
2769
+ fn = options;
2770
+ options = null;
2771
+ }
2772
+ if ("closing" === this.readyState || "closed" === this.readyState) {
2773
+ return;
2774
+ }
2775
+ options = options || {};
2776
+ options.compress = false !== options.compress;
2777
+ var packet = {
2778
+ type: type,
2779
+ data: data,
2780
+ options: options
2781
+ };
2782
+ this.emitReserved("packetCreate", packet);
2783
+ this.writeBuffer.push(packet);
2784
+ if (fn) this.once("flush", fn);
2785
+ this.flush();
2786
+ }
2787
+ /**
2788
+ * Closes the connection.
2789
+ */;
2790
+ _proto.close = function close() {
2791
+ var _this6 = this;
2792
+ var close = function close() {
2793
+ _this6._onClose("forced close");
2794
+ debug("socket closing - telling transport to close");
2795
+ _this6.transport.close();
2796
+ };
2797
+ var cleanupAndClose = function cleanupAndClose() {
2798
+ _this6.off("upgrade", cleanupAndClose);
2799
+ _this6.off("upgradeError", cleanupAndClose);
2800
+ close();
2801
+ };
2802
+ var waitForUpgrade = function waitForUpgrade() {
2803
+ // wait for upgrade to finish since we can't send packets while pausing a transport
2804
+ _this6.once("upgrade", cleanupAndClose);
2805
+ _this6.once("upgradeError", cleanupAndClose);
2806
+ };
2807
+ if ("opening" === this.readyState || "open" === this.readyState) {
2808
+ this.readyState = "closing";
2809
+ if (this.writeBuffer.length) {
2810
+ this.once("drain", function () {
2811
+ if (_this6.upgrading) {
2812
+ waitForUpgrade();
2813
+ } else {
2814
+ close();
2815
+ }
2816
+ });
2817
+ } else if (this.upgrading) {
2818
+ waitForUpgrade();
2819
+ } else {
2820
+ close();
2821
+ }
2822
+ }
2823
+ return this;
2824
+ }
2825
+ /**
2826
+ * Called upon transport error
2827
+ *
2828
+ * @private
2829
+ */;
2830
+ _proto._onError = function _onError(err) {
2831
+ debug("socket error %j", err);
2832
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
2833
+ if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
2834
+ debug("trying next transport");
2835
+ this.transports.shift();
2836
+ return this._open();
2837
+ }
2838
+ this.emitReserved("error", err);
2839
+ this._onClose("transport error", err);
2840
+ }
2841
+ /**
2842
+ * Called upon transport close.
2843
+ *
2844
+ * @private
2845
+ */;
2846
+ _proto._onClose = function _onClose(reason, description) {
2847
+ if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2848
+ debug('socket close with reason: "%s"', reason);
2849
+ // clear timers
2850
+ this.clearTimeoutFn(this._pingTimeoutTimer);
2851
+ // stop event from firing again for transport
2852
+ this.transport.removeAllListeners("close");
2853
+ // ensure transport won't stay open
2854
+ this.transport.close();
2855
+ // ignore further transport communication
2856
+ this.transport.removeAllListeners();
2857
+ if (withEventListeners) {
2858
+ if (this._beforeunloadEventListener) {
2859
+ removeEventListener("beforeunload", this._beforeunloadEventListener, false);
2860
+ }
2861
+ if (this._offlineEventListener) {
2862
+ var i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
2863
+ if (i !== -1) {
2864
+ debug("removing listener for the 'offline' event");
2865
+ OFFLINE_EVENT_LISTENERS.splice(i, 1);
2866
+ }
2867
+ }
2868
+ }
2869
+ // set ready state
2870
+ this.readyState = "closed";
2871
+ // clear session id
2872
+ this.id = null;
2873
+ // emit close event
2874
+ this.emitReserved("close", reason, description);
2875
+ // clean buffers after, so users can still
2876
+ // grab the buffers on `close` event
2877
+ this.writeBuffer = [];
2878
+ this._prevBufferLen = 0;
2879
+ }
2880
+ };
2881
+ return SocketWithoutUpgrade;
2882
+ }(Emitter);
2883
+ SocketWithoutUpgrade.protocol = protocol;
2884
+ /**
2885
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
2886
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
2887
+ *
2888
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
2889
+ * low-level transport, it will try to upgrade to a better transport.
2890
+ *
2891
+ * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
2892
+ *
2893
+ * @example
2894
+ * import { SocketWithUpgrade, WebSocket } from "engine.io-client";
2895
+ *
2896
+ * const socket = new SocketWithUpgrade({
2897
+ * transports: [WebSocket]
2898
+ * });
2899
+ *
2900
+ * socket.on("open", () => {
2901
+ * socket.send("hello");
2902
+ * });
2903
+ *
2904
+ * @see SocketWithoutUpgrade
2905
+ * @see Socket
2906
+ */
2907
+ var SocketWithUpgrade = /*#__PURE__*/function (_SocketWithoutUpgrade) {
2908
+ function SocketWithUpgrade() {
2909
+ var _this7;
2910
+ _this7 = _SocketWithoutUpgrade.apply(this, arguments) || this;
2911
+ _this7._upgrades = [];
2912
+ return _this7;
2913
+ }
2914
+ _inheritsLoose(SocketWithUpgrade, _SocketWithoutUpgrade);
2915
+ var _proto2 = SocketWithUpgrade.prototype;
2916
+ _proto2.onOpen = function onOpen() {
2917
+ _SocketWithoutUpgrade.prototype.onOpen.call(this);
2918
+ if ("open" === this.readyState && this.opts.upgrade) {
2919
+ debug("starting upgrade probes");
2920
+ for (var i = 0; i < this._upgrades.length; i++) {
2921
+ this._probe(this._upgrades[i]);
2922
+ }
2923
+ }
2924
+ }
2925
+ /**
2926
+ * Probes a transport.
2927
+ *
2928
+ * @param {String} name - transport name
2929
+ * @private
2930
+ */;
2931
+ _proto2._probe = function _probe(name) {
2932
+ var _this8 = this;
2933
+ debug('probing transport "%s"', name);
2934
+ var transport = this.createTransport(name);
2935
+ var failed = false;
2936
+ SocketWithoutUpgrade.priorWebsocketSuccess = false;
2937
+ var onTransportOpen = function onTransportOpen() {
2938
+ if (failed) return;
2939
+ debug('probe transport "%s" opened', name);
2940
+ transport.send([{
2941
+ type: "ping",
2942
+ data: "probe"
2943
+ }]);
2944
+ transport.once("packet", function (msg) {
2945
+ if (failed) return;
2946
+ if ("pong" === msg.type && "probe" === msg.data) {
2947
+ debug('probe transport "%s" pong', name);
2948
+ _this8.upgrading = true;
2949
+ _this8.emitReserved("upgrading", transport);
2950
+ if (!transport) return;
2951
+ SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
2952
+ debug('pausing current transport "%s"', _this8.transport.name);
2953
+ _this8.transport.pause(function () {
2954
+ if (failed) return;
2955
+ if ("closed" === _this8.readyState) return;
2956
+ debug("changing transport and sending upgrade packet");
2957
+ cleanup();
2958
+ _this8.setTransport(transport);
2959
+ transport.send([{
2960
+ type: "upgrade"
2961
+ }]);
2962
+ _this8.emitReserved("upgrade", transport);
2963
+ transport = null;
2964
+ _this8.upgrading = false;
2965
+ _this8.flush();
2966
+ });
2967
+ } else {
2968
+ debug('probe transport "%s" failed', name);
2969
+ var err = new Error("probe error");
2970
+ // @ts-ignore
2971
+ err.transport = transport.name;
2972
+ _this8.emitReserved("upgradeError", err);
2973
+ }
2974
+ });
2975
+ };
2976
+ function freezeTransport() {
2977
+ if (failed) return;
2978
+ // Any callback called by transport should be ignored since now
2979
+ failed = true;
2980
+ cleanup();
2981
+ transport.close();
2982
+ transport = null;
2983
+ }
2984
+ // Handle any error that happens while probing
2985
+ var onerror = function onerror(err) {
2986
+ var error = new Error("probe error: " + err);
2987
+ // @ts-ignore
2988
+ error.transport = transport.name;
2989
+ freezeTransport();
2990
+ debug('probe transport "%s" failed because of error: %s', name, err);
2991
+ _this8.emitReserved("upgradeError", error);
2992
+ };
2993
+ function onTransportClose() {
2994
+ onerror("transport closed");
2995
+ }
2996
+ // When the socket is closed while we're probing
2997
+ function onclose() {
2998
+ onerror("socket closed");
2999
+ }
3000
+ // When the socket is upgraded while we're probing
3001
+ function onupgrade(to) {
3002
+ if (transport && to.name !== transport.name) {
3003
+ debug('"%s" works - aborting "%s"', to.name, transport.name);
3004
+ freezeTransport();
3005
+ }
3006
+ }
3007
+ // Remove all listeners on the transport and on self
3008
+ var cleanup = function cleanup() {
3009
+ transport.removeListener("open", onTransportOpen);
3010
+ transport.removeListener("error", onerror);
3011
+ transport.removeListener("close", onTransportClose);
3012
+ _this8.off("close", onclose);
3013
+ _this8.off("upgrading", onupgrade);
3014
+ };
3015
+ transport.once("open", onTransportOpen);
3016
+ transport.once("error", onerror);
3017
+ transport.once("close", onTransportClose);
3018
+ this.once("close", onclose);
3019
+ this.once("upgrading", onupgrade);
3020
+ if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
3021
+ // favor WebTransport
3022
+ this.setTimeoutFn(function () {
3023
+ if (!failed) {
3024
+ transport.open();
3025
+ }
3026
+ }, 200);
3027
+ } else {
3028
+ transport.open();
3029
+ }
3030
+ };
3031
+ _proto2.onHandshake = function onHandshake(data) {
3032
+ this._upgrades = this._filterUpgrades(data.upgrades);
3033
+ _SocketWithoutUpgrade.prototype.onHandshake.call(this, data);
3034
+ }
3035
+ /**
3036
+ * Filters upgrades, returning only those matching client transports.
3037
+ *
3038
+ * @param {Array} upgrades - server upgrades
3039
+ * @private
3040
+ */;
3041
+ _proto2._filterUpgrades = function _filterUpgrades(upgrades) {
3042
+ var filteredUpgrades = [];
3043
+ for (var i = 0; i < upgrades.length; i++) {
3044
+ if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
3045
+ }
3046
+ return filteredUpgrades;
3047
+ };
3048
+ return SocketWithUpgrade;
3049
+ }(SocketWithoutUpgrade);
3050
+ /**
3051
+ * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
3052
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
3053
+ *
3054
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
3055
+ * low-level transport, it will try to upgrade to a better transport.
3056
+ *
3057
+ * @example
3058
+ * import { Socket } from "engine.io-client";
3059
+ *
3060
+ * const socket = new Socket();
3061
+ *
3062
+ * socket.on("open", () => {
3063
+ * socket.send("hello");
3064
+ * });
3065
+ *
3066
+ * @see SocketWithoutUpgrade
3067
+ * @see SocketWithUpgrade
3068
+ */
3069
+ var Socket = /*#__PURE__*/function (_SocketWithUpgrade) {
3070
+ function Socket(uri) {
3071
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3072
+ var isOptionsOnly = _typeof(uri) === "object";
3073
+ var o = isOptionsOnly ? _objectSpread2({}, uri) : _objectSpread2({}, opts);
3074
+ if (!o.transports || o.transports && typeof o.transports[0] === "string") {
3075
+ o.transports = (o.transports || ["polling", "websocket", "webtransport"]).map(function (transportName) {
3076
+ return transports[transportName];
3077
+ }).filter(function (t) {
3078
+ return !!t;
3079
+ });
3080
+ }
3081
+ return _SocketWithUpgrade.call(this, isOptionsOnly ? o : uri, o) || this;
3082
+ }
3083
+ _inheritsLoose(Socket, _SocketWithUpgrade);
3084
+ return Socket;
3085
+ }(SocketWithUpgrade);
3086
+
3087
+ var browserEntrypoint = (function (uri, opts) {
3088
+ return new Socket(uri, opts);
3089
+ });
3090
+
3091
+ return browserEntrypoint;
3092
+
3093
+ }));
3094
+ //# sourceMappingURL=engine.io.js.map