roxxie-proxy-u-prod 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.
- package/LICENSE +661 -0
- package/README.md +123 -0
- package/SOURCE.md +29 -0
- package/THIRD_PARTY_NOTICES.md +24 -0
- package/dist/assets/filters-Bu_3nHVy.bin +0 -0
- package/dist/assets/index-BdRlQ7d_.css +1 -0
- package/dist/assets/index-DcvPYWS3.js +3621 -0
- package/dist/assets/inject-BnVzMVpl.js +40 -0
- package/dist/assets/scramjet-C9HLwI-y.wasm +0 -0
- package/dist/defaultfavicon.png +0 -0
- package/dist/icon.png +0 -0
- package/dist/roxxie-icon.svg +12 -0
- package/embed.js +70 -0
- package/examples/single-page.html +25 -0
- package/package.json +42 -0
- package/runtime/controller.sw.js +273 -0
- package/runtime/index.html +18 -0
- package/runtime/localcontrollersw.js +7 -0
- package/runtime/roxxie-network.json +13 -0
- package/runtime/sw.js +6 -0
- package/scripts/build.mjs +344 -0
- package/scripts/smoke.mjs +123 -0
- package/scripts/verify.mjs +122 -0
- package/source/external/dreamlandjs/LICENSE +21 -0
- package/source/external/dreamlandjs/README.md +22 -0
- package/source/external/dreamlandjs/dist/core.d.ts +167 -0
- package/source/external/dreamlandjs/dist/core.js +2 -0
- package/source/external/dreamlandjs/dist/core.js.map +1 -0
- package/source/external/dreamlandjs/dist/core.size.html +4950 -0
- package/source/external/dreamlandjs/dist/js-runtime.d.ts +3 -0
- package/source/external/dreamlandjs/dist/js-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/js-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.d.ts +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/motion.d.ts +19 -0
- package/source/external/dreamlandjs/dist/motion.js +2 -0
- package/source/external/dreamlandjs/dist/motion.js.map +1 -0
- package/source/external/dreamlandjs/dist/router.d.ts +48 -0
- package/source/external/dreamlandjs/dist/router.js +2 -0
- package/source/external/dreamlandjs/dist/router.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.d.ts +3 -0
- package/source/external/dreamlandjs/dist/ssr.client.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.client.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.d.ts +7 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.server.d.ts +11 -0
- package/source/external/dreamlandjs/dist/ssr.server.js +2373 -0
- package/source/external/dreamlandjs/dist/ssr.server.js.map +1 -0
- package/source/external/dreamlandjs/dist/types/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/dist/types/core/css/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/css/selectorParser.d.ts +50 -0
- package/source/external/dreamlandjs/dist/types/core/delegate.d.ts +10 -0
- package/source/external/dreamlandjs/dist/types/core/index.d.ts +9 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/child.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/definitions.d.ts +76 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/dom.d.ts +28 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/index.d.ts +14 -0
- package/source/external/dreamlandjs/dist/types/core/state/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/core/state/pointers.d.ts +37 -0
- package/source/external/dreamlandjs/dist/types/core/state/state.d.ts +13 -0
- package/source/external/dreamlandjs/dist/types/core/state/use.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/utils.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/js-runtime/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/jsx-runtime/index.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/motion/index.d.ts +15 -0
- package/source/external/dreamlandjs/dist/types/router/index.d.ts +45 -0
- package/source/external/dreamlandjs/dist/types/ssr/client/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/consts.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/serialize.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/types.d.ts +21 -0
- package/source/external/dreamlandjs/dist/types/ssr/hybrid/index.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/index.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/vdom.d.ts +71 -0
- package/source/external/dreamlandjs/dist/types/util/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/util/store.d.ts +26 -0
- package/source/external/dreamlandjs/dist/types/vite/css-minifier.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/vite/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/util.d.ts +29 -0
- package/source/external/dreamlandjs/dist/util.js +2 -0
- package/source/external/dreamlandjs/dist/util.js.map +1 -0
- package/source/external/dreamlandjs/dist/vite.d.ts +19 -0
- package/source/external/dreamlandjs/dist/vite.js +2 -0
- package/source/external/dreamlandjs/dist/vite.js.map +1 -0
- package/source/external/dreamlandjs/package.json +101 -0
- package/source/external/dreamlandjs/rollup.config.ts +302 -0
- package/source/external/dreamlandjs/rollup.plugins.ts +1134 -0
- package/source/external/dreamlandjs/src/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/src/core/consts.js +18 -0
- package/source/external/dreamlandjs/src/core/css/index.ts +111 -0
- package/source/external/dreamlandjs/src/core/css/selectorParser.ts +313 -0
- package/source/external/dreamlandjs/src/core/delegate.ts +28 -0
- package/source/external/dreamlandjs/src/core/index.ts +31 -0
- package/source/external/dreamlandjs/src/core/jsx/child.ts +91 -0
- package/source/external/dreamlandjs/src/core/jsx/definitions.ts +125 -0
- package/source/external/dreamlandjs/src/core/jsx/dom.ts +49 -0
- package/source/external/dreamlandjs/src/core/jsx/index.ts +289 -0
- package/source/external/dreamlandjs/src/core/state/index.ts +1 -0
- package/source/external/dreamlandjs/src/core/state/pointers.ts +310 -0
- package/source/external/dreamlandjs/src/core/state/state.ts +112 -0
- package/source/external/dreamlandjs/src/core/state/use.ts +82 -0
- package/source/external/dreamlandjs/src/core/utils.ts +48 -0
- package/source/external/dreamlandjs/src/js-runtime/index.ts +4 -0
- package/source/external/dreamlandjs/src/jsx-runtime/index.ts +3 -0
- package/source/external/dreamlandjs/src/motion/index.ts +156 -0
- package/source/external/dreamlandjs/src/router/index.tsx +394 -0
- package/source/external/dreamlandjs/src/router/tsconfig.json +9 -0
- package/source/external/dreamlandjs/src/ssr/client/index.ts +193 -0
- package/source/external/dreamlandjs/src/ssr/common/consts.ts +5 -0
- package/source/external/dreamlandjs/src/ssr/common/serialize.ts +115 -0
- package/source/external/dreamlandjs/src/ssr/common/types.ts +28 -0
- package/source/external/dreamlandjs/src/ssr/hybrid/index.ts +144 -0
- package/source/external/dreamlandjs/src/ssr/server/index.ts +157 -0
- package/source/external/dreamlandjs/src/ssr/server/tsconfig.json +7 -0
- package/source/external/dreamlandjs/src/ssr/server/vdom.ts +285 -0
- package/source/external/dreamlandjs/src/util/index.ts +10 -0
- package/source/external/dreamlandjs/src/util/store.ts +134 -0
- package/source/external/dreamlandjs/src/vite/css-minifier.ts +222 -0
- package/source/external/dreamlandjs/src/vite/index.ts +60 -0
- package/source/external/dreamlandjs/src/vite/tsconfig.json +7 -0
- package/source/external/dreamlandjs/tsconfig.json +15 -0
- package/source/package.json +48 -0
- package/source/packages/adrift-protocol/package.json +31 -0
- package/source/packages/adrift-protocol/src/index.ts +348 -0
- package/source/packages/adrift-protocol/tsconfig.json +18 -0
- package/source/packages/cdp/LICENSE +21 -0
- package/source/packages/cdp/README.md +47 -0
- package/source/packages/cdp/dist/chobitsu.js +2 -0
- package/source/packages/cdp/dist/chobitsu.js.map +1 -0
- package/source/packages/cdp/package.json +73 -0
- package/source/packages/cdp/script/build.js +15 -0
- package/source/packages/cdp/src/Chobitsu.ts +110 -0
- package/source/packages/cdp/src/domains/CSS.ts +378 -0
- package/source/packages/cdp/src/domains/CacheStorage.ts +8 -0
- package/source/packages/cdp/src/domains/DOM.ts +487 -0
- package/source/packages/cdp/src/domains/DOMDebugger.ts +109 -0
- package/source/packages/cdp/src/domains/DOMStorage.ts +122 -0
- package/source/packages/cdp/src/domains/Debugger.ts +25 -0
- package/source/packages/cdp/src/domains/IndexedDB.ts +207 -0
- package/source/packages/cdp/src/domains/Input.ts +177 -0
- package/source/packages/cdp/src/domains/Network.ts +251 -0
- package/source/packages/cdp/src/domains/Overlay.ts +230 -0
- package/source/packages/cdp/src/domains/Page.ts +296 -0
- package/source/packages/cdp/src/domains/Runtime.ts +273 -0
- package/source/packages/cdp/src/domains/Storage.ts +71 -0
- package/source/packages/cdp/src/index.d.ts +8 -0
- package/source/packages/cdp/src/index.ts +153 -0
- package/source/packages/cdp/src/lib/connector.ts +15 -0
- package/source/packages/cdp/src/lib/constants.ts +1 -0
- package/source/packages/cdp/src/lib/evaluate.ts +59 -0
- package/source/packages/cdp/src/lib/mutationObserver.ts +39 -0
- package/source/packages/cdp/src/lib/nodeManager.ts +142 -0
- package/source/packages/cdp/src/lib/objManager.ts +422 -0
- package/source/packages/cdp/src/lib/request.ts +313 -0
- package/source/packages/cdp/src/lib/resources.ts +59 -0
- package/source/packages/cdp/src/lib/scriptMananger.ts +62 -0
- package/source/packages/cdp/src/lib/stylesheet.ts +146 -0
- package/source/packages/cdp/src/lib/util.ts +105 -0
- package/source/packages/cdp/tsconfig.json +16 -0
- package/source/packages/cdp/webpack.config.js +48 -0
- package/source/packages/chrome/index.html +17 -0
- package/source/packages/chrome/package.json +41 -0
- package/source/packages/chrome/public/ROXXIE_NETWORK.md +22 -0
- package/source/packages/chrome/public/controller.sw.js +273 -0
- package/source/packages/chrome/public/defaultfavicon.png +0 -0
- package/source/packages/chrome/public/icon.png +0 -0
- package/source/packages/chrome/public/localcontrollersw.js +7 -0
- package/source/packages/chrome/public/roxxie-icon.svg +12 -0
- package/source/packages/chrome/public/roxxie-network.json +13 -0
- package/source/packages/chrome/public/sw.js +6 -0
- package/source/packages/chrome/src/App.tsx +269 -0
- package/source/packages/chrome/src/CDP.ts +285 -0
- package/source/packages/chrome/src/Tab/History.ts +186 -0
- package/source/packages/chrome/src/Tab/Tab.tsx +219 -0
- package/source/packages/chrome/src/Tab/screenshot.ts +66 -0
- package/source/packages/chrome/src/Tab/serialize.ts +221 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.test.ts +159 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.ts +232 -0
- package/source/packages/chrome/src/adblock/AdBlockService.test.ts +148 -0
- package/source/packages/chrome/src/adblock/AdBlockService.ts +166 -0
- package/source/packages/chrome/src/adblock/NOTICE.md +14 -0
- package/source/packages/chrome/src/adblock/assets/filters.bin +0 -0
- package/source/packages/chrome/src/adblock/index.ts +18 -0
- package/source/packages/chrome/src/assets/favicon.ts +4 -0
- package/source/packages/chrome/src/components/BookmarkPopup.tsx +101 -0
- package/source/packages/chrome/src/components/BookmarksStrip.tsx +150 -0
- package/source/packages/chrome/src/components/Button.tsx +99 -0
- package/source/packages/chrome/src/components/Checkbox.tsx +89 -0
- package/source/packages/chrome/src/components/DownloadsPopup.tsx +230 -0
- package/source/packages/chrome/src/components/Favicon.tsx +65 -0
- package/source/packages/chrome/src/components/Icon.tsx +29 -0
- package/source/packages/chrome/src/components/Input.tsx +82 -0
- package/source/packages/chrome/src/components/Menu.tsx +287 -0
- package/source/packages/chrome/src/components/Omnibar/BookmarkButton.tsx +73 -0
- package/source/packages/chrome/src/components/Omnibar/CircularProgress.tsx +83 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibar.tsx +455 -0
- package/source/packages/chrome/src/components/Omnibar/OmnibarButton.tsx +48 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibox.tsx +466 -0
- package/source/packages/chrome/src/components/Omnibar/SiteOptionsButton.tsx +52 -0
- package/source/packages/chrome/src/components/Omnibar/Suggestion.tsx +186 -0
- package/source/packages/chrome/src/components/Omnibar/UrlInput.tsx +198 -0
- package/source/packages/chrome/src/components/Omnibar/suggestions.ts +468 -0
- package/source/packages/chrome/src/components/Omnibar/utils.ts +11 -0
- package/source/packages/chrome/src/components/ReportBrokenSiteModal.tsx +279 -0
- package/source/packages/chrome/src/components/Shell.tsx +191 -0
- package/source/packages/chrome/src/components/SiteInformationPopup.tsx +96 -0
- package/source/packages/chrome/src/components/SmallIconButton.tsx +36 -0
- package/source/packages/chrome/src/components/StartScreen.tsx +386 -0
- package/source/packages/chrome/src/components/TabStrip/DragTab.tsx +546 -0
- package/source/packages/chrome/src/components/TabStrip/Sidebar.tsx +820 -0
- package/source/packages/chrome/src/components/TabStrip/TabHoverCard.tsx +87 -0
- package/source/packages/chrome/src/components/TabStrip/TabStrip.tsx +510 -0
- package/source/packages/chrome/src/components/TopSiteButton.tsx +234 -0
- package/source/packages/chrome/src/consts.ts +3 -0
- package/source/packages/chrome/src/icons.ts +70 -0
- package/source/packages/chrome/src/index.ts +168 -0
- package/source/packages/chrome/src/migrations/0-from-legacy.ts +6 -0
- package/source/packages/chrome/src/migrations/1-vertical-tab-settings.ts +15 -0
- package/source/packages/chrome/src/migrations/index.ts +42 -0
- package/source/packages/chrome/src/pages/AboutPage.tsx +37 -0
- package/source/packages/chrome/src/pages/DownloadsPage.tsx +133 -0
- package/source/packages/chrome/src/pages/HistoryPage.tsx +99 -0
- package/source/packages/chrome/src/pages/NewTabPage.tsx +264 -0
- package/source/packages/chrome/src/pages/PlaygroundPage.tsx +43 -0
- package/source/packages/chrome/src/pages/SettingsPage.tsx +1931 -0
- package/source/packages/chrome/src/proxy/Controller.ts +331 -0
- package/source/packages/chrome/src/proxy/ProxyFrame.ts +26 -0
- package/source/packages/chrome/src/proxy/cache.ts +487 -0
- package/source/packages/chrome/src/proxy/codec.ts +11 -0
- package/source/packages/chrome/src/proxy/contextitems.ts +180 -0
- package/source/packages/chrome/src/proxy/index.ts +5 -0
- package/source/packages/chrome/src/proxy/roxxie.ts +85 -0
- package/source/packages/chrome/src/proxy/scramjet.ts +642 -0
- package/source/packages/chrome/src/reset.css +124 -0
- package/source/packages/chrome/src/runtime-base.ts +16 -0
- package/source/packages/chrome/src/sentry.tsx +45 -0
- package/source/packages/chrome/src/services/DownloadsService.ts +136 -0
- package/source/packages/chrome/src/services/FaviconService.ts +161 -0
- package/source/packages/chrome/src/services/KVWrapper.ts +169 -0
- package/source/packages/chrome/src/services/ProfileService.ts +94 -0
- package/source/packages/chrome/src/services/Service.ts +10 -0
- package/source/packages/chrome/src/services/SettingsService.ts +108 -0
- package/source/packages/chrome/src/services/TabsService.ts +161 -0
- package/source/packages/chrome/src/startup.test.ts +129 -0
- package/source/packages/chrome/src/startup.ts +161 -0
- package/source/packages/chrome/src/style.css +229 -0
- package/source/packages/chrome/src/themes.ts +756 -0
- package/source/packages/chrome/src/util/StatefulClass.ts +31 -0
- package/source/packages/chrome/src/util/index.ts +74 -0
- package/source/packages/chrome/src/util/memoize.ts +13 -0
- package/source/packages/chrome/src/vite-env.d.ts +16 -0
- package/source/packages/chrome/tsconfig.json +30 -0
- package/source/packages/chrome/vite.config.ts +47 -0
- package/source/packages/inject/package.json +20 -0
- package/source/packages/inject/src/context.ts +194 -0
- package/source/packages/inject/src/emulators/alwaysLastBubble.ts +168 -0
- package/source/packages/inject/src/emulators/anchors.ts +55 -0
- package/source/packages/inject/src/emulators/contextmenu.ts +46 -0
- package/source/packages/inject/src/emulators/history.ts +51 -0
- package/source/packages/inject/src/emulators/titlewatcher.ts +42 -0
- package/source/packages/inject/src/emulators/windowopen.ts +134 -0
- package/source/packages/inject/src/errorpage/errorpage.css +234 -0
- package/source/packages/inject/src/errorpage/errorpage.html +29 -0
- package/source/packages/inject/src/errorpage/errorpage.ts +76 -0
- package/source/packages/inject/src/index.ts +62 -0
- package/source/packages/inject/src/transport.ts +97 -0
- package/source/packages/inject/src/types.d.ts +136 -0
- package/source/packages/roxxie-transport/package.json +36 -0
- package/source/packages/roxxie-transport/src/binary.ts +398 -0
- package/source/packages/roxxie-transport/src/config.ts +254 -0
- package/source/packages/roxxie-transport/src/connection.ts +767 -0
- package/source/packages/roxxie-transport/src/index.ts +5 -0
- package/source/packages/roxxie-transport/src/tracker.ts +651 -0
- package/source/packages/roxxie-transport/src/transport.ts +414 -0
- package/source/packages/roxxie-transport/tsconfig.json +18 -0
- package/source/packages/scramjet/packages/controller/package.json +37 -0
- package/source/packages/scramjet/packages/controller/src/index.ts +861 -0
- package/source/packages/scramjet/packages/controller/src/inject.ts +365 -0
- package/source/packages/scramjet/packages/controller/src/sw.ts +231 -0
- package/source/packages/scramjet/packages/controller/src/symbols.ts +1 -0
- package/source/packages/scramjet/packages/controller/src/types.d.ts +140 -0
- package/source/packages/scramjet/packages/controller/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/controller/src/version.ts +30 -0
- package/source/packages/scramjet/packages/controller/tsconfig.json +24 -0
- package/source/packages/scramjet/packages/core/dist/scramjet-external.mjs +57 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js +13599 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs +13649 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.wasm +0 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js +13601 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs +13651 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js +23 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/types/Tap.d.ts +39 -0
- package/source/packages/scramjet/packages/core/dist/types/client/client.d.ts +115 -0
- package/source/packages/scramjet/packages/core/dist/types/client/entry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/dist/types/client/events.d.ts +10 -0
- package/source/packages/scramjet/packages/core/dist/types/client/helpers.d.ts +1 -0
- package/source/packages/scramjet/packages/core/dist/types/client/index.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/client/location.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/eval.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/sourcemaps.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/wrap.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/client/singletonbox.d.ts +18 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/body.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/fetch.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/headers.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/index.d.ts +128 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/parse.d.ts +23 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/util.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/index.d.ts +12 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/cookie.d.ts +26 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/headers.d.ts +13 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/htmlRules.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/index.d.ts +50 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/mime.d.ts +53 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/refresh.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/css.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/html.d.ts +33 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/index.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/js.d.ts +11 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/url.d.ts +24 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/wasm.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/worker.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/set-cookie-parser.d.ts +20 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/snapshot.d.ts +186 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/sniffEncoding.d.ts +65 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/util.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/symbols.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/types.d.ts +60 -0
- package/source/packages/scramjet/packages/core/dist/types/typesEntry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/lib/index.cjs +7 -0
- package/source/packages/scramjet/packages/core/lib/index.d.ts +8 -0
- package/source/packages/scramjet/packages/core/package.json +69 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.lock +1985 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.toml +20 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/Cargo.toml +15 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/analyze.rs +1118 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/ast_table.rs +927 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/helper_index.rs +556 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/lib.rs +455 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/reachability.rs +85 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/templates.rs +192 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/witness.rs +597 -0
- package/source/packages/scramjet/packages/core/rewriter/js/Cargo.toml +18 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/cfg.rs +45 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/changes.rs +379 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/lib.rs +171 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/rewrite.rs +290 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/visitor.rs +967 -0
- package/source/packages/scramjet/packages/core/rewriter/native/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/main.rs +166 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/rewriter.rs +161 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/test_runner.rs +156 -0
- package/source/packages/scramjet/packages/core/rewriter/rust-toolchain.toml +5 -0
- package/source/packages/scramjet/packages/core/rewriter/rustfmt.toml +2 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/Cargo.toml +16 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/lib.rs +242 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/transform.rs +123 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/build.sh +128 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/error.rs +56 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/jsr.rs +125 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/lib.rs +144 -0
- package/source/packages/scramjet/packages/core/src/Tap.ts +166 -0
- package/source/packages/scramjet/packages/core/src/client/client.ts +916 -0
- package/source/packages/scramjet/packages/core/src/client/dom/attr.ts +94 -0
- package/source/packages/scramjet/packages/core/src/client/dom/beacon.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/cookie.ts +21 -0
- package/source/packages/scramjet/packages/core/src/client/dom/css.ts +106 -0
- package/source/packages/scramjet/packages/core/src/client/dom/document.ts +140 -0
- package/source/packages/scramjet/packages/core/src/client/dom/element.ts +783 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fontface.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fragments.ts +32 -0
- package/source/packages/scramjet/packages/core/src/client/dom/history.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/dom/open.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/dom/origin.ts +13 -0
- package/source/packages/scramjet/packages/core/src/client/dom/performance.ts +50 -0
- package/source/packages/scramjet/packages/core/src/client/dom/protocol.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/dom/storage.ts +107 -0
- package/source/packages/scramjet/packages/core/src/client/entry.ts +12 -0
- package/source/packages/scramjet/packages/core/src/client/events.ts +10 -0
- package/source/packages/scramjet/packages/core/src/client/helpers.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/index.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/location.ts +139 -0
- package/source/packages/scramjet/packages/core/src/client/shared/antiantidebugger.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/blob.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/shared/caches.ts +31 -0
- package/source/packages/scramjet/packages/core/src/client/shared/chrome.ts +90 -0
- package/source/packages/scramjet/packages/core/src/client/shared/err.ts +55 -0
- package/source/packages/scramjet/packages/core/src/client/shared/error.ts +42 -0
- package/source/packages/scramjet/packages/core/src/client/shared/eval.ts +40 -0
- package/source/packages/scramjet/packages/core/src/client/shared/event.ts +215 -0
- package/source/packages/scramjet/packages/core/src/client/shared/function.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/shared/import.ts +46 -0
- package/source/packages/scramjet/packages/core/src/client/shared/indexeddb.ts +18 -0
- package/source/packages/scramjet/packages/core/src/client/shared/opfs.ts +27 -0
- package/source/packages/scramjet/packages/core/src/client/shared/postmessage.ts +113 -0
- package/source/packages/scramjet/packages/core/src/client/shared/realm.ts +26 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/eventsource.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/fetch.ts +67 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/websocket.ts +389 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/xmlhttprequest.ts +163 -0
- package/source/packages/scramjet/packages/core/src/client/shared/settimeout.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/sourcemaps.ts +203 -0
- package/source/packages/scramjet/packages/core/src/client/shared/worker.ts +72 -0
- package/source/packages/scramjet/packages/core/src/client/shared/wrap.ts +197 -0
- package/source/packages/scramjet/packages/core/src/client/singletonbox.ts +52 -0
- package/source/packages/scramjet/packages/core/src/client/worker/importScripts.ts +13 -0
- package/source/packages/scramjet/packages/core/src/fetch/body.ts +93 -0
- package/source/packages/scramjet/packages/core/src/fetch/fetch.ts +323 -0
- package/source/packages/scramjet/packages/core/src/fetch/headers.ts +528 -0
- package/source/packages/scramjet/packages/core/src/fetch/index.ts +198 -0
- package/source/packages/scramjet/packages/core/src/fetch/parse.ts +149 -0
- package/source/packages/scramjet/packages/core/src/fetch/util.ts +81 -0
- package/source/packages/scramjet/packages/core/src/global.d.ts +32 -0
- package/source/packages/scramjet/packages/core/src/index.ts +78 -0
- package/source/packages/scramjet/packages/core/src/log.ts +117 -0
- package/source/packages/scramjet/packages/core/src/shared/cookie.ts +199 -0
- package/source/packages/scramjet/packages/core/src/shared/headers.ts +76 -0
- package/source/packages/scramjet/packages/core/src/shared/htmlRules.ts +154 -0
- package/source/packages/scramjet/packages/core/src/shared/index.ts +79 -0
- package/source/packages/scramjet/packages/core/src/shared/mime.ts +234 -0
- package/source/packages/scramjet/packages/core/src/shared/refresh.ts +164 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/css.ts +67 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/html.ts +603 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/index.ts +6 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/js.ts +158 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/url.ts +248 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/wasm.ts +58 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/worker.ts +37 -0
- package/source/packages/scramjet/packages/core/src/shared/set-cookie-parser.ts +195 -0
- package/source/packages/scramjet/packages/core/src/shared/snapshot.ts +245 -0
- package/source/packages/scramjet/packages/core/src/shared/sniffEncoding.ts +1061 -0
- package/source/packages/scramjet/packages/core/src/shared/util.ts +35 -0
- package/source/packages/scramjet/packages/core/src/symbols.ts +9 -0
- package/source/packages/scramjet/packages/core/src/sync.ts +63 -0
- package/source/packages/scramjet/packages/core/src/types.ts +66 -0
- package/source/packages/scramjet/packages/core/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/core/tsconfig.json +21 -0
- package/source/packages/scramjet/packages/rpc/index.ts +100 -0
- package/source/packages/scramjet/packages/rpc/package.json +7 -0
- package/source/packages/scramjet/packages/utils/package.json +39 -0
- package/source/packages/scramjet/packages/utils/src/alwaysLastBubble.ts +172 -0
- package/source/packages/scramjet/packages/utils/src/catch-escaped-links.ts +34 -0
- package/source/packages/scramjet/packages/utils/src/event-handler-plugin.ts +86 -0
- package/source/packages/scramjet/packages/utils/src/global.d.ts +8 -0
- package/source/packages/scramjet/packages/utils/src/http-cache-plugin.ts +475 -0
- package/source/packages/scramjet/packages/utils/src/index.ts +26 -0
- package/source/packages/scramjet/packages/utils/src/link-handler-plugin.ts +75 -0
- package/source/packages/scramjet/packages/utils/src/typesEntry.ts +5 -0
- package/source/packages/scramjet/packages/utils/src/url-watcher.ts +37 -0
- package/source/packages/scramjet/packages/utils/src/version.ts +40 -0
- package/source/packages/scramjet/packages/utils/tsconfig.json +11 -0
- package/source/packages/scramjet/patches/htmlparser2@12.0.0.patch +124 -0
- package/source/packages/scramjet/rspack.config.ts +613 -0
- package/source/packages/scramjet/tsconfig.json +11 -0
- package/source/packages/tracker-protocol/package.json +31 -0
- package/source/packages/tracker-protocol/src/index.ts +745 -0
- package/source/packages/tracker-protocol/tsconfig.json +18 -0
- package/source/pnpm-lock.yaml +12018 -0
- package/source/pnpm-workspace.yaml +31 -0
- package/source/rspack.config.ts +103 -0
- package/source/scripts/update-adblock-assets.mjs +164 -0
- package/third_party/filter-lists/LICENSE-CC-BY-SA-3.0.txt +359 -0
- package/third_party/filter-lists/LICENSE-GPL-3.0.txt +674 -0
- package/third_party/filter-lists/LICENSE-MPL-2.0.txt +375 -0
- package/third_party/filter-lists/README.md +24 -0
- package/third_party/filter-lists/easylist.txt +83088 -0
- package/third_party/filter-lists/easyprivacy.txt +56361 -0
- package/third_party/filter-lists/manifest.json +56 -0
- package/third_party/filter-lists/ublock-filters.txt +10937 -0
- package/third_party/filter-lists/ublock-privacy.txt +3209 -0
- package/third_party/filter-lists/ublock-resources.json +1852 -0
- package/third_party/filter-lists/ublock-unbreak.txt +6026 -0
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C2SRequestTypes,
|
|
3
|
+
MAX_CHUNK_SIZE,
|
|
4
|
+
PROTOCOL_VERSION,
|
|
5
|
+
S2C_HELLO_ERR,
|
|
6
|
+
S2C_HELLO_OK,
|
|
7
|
+
S2CRequestTypes,
|
|
8
|
+
assertHeaderList,
|
|
9
|
+
decodeFrame,
|
|
10
|
+
decodeJSON,
|
|
11
|
+
decodeText,
|
|
12
|
+
encodeClientHello,
|
|
13
|
+
encodeFrame,
|
|
14
|
+
encodeJSONFrame,
|
|
15
|
+
type BinaryTransport,
|
|
16
|
+
type C2SWSOpenPayload,
|
|
17
|
+
type HeaderList,
|
|
18
|
+
type HTTPRequestPayload,
|
|
19
|
+
type HTTPResponsePayload,
|
|
20
|
+
type PingPayload,
|
|
21
|
+
type S2CWSOpenPayload,
|
|
22
|
+
type WSClosePayload,
|
|
23
|
+
type WSErrorPayload,
|
|
24
|
+
} from "roxxie-transports-adrift-protocol";
|
|
25
|
+
|
|
26
|
+
export const MAX_PROXY_WEBSOCKET_MESSAGE_BYTES = 16 * 1024 * 1024;
|
|
27
|
+
|
|
28
|
+
export interface ConnectionResponse {
|
|
29
|
+
body: ReadableStream<Uint8Array>;
|
|
30
|
+
headers: [string, string][];
|
|
31
|
+
status: number;
|
|
32
|
+
statusText: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SocketCallbacks {
|
|
36
|
+
onopen(protocol: string, extensions: string): void;
|
|
37
|
+
onmessage(data: ArrayBuffer | string): void;
|
|
38
|
+
onclose(code: number, reason: string): void;
|
|
39
|
+
onerror(message: string): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MultiplexedSocket {
|
|
43
|
+
readonly sequence: number;
|
|
44
|
+
send(data: Blob | ArrayBuffer | string): void;
|
|
45
|
+
close(code?: number, reason?: string): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface PendingHTTP {
|
|
49
|
+
resolve: (response: ConnectionResponse) => void;
|
|
50
|
+
reject: (error: unknown) => void;
|
|
51
|
+
controller?: ReadableStreamDefaultController<Uint8Array>;
|
|
52
|
+
responseStarted: boolean;
|
|
53
|
+
responseSettled: boolean;
|
|
54
|
+
cancelled: boolean;
|
|
55
|
+
removeAbort?: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface MessageAssembly {
|
|
59
|
+
kind: "text" | "binary";
|
|
60
|
+
chunks: Uint8Array[];
|
|
61
|
+
size: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface PendingSocket {
|
|
65
|
+
callbacks: SocketCallbacks;
|
|
66
|
+
assembly?: MessageAssembly;
|
|
67
|
+
sendQueue: Promise<void>;
|
|
68
|
+
closing: boolean;
|
|
69
|
+
closed: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface PendingPing {
|
|
73
|
+
nonce: string;
|
|
74
|
+
startedAt: number;
|
|
75
|
+
resolve: (roundTripMs: number) => void;
|
|
76
|
+
reject: (error: unknown) => void;
|
|
77
|
+
timer: ReturnType<typeof setTimeout>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
class VirtualSocketError extends Error {
|
|
81
|
+
constructor(
|
|
82
|
+
message: string,
|
|
83
|
+
readonly closeCode: number
|
|
84
|
+
) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.name = "VirtualSocketError";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function asError(reason: unknown, fallback: string): Error {
|
|
91
|
+
return reason instanceof Error
|
|
92
|
+
? reason
|
|
93
|
+
: new Error(reason === undefined ? fallback : String(reason));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function abortError(): DOMException {
|
|
97
|
+
return new DOMException("The proxy request was aborted", "AbortError");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function callSafely(callback: () => void): void {
|
|
101
|
+
try {
|
|
102
|
+
callback();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("A Roxxie proxy callback threw", error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function randomNonce(): string {
|
|
109
|
+
const bytes = new Uint8Array(16);
|
|
110
|
+
crypto.getRandomValues(bytes);
|
|
111
|
+
return Array.from(bytes, (value) => value.toString(16).padStart(2, "0")).join(
|
|
112
|
+
""
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function validateResponsePayload(value: unknown): HTTPResponsePayload {
|
|
117
|
+
if (value === null || typeof value !== "object") {
|
|
118
|
+
throw new Error("Node sent an invalid HTTP response header");
|
|
119
|
+
}
|
|
120
|
+
const result = value as Partial<HTTPResponsePayload>;
|
|
121
|
+
if (
|
|
122
|
+
typeof result.status !== "number" ||
|
|
123
|
+
!Number.isInteger(result.status) ||
|
|
124
|
+
result.status < 100 ||
|
|
125
|
+
result.status > 999 ||
|
|
126
|
+
typeof result.statusText !== "string" ||
|
|
127
|
+
result.headers === undefined
|
|
128
|
+
) {
|
|
129
|
+
throw new Error("Node sent an invalid HTTP response header");
|
|
130
|
+
}
|
|
131
|
+
assertHeaderList(result.headers);
|
|
132
|
+
return result as HTTPResponsePayload;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function validateSocketOpen(value: unknown): S2CWSOpenPayload {
|
|
136
|
+
if (value === null || typeof value !== "object") {
|
|
137
|
+
throw new Error("Node sent an invalid WebSocket open response");
|
|
138
|
+
}
|
|
139
|
+
const result = value as Partial<S2CWSOpenPayload>;
|
|
140
|
+
if (
|
|
141
|
+
typeof result.protocol !== "string" ||
|
|
142
|
+
typeof result.extensions !== "string"
|
|
143
|
+
) {
|
|
144
|
+
throw new Error("Node sent an invalid WebSocket open response");
|
|
145
|
+
}
|
|
146
|
+
return result as S2CWSOpenPayload;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function validateSocketClose(value: unknown): WSClosePayload {
|
|
150
|
+
if (value === null || typeof value !== "object") {
|
|
151
|
+
throw new Error("Node sent an invalid WebSocket close response");
|
|
152
|
+
}
|
|
153
|
+
const result = value as Partial<WSClosePayload>;
|
|
154
|
+
if (
|
|
155
|
+
typeof result.code !== "number" ||
|
|
156
|
+
!Number.isInteger(result.code) ||
|
|
157
|
+
typeof result.reason !== "string"
|
|
158
|
+
) {
|
|
159
|
+
throw new Error("Node sent an invalid WebSocket close response");
|
|
160
|
+
}
|
|
161
|
+
return result as WSClosePayload;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function concatenate(chunks: readonly Uint8Array[], size: number): Uint8Array {
|
|
165
|
+
const result = new Uint8Array(size);
|
|
166
|
+
let offset = 0;
|
|
167
|
+
for (const chunk of chunks) {
|
|
168
|
+
result.set(chunk, offset);
|
|
169
|
+
offset += chunk.byteLength;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function bodyByteStream(
|
|
175
|
+
body: BodyInit
|
|
176
|
+
): Promise<ReadableStream<Uint8Array>> {
|
|
177
|
+
const stream = new Response(body).body;
|
|
178
|
+
if (stream === null) throw new Error("Unable to encode proxy request body");
|
|
179
|
+
return stream;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export class RoxxieConnection {
|
|
183
|
+
private readonly http = new Map<number, PendingHTTP>();
|
|
184
|
+
private readonly ignoredHTTP = new Map<number, number>();
|
|
185
|
+
private readonly sockets = new Map<number, PendingSocket>();
|
|
186
|
+
private readonly pings = new Map<number, PendingPing>();
|
|
187
|
+
private sendQueue: Promise<void> = Promise.resolve();
|
|
188
|
+
private nextSequence = 1;
|
|
189
|
+
private failed = false;
|
|
190
|
+
private handshakeComplete = false;
|
|
191
|
+
private handshakeResolve: (() => void) | undefined;
|
|
192
|
+
private handshakeReject: ((error: unknown) => void) | undefined;
|
|
193
|
+
private failureHandler: ((error: Error) => void) | undefined;
|
|
194
|
+
|
|
195
|
+
private constructor(private readonly binary: BinaryTransport) {
|
|
196
|
+
binary.ondata = (data) => this.handleData(data);
|
|
197
|
+
binary.onclose = (reason) =>
|
|
198
|
+
this.fail(asError(reason, "Proxy transport closed"));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static async create(
|
|
202
|
+
binary: BinaryTransport,
|
|
203
|
+
handshakeTimeoutMs = 5_000
|
|
204
|
+
): Promise<RoxxieConnection> {
|
|
205
|
+
const connection = new RoxxieConnection(binary);
|
|
206
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
207
|
+
const handshake = new Promise<void>((resolve, reject) => {
|
|
208
|
+
connection.handshakeResolve = resolve;
|
|
209
|
+
connection.handshakeReject = reject;
|
|
210
|
+
timer = setTimeout(
|
|
211
|
+
() =>
|
|
212
|
+
reject(
|
|
213
|
+
new Error(
|
|
214
|
+
`Protocol handshake timed out after ${handshakeTimeoutMs} ms`
|
|
215
|
+
)
|
|
216
|
+
),
|
|
217
|
+
handshakeTimeoutMs
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
await connection.sendRaw(encodeClientHello());
|
|
222
|
+
await handshake;
|
|
223
|
+
return connection;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
connection.close(error);
|
|
226
|
+
throw error;
|
|
227
|
+
} finally {
|
|
228
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
229
|
+
connection.handshakeResolve = undefined;
|
|
230
|
+
connection.handshakeReject = undefined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
get ready(): boolean {
|
|
235
|
+
return this.handshakeComplete && !this.failed;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setFailureHandler(handler: (error: Error) => void): void {
|
|
239
|
+
this.failureHandler = handler;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Measures an application-level round trip over the active data channel. */
|
|
243
|
+
async ping(timeoutMs = 3_000): Promise<number> {
|
|
244
|
+
this.assertReady();
|
|
245
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 1 || timeoutMs > 120_000) {
|
|
246
|
+
throw new TypeError("Ping timeout must be between 1 and 120000 ms");
|
|
247
|
+
}
|
|
248
|
+
const sequence = this.allocateSequence();
|
|
249
|
+
const nonce = randomNonce();
|
|
250
|
+
const roundTrip = new Promise<number>((resolve, reject) => {
|
|
251
|
+
const timer = setTimeout(() => {
|
|
252
|
+
this.fail(new Error(`Protocol ping timed out after ${timeoutMs} ms`));
|
|
253
|
+
}, timeoutMs);
|
|
254
|
+
this.pings.set(sequence, {
|
|
255
|
+
nonce,
|
|
256
|
+
startedAt: performance.now(),
|
|
257
|
+
resolve,
|
|
258
|
+
reject,
|
|
259
|
+
timer,
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
await this.sendFrame(
|
|
265
|
+
encodeJSONFrame(sequence, C2SRequestTypes.Ping, { nonce })
|
|
266
|
+
);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
this.fail(error);
|
|
269
|
+
}
|
|
270
|
+
return roundTrip;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async request(
|
|
274
|
+
remote: URL,
|
|
275
|
+
method: string,
|
|
276
|
+
body: BodyInit | null | undefined,
|
|
277
|
+
headers: HeaderList,
|
|
278
|
+
signal?: AbortSignal
|
|
279
|
+
): Promise<ConnectionResponse> {
|
|
280
|
+
this.assertReady();
|
|
281
|
+
if (signal?.aborted === true) throw abortError();
|
|
282
|
+
assertHeaderList(headers);
|
|
283
|
+
const sequence = this.allocateSequence();
|
|
284
|
+
const response = new Promise<ConnectionResponse>((resolve, reject) => {
|
|
285
|
+
const pending: PendingHTTP = {
|
|
286
|
+
resolve,
|
|
287
|
+
reject,
|
|
288
|
+
responseStarted: false,
|
|
289
|
+
responseSettled: false,
|
|
290
|
+
cancelled: false,
|
|
291
|
+
};
|
|
292
|
+
if (signal !== undefined) {
|
|
293
|
+
const onAbort = () => this.cancelRequest(sequence, true);
|
|
294
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
295
|
+
pending.removeAbort = () =>
|
|
296
|
+
signal.removeEventListener("abort", onAbort);
|
|
297
|
+
}
|
|
298
|
+
this.http.set(sequence, pending);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const start: HTTPRequestPayload = {
|
|
302
|
+
method,
|
|
303
|
+
requestHeaders: headers,
|
|
304
|
+
remote: remote.href,
|
|
305
|
+
hasBody: body != null,
|
|
306
|
+
};
|
|
307
|
+
try {
|
|
308
|
+
await this.sendFrame(
|
|
309
|
+
encodeJSONFrame(sequence, C2SRequestTypes.HTTPRequestStart, start)
|
|
310
|
+
);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
this.fail(error);
|
|
313
|
+
return response;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
void this.sendRequestBody(sequence, body, signal).catch(
|
|
317
|
+
(error: unknown) => {
|
|
318
|
+
if (signal?.aborted !== true) this.fail(error);
|
|
319
|
+
}
|
|
320
|
+
);
|
|
321
|
+
return response;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
openSocket(
|
|
325
|
+
url: URL,
|
|
326
|
+
protocols: string[],
|
|
327
|
+
requestHeaders: HeaderList,
|
|
328
|
+
callbacks: SocketCallbacks
|
|
329
|
+
): MultiplexedSocket {
|
|
330
|
+
this.assertReady();
|
|
331
|
+
assertHeaderList(requestHeaders);
|
|
332
|
+
const sequence = this.allocateSequence();
|
|
333
|
+
const state: PendingSocket = {
|
|
334
|
+
callbacks,
|
|
335
|
+
sendQueue: Promise.resolve(),
|
|
336
|
+
closing: false,
|
|
337
|
+
closed: false,
|
|
338
|
+
};
|
|
339
|
+
this.sockets.set(sequence, state);
|
|
340
|
+
const payload: C2SWSOpenPayload = {
|
|
341
|
+
url: url.href,
|
|
342
|
+
protocols: [...protocols],
|
|
343
|
+
requestHeaders,
|
|
344
|
+
};
|
|
345
|
+
void this.sendFrame(
|
|
346
|
+
encodeJSONFrame(sequence, C2SRequestTypes.WSOpen, payload)
|
|
347
|
+
).catch((error: unknown) =>
|
|
348
|
+
this.socketError(sequence, asError(error, "Unable to open socket"))
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
sequence,
|
|
353
|
+
send: (data) => {
|
|
354
|
+
if (state.closing || state.closed) {
|
|
355
|
+
throw new Error("Proxy socket is closed");
|
|
356
|
+
}
|
|
357
|
+
state.sendQueue = state.sendQueue
|
|
358
|
+
.then(async () => this.sendSocketMessage(sequence, data))
|
|
359
|
+
.catch((error: unknown) => {
|
|
360
|
+
const resolved = asError(error, "Socket send failed");
|
|
361
|
+
this.socketError(
|
|
362
|
+
sequence,
|
|
363
|
+
resolved,
|
|
364
|
+
error instanceof VirtualSocketError ? error.closeCode : 1011
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
},
|
|
368
|
+
close: (code = 1000, reason = "") => {
|
|
369
|
+
if (state.closing || state.closed) return;
|
|
370
|
+
state.closing = true;
|
|
371
|
+
const payload: WSClosePayload = { code, reason };
|
|
372
|
+
state.sendQueue = state.sendQueue
|
|
373
|
+
.then(async () => {
|
|
374
|
+
if (this.sockets.get(sequence) !== state || state.closed) return;
|
|
375
|
+
await this.sendFrame(
|
|
376
|
+
encodeJSONFrame(sequence, C2SRequestTypes.WSClose, payload)
|
|
377
|
+
);
|
|
378
|
+
})
|
|
379
|
+
.catch((error: unknown) =>
|
|
380
|
+
this.socketError(sequence, asError(error, "Socket close failed"))
|
|
381
|
+
);
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
close(reason?: unknown): void {
|
|
387
|
+
if (this.failed) return;
|
|
388
|
+
this.fail(asError(reason, "Proxy connection closed"));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private async sendRequestBody(
|
|
392
|
+
sequence: number,
|
|
393
|
+
body: BodyInit | null | undefined,
|
|
394
|
+
signal?: AbortSignal
|
|
395
|
+
): Promise<void> {
|
|
396
|
+
const wasAborted = () => signal?.aborted === true;
|
|
397
|
+
if (body != null) {
|
|
398
|
+
const reader = (await bodyByteStream(body)).getReader();
|
|
399
|
+
const cancelReader = () => {
|
|
400
|
+
void reader.cancel(abortError()).catch(() => undefined);
|
|
401
|
+
};
|
|
402
|
+
signal?.addEventListener("abort", cancelReader, { once: true });
|
|
403
|
+
try {
|
|
404
|
+
for (;;) {
|
|
405
|
+
if (wasAborted()) return;
|
|
406
|
+
const { done, value } = await reader.read();
|
|
407
|
+
if (done) break;
|
|
408
|
+
if (wasAborted()) return;
|
|
409
|
+
for (
|
|
410
|
+
let offset = 0;
|
|
411
|
+
offset < value.byteLength;
|
|
412
|
+
offset += MAX_CHUNK_SIZE
|
|
413
|
+
) {
|
|
414
|
+
const chunk = value.subarray(offset, offset + MAX_CHUNK_SIZE);
|
|
415
|
+
await this.sendFrame(
|
|
416
|
+
encodeFrame(sequence, C2SRequestTypes.HTTPRequestChunk, chunk)
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
} finally {
|
|
421
|
+
signal?.removeEventListener("abort", cancelReader);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (wasAborted()) return;
|
|
425
|
+
await this.sendFrame(encodeFrame(sequence, C2SRequestTypes.HTTPRequestEnd));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private cancelRequest(sequence: number, errorStream: boolean): void {
|
|
429
|
+
const pending = this.http.get(sequence);
|
|
430
|
+
if (pending === undefined || pending.cancelled) return;
|
|
431
|
+
pending.cancelled = true;
|
|
432
|
+
pending.removeAbort?.();
|
|
433
|
+
const error = abortError();
|
|
434
|
+
if (!pending.responseSettled) {
|
|
435
|
+
pending.responseSettled = true;
|
|
436
|
+
pending.reject(error);
|
|
437
|
+
} else if (errorStream && pending.controller !== undefined) {
|
|
438
|
+
try {
|
|
439
|
+
pending.controller.error(error);
|
|
440
|
+
} catch {
|
|
441
|
+
// The consumer may already have closed its side of the stream.
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
void this.sendFrame(
|
|
445
|
+
encodeFrame(sequence, C2SRequestTypes.HTTPRequestAbort)
|
|
446
|
+
).catch((sendError: unknown) => this.fail(sendError));
|
|
447
|
+
this.http.delete(sequence);
|
|
448
|
+
// Frames already queued by the node can still arrive after its abort
|
|
449
|
+
// handler runs. Quarantine the sequence beyond the node's 60 s upstream
|
|
450
|
+
// timeout so those frames cannot collide with a newly allocated request.
|
|
451
|
+
this.ignoredHTTP.set(sequence, Date.now() + 120_000);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private async sendSocketMessage(
|
|
455
|
+
sequence: number,
|
|
456
|
+
data: Blob | ArrayBuffer | string
|
|
457
|
+
): Promise<void> {
|
|
458
|
+
const state = this.sockets.get(sequence);
|
|
459
|
+
if (state === undefined || state.closed)
|
|
460
|
+
throw new Error("Proxy socket is closed");
|
|
461
|
+
const isText = typeof data === "string";
|
|
462
|
+
const knownSize =
|
|
463
|
+
typeof data === "string"
|
|
464
|
+
? data.length
|
|
465
|
+
: data instanceof Blob
|
|
466
|
+
? data.size
|
|
467
|
+
: data.byteLength;
|
|
468
|
+
if (knownSize > MAX_PROXY_WEBSOCKET_MESSAGE_BYTES) {
|
|
469
|
+
throw new VirtualSocketError(
|
|
470
|
+
"Proxied WebSocket message exceeds the 16 MiB limit",
|
|
471
|
+
1009
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
const bytes = isText
|
|
475
|
+
? new TextEncoder().encode(data)
|
|
476
|
+
: new Uint8Array(data instanceof Blob ? await data.arrayBuffer() : data);
|
|
477
|
+
if (bytes.byteLength > MAX_PROXY_WEBSOCKET_MESSAGE_BYTES) {
|
|
478
|
+
throw new VirtualSocketError(
|
|
479
|
+
"Proxied WebSocket message exceeds the 16 MiB limit",
|
|
480
|
+
1009
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (bytes.byteLength <= MAX_CHUNK_SIZE) {
|
|
484
|
+
await this.sendFrame(
|
|
485
|
+
encodeFrame(
|
|
486
|
+
sequence,
|
|
487
|
+
isText ? C2SRequestTypes.WSSendText : C2SRequestTypes.WSSendBinary,
|
|
488
|
+
bytes
|
|
489
|
+
)
|
|
490
|
+
);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
await this.sendFrame(
|
|
495
|
+
encodeFrame(
|
|
496
|
+
sequence,
|
|
497
|
+
isText ? C2SRequestTypes.WSTextStart : C2SRequestTypes.WSBinaryStart
|
|
498
|
+
)
|
|
499
|
+
);
|
|
500
|
+
for (let offset = 0; offset < bytes.byteLength; offset += MAX_CHUNK_SIZE) {
|
|
501
|
+
await this.sendFrame(
|
|
502
|
+
encodeFrame(
|
|
503
|
+
sequence,
|
|
504
|
+
C2SRequestTypes.WSDataChunk,
|
|
505
|
+
bytes.subarray(offset, offset + MAX_CHUNK_SIZE)
|
|
506
|
+
)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
await this.sendFrame(encodeFrame(sequence, C2SRequestTypes.WSDataEnd));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
private handleData(data: ArrayBuffer): void {
|
|
513
|
+
try {
|
|
514
|
+
if (!this.handshakeComplete) {
|
|
515
|
+
const hello = decodeText(data);
|
|
516
|
+
if (hello === S2C_HELLO_OK) {
|
|
517
|
+
this.handshakeComplete = true;
|
|
518
|
+
this.handshakeResolve?.();
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (hello.startsWith(S2C_HELLO_ERR)) {
|
|
522
|
+
throw new Error(
|
|
523
|
+
`Proxy protocol mismatch; node expects ${hello.slice(S2C_HELLO_ERR.length)}`
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
throw new Error("Proxy node sent an invalid protocol handshake");
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const frame = decodeFrame(data);
|
|
530
|
+
if (this.pings.has(frame.sequence)) {
|
|
531
|
+
this.handlePong(frame.sequence, frame.operation, frame.payload);
|
|
532
|
+
} else if (this.http.has(frame.sequence))
|
|
533
|
+
this.handleHTTPFrame(frame.sequence, frame.operation, frame.payload);
|
|
534
|
+
else if (this.sockets.has(frame.sequence)) {
|
|
535
|
+
this.handleSocketFrame(frame.sequence, frame.operation, frame.payload);
|
|
536
|
+
} else if (this.ignoredHTTP.has(frame.sequence)) {
|
|
537
|
+
if (frame.operation === S2CRequestTypes.HTTPResponseEnd) {
|
|
538
|
+
this.ignoredHTTP.delete(frame.sequence);
|
|
539
|
+
} else if (
|
|
540
|
+
frame.operation !== S2CRequestTypes.HTTPResponseStart &&
|
|
541
|
+
frame.operation !== S2CRequestTypes.HTTPResponseChunk
|
|
542
|
+
) {
|
|
543
|
+
throw new Error(
|
|
544
|
+
`Node sent invalid operation for canceled HTTP sequence`
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
} else {
|
|
548
|
+
throw new Error(
|
|
549
|
+
`Node sent a frame for unknown sequence ${frame.sequence}`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
} catch (error) {
|
|
553
|
+
this.handshakeReject?.(error);
|
|
554
|
+
this.fail(error);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
private handlePong(
|
|
559
|
+
sequence: number,
|
|
560
|
+
operation: number,
|
|
561
|
+
payload: ArrayBuffer
|
|
562
|
+
): void {
|
|
563
|
+
const pending = this.pings.get(sequence);
|
|
564
|
+
if (pending === undefined) return;
|
|
565
|
+
if (operation !== S2CRequestTypes.Pong) {
|
|
566
|
+
throw new Error(`Node sent invalid ping operation ${operation}`);
|
|
567
|
+
}
|
|
568
|
+
const value = decodeJSON<Partial<PingPayload>>(payload);
|
|
569
|
+
if (typeof value.nonce !== "string" || value.nonce !== pending.nonce) {
|
|
570
|
+
throw new Error("Node sent an invalid protocol pong");
|
|
571
|
+
}
|
|
572
|
+
clearTimeout(pending.timer);
|
|
573
|
+
this.pings.delete(sequence);
|
|
574
|
+
pending.resolve(performance.now() - pending.startedAt);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
private handleHTTPFrame(
|
|
578
|
+
sequence: number,
|
|
579
|
+
operation: number,
|
|
580
|
+
payload: ArrayBuffer
|
|
581
|
+
): void {
|
|
582
|
+
const pending = this.http.get(sequence);
|
|
583
|
+
if (pending === undefined) return;
|
|
584
|
+
switch (operation) {
|
|
585
|
+
case S2CRequestTypes.HTTPResponseStart: {
|
|
586
|
+
if (pending.responseStarted)
|
|
587
|
+
throw new Error("Node sent duplicate HTTP response headers");
|
|
588
|
+
const response = validateResponsePayload(decodeJSON(payload));
|
|
589
|
+
pending.responseStarted = true;
|
|
590
|
+
const body = new ReadableStream<Uint8Array>({
|
|
591
|
+
start: (controller) => {
|
|
592
|
+
pending.controller = controller;
|
|
593
|
+
},
|
|
594
|
+
cancel: () => {
|
|
595
|
+
this.cancelRequest(sequence, false);
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
pending.responseSettled = true;
|
|
599
|
+
pending.resolve({
|
|
600
|
+
body,
|
|
601
|
+
headers: response.headers.map(([name, value]) => [name, value]),
|
|
602
|
+
status: response.status,
|
|
603
|
+
statusText: response.statusText,
|
|
604
|
+
});
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
case S2CRequestTypes.HTTPResponseChunk:
|
|
608
|
+
if (!pending.responseStarted || pending.controller === undefined) {
|
|
609
|
+
throw new Error("Node sent HTTP body data before response headers");
|
|
610
|
+
}
|
|
611
|
+
pending.controller.enqueue(new Uint8Array(payload));
|
|
612
|
+
break;
|
|
613
|
+
case S2CRequestTypes.HTTPResponseEnd:
|
|
614
|
+
if (!pending.responseStarted || pending.controller === undefined) {
|
|
615
|
+
throw new Error("Node ended HTTP response before response headers");
|
|
616
|
+
}
|
|
617
|
+
pending.controller.close();
|
|
618
|
+
pending.removeAbort?.();
|
|
619
|
+
this.http.delete(sequence);
|
|
620
|
+
break;
|
|
621
|
+
default:
|
|
622
|
+
throw new Error(`Node sent invalid HTTP operation ${operation}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
private handleSocketFrame(
|
|
627
|
+
sequence: number,
|
|
628
|
+
operation: number,
|
|
629
|
+
payload: ArrayBuffer
|
|
630
|
+
): void {
|
|
631
|
+
const state = this.sockets.get(sequence);
|
|
632
|
+
if (state === undefined) return;
|
|
633
|
+
switch (operation) {
|
|
634
|
+
case S2CRequestTypes.WSOpen: {
|
|
635
|
+
const open = validateSocketOpen(decodeJSON(payload));
|
|
636
|
+
callSafely(() =>
|
|
637
|
+
state.callbacks.onopen(open.protocol, open.extensions)
|
|
638
|
+
);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
case S2CRequestTypes.WSClose: {
|
|
642
|
+
const close = validateSocketClose(decodeJSON(payload));
|
|
643
|
+
state.closed = true;
|
|
644
|
+
this.sockets.delete(sequence);
|
|
645
|
+
callSafely(() => state.callbacks.onclose(close.code, close.reason));
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
case S2CRequestTypes.WSError: {
|
|
649
|
+
const error = decodeJSON<Partial<WSErrorPayload>>(payload);
|
|
650
|
+
if (typeof error.message !== "string")
|
|
651
|
+
throw new Error("Node sent invalid socket error");
|
|
652
|
+
callSafely(() => state.callbacks.onerror(error.message as string));
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
case S2CRequestTypes.WSTextStart:
|
|
656
|
+
case S2CRequestTypes.WSBinaryStart:
|
|
657
|
+
if (state.assembly !== undefined)
|
|
658
|
+
throw new Error("Node overlapped WebSocket messages");
|
|
659
|
+
state.assembly = {
|
|
660
|
+
kind: operation === S2CRequestTypes.WSTextStart ? "text" : "binary",
|
|
661
|
+
chunks: [],
|
|
662
|
+
size: 0,
|
|
663
|
+
};
|
|
664
|
+
break;
|
|
665
|
+
case S2CRequestTypes.WSDataChunk: {
|
|
666
|
+
if (state.assembly === undefined)
|
|
667
|
+
throw new Error("Node sent an orphan socket chunk");
|
|
668
|
+
state.assembly.size += payload.byteLength;
|
|
669
|
+
if (state.assembly.size > MAX_PROXY_WEBSOCKET_MESSAGE_BYTES) {
|
|
670
|
+
throw new Error(
|
|
671
|
+
"Node exceeded maximum proxied WebSocket message size"
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
state.assembly.chunks.push(new Uint8Array(payload));
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case S2CRequestTypes.WSDataEnd: {
|
|
678
|
+
if (state.assembly === undefined)
|
|
679
|
+
throw new Error("Node ended an absent socket message");
|
|
680
|
+
const assembly = state.assembly;
|
|
681
|
+
delete state.assembly;
|
|
682
|
+
const bytes = concatenate(assembly.chunks, assembly.size);
|
|
683
|
+
if (assembly.kind === "text") {
|
|
684
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
685
|
+
callSafely(() => state.callbacks.onmessage(text));
|
|
686
|
+
} else {
|
|
687
|
+
callSafely(() =>
|
|
688
|
+
state.callbacks.onmessage(bytes.slice().buffer as ArrayBuffer)
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
default:
|
|
694
|
+
throw new Error(`Node sent invalid WebSocket operation ${operation}`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
private socketError(sequence: number, error: Error, closeCode = 1011): void {
|
|
699
|
+
const state = this.sockets.get(sequence);
|
|
700
|
+
if (state === undefined) return;
|
|
701
|
+
state.closed = true;
|
|
702
|
+
this.sockets.delete(sequence);
|
|
703
|
+
callSafely(() => state.callbacks.onerror(error.message));
|
|
704
|
+
callSafely(() => state.callbacks.onclose(closeCode, error.message));
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
private allocateSequence(): number {
|
|
708
|
+
for (let attempts = 0; attempts < 0xffff; attempts += 1) {
|
|
709
|
+
const candidate = this.nextSequence;
|
|
710
|
+
this.nextSequence = candidate === 0xffff ? 1 : candidate + 1;
|
|
711
|
+
const ignoredUntil = this.ignoredHTTP.get(candidate);
|
|
712
|
+
if (ignoredUntil !== undefined && ignoredUntil <= Date.now()) {
|
|
713
|
+
this.ignoredHTTP.delete(candidate);
|
|
714
|
+
}
|
|
715
|
+
if (
|
|
716
|
+
!this.http.has(candidate) &&
|
|
717
|
+
!this.sockets.has(candidate) &&
|
|
718
|
+
!this.pings.has(candidate) &&
|
|
719
|
+
!this.ignoredHTTP.has(candidate)
|
|
720
|
+
) {
|
|
721
|
+
return candidate;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
throw new Error("Proxy connection exhausted its request sequence space");
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
private sendRaw(data: ArrayBuffer): Promise<void> {
|
|
728
|
+
const result = this.sendQueue.then(async () => this.binary.send(data));
|
|
729
|
+
this.sendQueue = result.catch(() => undefined);
|
|
730
|
+
return result;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
private sendFrame(data: ArrayBuffer): Promise<void> {
|
|
734
|
+
this.assertReady();
|
|
735
|
+
return this.sendRaw(data);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private assertReady(): void {
|
|
739
|
+
if (!this.ready) throw new Error("Proxy connection is not ready");
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
private fail(reason: unknown): void {
|
|
743
|
+
if (this.failed) return;
|
|
744
|
+
this.failed = true;
|
|
745
|
+
const error = asError(reason, "Proxy connection failed");
|
|
746
|
+
this.handshakeReject?.(error);
|
|
747
|
+
for (const pending of this.http.values()) {
|
|
748
|
+
pending.removeAbort?.();
|
|
749
|
+
if (pending.controller !== undefined) pending.controller.error(error);
|
|
750
|
+
if (!pending.responseSettled) pending.reject(error);
|
|
751
|
+
}
|
|
752
|
+
this.http.clear();
|
|
753
|
+
this.ignoredHTTP.clear();
|
|
754
|
+
for (const socket of this.sockets.values()) {
|
|
755
|
+
callSafely(() => socket.callbacks.onerror(error.message));
|
|
756
|
+
callSafely(() => socket.callbacks.onclose(1011, error.message));
|
|
757
|
+
}
|
|
758
|
+
this.sockets.clear();
|
|
759
|
+
for (const ping of this.pings.values()) {
|
|
760
|
+
clearTimeout(ping.timer);
|
|
761
|
+
ping.reject(error);
|
|
762
|
+
}
|
|
763
|
+
this.pings.clear();
|
|
764
|
+
this.binary.close(1011, error.message.slice(0, 123));
|
|
765
|
+
this.failureHandler?.(error);
|
|
766
|
+
}
|
|
767
|
+
}
|