@remix_labs/machine-starter 2.1961.0-dev → 2.1963.0-dev
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/common.js +33 -90
- package/groovebox_build.js +1 -1
- package/index.js +1 -0
- package/machine-wasm.worker.js +1 -1
- package/package.json +2 -2
- package/start.js +1 -2
package/common.js
CHANGED
|
@@ -1,44 +1,18 @@
|
|
|
1
1
|
import { GROOVEBOX_BUILD } from "./groovebox_build.js";
|
|
2
2
|
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
workers = {};
|
|
11
|
-
parents = {};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function terminateVM(vmID) {
|
|
15
|
-
let worker = workers[vmID];
|
|
16
|
-
if (worker) {
|
|
17
|
-
delete workers[vmID];
|
|
18
|
-
delete parents[vmID];
|
|
19
|
-
worker.terminate();
|
|
20
|
-
for (let [subID, parentID] of Object.entries(parents)) {
|
|
21
|
-
terminateVM(subID);
|
|
22
|
-
};
|
|
3
|
+
let terminate = function(f) {};
|
|
4
|
+
if (globalThis.ThisIsNode) {
|
|
5
|
+
terminate = function(f) {
|
|
6
|
+
Process.on("exit", () => {
|
|
7
|
+
console.log("terminating machine worker");
|
|
8
|
+
f()
|
|
9
|
+
})
|
|
23
10
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (globalThis.Process) {
|
|
27
|
-
Process.on("exit", () => {
|
|
28
|
-
console.log("terminating machine workers");
|
|
29
|
-
terminateAll()
|
|
30
|
-
})
|
|
31
11
|
};
|
|
32
12
|
|
|
33
13
|
let initialMask = 64 + 1024; // default for web
|
|
34
|
-
|
|
35
14
|
globalThis.MixSetMask = (m => {
|
|
36
15
|
initialMask = m;
|
|
37
|
-
for (let [vmID, worker] of Object.entries(workers)) {
|
|
38
|
-
worker.postMessage({ "_rmx_type": "msg_vm_logMask",
|
|
39
|
-
"mask": m
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
16
|
});
|
|
43
17
|
|
|
44
18
|
function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaMQTT) {
|
|
@@ -57,24 +31,16 @@ function StartWASM2(hub, config) {
|
|
|
57
31
|
return hub.newChannel().then(channel => {
|
|
58
32
|
// injected by either index.js or node.js
|
|
59
33
|
let worker = globalThis.GetMachineWASMWorker();
|
|
60
|
-
|
|
61
|
-
let localFFIkind = {};
|
|
62
|
-
let localFFIfuns = {};
|
|
34
|
+
let localFFIs = {};
|
|
63
35
|
if (config.localFFIs) {
|
|
64
36
|
for (const [k, v] of Object.entries(config.localFFIs)) {
|
|
65
|
-
localFFIfuns[k] = {...v};
|
|
66
37
|
if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
|
|
67
38
|
console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
|
|
68
39
|
} else {
|
|
69
|
-
|
|
70
|
-
delete
|
|
40
|
+
localFFIs[k] = {...v};
|
|
41
|
+
delete localFFIs[k].run;
|
|
71
42
|
}
|
|
72
|
-
}
|
|
73
|
-
let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
|
|
74
|
-
localFFIkind["$vm_start"] = vm_kind;
|
|
75
|
-
localFFIfuns["$vm_start"] = ffi_vm_start;
|
|
76
|
-
localFFIkind["$vm_stop"] = vm_kind;
|
|
77
|
-
localFFIfuns["$vm_stop"] = ffi_vm_stop;
|
|
43
|
+
}
|
|
78
44
|
}
|
|
79
45
|
let config_msg =
|
|
80
46
|
{ "_rmx_type": "msg_vm_configure",
|
|
@@ -88,43 +54,24 @@ function StartWASM2(hub, config) {
|
|
|
88
54
|
"outputViaMQTT": !(config.noOutputViaMQTT),
|
|
89
55
|
"machType": config.machType,
|
|
90
56
|
"debugMask": initialMask,
|
|
91
|
-
"localFFIs":
|
|
57
|
+
"localFFIs": localFFIs,
|
|
92
58
|
"allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
|
|
93
59
|
"interceptFFI": config.interceptFFI,
|
|
94
60
|
"interceptDynloadFFI": config.interceptDynloadFFI,
|
|
95
61
|
};
|
|
96
62
|
worker.postMessage(config_msg, [ channel.port ]);
|
|
63
|
+
terminate(() => worker.terminate());
|
|
64
|
+
globalThis.MixSetMask = (m => {
|
|
65
|
+
worker.postMessage({ "_rmx_type": "msg_vm_logMask",
|
|
66
|
+
"mask": m
|
|
67
|
+
})
|
|
68
|
+
});
|
|
97
69
|
if (config.localFFIs)
|
|
98
|
-
setupLocalFFIs(hub, config
|
|
70
|
+
setupLocalFFIs(hub, config); // don't await!
|
|
99
71
|
return worker;
|
|
100
72
|
})
|
|
101
73
|
}
|
|
102
74
|
|
|
103
|
-
async function ffi_vm_start(conn, args) {
|
|
104
|
-
let vm_id = "embedded." + nanoid();
|
|
105
|
-
let config = {};
|
|
106
|
-
for (const [k, v] of Object.entries(conn.config)) {
|
|
107
|
-
config[k] = v;
|
|
108
|
-
}
|
|
109
|
-
config["vmID"] = vm_id;
|
|
110
|
-
parents[vm_id] = conn.config.vmID;
|
|
111
|
-
let arg_config = args[0];
|
|
112
|
-
if (arg_config.interceptFFI !== undefined)
|
|
113
|
-
config["interceptFFI"] = arg_config.interceptFFI;
|
|
114
|
-
if (arg_config.interceptDynloadFFI !== undefined)
|
|
115
|
-
config["interceptDynloadFFI"] = arg_config.interceptDynloadFFI;
|
|
116
|
-
let worker = await StartWASM2(conn.hub, config);
|
|
117
|
-
return vm_id;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function ffi_vm_stop(conn, args) {
|
|
121
|
-
let vm_id = args[0];
|
|
122
|
-
let worker = workers[vm_id];
|
|
123
|
-
if (!worker) throw new Error("no such VM: " + vm_id);
|
|
124
|
-
terminateVM(vm_id);
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
75
|
class Token {
|
|
129
76
|
constructor(data, enabled, extras) {
|
|
130
77
|
// data: must be an Uint8Array
|
|
@@ -240,13 +187,13 @@ function decode(val) {
|
|
|
240
187
|
}
|
|
241
188
|
}
|
|
242
189
|
|
|
243
|
-
async function setupLocalFFIs(hub, config
|
|
244
|
-
let vmID = config.vmID;
|
|
190
|
+
async function setupLocalFFIs(hub, config) {
|
|
245
191
|
let channel = await hub.newChannel();
|
|
246
|
-
let comm = new FFIComm(
|
|
247
|
-
|
|
248
|
-
await channel.
|
|
249
|
-
|
|
192
|
+
let comm = new FFIComm(hub, channel);
|
|
193
|
+
let localFFIs = config.localFFIs;
|
|
194
|
+
await channel.setLocalSubTopic("/local/ffi/call");
|
|
195
|
+
await channel.setLocalPubTopic("/local/ffi/return");
|
|
196
|
+
let sub = await channel.subscribe("/local/ffi/call");
|
|
250
197
|
while (true) {
|
|
251
198
|
let msg = await sub.next();
|
|
252
199
|
let name = msg.payload.name;
|
|
@@ -260,15 +207,14 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
260
207
|
{ call_id: call_id,
|
|
261
208
|
hub: hub,
|
|
262
209
|
channel: channel,
|
|
263
|
-
config: config,
|
|
264
210
|
state: config.state,
|
|
265
211
|
};
|
|
266
212
|
let r = fun instanceof Function ? fun(connector, args) : fun.run(connector, args);
|
|
267
213
|
if (r instanceof Promise) {
|
|
268
|
-
r.catch(_ => null); // prevent "unhandled rejection"
|
|
269
214
|
await comm.later(call_id);
|
|
270
|
-
|
|
271
|
-
|
|
215
|
+
r.then(
|
|
216
|
+
(value) => comm.returnOrFail(fun, call_id, value),
|
|
217
|
+
(reason) => comm.error(call_id, reason.message, reason.stack));
|
|
272
218
|
} else {
|
|
273
219
|
await comm.returnOrFail(fun, call_id, r);
|
|
274
220
|
}
|
|
@@ -279,8 +225,7 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
279
225
|
}
|
|
280
226
|
|
|
281
227
|
class FFIComm {
|
|
282
|
-
constructor(
|
|
283
|
-
this.vmID = vmID;
|
|
228
|
+
constructor(hub, channel) {
|
|
284
229
|
this.hub = hub;
|
|
285
230
|
this.channel = channel;
|
|
286
231
|
}
|
|
@@ -289,7 +234,7 @@ class FFIComm {
|
|
|
289
234
|
{ call_id: call_id,
|
|
290
235
|
};
|
|
291
236
|
let response = this.hub.newLocalMessage("msg_ffi_later", "starter", r_payload);
|
|
292
|
-
return this.channel.publish("/local/
|
|
237
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
293
238
|
}
|
|
294
239
|
return_(fun, call_id, result) {
|
|
295
240
|
let r_payload =
|
|
@@ -297,7 +242,7 @@ class FFIComm {
|
|
|
297
242
|
value: fun.useJsonDecoder ? result : encode(result)
|
|
298
243
|
};
|
|
299
244
|
let response = this.hub.newLocalMessage("msg_ffi_return", "starter", r_payload);
|
|
300
|
-
return this.channel.publish("/local/
|
|
245
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
301
246
|
}
|
|
302
247
|
error(call_id, message, stack) {
|
|
303
248
|
let r_payload =
|
|
@@ -306,7 +251,7 @@ class FFIComm {
|
|
|
306
251
|
stack: stack === undefined ? [] : stack,
|
|
307
252
|
};
|
|
308
253
|
let response = this.hub.newLocalMessage("msg_ffi_error", "starter", r_payload);
|
|
309
|
-
this.channel.publish("/local/
|
|
254
|
+
this.channel.publish("/local/ffi/return", response, false);
|
|
310
255
|
}
|
|
311
256
|
returnOrFail(fun, call_id, result) {
|
|
312
257
|
if (fun.canFail) {
|
|
@@ -336,6 +281,4 @@ class FFIComm {
|
|
|
336
281
|
|
|
337
282
|
// use worker.terminate() to shut a worker down!
|
|
338
283
|
|
|
339
|
-
export { StartWASM, StartWASM2,
|
|
340
|
-
Token, Case, Opaque
|
|
341
|
-
}
|
|
284
|
+
export { StartWASM, StartWASM2, Token, Case, Opaque }
|
package/groovebox_build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GROOVEBOX_BUILD = "
|
|
1
|
+
var GROOVEBOX_BUILD = "2081";
|
|
2
2
|
export { GROOVEBOX_BUILD }
|
package/index.js
CHANGED