@remix_labs/machine-starter 1.1872.0-dev → 1.1874.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/groovebox_build.js +1 -1
- package/index.js +32 -89
- package/package.json +2 -2
- package/start.js +1 -2
package/groovebox_build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GROOVEBOX_BUILD = "
|
|
1
|
+
var GROOVEBOX_BUILD = "1874";
|
|
2
2
|
export { GROOVEBOX_BUILD }
|
package/index.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import { nanoid } from "nanoid";
|
|
2
2
|
import { GROOVEBOX_BUILD } from "./groovebox_build.js";
|
|
3
3
|
|
|
4
|
-
let
|
|
5
|
-
let parents = {};
|
|
6
|
-
|
|
7
|
-
function terminateAll() {
|
|
8
|
-
for (let [vmID, worker] of Object.entries(workers)) {
|
|
9
|
-
worker.terminate();
|
|
10
|
-
};
|
|
11
|
-
workers = {};
|
|
12
|
-
parents = {};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function terminateVM(vmID) {
|
|
16
|
-
let worker = workers[vmID];
|
|
17
|
-
if (worker) {
|
|
18
|
-
delete workers[vmID];
|
|
19
|
-
delete parents[vmID];
|
|
20
|
-
worker.terminate();
|
|
21
|
-
for (let [subID, parentID] of Object.entries(parents)) {
|
|
22
|
-
terminateVM(subID);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
4
|
+
let terminate = function(f) {};
|
|
27
5
|
if (globalThis.ThisIsNode) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
terminate = function(f) {
|
|
7
|
+
Process.on("exit", () => {
|
|
8
|
+
console.log("terminating machine worker");
|
|
9
|
+
f()
|
|
10
|
+
})
|
|
11
|
+
}
|
|
32
12
|
};
|
|
33
13
|
|
|
34
14
|
function CreateVMID() {
|
|
@@ -36,14 +16,8 @@ function CreateVMID() {
|
|
|
36
16
|
}
|
|
37
17
|
|
|
38
18
|
let initialMask = 64 + 1024; // default for web
|
|
39
|
-
|
|
40
19
|
globalThis.MixSetMask = (m => {
|
|
41
20
|
initialMask = m;
|
|
42
|
-
for (let [vmID, worker] of Object.entries(workers)) {
|
|
43
|
-
worker.postMessage({ "_rmx_type": "msg_vm_logMask",
|
|
44
|
-
"mask": m
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
21
|
});
|
|
48
22
|
|
|
49
23
|
function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaMQTT) {
|
|
@@ -77,29 +51,20 @@ function StartWASM2(hub, config) {
|
|
|
77
51
|
fetch(code_url, {cache:"default"}).then(resp => { return resp.arrayBuffer() });
|
|
78
52
|
bundle = new URL("/g/machine-wasm-core.js", window.location.href);
|
|
79
53
|
}
|
|
80
|
-
let
|
|
81
|
-
let localFFIfuns = {};
|
|
54
|
+
let localFFIs = {};
|
|
82
55
|
if (config.localFFIs) {
|
|
83
56
|
for (const [k, v] of Object.entries(config.localFFIs)) {
|
|
84
|
-
localFFIfuns[k] = {...v};
|
|
85
57
|
if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
|
|
86
58
|
console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
|
|
87
59
|
} else {
|
|
88
|
-
|
|
89
|
-
delete
|
|
60
|
+
localFFIs[k] = {...v};
|
|
61
|
+
delete localFFIs[k].run;
|
|
90
62
|
}
|
|
91
|
-
}
|
|
92
|
-
let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
|
|
93
|
-
localFFIkind["$vm_start"] = vm_kind;
|
|
94
|
-
localFFIfuns["$vm_start"] = ffi_vm_start;
|
|
95
|
-
localFFIkind["$vm_stop"] = vm_kind;
|
|
96
|
-
localFFIfuns["$vm_stop"] = ffi_vm_stop;
|
|
63
|
+
}
|
|
97
64
|
}
|
|
98
65
|
let worker = new Worker(bundle);
|
|
99
|
-
workers[config.vmID] = worker;
|
|
100
66
|
let config_msg =
|
|
101
67
|
{ "_rmx_type": "msg_vm_configure",
|
|
102
|
-
"workerURL": bundle.toString(),
|
|
103
68
|
"baseURL": config.baseURL,
|
|
104
69
|
"org": config.org,
|
|
105
70
|
"workspace": config.workspace,
|
|
@@ -110,44 +75,25 @@ function StartWASM2(hub, config) {
|
|
|
110
75
|
"outputViaMQTT": !(config.noOutputViaMQTT),
|
|
111
76
|
"machType": config.machType,
|
|
112
77
|
"debugMask": initialMask,
|
|
113
|
-
"localFFIs":
|
|
78
|
+
"localFFIs": localFFIs,
|
|
114
79
|
"grooveboxUrlPrefix": globalThis.GROOVEBOX_URL_PREFIX,
|
|
115
80
|
"allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
|
|
116
81
|
"interceptFFI": config.interceptFFI,
|
|
117
82
|
"interceptDynloadFFI": config.interceptDynloadFFI,
|
|
118
83
|
};
|
|
119
84
|
worker.postMessage(config_msg, [ channel.port ]);
|
|
85
|
+
terminate(() => worker.terminate());
|
|
86
|
+
globalThis.MixSetMask = (m => {
|
|
87
|
+
worker.postMessage({ "_rmx_type": "msg_vm_logMask",
|
|
88
|
+
"mask": m
|
|
89
|
+
})
|
|
90
|
+
});
|
|
120
91
|
if (config.localFFIs)
|
|
121
|
-
setupLocalFFIs(hub, config
|
|
92
|
+
setupLocalFFIs(hub, config); // don't await!
|
|
122
93
|
return worker;
|
|
123
94
|
})
|
|
124
95
|
}
|
|
125
96
|
|
|
126
|
-
async function ffi_vm_start(conn, args) {
|
|
127
|
-
let vm_id = "embedded." + nanoid();
|
|
128
|
-
let config = {};
|
|
129
|
-
for (const [k, v] of Object.entries(conn.config)) {
|
|
130
|
-
config[k] = v;
|
|
131
|
-
}
|
|
132
|
-
config["vmID"] = vm_id;
|
|
133
|
-
parents[vm_id] = conn.config.vmID;
|
|
134
|
-
let arg_config = args[0];
|
|
135
|
-
if (arg_config.interceptFFI !== undefined)
|
|
136
|
-
config["interceptFFI"] = arg_config.interceptFFI;
|
|
137
|
-
if (arg_config.interceptDynloadFFI !== undefined)
|
|
138
|
-
config["interceptDynloadFFI"] = arg_config.interceptDynloadFFI;
|
|
139
|
-
let worker = await StartWASM2(conn.hub, config);
|
|
140
|
-
return vm_id;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function ffi_vm_stop(conn, args) {
|
|
144
|
-
let vm_id = args[0];
|
|
145
|
-
let worker = workers[vm_id];
|
|
146
|
-
if (!worker) throw new Error("no such VM: " + vm_id);
|
|
147
|
-
terminateVM(vm_id);
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
97
|
class Token {
|
|
152
98
|
constructor(data, enabled, extras) {
|
|
153
99
|
// data: must be an Uint8Array
|
|
@@ -263,13 +209,13 @@ function decode(val) {
|
|
|
263
209
|
}
|
|
264
210
|
}
|
|
265
211
|
|
|
266
|
-
async function setupLocalFFIs(hub, config
|
|
267
|
-
let vmID = config.vmID;
|
|
212
|
+
async function setupLocalFFIs(hub, config) {
|
|
268
213
|
let channel = await hub.newChannel();
|
|
269
|
-
let comm = new FFIComm(
|
|
270
|
-
|
|
271
|
-
await channel.
|
|
272
|
-
|
|
214
|
+
let comm = new FFIComm(hub, channel);
|
|
215
|
+
let localFFIs = config.localFFIs;
|
|
216
|
+
await channel.setLocalSubTopic("/local/ffi/call");
|
|
217
|
+
await channel.setLocalPubTopic("/local/ffi/return");
|
|
218
|
+
let sub = await channel.subscribe("/local/ffi/call");
|
|
273
219
|
while (true) {
|
|
274
220
|
let msg = await sub.next();
|
|
275
221
|
let name = msg.payload.name;
|
|
@@ -283,15 +229,14 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
283
229
|
{ call_id: call_id,
|
|
284
230
|
hub: hub,
|
|
285
231
|
channel: channel,
|
|
286
|
-
config: config,
|
|
287
232
|
state: config.state,
|
|
288
233
|
};
|
|
289
234
|
let r = fun instanceof Function ? fun(connector, args) : fun.run(connector, args);
|
|
290
235
|
if (r instanceof Promise) {
|
|
291
|
-
r.catch(_ => null); // prevent "unhandled rejection"
|
|
292
236
|
await comm.later(call_id);
|
|
293
|
-
|
|
294
|
-
|
|
237
|
+
r.then(
|
|
238
|
+
(value) => comm.returnOrFail(fun, call_id, value),
|
|
239
|
+
(reason) => comm.error(call_id, reason.message, reason.stack));
|
|
295
240
|
} else {
|
|
296
241
|
await comm.returnOrFail(fun, call_id, r);
|
|
297
242
|
}
|
|
@@ -302,8 +247,7 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
302
247
|
}
|
|
303
248
|
|
|
304
249
|
class FFIComm {
|
|
305
|
-
constructor(
|
|
306
|
-
this.vmID = vmID;
|
|
250
|
+
constructor(hub, channel) {
|
|
307
251
|
this.hub = hub;
|
|
308
252
|
this.channel = channel;
|
|
309
253
|
}
|
|
@@ -312,7 +256,7 @@ class FFIComm {
|
|
|
312
256
|
{ call_id: call_id,
|
|
313
257
|
};
|
|
314
258
|
let response = this.hub.newLocalMessage("msg_ffi_later", "starter", r_payload);
|
|
315
|
-
return this.channel.publish("/local/
|
|
259
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
316
260
|
}
|
|
317
261
|
return_(fun, call_id, result) {
|
|
318
262
|
let r_payload =
|
|
@@ -320,7 +264,7 @@ class FFIComm {
|
|
|
320
264
|
value: fun.useJsonDecoder ? result : encode(result)
|
|
321
265
|
};
|
|
322
266
|
let response = this.hub.newLocalMessage("msg_ffi_return", "starter", r_payload);
|
|
323
|
-
return this.channel.publish("/local/
|
|
267
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
324
268
|
}
|
|
325
269
|
error(call_id, message, stack) {
|
|
326
270
|
let r_payload =
|
|
@@ -329,7 +273,7 @@ class FFIComm {
|
|
|
329
273
|
stack: stack === undefined ? [] : stack,
|
|
330
274
|
};
|
|
331
275
|
let response = this.hub.newLocalMessage("msg_ffi_error", "starter", r_payload);
|
|
332
|
-
this.channel.publish("/local/
|
|
276
|
+
this.channel.publish("/local/ffi/return", response, false);
|
|
333
277
|
}
|
|
334
278
|
returnOrFail(fun, call_id, result) {
|
|
335
279
|
if (fun.canFail) {
|
|
@@ -360,6 +304,5 @@ class FFIComm {
|
|
|
360
304
|
// use worker.terminate() to shut a worker down!
|
|
361
305
|
|
|
362
306
|
export { CreateVMID, StartWASM, StartWASM2,
|
|
363
|
-
terminateAll, terminateVM,
|
|
364
307
|
Token, Case, Opaque
|
|
365
308
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix_labs/machine-starter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1874.0-dev",
|
|
4
4
|
"description": "start the groove",
|
|
5
5
|
"main": "node.js",
|
|
6
6
|
"browser": "index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"author": "Remixlabs staff",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@remix_labs/hub-client": "1.
|
|
14
|
+
"@remix_labs/hub-client": "1.1874.0-dev",
|
|
15
15
|
"nanoid": "^3.1.12",
|
|
16
16
|
"web-worker": "^1.2.0"
|
|
17
17
|
},
|
package/start.js
CHANGED