@floegence/floe-webapp-protocol 0.16.0 → 0.18.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.
- package/dist/client.d.ts +2 -0
- package/dist/index2.js +71 -57
- package/package.json +2 -1
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface ProtocolContextValue {
|
|
|
9
9
|
client: () => Client | null;
|
|
10
10
|
contract: () => ProtocolContract;
|
|
11
11
|
connect: (config: ConnectConfig) => Promise<void>;
|
|
12
|
+
/** Force a hard reconnect (disconnect old client and build a new one). */
|
|
13
|
+
reconnect: (config?: ConnectConfig) => Promise<void>;
|
|
12
14
|
disconnect: () => void;
|
|
13
15
|
}
|
|
14
16
|
export type { AutoReconnectConfig, ConnectionStatus };
|
package/dist/index2.js
CHANGED
|
@@ -1,74 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createStore as
|
|
3
|
-
import { createReconnectManager as
|
|
4
|
-
import { requestChannelGrant as
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
status:
|
|
9
|
-
error:
|
|
10
|
-
client:
|
|
11
|
-
}),
|
|
12
|
-
|
|
1
|
+
import { onCleanup as C, createComponent as P, useContext as M, createContext as I } from "solid-js";
|
|
2
|
+
import { createStore as T } from "solid-js/store";
|
|
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({
|
|
8
|
+
status: n.state().status,
|
|
9
|
+
error: n.state().error,
|
|
10
|
+
client: n.state().client
|
|
11
|
+
}), m = o.contract, w = n.subscribe((t) => {
|
|
12
|
+
d({
|
|
13
13
|
status: t.status,
|
|
14
14
|
error: t.error,
|
|
15
15
|
client: t.client
|
|
16
16
|
});
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
observer:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!c)
|
|
43
|
-
throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
|
|
44
|
-
return w(c, o);
|
|
45
|
-
}
|
|
46
|
-
if (!t.directInfo)
|
|
47
|
-
throw new Error("Direct mode requires `directInfo`");
|
|
48
|
-
return p(t.directInfo, o);
|
|
17
|
+
});
|
|
18
|
+
let s = null, r = null;
|
|
19
|
+
const h = async (t) => {
|
|
20
|
+
await n.connect({
|
|
21
|
+
autoReconnect: t.autoReconnect,
|
|
22
|
+
observer: t.observer,
|
|
23
|
+
connectOnce: async ({
|
|
24
|
+
signal: e,
|
|
25
|
+
observer: p
|
|
26
|
+
}) => {
|
|
27
|
+
const {
|
|
28
|
+
connectTunnelBrowser: v,
|
|
29
|
+
connectDirectBrowser: b
|
|
30
|
+
} = await import("@floegence/flowersec-core/browser"), i = {
|
|
31
|
+
observer: p,
|
|
32
|
+
signal: e,
|
|
33
|
+
keepaliveIntervalMs: t.keepaliveIntervalMs ?? 15e3,
|
|
34
|
+
connectTimeoutMs: t.connectTimeoutMs ?? 1e4,
|
|
35
|
+
handshakeTimeoutMs: t.handshakeTimeoutMs ?? 1e4
|
|
36
|
+
};
|
|
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)
|
|
40
|
+
throw new Error("Tunnel mode requires `getGrant`, `grant`, or `controlplane` config");
|
|
41
|
+
return v(l, i);
|
|
49
42
|
}
|
|
50
|
-
|
|
43
|
+
if (!t.directInfo)
|
|
44
|
+
throw new Error("Direct mode requires `directInfo`");
|
|
45
|
+
return b(t.directInfo, i);
|
|
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 = {
|
|
56
|
+
status: () => c.status,
|
|
57
|
+
error: () => c.error,
|
|
58
|
+
client: () => c.client,
|
|
59
|
+
contract: () => m,
|
|
60
|
+
connect: async (t) => {
|
|
61
|
+
s = t;
|
|
62
|
+
const e = n.state();
|
|
63
|
+
e.status === "connected" && e.client || e.status === "connecting" && !r || await a(t);
|
|
51
64
|
},
|
|
65
|
+
reconnect: a,
|
|
52
66
|
disconnect: () => {
|
|
53
|
-
|
|
67
|
+
n.disconnect();
|
|
54
68
|
}
|
|
55
69
|
};
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
}), P(
|
|
59
|
-
value:
|
|
70
|
+
return C(() => {
|
|
71
|
+
w(), n.disconnect();
|
|
72
|
+
}), P(u.Provider, {
|
|
73
|
+
value: f,
|
|
60
74
|
get children() {
|
|
61
|
-
return
|
|
75
|
+
return o.children;
|
|
62
76
|
}
|
|
63
77
|
});
|
|
64
78
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
79
|
+
function O() {
|
|
80
|
+
const o = M(u);
|
|
81
|
+
if (!o)
|
|
68
82
|
throw new Error("useProtocol must be used within a ProtocolProvider");
|
|
69
|
-
return
|
|
83
|
+
return o;
|
|
70
84
|
}
|
|
71
85
|
export {
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
D as ProtocolProvider,
|
|
87
|
+
O as useProtocol
|
|
74
88
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/index.d.ts",
|