@mercuryworkshop/epoxy-transport 2.0.0 → 2.0.2

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 CHANGED
@@ -1530,14 +1530,17 @@ var EpoxyClient = class {
1530
1530
  canstart = true;
1531
1531
  epxclient = null;
1532
1532
  wisp;
1533
+ EpoxyHandlers = null;
1533
1534
  constructor({ wisp }) {
1534
1535
  this.wisp = wisp;
1535
1536
  }
1536
1537
  async init() {
1537
- const { EpoxyClient: EpoxyClient2, EpoxyClientOptions } = await epoxy_module_bundled_default();
1538
+ const { EpoxyClient: EpoxyClient2, EpoxyClientOptions, EpoxyHandlers } = await epoxy_module_bundled_default();
1538
1539
  let options = new EpoxyClientOptions();
1539
1540
  options.user_agent = navigator.userAgent;
1541
+ options.udp_extension_required = false;
1540
1542
  this.epxclient = await new EpoxyClient2(this.wisp, certs_module_default, options);
1543
+ this.EpoxyHandlers = EpoxyHandlers;
1541
1544
  this.ready = true;
1542
1545
  }
1543
1546
  ready = false;
@@ -1560,18 +1563,26 @@ var EpoxyClient = class {
1560
1563
  }
1561
1564
  }
1562
1565
  connect(url, origin, protocols, requestHeaders, onopen, onmessage, onclose, onerror) {
1563
- let epsocket = this.epxclient.connect_ws(
1566
+ let handlers = new this.EpoxyHandlers(
1564
1567
  onopen,
1565
1568
  onclose,
1566
1569
  onerror,
1567
- (data) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
1570
+ (data) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
1571
+ );
1572
+ let epsocket = this.epxclient.connect_websocket(
1573
+ handlers,
1568
1574
  url.href,
1569
1575
  protocols,
1570
- origin
1576
+ Object.assign({ "Origin": origin }, requestHeaders)
1571
1577
  );
1572
- return async (data) => {
1573
- await epsocket.send(data);
1574
- };
1578
+ return [
1579
+ async (data) => {
1580
+ (await epsocket).send(data);
1581
+ },
1582
+ async (code, reason) => {
1583
+ (await epsocket).close(close, reason);
1584
+ }
1585
+ ];
1575
1586
  }
1576
1587
  };
