@mercuryworkshop/epoxy-transport 2.1.13 → 2.1.15
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/dist/index.js +581 -632
- package/dist/index.mjs +487 -631
- package/esbuild.bundle.mjs +20 -2
- package/package.json +2 -2
- package/src/main.ts +19 -16
- package/dist/module.js +0 -1561
package/esbuild.bundle.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// import { dtsPlugin } from "esbuild-plugin-d.ts";
|
|
2
2
|
import { build } from "esbuild";
|
|
3
3
|
import path from 'node:path'
|
|
4
|
-
import fs from 'node:fs'
|
|
4
|
+
import fs, { readFileSync } from 'node:fs'
|
|
5
5
|
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
6
6
|
|
|
7
7
|
const umdWrapperOptions = {
|
|
@@ -10,6 +10,24 @@ const umdWrapperOptions = {
|
|
|
10
10
|
amdLoaderName: "define" // <= default
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
//for the CJS build: we take the import url and translate it into it's corresponding functions and annd that back to the file.
|
|
14
|
+
const dataUrl = {
|
|
15
|
+
name: 'data-url-to-functions',
|
|
16
|
+
setup(build) {
|
|
17
|
+
build.onLoad({ filter: /\.js$/ }, (args) => {
|
|
18
|
+
const source = readFileSync(args.path, 'utf-8');
|
|
19
|
+
const transformedSource = source.replace(/import\s+(?:{[^}]*}\s+from\s+)?['"]data:application\/javascript;base64,([^'"]+)['"];\s*/g, (_, b64) => {
|
|
20
|
+
const code = Buffer.from(b64, 'base64').toString('utf-8');
|
|
21
|
+
return code;
|
|
22
|
+
})
|
|
23
|
+
return {
|
|
24
|
+
contents: transformedSource,
|
|
25
|
+
loader: 'js'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
let wasmPlugin = {
|
|
14
32
|
name: 'wasm',
|
|
15
33
|
setup(build) {
|
|
@@ -86,7 +104,7 @@ build({
|
|
|
86
104
|
entryPoints: [`./src/main.ts`],
|
|
87
105
|
outfile: `./dist/index.js`,
|
|
88
106
|
external: ["fs", "ws", "path"],
|
|
89
|
-
plugins: [wasmPlugin, umdWrapper(umdWrapperOptions)]
|
|
107
|
+
plugins: [wasmPlugin, dataUrl, umdWrapper(umdWrapperOptions)]
|
|
90
108
|
// plugins: [dtsPlugin({
|
|
91
109
|
// outDir: `./dist/`,
|
|
92
110
|
// tsconfig: "tsconfig.json"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercuryworkshop/epoxy-transport",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.15",
|
|
4
4
|
"description": "a bare transport that implements end-to-end encryption with epoxy-tls and wisp",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"keywords": [],
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"prepare": "npm run build"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@mercuryworkshop/epoxy-tls": "2.1.
|
|
15
|
+
"@mercuryworkshop/epoxy-tls": "2.1.7-1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@mercuryworkshop/bare-mux": "^2.0.9",
|
package/src/main.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { BareHeaders, TransferrableResponse, BareTransport } from "@mercuryworkshop/bare-mux";
|
|
2
|
-
import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers } from "@mercuryworkshop/epoxy-tls";
|
|
2
|
+
import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers, info } from "@mercuryworkshop/epoxy-tls";
|
|
3
|
+
|
|
4
|
+
export { info as epoxyInfo };
|
|
5
|
+
|
|
3
6
|
export default class EpoxyTransport implements BareTransport {
|
|
4
7
|
canstart = true;
|
|
5
|
-
|
|
8
|
+
ready = false;
|
|
9
|
+
|
|
10
|
+
client: EpoxyClient = null!;
|
|
11
|
+
|
|
6
12
|
wisp: string;
|
|
7
13
|
wisp_v2: boolean;
|
|
8
14
|
udp_extension_required: boolean;
|
|
9
|
-
EpoxyHandlers: Awaited<ReturnType<any>>["EpoxyHandlers"]["prototype"] = null!;
|
|
10
15
|
|
|
11
16
|
constructor({ wisp, wisp_v2, udp_extension_required }) {
|
|
12
17
|
this.wisp = wisp;
|
|
@@ -20,12 +25,10 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
20
25
|
options.user_agent = navigator.userAgent;
|
|
21
26
|
options.udp_extension_required = this.udp_extension_required;
|
|
22
27
|
options.wisp_v2 = this.wisp_v2;
|
|
23
|
-
this.
|
|
24
|
-
this.EpoxyHandlers = EpoxyHandlers;
|
|
28
|
+
this.client = new EpoxyClient(this.wisp, options);
|
|
25
29
|
|
|
26
30
|
this.ready = true;
|
|
27
31
|
}
|
|
28
|
-
ready = false;
|
|
29
32
|
async meta() { }
|
|
30
33
|
|
|
31
34
|
async request(
|
|
@@ -39,12 +42,12 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
39
42
|
body = await body.arrayBuffer();
|
|
40
43
|
|
|
41
44
|
try {
|
|
42
|
-
let
|
|
45
|
+
let res = await this.client.fetch(remote.href, { method, body, headers, redirect: "manual" });
|
|
43
46
|
return {
|
|
44
|
-
body:
|
|
45
|
-
headers: (
|
|
46
|
-
status:
|
|
47
|
-
statusText:
|
|
47
|
+
body: res.body!,
|
|
48
|
+
headers: (res as any).rawHeaders,
|
|
49
|
+
status: res.status,
|
|
50
|
+
statusText: res.statusText,
|
|
48
51
|
};
|
|
49
52
|
} catch (err) {
|
|
50
53
|
console.error(err);
|
|
@@ -62,25 +65,25 @@ export default class EpoxyTransport implements BareTransport {
|
|
|
62
65
|
onclose: (code: number, reason: string) => void,
|
|
63
66
|
onerror: (error: string) => void,
|
|
64
67
|
): [(data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void] {
|
|
65
|
-
let handlers = new
|
|
68
|
+
let handlers = new EpoxyHandlers(
|
|
66
69
|
onopen,
|
|
67
70
|
onclose,
|
|
68
71
|
onerror,
|
|
69
72
|
(data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
|
|
70
73
|
);
|
|
71
|
-
let
|
|
74
|
+
let ws = this.client.connect_websocket(
|
|
72
75
|
handlers,
|
|
73
76
|
url.href,
|
|
74
77
|
protocols,
|
|
75
|
-
{ "Origin": origin }
|
|
78
|
+
Object.assign({ "Origin": origin }, requestHeaders)
|
|
76
79
|
);
|
|
77
80
|
|
|
78
81
|
return [
|
|
79
82
|
async (data) => {
|
|
80
|
-
(await
|
|
83
|
+
(await ws).send(data);
|
|
81
84
|
},
|
|
82
85
|
async (code, reason) => {
|
|
83
|
-
(await
|
|
86
|
+
(await ws).close(code, reason || "")
|
|
84
87
|
}
|
|
85
88
|
]
|
|
86
89
|
}
|