diff --git a/package.json b/package.json index 7201783c..67a6e550 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@plasmohq/storage": "^1.9.0", "@react-hooks-library/core": "^0.5.1", "autoprefixer": "^10.4.16", - "brotli-dec-wasm": "^2.1.0", + "brotli": "^1.3.3", "dexie": "^3.2.4", "dexie-react-hooks": "^1.1.7", "hash-wasm": "^4.11.0", @@ -41,6 +41,7 @@ }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "4.1.1", + "@types/brotli": "^1.3.4", "@types/chrome": "^0.0.254", "@types/glob": "^8.1.0", "@types/node": "20.9.0", diff --git a/src/adapters/websocket-hook.js b/src/adapters/websocket-hook.js index 972f1da8..5b2a131c 100644 --- a/src/adapters/websocket-hook.js +++ b/src/adapters/websocket-hook.js @@ -1,6 +1,6 @@ import { injectFuncAsListener } from "~utils/event" import { sendBLiveMessage } from "~utils/messaging" -import brotliPromise from 'brotli-dec-wasm' +import decompress from "brotli/decompress" // @名称 bliveproxy // @版本 0.4 @@ -23,7 +23,6 @@ const OP_AUTH_REPLY = 8 // WS_OP_CONNECT_SUCCESS const textEncoder = new TextEncoder() const textDecoder = new TextDecoder() -let brotli = null let hooked = false let abortController = {} @@ -98,7 +97,7 @@ async function handleMessage(data, callRealOnMessageByPacket) { } case WS_BODY_PROTOCOL_VERSION_BROTLI: { // body是压缩过的多个消息 - body = brotli.decompress(body) + body = decompress(body) await handleMessage(body, callRealOnMessageByPacket) break } @@ -165,10 +164,6 @@ async function handleCommand(command, callRealOnMessageByPacket) { //修改掛接方式,將不再採用Proxy async function hook() { - // singleton - if (brotli === null) { - brotli = await brotliPromise - } if (hooked) { console.warn('cannot hook websocket, please unhook first.') diff --git a/yarn.lock b/yarn.lock index 3cde2404..3ccf07cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2207,6 +2207,13 @@ resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA== +"@types/brotli@^1.3.4": + version "1.3.4" + resolved "https://registry.yarnpkg.com/@types/brotli/-/brotli-1.3.4.tgz#3eefc5493218a99141771f351142dd640efde5d8" + integrity sha512-cKYjgaS2DMdCKF7R0F5cgx1nfBYObN2ihIuPGQ4/dlIY6RpV7OWNwe9L8V4tTVKL2eZqOkNM9FM/rgTvLf4oXw== + dependencies: + "@types/node" "*" + "@types/chrome@^0.0.254": version "0.0.254" resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.254.tgz#f1caadc129134f71bfaa29f9f0295939048da173" @@ -2532,7 +2539,7 @@ base-x@^3.0.8: dependencies: safe-buffer "^5.0.1" -base64-js@^1.3.1: +base64-js@^1.1.2, base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== @@ -2576,10 +2583,12 @@ braces@^3.0.2, braces@~3.0.2: dependencies: fill-range "^7.0.1" -brotli-dec-wasm@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/brotli-dec-wasm/-/brotli-dec-wasm-2.1.0.tgz#d0a7f4887ec12123e689e93a30f2c5b3cde98aa7" - integrity sha512-ibXultYwKMk+8Zy2utgLuIcoTjwkrV1I1QkNToLndgVJq73JuUwJiUix2A28L6X9dMCJByyylzgcqW7KoRHGEQ== +brotli@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/brotli/-/brotli-1.3.3.tgz#7365d8cc00f12cf765d2b2c898716bcf4b604d48" + integrity sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg== + dependencies: + base64-js "^1.1.2" browserslist@4.21.10: version "4.21.10"