1577
1588
  if (typeof module.exports == "object" && typeof exports == "object") {
package/dist/module.js CHANGED
@@ -1491,14 +1491,17 @@ var EpoxyClient = class {
1491
1491
  canstart = true;
1492
1492
  epxclient = null;
1493
1493
  wisp;
1494
+ EpoxyHandlers = null;
1494
1495
  constructor({ wisp }) {
1495
1496
  this.wisp = wisp;
1496
1497
  }
1497
1498
  async init() {
1498
- const { EpoxyClient: EpoxyClient2, EpoxyClientOptions } = await epoxy_module_bundled_default();
1499
+ const { EpoxyClient: EpoxyClient2, EpoxyClientOptions, EpoxyHandlers } = await epoxy_module_bundled_default();
1499
1500
  let options = new EpoxyClientOptions();
1500
1501
  options.user_agent = navigator.userAgent;
1502
+ options.udp_extension_required = false;
1501
1503
  this.epxclient = await new EpoxyClient2(this.wisp, certs_module_default, options);
1504
+ this.EpoxyHandlers = EpoxyHandlers;
1502
1505
  this.ready = true;
1503
1506
  }
1504
1507
  ready = false;
@@ -1521,18 +1524,26 @@ var EpoxyClient = class {
1521
1524
  }
1522
1525
  }
1523
1526
  connect(url, origin, protocols, requestHeaders, onopen, onmessage, onclose, onerror) {
1524
- let epsocket = this.epxclient.connect_ws(
1527
+ let handlers = new this.EpoxyHandlers(
1525
1528
  onopen,
1526
1529
  onclose,
1527
1530
  onerror,
1528
- (data) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
1531
+ (data) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
1532
+ );
1533
+ let epsocket = this.epxclient.connect_websocket(
1534
+ handlers,
1529
1535
  url.href,
1530
1536
  protocols,
1531
- origin
1537
+ Object.assign({ "Origin": origin }, requestHeaders)
1532
1538
  );
1533
- return async (data) => {
1534
- await epsocket.send(data);
1535
- };
1539
+ return [
1540
+ async (data) => {
1541
+ (await epsocket).send(data);
1542
+ },
1543
+ async (code, reason) => {
1544
+ (await epsocket).close(close, reason);
1545
+ }
1546
+ ];
1536
1547
  }
1537
1548
  };
1538
1549
  export {
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@mercuryworkshop/epoxy-transport",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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
10
  "@mercuryworkshop/epoxy-tls": "^2.0.0-3",
14
11
  "esbuild-plugin-umd-wrapper": "^2.0.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
@@ -3,71 +3,82 @@ import epoxy from "@mercuryworkshop/epoxy-tls";
3
3
  //@ts-expect-error typescript doesnt follow the npm exports for some reason
4
4
  import ROOTS from "@mercuryworkshop/epoxy-tls/certs"
5
5
  export class EpoxyClient implements BareTransport {
6
- canstart = true;
7
- epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
8
- wisp: string;
6
+ canstart = true;
7
+ epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
8
+ wisp: string;
9
+ EpoxyHandlers: Awaited<ReturnType<any>>["EpoxyHandlers"]["prototype"] = null!;
9
10
 
10
- constructor({ wisp }) {
11
- this.wisp = wisp;
12
- }
13
- async init() {
14
- const { EpoxyClient, EpoxyClientOptions } = await epoxy();
11
+ constructor({ wisp }) {
12
+ this.wisp = wisp;
13
+ }
14
+ async init() {
15
+ const { EpoxyClient, EpoxyClientOptions, EpoxyHandlers } = await epoxy();
15
16
 
16
- let options = new EpoxyClientOptions();
17
- options.user_agent = navigator.userAgent;
18
- this.epxclient = await new EpoxyClient(this.wisp, ROOTS, options);
17
+ let options = new EpoxyClientOptions();
18
+ options.user_agent = navigator.userAgent;
19
+ options.udp_extension_required = false;
20
+ this.epxclient = await new EpoxyClient(this.wisp, ROOTS, options);
21
+ this.EpoxyHandlers = EpoxyHandlers;
19
22
 
20
- this.ready = true;
21
- }
22
- ready = false;
23
- async meta() { }
23
+ this.ready = true;
24
+ }
25
+ ready = false;
26
+ async meta() { }
24
27
 
25
- async request(
26
- remote: URL,
27
- method: string,
28
- body: BodyInit | null,
29
- headers: BareHeaders,
30
- signal: AbortSignal | undefined
31
- ): Promise<TransferrableResponse> {
32
- if (body instanceof Blob)
33
- body = await body.arrayBuffer();
28
+ async request(
29
+ remote: URL,
30
+ method: string,
31
+ body: BodyInit | null,
32
+ headers: BareHeaders,
33
+ signal: AbortSignal | undefined
34
+ ): Promise<TransferrableResponse> {
35
+ if (body instanceof Blob)
36
+ body = await body.arrayBuffer();
34
37
 
35
- try {
36
- let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
37
- return {
38
- body: payload.body!,
39
- headers: (payload as any).rawHeaders,
40
- status: payload.status,
41
- statusText: payload.statusText,
42
- };
43
- } catch (err) {
44
- console.error(err);
45
- throw err;
46
- }
47
- }
38
+ try {
39
+ let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
40
+ return {
41
+ body: payload.body!,
42
+ headers: (payload as any).rawHeaders,
43
+ status: payload.status,
44
+ statusText: payload.statusText,
45
+ };
46
+ } catch (err) {
47
+ console.error(err);
48
+ throw err;
49
+ }
50
+ }
48
51
 
49
- connect(
50
- url: URL,
51
- origin: string,
52
- protocols: string[],
53
- requestHeaders: BareHeaders,
54
- onopen: (protocol: string) => void,
55
- onmessage: (data: Blob | ArrayBuffer | string) => void,
56
- onclose: (code: number, reason: string) => void,
57
- onerror: (error: string) => void,
58
- ): (data: Blob | ArrayBuffer | string) => void {
59
- let epsocket = this.epxclient.connect_ws(
60
- onopen,
61
- onclose,
62
- onerror,
63
- (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
64
- url.href,
65
- protocols,
66
- origin,
67
- );
52
+ connect(
53
+ url: URL,
54
+ origin: string,
55
+ protocols: string[],
56
+ requestHeaders: BareHeaders,
57
+ onopen: (protocol: string) => void,
58
+ onmessage: (data: Blob | ArrayBuffer | string) => void,
59
+ onclose: (code: number, reason: string) => void,
60
+ onerror: (error: string) => void,
61
+ ): [ (data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void ] {
62
+ let handlers = new this.EpoxyHandlers(
63
+ onopen,
64
+ onclose,
65
+ onerror,
66
+ (data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data)
67
+ );
68
+ let epsocket = this.epxclient.connect_websocket(
69
+ handlers,
70
+ url.href,
71
+ protocols,
72
+ Object.assign({ "Origin": origin }, requestHeaders)
73
+ );
68
74
 
69
- return async (data) => {
70
- await epsocket.send(data);
71
- }
72
- }
75
+ return [
76
+ async (data) => {
77
+ (await epsocket).send(data);
78
+ },
79
+ async (code, reason) => {
80
+ (await epsocket).close(close, reason)
81
+ }
82
+ ]
83
+ }
73
84
  }