@mercuryworkshop/epoxy-transport 2.0.1 → 2.0.3

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,16 +1,13 @@
1
1
  {
2
2
  "name": "@mercuryworkshop/epoxy-transport",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
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": [],
7
7
  "author": "",
8
8
  "type": "module",
9
- "scripts": {
10
- "build": "node esbuild.bundle.mjs"
11
- },
12
9
  "dependencies": {
13
- "@mercuryworkshop/epoxy-tls": "^2.0.0-3",
10
+ "@mercuryworkshop/epoxy-tls": "^2.0.2-1",
14
11
  "esbuild-plugin-umd-wrapper": "^2.0.0",
15
12
  "rollup": "^4.12.0",
16
13
  "rollup-plugin-node-resolve": "^5.2.0",
@@ -18,7 +15,7 @@
18
15
  "ws": "8.16.0"
19
16
  },
20
17
  "devDependencies": {
21
- "@mercuryworkshop/bare-mux": "^1.1.1",
18
+ "@mercuryworkshop/bare-mux": "^1.1.3",
22
19
  "esbuild": "^0.19.11",
23
20
  "esbuild-plugin-d.ts": "^1.2.2"
24
21
  },
@@ -33,5 +30,8 @@
33
30
  "import": "./lib/index.cjs"
34
31
  }
35
32
  }
33
+ },
34
+ "scripts": {
35
+ "build": "node esbuild.bundle.mjs"
36
36
  }
37
- }
37
+ }
package/src/main.ts CHANGED
@@ -6,17 +6,19 @@ export class EpoxyClient implements BareTransport {
6
6
  canstart = true;
7
7
  epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
8
8
  wisp: string;
9
+ EpoxyHandlers: Awaited<ReturnType<any>>["EpoxyHandlers"]["prototype"] = null!;
9
10
 
10
11
  constructor({ wisp }) {
11
12
  this.wisp = wisp;
12
13
  }
13
14
  async init() {
14
- const { EpoxyClient, EpoxyClientOptions } = await epoxy();
15
+ const { EpoxyClient, EpoxyClientOptions, EpoxyHandlers } = await epoxy();
15
16
 
16
17
  let options = new EpoxyClientOptions();
17
18
  options.user_agent = navigator.userAgent;
18
19
  options.udp_extension_required = false;
19
20
  this.epxclient = await new EpoxyClient(this.wisp, ROOTS, options);
21
+ this.EpoxyHandlers = EpoxyHandlers;
20
22
 
21
23
  this.ready = true;
22
24
  }
@@ -56,19 +58,27 @@ export class EpoxyClient implements BareTransport {
56
58
  onmessage: (data: Blob | ArrayBuffer | string) => void,
57
59
  onclose: (code: number, reason: string) => void,
58
60
  onerror: (error: string) => void,
59
- ): (data: Blob | ArrayBuffer | string) => void {
60
- let epsocket = this.epxclient.connect_ws(
61
+ ): [ (data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void ] {
62
+ let handlers = new this.EpoxyHandlers(
61
63
  onopen,
62
64
  onclose,
63
65
  onerror,
64
- (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
66
+ (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
67
+ );
68
+ let epsocket = this.epxclient.connect_websocket(
69
+ handlers,
65
70
  url.href,
66
71
  protocols,
67
- origin,
72
+ Object.assign({ "Origin": origin }, requestHeaders)
68
73
  );
69
74
 
70
- return async (data) => {
71
- await epsocket.send(data);
72
- }
75
+ return [
76
+ async (data) => {
77
+ (await epsocket).send(data);
78
+ },
79
+ async (code, reason) => {
80
+ (await epsocket).close(close, reason)
81
+ }
82
+ ]
73
83
  }
74
84
  }