@mercuryworkshop/epoxy-transport 2.1.19 → 2.1.20

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercuryworkshop/epoxy-transport",
3
- "version": "2.1.19",
3
+ "version": "2.1.20",
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
  "prepack": "npm run build"
13
13
  },
14
14
  "dependencies": {
15
- "@mercuryworkshop/epoxy-tls": "2.1.10-1"
15
+ "@mercuryworkshop/epoxy-tls": "2.1.11-1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@mercuryworkshop/bare-mux": "^2.1.3",
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(
@@ -74,6 +101,7 @@ export default class EpoxyTransport implements BareTransport {
74
101
  onerror,
75
102
  (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
76
103
  );
104
+
77
105
  let ws = this.client.connect_websocket(
78
106
  handlers,
79
107
  url.href,