@mercuryworkshop/epoxy-transport 2.1.19 → 2.1.21

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/package.json CHANGED
@@ -1,35 +1,34 @@
1
1
  {
2
- "name": "@mercuryworkshop/epoxy-transport",
3
- "version": "2.1.19",
4
- "description": "a bare transport that implements end-to-end encryption with epoxy-tls and wisp",
5
- "main": "./dist/index.mjs",
6
- "keywords": [],
7
- "author": "",
8
- "type": "module",
9
- "license": "AGPL-3.0-only",
10
- "scripts": {
11
- "build": "node esbuild.bundle.mjs",
12
- "prepack": "npm run build"
13
- },
14
- "dependencies": {
15
- "@mercuryworkshop/epoxy-tls": "2.1.10-1"
16
- },
17
- "devDependencies": {
18
- "@mercuryworkshop/bare-mux": "^2.1.3",
19
- "esbuild": "^0.24.0",
20
- "esbuild-plugin-d.ts": "^1.3.1",
21
- "esbuild-plugin-umd-wrapper": "^3.0.0"
22
- },
23
- "exports": {
24
- ".": {
25
- "browser": {
26
- "import": "./dist/index.mjs",
27
- "require": "./dist/index.js"
28
- },
29
- "node": {
30
- "require": "./lib/index.cjs",
31
- "import": "./lib/index.cjs"
32
- }
33
- }
34
- }
35
- }
2
+ "name": "@mercuryworkshop/epoxy-transport",
3
+ "version": "2.1.21",
4
+ "description": "a bare transport that implements end-to-end encryption with epoxy-tls and wisp",
5
+ "main": "./dist/index.mjs",
6
+ "keywords": [],
7
+ "author": "",
8
+ "type": "module",
9
+ "license": "AGPL-3.0-only",
10
+ "dependencies": {
11
+ "@mercuryworkshop/epoxy-tls": "2.1.11-1"
12
+ },
13
+ "devDependencies": {
14
+ "@mercuryworkshop/bare-mux": "^2.1.4",
15
+ "esbuild": "^0.24.0",
16
+ "esbuild-plugin-d.ts": "^1.3.1",
17
+ "esbuild-plugin-umd-wrapper": "^3.0.0"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "browser": {
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.js"
24
+ },
25
+ "node": {
26
+ "require": "./lib/index.cjs",
27
+ "import": "./lib/index.cjs"
28
+ }
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "node esbuild.bundle.mjs"
33
+ }
34
+ }
package/src/main.ts CHANGED
@@ -1,37 +1,64 @@
1
1
  import type { BareHeaders, TransferrableResponse, BareTransport } from "@mercuryworkshop/bare-mux";
2
- import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers, info } from "@mercuryworkshop/epoxy-tls";
2
+ import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers, info as epoxyInfo } from "@mercuryworkshop/epoxy-tls";
3
3
 
4
- export { info as epoxyInfo };
4
+ export { epoxyInfo };
5
+
6
+ export type EpoxyOptions = {
7
+ wisp_v2?: boolean,
8
+ udp_extension_required?: boolean,
9
+
10
+ title_case_headers?: boolean,
11
+ ws_title_case_headers?: boolean,
12
+
13
+ wisp_ws_protocols?: string[],
14
+
15
+ redirect_limit?: number,
16
+ header_limit?: number,
17
+ buffer_size?: number,
18
+ }
19
+ const opts = [
20
+ "wisp_v2",
21
+ "udp_extension_required",
22
+ "title_case_headers",
23
+ "ws_title_case_headers",
24
+ "wisp_ws_protocols",
25
+ "redirect_limit",
26
+ "header_limit",
27
+ "buffer_size"
28
+ ];
5
29
 
6
30
  export default class EpoxyTransport implements BareTransport {
7
31
  canstart = true;
8
32
  ready = false;
9
33
 
34
+ client_version: typeof epoxyInfo;
10
35
  client: EpoxyClient = null!;
11
-
12
36
  wisp: string;
13
- wisp_v2: boolean;
14
- udp_extension_required: boolean;
15
- title_case_headers: boolean;
16
-
17
- constructor({ wisp, wisp_v2, udp_extension_required, title_case_headers }) {
18
- this.wisp = wisp;
19
- this.wisp_v2 = wisp_v2 || false;
20
- this.udp_extension_required = udp_extension_required || false;
21
- this.title_case_headers = title_case_headers || true;
37
+ opts: EpoxyOptions;
38
+
39
+ constructor(opts: EpoxyOptions & { wisp: string }) {
40
+ this.wisp = opts.wisp;
41
+ this.opts = opts;
42
+
43
+ this.client_version = epoxyInfo;
44
+ }
45
+
46
+ setopt(opts: EpoxyClientOptions, opt: string) {
47
+ // == allows both null and undefined
48
+ if (this.opts[opt] != null) opts[opt] = this.opts[opt];
22
49
  }
50
+
23
51
  async init() {
24
52
  await initEpoxy();
25
53
 
26
54
  let options = new EpoxyClientOptions();
27
55
  options.user_agent = navigator.userAgent;
28
- options.udp_extension_required = this.udp_extension_required;
29
- options.wisp_v2 = this.wisp_v2;
30
- options.title_case_headers = this.title_case_headers;
56
+ opts.forEach(x => this.setopt(options, x))
31
57
  this.client = new EpoxyClient(this.wisp, options);
32
58
 
33
59
  this.ready = true;
34
60
  }
61
+
35
62
  async meta() { }
36
63
 
37
64
  async request(
@@ -60,7 +87,6 @@ export default class EpoxyTransport implements BareTransport {
60
87
 
61
88
  connect(
62
89
  url: URL,
63
- origin: string,
64
90
  protocols: string[],
65
91
  requestHeaders: BareHeaders,
66
92
  onopen: (protocol: string) => void,
@@ -74,15 +100,17 @@ export default class EpoxyTransport implements BareTransport {
74
100
  onerror,
75
101
  (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
76
102
  );
103
+
77
104
  let ws = this.client.connect_websocket(
78
105
  handlers,
79
106
  url.href,
80
107
  protocols,
81
- Object.assign({ "Origin": origin }, requestHeaders)
108
+ Object.assign(requestHeaders)
82
109
  );
83
110
 
84
111
  return [
85
112
  async (data) => {
113
+ if (data instanceof Blob) data = await data.arrayBuffer();
86
114
  (await ws).send(data);
87
115
  },
88
116
  async (code, reason) => {