@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,530 @@
1
+ 'use strict';
2
+
3
+ const zlib = require('zlib');
4
+
5
+ const bufferUtil = require('./buffer-util');
6
+ const Limiter = require('./limiter');
7
+ const { kStatusCode } = require('./constants');
8
+
9
+ const FastBuffer = Buffer[Symbol.species];
10
+ const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
11
+ const kPerMessageDeflate = Symbol('permessage-deflate');
12
+ const kTotalLength = Symbol('total-length');
13
+ const kCallback = Symbol('callback');
14
+ const kBuffers = Symbol('buffers');
15
+ const kError = Symbol('error');
16
+
17
+ //
18
+ // We limit zlib concurrency, which prevents severe memory fragmentation
19
+ // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
20
+ // and https://github.com/websockets/ws/issues/1202
21
+ //
22
+ // Intentionally global; it's the global thread pool that's an issue.
23
+ //
24
+ let zlibLimiter;
25
+
26
+ /**
27
+ * permessage-deflate implementation.
28
+ */
29
+ class PerMessageDeflate {
30
+ /**
31
+ * Creates a PerMessageDeflate instance.
32
+ *
33
+ * @param {Object} [options] Configuration options
34
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
35
+ * for, or request, a custom client window size
36
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
37
+ * acknowledge disabling of client context takeover
38
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
39
+ * calls to zlib
40
+ * @param {Boolean} [options.isServer=false] Create the instance in either
41
+ * server or client mode
42
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
43
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
44
+ * use of a custom server window size
45
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
46
+ * disabling of server context takeover
47
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
48
+ * messages should not be compressed if context takeover is disabled
49
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
50
+ * deflate
51
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
52
+ * inflate
53
+ */
54
+ constructor(options) {
55
+ this._options = options || {};
56
+ this._threshold =
57
+ this._options.threshold !== undefined ? this._options.threshold : 1024;
58
+ this._maxPayload = this._options.maxPayload | 0;
59
+ this._isServer = !!this._options.isServer;
60
+ this._deflate = null;
61
+ this._inflate = null;
62
+
63
+ this.params = null;
64
+
65
+ if (!zlibLimiter) {
66
+ const concurrency =
67
+ this._options.concurrencyLimit !== undefined
68
+ ? this._options.concurrencyLimit
69
+ : 10;
70
+ zlibLimiter = new Limiter(concurrency);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @type {String}
76
+ */
77
+ static get extensionName() {
78
+ return 'permessage-deflate';
79
+ }
80
+
81
+ /**
82
+ * Create an extension negotiation offer.
83
+ *
84
+ * @return {Object} Extension parameters
85
+ * @public
86
+ */
87
+ offer() {
88
+ const params = {};
89
+
90
+ if (this._options.serverNoContextTakeover) {
91
+ params.server_no_context_takeover = true;
92
+ }
93
+ if (this._options.clientNoContextTakeover) {
94
+ params.client_no_context_takeover = true;
95
+ }
96
+ if (this._options.serverMaxWindowBits) {
97
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
98
+ }
99
+ if (this._options.clientMaxWindowBits) {
100
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
101
+ } else if (this._options.clientMaxWindowBits == null) {
102
+ params.client_max_window_bits = true;
103
+ }
104
+
105
+ return params;
106
+ }
107
+
108
+ /**
109
+ * Accept an extension negotiation offer/response.
110
+ *
111
+ * @param {Array} configurations The extension negotiation offers/reponse
112
+ * @return {Object} Accepted configuration
113
+ * @public
114
+ */
115
+ accept(configurations) {
116
+ configurations = this.normalizeParams(configurations);
117
+
118
+ this.params = this._isServer
119
+ ? this.acceptAsServer(configurations)
120
+ : this.acceptAsClient(configurations);
121
+
122
+ return this.params;
123
+ }
124
+
125
+ /**
126
+ * Releases all resources used by the extension.
127
+ *
128
+ * @public
129
+ */
130
+ cleanup() {
131
+ if (this._inflate) {
132
+ this._inflate.close();
133
+ this._inflate = null;
134
+ }
135
+
136
+ if (this._deflate) {
137
+ const callback = this._deflate[kCallback];
138
+
139
+ this._deflate.close();
140
+ this._deflate = null;
141
+
142
+ if (callback) {
143
+ callback(
144
+ new Error(
145
+ 'The deflate stream was closed while data was being processed'
146
+ )
147
+ );
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Accept an extension negotiation offer.
154
+ *
155
+ * @param {Array} offers The extension negotiation offers
156
+ * @return {Object} Accepted configuration
157
+ * @private
158
+ */
159
+ acceptAsServer(offers) {
160
+ const opts = this._options;
161
+ const accepted = offers.find((params) => {
162
+ if (
163
+ (opts.serverNoContextTakeover === false &&
164
+ params.server_no_context_takeover) ||
165
+ (params.server_max_window_bits &&
166
+ (opts.serverMaxWindowBits === false ||
167
+ (typeof opts.serverMaxWindowBits === 'number' &&
168
+ opts.serverMaxWindowBits > params.server_max_window_bits))) ||
169
+ (typeof opts.clientMaxWindowBits === 'number' &&
170
+ (typeof params.client_max_window_bits === 'number'
171
+ ? opts.clientMaxWindowBits > params.client_max_window_bits
172
+ : !params.client_max_window_bits))
173
+ ) {
174
+ return false;
175
+ }
176
+
177
+ return true;
178
+ });
179
+
180
+ if (!accepted) {
181
+ throw new Error('None of the extension offers can be accepted');
182
+ }
183
+
184
+ if (opts.serverNoContextTakeover) {
185
+ accepted.server_no_context_takeover = true;
186
+ }
187
+ if (opts.clientNoContextTakeover) {
188
+ accepted.client_no_context_takeover = true;
189
+ }
190
+ if (typeof opts.serverMaxWindowBits === 'number') {
191
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
192
+ }
193
+ if (typeof opts.clientMaxWindowBits === 'number') {
194
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
195
+ } else if (
196
+ accepted.client_max_window_bits === true ||
197
+ opts.clientMaxWindowBits === false
198
+ ) {
199
+ delete accepted.client_max_window_bits;
200
+ }
201
+
202
+ return accepted;
203
+ }
204
+
205
+ /**
206
+ * Accept the extension negotiation response.
207
+ *
208
+ * @param {Array} response The extension negotiation response
209
+ * @return {Object} Accepted configuration
210
+ * @private
211
+ */
212
+ acceptAsClient(response) {
213
+ const params = response[0];
214
+
215
+ if (
216
+ this._options.clientNoContextTakeover === false &&
217
+ params.client_no_context_takeover
218
+ ) {
219
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
220
+ }
221
+
222
+ if (!params.client_max_window_bits) {
223
+ if (typeof this._options.clientMaxWindowBits === 'number') {
224
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
225
+ }
226
+ } else if (
227
+ this._options.clientMaxWindowBits === false ||
228
+ (typeof this._options.clientMaxWindowBits === 'number' &&
229
+ params.client_max_window_bits > this._options.clientMaxWindowBits)
230
+ ) {
231
+ throw new Error(
232
+ 'Unexpected or invalid parameter "client_max_window_bits"'
233
+ );
234
+ }
235
+
236
+ return params;
237
+ }
238
+
239
+ /**
240
+ * Normalize parameters.
241
+ *
242
+ * @param {Array} configurations The extension negotiation offers/reponse
243
+ * @return {Array} The offers/response with normalized parameters
244
+ * @private
245
+ */
246
+ normalizeParams(configurations) {
247
+ configurations.forEach((params) => {
248
+ Object.keys(params).forEach((key) => {
249
+ let value = params[key];
250
+
251
+ if (value.length > 1) {
252
+ throw new Error(`Parameter "${key}" must have only a single value`);
253
+ }
254
+
255
+ value = value[0];
256
+
257
+ if (key === 'client_max_window_bits') {
258
+ if (value !== true) {
259
+ const num = +value;
260
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
261
+ throw new TypeError(
262
+ `Invalid value for parameter "${key}": ${value}`
263
+ );
264
+ }
265
+ value = num;
266
+ } else if (!this._isServer) {
267
+ throw new TypeError(
268
+ `Invalid value for parameter "${key}": ${value}`
269
+ );
270
+ }
271
+ } else if (key === 'server_max_window_bits') {
272
+ const num = +value;
273
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
274
+ throw new TypeError(
275
+ `Invalid value for parameter "${key}": ${value}`
276
+ );
277
+ }
278
+ value = num;
279
+ } else if (
280
+ key === 'client_no_context_takeover' ||
281
+ key === 'server_no_context_takeover'
282
+ ) {
283
+ if (value !== true) {
284
+ throw new TypeError(
285
+ `Invalid value for parameter "${key}": ${value}`
286
+ );
287
+ }
288
+ } else {
289
+ throw new Error(`Unknown parameter "${key}"`);
290
+ }
291
+
292
+ params[key] = value;
293
+ });
294
+ });
295
+
296
+ return configurations;
297
+ }
298
+
299
+ /**
300
+ * Decompress data. Concurrency limited.
301
+ *
302
+ * @param {Buffer} data Compressed data
303
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
304
+ * @param {Function} callback Callback
305
+ * @public
306
+ */
307
+ decompress(data, fin, callback) {
308
+ zlibLimiter.add((done) => {
309
+ this._decompress(data, fin, (err, result) => {
310
+ done();
311
+ callback(err, result);
312
+ });
313
+ });
314
+ }
315
+
316
+ /**
317
+ * Compress data. Concurrency limited.
318
+ *
319
+ * @param {(Buffer|String)} data Data to compress
320
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
321
+ * @param {Function} callback Callback
322
+ * @public
323
+ */
324
+ compress(data, fin, callback) {
325
+ zlibLimiter.add((done) => {
326
+ this._compress(data, fin, (err, result) => {
327
+ done();
328
+ callback(err, result);
329
+ });
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Decompress data.
335
+ *
336
+ * @param {Buffer} data Compressed data
337
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
338
+ * @param {Function} callback Callback
339
+ * @private
340
+ */
341
+ _decompress(data, fin, callback) {
342
+ const endpoint = this._isServer ? 'client' : 'server';
343
+
344
+ if (!this._inflate) {
345
+ const key = `${endpoint}_max_window_bits`;
346
+ const windowBits =
347
+ typeof this.params[key] !== 'number'
348
+ ? zlib.Z_DEFAULT_WINDOWBITS
349
+ : this.params[key];
350
+
351
+ this._inflate = zlib.createInflateRaw({
352
+ ...this._options.zlibInflateOptions,
353
+ windowBits
354
+ });
355
+ this._inflate[kPerMessageDeflate] = this;
356
+ this._inflate[kTotalLength] = 0;
357
+ this._inflate[kBuffers] = [];
358
+ this._inflate.on('error', inflateOnError);
359
+ this._inflate.on('data', inflateOnData);
360
+ }
361
+
362
+ this._inflate[kCallback] = callback;
363
+
364
+ this._inflate.write(data);
365
+ if (fin) this._inflate.write(TRAILER);
366
+
367
+ this._inflate.flush(() => {
368
+ const err = this._inflate[kError];
369
+
370
+ if (err) {
371
+ this._inflate.close();
372
+ this._inflate = null;
373
+ callback(err);
374
+ return;
375
+ }
376
+
377
+ const data = bufferUtil.concat(
378
+ this._inflate[kBuffers],
379
+ this._inflate[kTotalLength]
380
+ );
381
+
382
+ if (this._inflate._readableState.endEmitted) {
383
+ this._inflate.close();
384
+ this._inflate = null;
385
+ } else {
386
+ this._inflate[kTotalLength] = 0;
387
+ this._inflate[kBuffers] = [];
388
+
389
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
390
+ this._inflate.reset();
391
+ }
392
+ }
393
+
394
+ callback(null, data);
395
+ });
396
+ }
397
+
398
+ /**
399
+ * Compress data.
400
+ *
401
+ * @param {(Buffer|String)} data Data to compress
402
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
403
+ * @param {Function} callback Callback
404
+ * @private
405
+ */
406
+ _compress(data, fin, callback) {
407
+ const endpoint = this._isServer ? 'server' : 'client';
408
+
409
+ if (!this._deflate) {
410
+ const key = `${endpoint}_max_window_bits`;
411
+ const windowBits =
412
+ typeof this.params[key] !== 'number'
413
+ ? zlib.Z_DEFAULT_WINDOWBITS
414
+ : this.params[key];
415
+
416
+ this._deflate = zlib.createDeflateRaw({
417
+ ...this._options.zlibDeflateOptions,
418
+ windowBits
419
+ });
420
+
421
+ this._deflate[kTotalLength] = 0;
422
+ this._deflate[kBuffers] = [];
423
+
424
+ this._deflate.on('data', deflateOnData);
425
+ }
426
+
427
+ this._deflate[kCallback] = callback;
428
+
429
+ this._deflate.write(data);
430
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
431
+ if (!this._deflate) {
432
+ //
433
+ // The deflate stream was closed while data was being processed.
434
+ //
435
+ return;
436
+ }
437
+
438
+ let data = bufferUtil.concat(
439
+ this._deflate[kBuffers],
440
+ this._deflate[kTotalLength]
441
+ );
442
+
443
+ if (fin) {
444
+ data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
445
+ }
446
+
447
+ //
448
+ // Ensure that the callback will not be called again in
449
+ // `PerMessageDeflate#cleanup()`.
450
+ //
451
+ this._deflate[kCallback] = null;
452
+
453
+ this._deflate[kTotalLength] = 0;
454
+ this._deflate[kBuffers] = [];
455
+
456
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
457
+ this._deflate.reset();
458
+ }
459
+
460
+ callback(null, data);
461
+ });
462
+ }
463
+ }
464
+
465
+ module.exports = PerMessageDeflate;
466
+
467
+ /**
468
+ * The listener of the `zlib.DeflateRaw` stream `'data'` event.
469
+ *
470
+ * @param {Buffer} chunk A chunk of data
471
+ * @private
472
+ */
473
+ function deflateOnData(chunk) {
474
+ this[kBuffers].push(chunk);
475
+ this[kTotalLength] += chunk.length;
476
+ }
477
+
478
+ /**
479
+ * The listener of the `zlib.InflateRaw` stream `'data'` event.
480
+ *
481
+ * @param {Buffer} chunk A chunk of data
482
+ * @private
483
+ */
484
+ function inflateOnData(chunk) {
485
+ this[kTotalLength] += chunk.length;
486
+
487
+ if (
488
+ this[kPerMessageDeflate]._maxPayload < 1 ||
489
+ this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
490
+ ) {
491
+ this[kBuffers].push(chunk);
492
+ return;
493
+ }
494
+
495
+ this[kError] = new RangeError('Max payload size exceeded');
496
+ this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
497
+ this[kError][kStatusCode] = 1009;
498
+ this.removeListener('data', inflateOnData);
499
+
500
+ //
501
+ // The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
502
+ // fact that in Node.js versions prior to 13.10.0, the callback for
503
+ // `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
504
+ // `zlib.reset()` ensures that either the callback is invoked or an error is
505
+ // emitted.
506
+ //
507
+ this.reset();
508
+ }
509
+
510
+ /**
511
+ * The listener of the `zlib.InflateRaw` stream `'error'` event.
512
+ *
513
+ * @param {Error} err The emitted error
514
+ * @private
515
+ */
516
+ function inflateOnError(err) {
517
+ //
518
+ // There is no need to call `Zlib#close()` as the handle is automatically
519
+ // closed when an error is emitted.
520
+ //
521
+ this[kPerMessageDeflate]._inflate = null;
522
+
523
+ if (this[kError]) {
524
+ this[kCallback](this[kError]);
525
+ return;
526
+ }
527
+
528
+ err[kStatusCode] = 1007;
529
+ this[kCallback](err);
530
+ }