Skip to content

Commit

Permalink
changed brotli from wasm to js for fixing Conflicts with other extens…
Browse files Browse the repository at this point in the history
…ions #37
  • Loading branch information
eric2788 committed Jan 13, 2024
1 parent bcee285 commit d95166e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 2 additions & 7 deletions src/adapters/websocket-hook.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = {}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.')
Expand Down
19 changes: 14 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"

[email protected]:
version "4.21.10"
Expand Down

0 comments on commit d95166e

Please sign in to comment.