@floegence/floe-webapp-protocol 0.27.4 → 0.28.0

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.
Files changed (2) hide show
  1. package/dist/index2.js +54 -41
  2. package/package.json +2 -2
package/dist/index2.js CHANGED
@@ -1,88 +1,101 @@
1
- import { onCleanup as C, createComponent as P, useContext as M, createContext as I } from "solid-js";
1
+ import { onCleanup as P, createComponent as I, useContext as M, createContext as y } from "solid-js";
2
2
  import { createStore as T } from "solid-js/store";
3
3
  import { createReconnectManager as x } from "@floegence/flowersec-core/reconnect";
4
- import { requestChannelGrant as y } from "./index4.js";
5
- const u = I();
6
- function D(o) {
7
- const n = x(), [c, d] = T({
4
+ import { requestChannelGrant as k } from "./index4.js";
5
+ const d = y();
6
+ function S(o) {
7
+ const n = x(), [c, m] = T({
8
8
  status: n.state().status,
9
9
  error: n.state().error,
10
10
  client: n.state().client
11
- }), m = o.contract, w = n.subscribe((t) => {
12
- d({
11
+ }), f = o.contract, w = n.subscribe((t) => {
12
+ m({
13
13
  status: t.status,
14
14
  error: t.error,
15
15
  client: t.client
16
16
  });
17
17
  });
18
- let s = null, r = null;
19
- const h = async (t) => {
20
- await n.connect({
18
+ let s = null, e = null;
19
+ const a = async (t, r) => {
20
+ const i = {
21
21
  autoReconnect: t.autoReconnect,
22
22
  observer: t.observer,
23
23
  connectOnce: async ({
24
- signal: e,
25
- observer: p
24
+ signal: p,
25
+ observer: v
26
26
  }) => {
27
27
  const {
28
- connectTunnelBrowser: v,
29
- connectDirectBrowser: b
30
- } = await import("@floegence/flowersec-core/browser"), i = {
31
- observer: p,
32
- signal: e,
28
+ connectTunnelBrowser: b,
29
+ connectDirectBrowser: C
30
+ } = await import("@floegence/flowersec-core/browser"), l = {
31
+ observer: v,
32
+ signal: p,
33
33
  keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
34
34
  connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
35
35
  handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
36
36
  };
37
37
  if ((t.mode ?? "tunnel") === "tunnel") {
38
- const l = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await y(t.controlplane) : null);
39
- if (!l)
38
+ const u = (t.getGrant ? await t.getGrant() : null) ?? t.grant ?? (t.controlplane ? await k(t.controlplane) : null);
39
+ if (!u)
40
40
  throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
41
- return v(l, i);
41
+ return b(u, l);
42
42
  }
43
43
  if (!t.directInfo)
44
44
  throw new Error("Direct mode requires `directInfo`");
45
- return b(t.directInfo, i);
45
+ return C(t.directInfo, l);
46
46
  }
47
- });
48
- }, a = async (t) => {
49
- const e = t ?? s;
50
- if (!e)
51
- throw new Error("reconnect() requires a config before the first connect() call");
52
- return r || (s = e, r = h(e).finally(() => {
53
- r = null;
54
- }), r);
55
- }, f = {
47
+ };
48
+ if (r === "hard") {
49
+ await n.connect(i);
50
+ return;
51
+ }
52
+ await n.connectIfNeeded(i);
53
+ }, h = {
56
54
  status: () => c.status,
57
55
  error: () => c.error,
58
56
  client: () => c.client,
59
- contract: () => m,
57
+ contract: () => f,
60
58
  connect: async (t) => {
61
59
  s = t;
62
- const e = n.state();
63
- e.status === "connected" && e.client || e.status === "connecting" && !r || await a(t);
60
+ const r = n.state();
61
+ if (!(r.status === "connected" && r.client) && !(r.status === "connecting" && !e)) {
62
+ if (e) {
63
+ await e;
64
+ return;
65
+ }
66
+ e = a(t, "if_needed").finally(() => {
67
+ e = null;
68
+ }), await e;
69
+ }
70
+ },
71
+ reconnect: async (t) => {
72
+ const r = t ?? s;
73
+ if (!r)
74
+ throw new Error("reconnect() requires a config before the first connect() call");
75
+ return e || (s = r, e = a(r, "hard").finally(() => {
76
+ e = null;
77
+ }), e);
64
78
  },
65
- reconnect: a,
66
79
  disconnect: () => {
67
80
  n.disconnect();
68
81
  }
69
82
  };
70
- return C(() => {
83
+ return P(() => {
71
84
  w(), n.disconnect();
72
- }), P(u.Provider, {
73
- value: f,
85
+ }), I(d.Provider, {
86
+ value: h,
74
87
  get children() {
75
88
  return o.children;
76
89
  }
77
90
  });
78
91
  }
79
- function O() {
80
- const o = M(u);
92
+ function A() {
93
+ const o = M(d);
81
94
  if (!o)
82
95
  throw new Error("useProtocol must be used within a ProtocolProvider");
83
96
  return o;
84
97
  }
85
98
  export {
86
- D as ProtocolProvider,
87
- O as useProtocol
99
+ S as ProtocolProvider,
100
+ A as useProtocol
88
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-protocol",
3
- "version": "0.27.4",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "solid-js": "^1.8.0"
31
31
  },
32
32
  "dependencies": {
33
- "@floegence/flowersec-core": "^0.9.0"
33
+ "@floegence/flowersec-core": "^0.11.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "solid-js": "^1.9.11",