@mercuryworkshop/epoxy-transport 2.1.12 → 2.1.14
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 +496 -640
- package/dist/index.mjs +496 -640
- package/package.json +2 -2
- package/src/main.ts +19 -16
- package/dist/module.js +0 -1561
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercuryworkshop/epoxy-transport",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.14",
|
|
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
|
}
|