@linkdlab/funcnodes_react_flow 0.1.1 → 0.1.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/module/dist/css/style.css +43 -0
- package/module/dist/frontend/datarenderer/images.d.ts +12 -0
- package/module/dist/frontend/datarenderer/images.d.ts.map +1 -0
- package/module/dist/frontend/datarenderer/index.d.ts +17 -0
- package/module/dist/frontend/datarenderer/index.d.ts.map +1 -0
- package/module/dist/frontend/datarenderer/plotly.d.ts +15 -0
- package/module/dist/frontend/datarenderer/plotly.d.ts.map +1 -0
- package/module/dist/frontend/dialog.d.ts +18 -0
- package/module/dist/frontend/dialog.d.ts.map +1 -0
- package/module/dist/frontend/edge.d.ts +6 -0
- package/module/dist/frontend/edge.d.ts.map +1 -0
- package/module/dist/frontend/funcnodesreactflow/index.d.ts +7 -0
- package/module/dist/frontend/funcnodesreactflow/index.d.ts.map +1 -0
- package/module/dist/frontend/funcnodesreactflow/react_flow_layer.d.ts +6 -0
- package/module/dist/frontend/funcnodesreactflow/react_flow_layer.d.ts.map +1 -0
- package/module/dist/frontend/header/index.d.ts +5 -0
- package/module/dist/frontend/header/index.d.ts.map +1 -0
- package/module/dist/frontend/index.d.ts +4 -0
- package/module/dist/frontend/index.d.ts.map +1 -0
- package/module/dist/frontend/lib.d.ts +11 -0
- package/module/dist/frontend/lib.d.ts.map +1 -0
- package/module/{src/frontend/node/index.tsx → dist/frontend/node/index.d.ts} +3 -3
- package/module/dist/frontend/node/index.d.ts.map +1 -0
- package/module/dist/frontend/node/io/default_input_renderer.d.ts +12 -0
- package/module/dist/frontend/node/io/default_input_renderer.d.ts.map +1 -0
- package/module/dist/frontend/node/io/default_output_render.d.ts +7 -0
- package/module/dist/frontend/node/io/default_output_render.d.ts.map +1 -0
- package/module/dist/frontend/node/io/handle_renderer.d.ts +6 -0
- package/module/dist/frontend/node/io/handle_renderer.d.ts.map +1 -0
- package/module/{src/frontend/node/io/index.tsx → dist/frontend/node/io/index.d.ts} +4 -4
- package/module/dist/frontend/node/io/index.d.ts.map +1 -0
- package/module/dist/frontend/node/io/io.d.ts +17 -0
- package/module/dist/frontend/node/io/io.d.ts.map +1 -0
- package/module/dist/frontend/node/io/nodeinput.d.ts +7 -0
- package/module/dist/frontend/node/io/nodeinput.d.ts.map +1 -0
- package/module/dist/frontend/node/io/nodeoutput.d.ts +7 -0
- package/module/dist/frontend/node/io/nodeoutput.d.ts.map +1 -0
- package/module/dist/frontend/node/node.d.ts +21 -0
- package/module/dist/frontend/node/node.d.ts.map +1 -0
- package/module/dist/frontend/utils/colorpicker.d.ts +20 -0
- package/module/dist/frontend/utils/colorpicker.d.ts.map +1 -0
- package/module/dist/frontend/utils/jsondata.d.ts +7 -0
- package/module/dist/frontend/utils/jsondata.d.ts.map +1 -0
- package/module/dist/frontend/utils/table.d.ts +12 -0
- package/module/dist/frontend/utils/table.d.ts.map +1 -0
- package/module/dist/funcnodes/funcnodesworker.d.ts +73 -0
- package/module/dist/funcnodes/funcnodesworker.d.ts.map +1 -0
- package/module/{src/funcnodes/index.ts → dist/funcnodes/index.d.ts} +5 -4
- package/module/dist/funcnodes/index.d.ts.map +1 -0
- package/module/dist/funcnodes/websocketworker.d.ts +28 -0
- package/module/dist/funcnodes/websocketworker.d.ts.map +1 -0
- package/module/dist/funcnodes/workermanager.d.ts +33 -0
- package/module/dist/funcnodes/workermanager.d.ts.map +1 -0
- package/module/dist/index.d.ts +3 -0
- package/module/dist/index.d.ts.map +1 -0
- package/module/dist/index.js +4673 -0
- package/module/dist/states/edge.d.ts +8 -0
- package/module/dist/states/edge.d.ts.map +1 -0
- package/module/{src/states/edge.t.ts → dist/states/edge.t.d.ts} +17 -20
- package/module/dist/states/edge.t.d.ts.map +1 -0
- package/module/dist/states/fnrfzst.d.ts +11 -0
- package/module/dist/states/fnrfzst.d.ts.map +1 -0
- package/module/dist/states/fnrfzst.t.d.ts +101 -0
- package/module/dist/states/fnrfzst.t.d.ts.map +1 -0
- package/module/{src/states/index.ts → dist/states/index.d.ts} +8 -7
- package/module/dist/states/index.d.ts.map +1 -0
- package/module/dist/states/lib.d.ts +4 -0
- package/module/dist/states/lib.d.ts.map +1 -0
- package/module/dist/states/lib.t.d.ts +25 -0
- package/module/dist/states/lib.t.d.ts.map +1 -0
- package/module/dist/states/node.d.ts +5 -0
- package/module/dist/states/node.d.ts.map +1 -0
- package/module/{src/states/node.t.ts → dist/states/node.t.d.ts} +74 -98
- package/module/dist/states/node.t.d.ts.map +1 -0
- package/module/dist/states/nodeio.t.d.ts +68 -0
- package/module/dist/states/nodeio.t.d.ts.map +1 -0
- package/module/dist/states/nodespace.d.ts +4 -0
- package/module/dist/states/nodespace.d.ts.map +1 -0
- package/module/dist/states/nodespace.t.d.ts +17 -0
- package/module/dist/states/nodespace.t.d.ts.map +1 -0
- package/module/dist/states/reactflow.d.ts +9 -0
- package/module/dist/states/reactflow.d.ts.map +1 -0
- package/module/dist/states/reactflow.t.d.ts +12 -0
- package/module/dist/states/reactflow.t.d.ts.map +1 -0
- package/module/{src/types/rendering.t.ts → dist/types/rendering.t.d.ts} +11 -13
- package/module/dist/types/rendering.t.d.ts.map +1 -0
- package/module/{src/utils/index.ts → dist/utils/index.d.ts} +4 -4
- package/module/dist/utils/index.d.ts.map +1 -0
- package/module/dist/utils/objects.d.ts +20 -0
- package/module/dist/utils/objects.d.ts.map +1 -0
- package/package.json +32 -23
- package/app/public/favicon.ico +0 -0
- package/app/public/index.html +0 -43
- package/app/public/logo192.png +0 -0
- package/app/public/logo512.png +0 -0
- package/app/public/manifest.json +0 -25
- package/app/public/robots.txt +0 -3
- package/app/public/worker_manager +0 -1
- package/app/src/App.css +0 -38
- package/app/src/App.test.tsx +0 -9
- package/app/src/App.tsx +0 -22
- package/app/src/index.css +0 -13
- package/app/src/index.tsx +0 -19
- package/app/src/react-app-env.d.ts +0 -1
- package/app/src/reportWebVitals.ts +0 -15
- package/app/src/setupTests.ts +0 -5
- package/app/tsconfig.app.json +0 -10
- package/app/webpack.config.js +0 -143
- package/module/src/frontend/datarenderer/images.tsx +0 -28
- package/module/src/frontend/datarenderer/index.tsx +0 -54
- package/module/src/frontend/datarenderer/plotly.tsx +0 -82
- package/module/src/frontend/dialog.scss +0 -88
- package/module/src/frontend/dialog.tsx +0 -71
- package/module/src/frontend/edge.scss +0 -15
- package/module/src/frontend/edge.tsx +0 -32
- package/module/src/frontend/funcnodesreactflow/funcnodesreactflow.scss +0 -63
- package/module/src/frontend/funcnodesreactflow/index.tsx +0 -68
- package/module/src/frontend/funcnodesreactflow/react_flow_layer.tsx +0 -212
- package/module/src/frontend/header/header.scss +0 -48
- package/module/src/frontend/header/index.tsx +0 -269
- package/module/src/frontend/index.tsx +0 -4
- package/module/src/frontend/layout/htmlelements.scss +0 -63
- package/module/src/frontend/lib.scss +0 -157
- package/module/src/frontend/lib.tsx +0 -199
- package/module/src/frontend/node/io/default_input_renderer.tsx +0 -329
- package/module/src/frontend/node/io/default_output_render.tsx +0 -25
- package/module/src/frontend/node/io/handle_renderer.tsx +0 -94
- package/module/src/frontend/node/io/io.scss +0 -91
- package/module/src/frontend/node/io/io.tsx +0 -115
- package/module/src/frontend/node/io/nodeinput.tsx +0 -127
- package/module/src/frontend/node/io/nodeoutput.tsx +0 -43
- package/module/src/frontend/node/node.scss +0 -265
- package/module/src/frontend/node/node.tsx +0 -209
- package/module/src/frontend/utils/colorpicker.scss +0 -37
- package/module/src/frontend/utils/colorpicker.tsx +0 -342
- package/module/src/frontend/utils/jsondata.tsx +0 -19
- package/module/src/frontend/utils/table.scss +0 -22
- package/module/src/frontend/utils/table.tsx +0 -160
- package/module/src/funcnodes/funcnodesworker.ts +0 -456
- package/module/src/funcnodes/websocketworker.ts +0 -152
- package/module/src/funcnodes/workermanager.ts +0 -233
- package/module/src/index.tsx +0 -4
- package/module/src/states/edge.ts +0 -15
- package/module/src/states/fnrfzst.t.ts +0 -117
- package/module/src/states/fnrfzst.ts +0 -415
- package/module/src/states/lib.t.ts +0 -30
- package/module/src/states/lib.ts +0 -16
- package/module/src/states/node.ts +0 -46
- package/module/src/states/nodeio.t.ts +0 -103
- package/module/src/states/nodespace.t.ts +0 -57
- package/module/src/states/nodespace.ts +0 -90
- package/module/src/states/reactflow.t.ts +0 -27
- package/module/src/states/reactflow.ts +0 -49
- package/module/src/types/funcnodesreactflow.d.ts +0 -1
- package/module/src/utils/objects.ts +0 -131
- package/module/tsconfig.module.json +0 -15
- package/module/webpack.config.js +0 -140
- package/tsconfig.json +0 -18
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import {
|
|
3
|
-
FullState,
|
|
4
|
-
FuncNodesReactFlowZustandInterface,
|
|
5
|
-
JSONMessage,
|
|
6
|
-
NodeSpaceEvent,
|
|
7
|
-
} from "../states/fnrfzst.t";
|
|
8
|
-
import { NodeActionUpdate, NodeType, PartialNodeType } from "../states/node.t"; // Import the missing type
|
|
9
|
-
import { deep_merge } from "../utils";
|
|
10
|
-
type CmdMessage = {
|
|
11
|
-
type: string;
|
|
12
|
-
cmd: string;
|
|
13
|
-
kwargs: any;
|
|
14
|
-
id?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
interface WorkerProps {
|
|
18
|
-
zustand: FuncNodesReactFlowZustandInterface;
|
|
19
|
-
uuid: string;
|
|
20
|
-
on_error?: (error: string | Error) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class FuncNodesWorker {
|
|
24
|
-
messagePromises: Map<string, any>;
|
|
25
|
-
_zustand: FuncNodesReactFlowZustandInterface;
|
|
26
|
-
_nodeupdates: Map<string, PartialNodeType>;
|
|
27
|
-
_nodeupdatetimer: NodeJS.Timeout;
|
|
28
|
-
uuid: string;
|
|
29
|
-
is_open: boolean;
|
|
30
|
-
on_error: (error: any) => void;
|
|
31
|
-
constructor(data: WorkerProps) {
|
|
32
|
-
this.uuid = data.uuid;
|
|
33
|
-
this.on_error = data.on_error || console.error;
|
|
34
|
-
this.messagePromises = new Map();
|
|
35
|
-
this._zustand = data.zustand;
|
|
36
|
-
this._nodeupdates = new Map();
|
|
37
|
-
this._nodeupdatetimer = setTimeout(() => {
|
|
38
|
-
this.perform_update();
|
|
39
|
-
}, 1000);
|
|
40
|
-
this.is_open = true;
|
|
41
|
-
}
|
|
42
|
-
async fullsync() {
|
|
43
|
-
const resp = (await this._send_cmd({ cmd: "full_state" })) as FullState;
|
|
44
|
-
console.log("Full state", resp);
|
|
45
|
-
this._zustand.lib.libstate.getState().set(resp.backend.lib);
|
|
46
|
-
if (resp.view.renderoptions)
|
|
47
|
-
this._zustand.update_render_options(resp.view.renderoptions);
|
|
48
|
-
const nodeview = resp.view.nodes;
|
|
49
|
-
for (const node of resp.backend.nodes) {
|
|
50
|
-
if (nodeview[node.id] !== undefined) {
|
|
51
|
-
node.frontend = nodeview[node.id];
|
|
52
|
-
}
|
|
53
|
-
this._recieve_node_added(node);
|
|
54
|
-
}
|
|
55
|
-
for (const edge of resp.backend.edges) {
|
|
56
|
-
this._recieve_edge_added(...edge);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async _recieve_edge_added(
|
|
61
|
-
src_nid: string,
|
|
62
|
-
src_ioid: string,
|
|
63
|
-
trg_nid: string,
|
|
64
|
-
trg_ioid: string
|
|
65
|
-
) {
|
|
66
|
-
this._zustand.on_edge_action({
|
|
67
|
-
type: "add",
|
|
68
|
-
from_remote: true,
|
|
69
|
-
...{ src_nid, src_ioid, trg_nid, trg_ioid },
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async trigger_node(node_id: string) {
|
|
74
|
-
await this._send_cmd({
|
|
75
|
-
cmd: "trigger_node",
|
|
76
|
-
kwargs: { nid: node_id },
|
|
77
|
-
wait_for_response: false,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async add_node(node_id: string) {
|
|
82
|
-
const resp = await this._send_cmd({
|
|
83
|
-
cmd: "add_node",
|
|
84
|
-
kwargs: { id: node_id },
|
|
85
|
-
});
|
|
86
|
-
this._recieve_node_added(resp as NodeType);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async remove_node(node_id: string) {
|
|
90
|
-
const resp = await this._send_cmd({
|
|
91
|
-
cmd: "remove_node",
|
|
92
|
-
kwargs: { id: node_id },
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async _recieve_node_added(data: NodeType) {
|
|
97
|
-
this._zustand.on_node_action({
|
|
98
|
-
type: "add",
|
|
99
|
-
node: data,
|
|
100
|
-
id: data.id,
|
|
101
|
-
from_remote: true,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
add_edge({
|
|
106
|
-
src_nid,
|
|
107
|
-
src_ioid,
|
|
108
|
-
trg_nid,
|
|
109
|
-
trg_ioid,
|
|
110
|
-
replace = false,
|
|
111
|
-
}: {
|
|
112
|
-
src_nid: string;
|
|
113
|
-
src_ioid: string;
|
|
114
|
-
trg_nid: string;
|
|
115
|
-
trg_ioid: string;
|
|
116
|
-
replace?: boolean;
|
|
117
|
-
}) {
|
|
118
|
-
return this._send_cmd({
|
|
119
|
-
cmd: "add_edge",
|
|
120
|
-
kwargs: { src_nid, src_ioid, trg_nid, trg_ioid, replace },
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
remove_edge({
|
|
125
|
-
src_nid,
|
|
126
|
-
src_ioid,
|
|
127
|
-
trg_nid,
|
|
128
|
-
trg_ioid,
|
|
129
|
-
}: {
|
|
130
|
-
src_nid: string;
|
|
131
|
-
src_ioid: string;
|
|
132
|
-
trg_nid: string;
|
|
133
|
-
trg_ioid: string;
|
|
134
|
-
}) {
|
|
135
|
-
return this._send_cmd({
|
|
136
|
-
cmd: "remove_edge",
|
|
137
|
-
kwargs: { src_nid, src_ioid, trg_nid, trg_ioid },
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
perform_update() {
|
|
142
|
-
clearTimeout(this._nodeupdatetimer);
|
|
143
|
-
this._nodeupdates.forEach(async (node, id) => {
|
|
144
|
-
const ans = await this._send_cmd({
|
|
145
|
-
cmd: "update_node",
|
|
146
|
-
kwargs: { nid: id, data: node },
|
|
147
|
-
wait_for_response: true,
|
|
148
|
-
});
|
|
149
|
-
this._zustand.on_node_action({
|
|
150
|
-
type: "update",
|
|
151
|
-
node: ans,
|
|
152
|
-
id: id,
|
|
153
|
-
from_remote: true,
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
this._nodeupdates.clear();
|
|
157
|
-
this._nodeupdatetimer = setTimeout(() => {
|
|
158
|
-
this.perform_update();
|
|
159
|
-
}, 1000);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
update_node(action: NodeActionUpdate) {
|
|
163
|
-
// Add the type to the parameter
|
|
164
|
-
const currentstate = this._nodeupdates.get(action.id);
|
|
165
|
-
if (currentstate) {
|
|
166
|
-
const { new_obj, change } = deep_merge(currentstate, action.node);
|
|
167
|
-
if (change) {
|
|
168
|
-
this._nodeupdates.set(action.id, new_obj);
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
this._nodeupdates.set(action.id, action.node);
|
|
172
|
-
}
|
|
173
|
-
if (action.immediate) {
|
|
174
|
-
this.perform_update();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
set_io_value({
|
|
179
|
-
nid,
|
|
180
|
-
ioid,
|
|
181
|
-
value,
|
|
182
|
-
set_default,
|
|
183
|
-
}: {
|
|
184
|
-
nid: string;
|
|
185
|
-
ioid: string;
|
|
186
|
-
value: any;
|
|
187
|
-
set_default?: boolean;
|
|
188
|
-
}) {
|
|
189
|
-
return this._send_cmd({
|
|
190
|
-
cmd: "set_io_value",
|
|
191
|
-
kwargs: { nid, ioid, value, set_default },
|
|
192
|
-
wait_for_response: true,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
clear() {
|
|
197
|
-
return this._send_cmd({ cmd: "clear" });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
save() {
|
|
201
|
-
return this._send_cmd({ cmd: "save", wait_for_response: true });
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
load(data: any) {
|
|
205
|
-
return this._send_cmd({
|
|
206
|
-
cmd: "load_data",
|
|
207
|
-
kwargs: { data },
|
|
208
|
-
wait_for_response: true,
|
|
209
|
-
}).then(() => {
|
|
210
|
-
this.fullsync();
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
get_io_value({ nid, ioid }: { nid: string; ioid: string }) {
|
|
215
|
-
return this._send_cmd({
|
|
216
|
-
cmd: "get_io_value",
|
|
217
|
-
kwargs: { nid, ioid },
|
|
218
|
-
wait_for_response: true,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async _send_cmd({
|
|
223
|
-
cmd,
|
|
224
|
-
kwargs,
|
|
225
|
-
wait_for_response = true,
|
|
226
|
-
response_timeout = 5000,
|
|
227
|
-
}: {
|
|
228
|
-
cmd: string;
|
|
229
|
-
kwargs?: any;
|
|
230
|
-
wait_for_response?: boolean;
|
|
231
|
-
response_timeout?: number;
|
|
232
|
-
}) {
|
|
233
|
-
const msg: CmdMessage = {
|
|
234
|
-
type: "cmd",
|
|
235
|
-
cmd,
|
|
236
|
-
kwargs: kwargs || {},
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// await self.assert_connection()
|
|
240
|
-
if (wait_for_response) {
|
|
241
|
-
const msid = msg.id || uuidv4();
|
|
242
|
-
msg.id = msid;
|
|
243
|
-
const promise = new Promise<any>((resolve, reject) => {
|
|
244
|
-
const timeout = setTimeout(() => {
|
|
245
|
-
reject("Timeout");
|
|
246
|
-
}, response_timeout);
|
|
247
|
-
this.messagePromises.set(msid, {
|
|
248
|
-
resolve: (data: any) => {
|
|
249
|
-
clearTimeout(timeout);
|
|
250
|
-
resolve(data);
|
|
251
|
-
this.messagePromises.delete(msid);
|
|
252
|
-
},
|
|
253
|
-
reject: (err: any) => {
|
|
254
|
-
clearTimeout(timeout);
|
|
255
|
-
reject(err);
|
|
256
|
-
this.messagePromises.delete(msid);
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
await this.send(msg);
|
|
261
|
-
return promise;
|
|
262
|
-
}
|
|
263
|
-
return this.send(msg);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
async send(data: any) {
|
|
267
|
-
// this is the abstract method that should be implemented by subclasses
|
|
268
|
-
throw new Error("Not implemented");
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
async recieve_nodespace_event({ event, data }: NodeSpaceEvent) {
|
|
272
|
-
switch (event) {
|
|
273
|
-
case "after_set_value":
|
|
274
|
-
return this._zustand.on_node_action({
|
|
275
|
-
type: "update",
|
|
276
|
-
node: {
|
|
277
|
-
id: data.node,
|
|
278
|
-
io: {
|
|
279
|
-
[data.io]: {
|
|
280
|
-
value: data.result,
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
id: data.node,
|
|
285
|
-
from_remote: true,
|
|
286
|
-
});
|
|
287
|
-
case "after_update_value_options":
|
|
288
|
-
return this._zustand.on_node_action({
|
|
289
|
-
type: "update",
|
|
290
|
-
node: {
|
|
291
|
-
id: data.node,
|
|
292
|
-
io: {
|
|
293
|
-
[data.io]: {
|
|
294
|
-
value_options: data.result,
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
id: data.node,
|
|
299
|
-
from_remote: true,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
case "triggerstart":
|
|
303
|
-
return this._zustand.on_node_action({
|
|
304
|
-
type: "update",
|
|
305
|
-
node: {
|
|
306
|
-
id: data.node,
|
|
307
|
-
in_trigger: true,
|
|
308
|
-
},
|
|
309
|
-
id: data.node,
|
|
310
|
-
from_remote: true,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
case "triggerdone":
|
|
314
|
-
return this._zustand.on_node_action({
|
|
315
|
-
type: "update",
|
|
316
|
-
node: {
|
|
317
|
-
id: data.node,
|
|
318
|
-
in_trigger: false,
|
|
319
|
-
},
|
|
320
|
-
id: data.node,
|
|
321
|
-
from_remote: true,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
case "node_trigger_error":
|
|
325
|
-
return this._zustand.on_node_action({
|
|
326
|
-
type: "error",
|
|
327
|
-
errortype: "trigger",
|
|
328
|
-
error: data.error,
|
|
329
|
-
id: data.node,
|
|
330
|
-
from_remote: true,
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
case "node_removed":
|
|
334
|
-
return this._zustand.on_node_action({
|
|
335
|
-
type: "delete",
|
|
336
|
-
id: data.node,
|
|
337
|
-
from_remote: true,
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
case "node_added":
|
|
341
|
-
return this._recieve_node_added(data.node as NodeType);
|
|
342
|
-
|
|
343
|
-
case "after_disconnect":
|
|
344
|
-
if (!data.result) return;
|
|
345
|
-
if (!Array.isArray(data.result)) return;
|
|
346
|
-
if (data.result.length !== 4) return;
|
|
347
|
-
return this._zustand.on_edge_action({
|
|
348
|
-
type: "delete",
|
|
349
|
-
from_remote: true,
|
|
350
|
-
src_nid: data.result[0],
|
|
351
|
-
src_ioid: data.result[1],
|
|
352
|
-
trg_nid: data.result[2],
|
|
353
|
-
trg_ioid: data.result[3],
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
case "after_connect":
|
|
357
|
-
if (!data.result) return;
|
|
358
|
-
if (!Array.isArray(data.result)) return;
|
|
359
|
-
if (data.result.length !== 4) return;
|
|
360
|
-
return this._recieve_edge_added(
|
|
361
|
-
...(data.result as [string, string, string, string])
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
case "after_add_shelf":
|
|
365
|
-
if (!data.result) return;
|
|
366
|
-
return this._zustand.lib.libstate.getState().set(data.result);
|
|
367
|
-
|
|
368
|
-
default:
|
|
369
|
-
console.warn("Unhandled nodepsace event", event, data);
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
async add_lib(lib: string) {
|
|
375
|
-
const ans = await this._send_cmd({
|
|
376
|
-
cmd: "add_shelf",
|
|
377
|
-
kwargs: { src: lib },
|
|
378
|
-
wait_for_response: false,
|
|
379
|
-
});
|
|
380
|
-
return ans;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
async recieve(data: JSONMessage) {
|
|
384
|
-
let promise;
|
|
385
|
-
switch (data.type) {
|
|
386
|
-
case "nsevent":
|
|
387
|
-
return await this.recieve_nodespace_event(data);
|
|
388
|
-
case "result":
|
|
389
|
-
promise = data.id && this.messagePromises.get(data.id);
|
|
390
|
-
if (promise) {
|
|
391
|
-
return promise.resolve(data.result);
|
|
392
|
-
}
|
|
393
|
-
break;
|
|
394
|
-
case "error":
|
|
395
|
-
this.on_error(data.tb + "\n" + data.error);
|
|
396
|
-
promise = data.id && this.messagePromises.get(data.id);
|
|
397
|
-
if (promise) {
|
|
398
|
-
return promise.reject(data.error);
|
|
399
|
-
}
|
|
400
|
-
break;
|
|
401
|
-
case "progress":
|
|
402
|
-
this._zustand.set_progress(data);
|
|
403
|
-
break;
|
|
404
|
-
default:
|
|
405
|
-
console.warn("Unhandled message", data);
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
disconnect() {}
|
|
411
|
-
|
|
412
|
-
onclose() {
|
|
413
|
-
this.is_open = false;
|
|
414
|
-
this._zustand.auto_progress();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async reconnect() {}
|
|
418
|
-
|
|
419
|
-
async stop() {
|
|
420
|
-
await this._send_cmd({ cmd: "stop_worker", wait_for_response: false });
|
|
421
|
-
const oldonclose = this.onclose.bind(this);
|
|
422
|
-
this.onclose = () => {
|
|
423
|
-
oldonclose();
|
|
424
|
-
if (this._zustand.worker === this) {
|
|
425
|
-
this._zustand.clear_all();
|
|
426
|
-
}
|
|
427
|
-
this.onclose = oldonclose;
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async get_io_full_value({ nid, ioid }: { nid: string; ioid: string }) {
|
|
432
|
-
const res = await this._send_cmd({
|
|
433
|
-
cmd: "get_io_full_value",
|
|
434
|
-
kwargs: { nid, ioid },
|
|
435
|
-
wait_for_response: true,
|
|
436
|
-
});
|
|
437
|
-
//console.log("Full value", res);
|
|
438
|
-
|
|
439
|
-
this._zustand.on_node_action({
|
|
440
|
-
type: "update",
|
|
441
|
-
node: {
|
|
442
|
-
io: {
|
|
443
|
-
[ioid]: {
|
|
444
|
-
fullvalue: res,
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
},
|
|
448
|
-
id: nid,
|
|
449
|
-
from_remote: true,
|
|
450
|
-
});
|
|
451
|
-
return res;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
export default FuncNodesWorker;
|
|
456
|
-
export type { WorkerProps };
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import FuncNodesWorker, { WorkerProps } from "./funcnodesworker";
|
|
2
|
-
|
|
3
|
-
interface WebSocketWorkerProps extends WorkerProps {
|
|
4
|
-
url: string;
|
|
5
|
-
}
|
|
6
|
-
class WebSocketWorker extends FuncNodesWorker {
|
|
7
|
-
private _url: string;
|
|
8
|
-
private _websocket: WebSocket | null = null;
|
|
9
|
-
private reconnectAttempts: number = 0;
|
|
10
|
-
private maxReconnectAttempts: number = 999;
|
|
11
|
-
private initialTimeout: number = 200; // Initial reconnect delay in ms
|
|
12
|
-
private maxTimeout: number = 5000; // Maximum reconnect delay
|
|
13
|
-
private _reconnect: boolean = true;
|
|
14
|
-
constructor(data: WebSocketWorkerProps) {
|
|
15
|
-
super(data);
|
|
16
|
-
this._url = data.url;
|
|
17
|
-
this.connect();
|
|
18
|
-
this._zustand.auto_progress();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private connect(): void {
|
|
22
|
-
console.log("Connecting to websocket");
|
|
23
|
-
this.is_open = false;
|
|
24
|
-
this._websocket = new WebSocket(this._url);
|
|
25
|
-
|
|
26
|
-
this._websocket.onopen = () => {
|
|
27
|
-
this.onopen();
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
this._websocket.onclose = () => {
|
|
31
|
-
this.onclose();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
this._websocket.onerror = () => {
|
|
35
|
-
this.on_ws_error();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
this._websocket.onmessage = (event) => {
|
|
39
|
-
this.onmessage(event.data);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private calculateReconnectTimeout(): number {
|
|
44
|
-
// Increase timeout exponentially, capped at maxTimeout
|
|
45
|
-
let timeout = Math.min(
|
|
46
|
-
this.initialTimeout * Math.pow(2, this.reconnectAttempts),
|
|
47
|
-
this.maxTimeout
|
|
48
|
-
);
|
|
49
|
-
return timeout;
|
|
50
|
-
}
|
|
51
|
-
private auto_reconnect(): void {
|
|
52
|
-
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
53
|
-
let timeout = this.calculateReconnectTimeout();
|
|
54
|
-
console.log(`Attempting to reconnect in ${timeout} ms`);
|
|
55
|
-
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
if (this._websocket) {
|
|
58
|
-
if (this._websocket.readyState === WebSocket.OPEN) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
this.reconnectAttempts++;
|
|
63
|
-
this.connect();
|
|
64
|
-
}, timeout);
|
|
65
|
-
} else {
|
|
66
|
-
console.warn("Maximum reconnect attempts reached. Giving up.");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async onmessage(data: string) {
|
|
71
|
-
await this.recieve(JSON.parse(data));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
onopen() {
|
|
75
|
-
console.log("Websocket opened");
|
|
76
|
-
this.is_open = true;
|
|
77
|
-
this._zustand.auto_progress();
|
|
78
|
-
this.reconnectAttempts = 0;
|
|
79
|
-
this.fullsync();
|
|
80
|
-
}
|
|
81
|
-
onclose() {
|
|
82
|
-
console.log("Websocket closed", this);
|
|
83
|
-
super.onclose();
|
|
84
|
-
if (this._reconnect) {
|
|
85
|
-
console.log("Websocket closed,reconnecting");
|
|
86
|
-
this.auto_reconnect(); // Attempt to reconnect
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
on_ws_error() {
|
|
91
|
-
console.warn("Websocket error");
|
|
92
|
-
if (this._websocket) {
|
|
93
|
-
this._websocket.close(); // Ensure the connection is closed before attempting to reconnect
|
|
94
|
-
} else {
|
|
95
|
-
this.auto_reconnect();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async send(data: any) {
|
|
100
|
-
if (!this._websocket || this._websocket.readyState !== WebSocket.OPEN) {
|
|
101
|
-
throw new Error("Websocket not connected");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this._websocket.send(JSON.stringify(data));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async stop() {
|
|
108
|
-
await super.stop();
|
|
109
|
-
this._reconnect = false;
|
|
110
|
-
// this.close();
|
|
111
|
-
}
|
|
112
|
-
close() {
|
|
113
|
-
if (this._websocket) this._websocket.close();
|
|
114
|
-
}
|
|
115
|
-
disconnect() {
|
|
116
|
-
super.disconnect();
|
|
117
|
-
this._reconnect = false;
|
|
118
|
-
this.close();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async reconnect() {
|
|
122
|
-
await super.reconnect();
|
|
123
|
-
this._reconnect = true;
|
|
124
|
-
if (this._websocket) {
|
|
125
|
-
console.log("Reconnecting", this._websocket.readyState);
|
|
126
|
-
if (
|
|
127
|
-
this._websocket.readyState === WebSocket.OPEN ||
|
|
128
|
-
this._websocket.readyState === WebSocket.CONNECTING
|
|
129
|
-
) {
|
|
130
|
-
if (this._websocket.readyState === WebSocket.CONNECTING) {
|
|
131
|
-
//await to ensure the websocket is connected, with a timeout of 2 seconds
|
|
132
|
-
await new Promise((resolve, reject) => {
|
|
133
|
-
let timeout = setTimeout(() => {
|
|
134
|
-
reject("Timeout");
|
|
135
|
-
}, 2000);
|
|
136
|
-
this._websocket?.addEventListener("open", () => {
|
|
137
|
-
clearTimeout(timeout);
|
|
138
|
-
resolve(null);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (this._websocket.readyState === WebSocket.OPEN) {
|
|
143
|
-
this.fullsync();
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
this.connect();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export default WebSocketWorker;
|