mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
npm packaging
This commit is contained in:
parent
6e3f968f9c
commit
656eb67bfb
9 changed files with 82 additions and 24 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -3,3 +3,7 @@ server/src/*.pem
|
|||
client/pkg
|
||||
client/out
|
||||
.direnv
|
||||
client/index.js
|
||||
client/module.js
|
||||
client/module.d.ts
|
||||
pnpm-lock.yaml
|
||||
|
|
14
.npmignore
Normal file
14
.npmignore
Normal file
|
@ -0,0 +1,14 @@
|
|||
/target
|
||||
server/
|
||||
out/
|
||||
client/src
|
||||
client/pkg
|
||||
client/out
|
||||
client/demo.js
|
||||
client/index.html
|
||||
client/build.sh
|
||||
client/Cargo.toml
|
||||
.direnv
|
||||
Cargo.toml
|
||||
Cargo.lock
|
||||
pnpm-lock.yaml
|
|
@ -7,20 +7,25 @@ mkdir out/
|
|||
|
||||
cargo build --target wasm32-unknown-unknown --release
|
||||
echo "[ws] built rust"
|
||||
wasm-bindgen --weak-refs --no-typescript --target no-modules --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
|
||||
wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
|
||||
echo "[ws] bindgen finished"
|
||||
|
||||
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
||||
time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
time wasm-opt out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
echo "[ws] optimized"
|
||||
|
||||
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
||||
WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm)
|
||||
AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init(input) \{input=\'data:application/wasm;base64,$WASM_BASE64\'}"
|
||||
AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//let wasm_bindgen/let epoxy}"
|
||||
AUTOGENERATED_SOURCE="${AUTOGENERATED_SOURCE//wasm_bindgen =/epoxy =}"
|
||||
echo "${AUTOGENERATED_SOURCE}" > out/epoxy_client_bundled.js
|
||||
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init() \{let input=\'data:application/wasm;base64,$WASM_BASE64\'}
|
||||
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init\(instance\, module\);/__wbg_finalize_init\(instance\, module\); return epoxy}
|
||||
echo "$AUTOGENERATED_SOURCE" > index.js
|
||||
cp index.js module.js
|
||||
echo "module.exports = epoxy" >> module.js
|
||||
|
||||
cp -r src/web/* out/
|
||||
AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts")
|
||||
AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*}
|
||||
echo "$AUTOGENERATED_TYPEDEFS" >"module.d.ts"
|
||||
echo "} export default function epoxy(): Promise<typeof wasm_bindgen>;" >> "module.d.ts"
|
||||
|
||||
rm -rf out/
|
||||
echo "[ws] done!"
|
||||
(cd out; python3 -m http.server)
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test");
|
||||
const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test");
|
||||
|
||||
await epoxy();
|
||||
let { EpoxyClient } = await epoxy();
|
||||
|
||||
const tconn0 = performance.now();
|
||||
// args: websocket url, user agent, redirect limit
|
||||
let epoxy_client = await new epoxy.EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
||||
let epoxy_client = await new EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
||||
const tconn1 = performance.now();
|
||||
console.warn(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
|
||||
|
13
client/index.html
Normal file
13
client/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>epoxy</title>
|
||||
<script src="out.cjs"></script>
|
||||
<script src="index.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
running... (wait for the browser alert if not running ws test)
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -7,8 +7,8 @@ mod wrappers;
|
|||
|
||||
use tokioio::TokioIo;
|
||||
use utils::{ReplaceErr, UriExt};
|
||||
use wrappers::{IncomingBody, WsStreamWrapper};
|
||||
use websocket::EpxWebSocket;
|
||||
use wrappers::{IncomingBody, WsStreamWrapper};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -17,7 +17,7 @@ use bytes::Bytes;
|
|||
use futures_util::StreamExt;
|
||||
use http::{uri, HeaderName, HeaderValue, Request, Response};
|
||||
use hyper::{body::Incoming, client::conn::http1::Builder, Uri};
|
||||
use js_sys::{Function, Array, Object, Reflect, Uint8Array};
|
||||
use js_sys::{Array, Function, Object, Reflect, Uint8Array};
|
||||
use penguin_mux_wasm::{Multiplexor, MuxStream};
|
||||
use tokio_rustls::{client::TlsStream, rustls, rustls::RootCertStore, TlsConnector};
|
||||
use tokio_util::{
|
||||
|
@ -226,7 +226,10 @@ impl EpoxyClient {
|
|||
protocols: Vec<String>,
|
||||
origin: String,
|
||||
) -> Result<EpxWebSocket, JsError> {
|
||||
EpxWebSocket::connect(self, onopen, onclose, onerror, onmessage, url, protocols, origin).await
|
||||
EpxWebSocket::connect(
|
||||
self, onopen, onclose, onerror, onmessage, url, protocols, origin,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch(&self, url: String, options: Object) -> Result<web_sys::Response, JsError> {
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>epoxy</title>
|
||||
<script src="epoxy_client_bundled.js"></script>
|
||||
<script src="index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
running... (wait for the browser alert if not running ws test)
|
||||
</body>
|
||||
</html>
|
|
@ -26,6 +26,7 @@ pub struct EpxWebSocket {
|
|||
#[wasm_bindgen]
|
||||
impl EpxWebSocket {
|
||||
#[wasm_bindgen(constructor)]
|
||||
/// DO NOT CALL THIS!!!!!!!!!!!!!!!!!!!
|
||||
pub fn new() -> Result<EpxWebSocket, JsError> {
|
||||
Err(jerr!("Use EpoxyClient.connect_ws() instead."))
|
||||
}
|
||||
|
@ -156,7 +157,8 @@ impl EpxWebSocket {
|
|||
let (tx, rx) = oneshot::channel();
|
||||
self.msg_sender.send(EpxMsg::SendText(payload, tx)).await?;
|
||||
Ok(rx.await??)
|
||||
}.await;
|
||||
}
|
||||
.await;
|
||||
if let Err(ret) = ret {
|
||||
let _ = onerr.call1(&JsValue::null(), &jval!(ret.clone()));
|
||||
Err(ret)
|
||||
|
|
27
package.json
Normal file
27
package.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "@mercuryworkshop/epoxy-tls",
|
||||
"version": "1.0.1",
|
||||
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
|
||||
"scripts": {
|
||||
"build": "cd client && ./build.sh"
|
||||
},
|
||||
"keywords": [
|
||||
"wasm",
|
||||
"ssl",
|
||||
"tls",
|
||||
"rust",
|
||||
"proxy",
|
||||
"http"
|
||||
],
|
||||
"author": "MercuryWorkshop",
|
||||
"repository": "https://github.com/MercuryWorkshop/epoxy-tls",
|
||||
"license": "MIT",
|
||||
"browser": "./client/module.js",
|
||||
"module": "./client/module.js",
|
||||
"main": "./client/module.js",
|
||||
"types": "./client/module.d.ts",
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.19.11",
|
||||
"esbuild-plugin-wasm": "^1.1.0"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue