@remix_labs/machine-starter 1.1833.0-dev → 1.1836.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 -91
- 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 = "1836";
|
|
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,23 @@ 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
|
-
"interceptFFI": config.interceptFFI,
|
|
117
|
-
"interceptDynloadFFI": config.interceptDynloadFFI,
|
|
118
81
|
};
|
|
119
82
|
worker.postMessage(config_msg, [ channel.port ]);
|
|
83
|
+
terminate(() => worker.terminate());
|
|
84
|
+
globalThis.MixSetMask = (m => {
|
|
85
|
+
worker.postMessage({ "_rmx_type": "msg_vm_logMask",
|
|
86
|
+
"mask": m
|
|
87
|
+
})
|
|
88
|
+
});
|
|
120
89
|
if (config.localFFIs)
|
|
121
|
-
setupLocalFFIs(hub, config
|
|
90
|
+
setupLocalFFIs(hub, config); // don't await!
|
|
122
91
|
return worker;
|
|
123
92
|
})
|
|
124
93
|
}
|
|
125
94
|
|
|
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
95
|
class Token {
|
|
152
96
|
constructor(data, enabled, extras) {
|
|
153
97
|
// data: must be an Uint8Array
|
|
@@ -263,13 +207,13 @@ function decode(val) {
|
|
|
263
207
|
}
|
|
264
208
|
}
|
|
265
209
|
|
|
266
|
-
async function setupLocalFFIs(hub, config
|
|
267
|
-
let vmID = config.vmID;
|
|
210
|
+
async function setupLocalFFIs(hub, config) {
|
|
268
211
|
let channel = await hub.newChannel();
|
|
269
|
-
let comm = new FFIComm(
|
|
270
|
-
|
|
271
|
-
await channel.
|
|
272
|
-
|
|
212
|
+
let comm = new FFIComm(hub, channel);
|
|
213
|
+
let localFFIs = config.localFFIs;
|
|
214
|
+
await channel.setLocalSubTopic("/local/ffi/call");
|
|
215
|
+
await channel.setLocalPubTopic("/local/ffi/return");
|
|
216
|
+
let sub = await channel.subscribe("/local/ffi/call");
|
|
273
217
|
while (true) {
|
|
274
218
|
let msg = await sub.next();
|
|
275
219
|
let name = msg.payload.name;
|
|
@@ -283,15 +227,14 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
283
227
|
{ call_id: call_id,
|
|
284
228
|
hub: hub,
|
|
285
229
|
channel: channel,
|
|
286
|
-
config: config,
|
|
287
230
|
state: config.state,
|
|
288
231
|
};
|
|
289
232
|
let r = fun instanceof Function ? fun(connector, args) : fun.run(connector, args);
|
|
290
233
|
if (r instanceof Promise) {
|
|
291
|
-
r.catch(_ => null); // prevent "unhandled rejection"
|
|
292
234
|
await comm.later(call_id);
|
|
293
|
-
|
|
294
|
-
|
|
235
|
+
r.then(
|
|
236
|
+
(value) => comm.returnOrFail(fun, call_id, value),
|
|
237
|
+
(reason) => comm.error(call_id, reason.message, reason.stack));
|
|
295
238
|
} else {
|
|
296
239
|
await comm.returnOrFail(fun, call_id, r);
|
|
297
240
|
}
|
|
@@ -302,8 +245,7 @@ async function setupLocalFFIs(hub, config, localFFIs) {
|
|
|
302
245
|
}
|
|
303
246
|
|
|
304
247
|
class FFIComm {
|
|
305
|
-
constructor(
|
|
306
|
-
this.vmID = vmID;
|
|
248
|
+
constructor(hub, channel) {
|
|
307
249
|
this.hub = hub;
|
|
308
250
|
this.channel = channel;
|
|
309
251
|
}
|
|
@@ -312,7 +254,7 @@ class FFIComm {
|
|
|
312
254
|
{ call_id: call_id,
|
|
313
255
|
};
|
|
314
256
|
let response = this.hub.newLocalMessage("msg_ffi_later", "starter", r_payload);
|
|
315
|
-
return this.channel.publish("/local/
|
|
257
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
316
258
|
}
|
|
317
259
|
return_(fun, call_id, result) {
|
|
318
260
|
let r_payload =
|
|
@@ -320,7 +262,7 @@ class FFIComm {
|
|
|
320
262
|
value: fun.useJsonDecoder ? result : encode(result)
|
|
321
263
|
};
|
|
322
264
|
let response = this.hub.newLocalMessage("msg_ffi_return", "starter", r_payload);
|
|
323
|
-
return this.channel.publish("/local/
|
|
265
|
+
return this.channel.publish("/local/ffi/return", response, false);
|
|
324
266
|
}
|
|
325
267
|
error(call_id, message, stack) {
|
|
326
268
|
let r_payload =
|
|
@@ -329,7 +271,7 @@ class FFIComm {
|
|
|
329
271
|
stack: stack === undefined ? [] : stack,
|
|
330
272
|
};
|
|
331
273
|
let response = this.hub.newLocalMessage("msg_ffi_error", "starter", r_payload);
|
|
332
|
-
this.channel.publish("/local/
|
|
274
|
+
this.channel.publish("/local/ffi/return", response, false);
|
|
333
275
|
}
|
|
334
276
|
returnOrFail(fun, call_id, result) {
|
|
335
277
|
if (fun.canFail) {
|
|
@@ -360,6 +302,5 @@ class FFIComm {
|
|
|
360
302
|
// use worker.terminate() to shut a worker down!
|
|
361
303
|
|
|
362
304
|
export { CreateVMID, StartWASM, StartWASM2,
|
|
363
|
-
terminateAll, terminateVM,
|
|
364
305
|
Token, Case, Opaque
|
|
365
306
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix_labs/machine-starter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1836.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.1836.0-dev",
|
|
15
15
|
"nanoid": "^3.1.12",
|
|
16
16
|
"web-worker": "^1.2.0"
|
|
17
17
|
},
|
package/start.js
CHANGED