@remix_labs/machine-starter 2.12939.0-dev → 2.12943.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 +111 -157
- package/groovebox_build.js +1 -1
- package/package.json +2 -2
package/common.js
CHANGED
|
@@ -12,7 +12,6 @@ let children = {};
|
|
|
12
12
|
let ffiLoops = {};
|
|
13
13
|
let blobs = {};
|
|
14
14
|
let blobsLoops = {};
|
|
15
|
-
let coordination = {};
|
|
16
15
|
|
|
17
16
|
function terminateAll() {
|
|
18
17
|
console.log("[machine-starter] terminate all VMs");
|
|
@@ -38,66 +37,47 @@ function terminateAll() {
|
|
|
38
37
|
blobsLoops = {};
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
function terminateVM(vmID) {
|
|
42
41
|
console.log("[machine-starter] terminate VM", vmID);
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
delete children[vmID];
|
|
63
|
-
delete ffiLoops[vmID];
|
|
64
|
-
delete blobsLoops[vmID];
|
|
65
|
-
delete worker_topics[vmID];
|
|
66
|
-
delete workers[vmID];
|
|
67
|
-
// terminate our endpoints of communication
|
|
68
|
-
if (ffiLoop) {
|
|
69
|
-
ffiLoop.terminate();
|
|
70
|
-
}
|
|
71
|
-
if (blobsLoop) {
|
|
72
|
-
blobsLoop.terminate();
|
|
73
|
-
}
|
|
74
|
-
for (let blob_url of blobList) {
|
|
75
|
-
console.log("[machine-starter] revoke ", blob_url);
|
|
76
|
-
URL.revokeObjectURL(blob_url);
|
|
77
|
-
}
|
|
78
|
-
// kill the worker:
|
|
79
|
-
worker.terminate();
|
|
80
|
-
// go on with sub VMs
|
|
42
|
+
let worker = workers[vmID];
|
|
43
|
+
if (worker) {
|
|
44
|
+
let vmChildren = children[vmID];
|
|
45
|
+
let blobList = blobs[vmID] || [];
|
|
46
|
+
let ffiLoop = ffiLoops[vmID];
|
|
47
|
+
let blobsLoop = blobsLoops[vmID];
|
|
48
|
+
delete children[vmID];
|
|
49
|
+
delete ffiLoops[vmID];
|
|
50
|
+
delete blobsLoops[vmID];
|
|
51
|
+
killVM(vmID);
|
|
52
|
+
ffiLoop.terminate();
|
|
53
|
+
if (blobsLoop) {
|
|
54
|
+
blobsLoop.terminate();
|
|
55
|
+
}
|
|
56
|
+
for (let blob_url of blobList) {
|
|
57
|
+
console.log("[machine-starter] revoke ", blob_url);
|
|
58
|
+
URL.revokeObjectURL(blob_url);
|
|
59
|
+
};
|
|
60
|
+
if (vmChildren) {
|
|
81
61
|
for (let subID of vmChildren) {
|
|
82
|
-
terminateVM(subID)
|
|
62
|
+
terminateVM(subID)
|
|
83
63
|
}
|
|
84
|
-
});
|
|
85
|
-
// if termination is already in progress, just wait for completion
|
|
86
|
-
while (coord.term_promise) {
|
|
87
|
-
await coord.term_promise;
|
|
88
|
-
return; // that's it!
|
|
89
64
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function killVM(vmID) {
|
|
69
|
+
let worker = workers[vmID];
|
|
70
|
+
let topic = worker_topics[vmID];
|
|
71
|
+
delete workers[vmID];
|
|
72
|
+
delete worker_topics[vmID];
|
|
73
|
+
if (topic && last_hub) {
|
|
74
|
+
let payload = { _rmx_type:"msg_vm_register", id: vmID, alive: false };
|
|
75
|
+
last_hub.newChannel().then(channel => {
|
|
76
|
+
let msg = channel.newJSONMessage("msg_vm_register", "vm", payload);
|
|
77
|
+
channel.publish(topic + "/announce", msg, true)
|
|
78
|
+
}).then(_ => worker.terminate())
|
|
79
|
+
} else {
|
|
80
|
+
worker.terminate()
|
|
101
81
|
}
|
|
102
82
|
}
|
|
103
83
|
|
|
@@ -153,110 +133,84 @@ async function StartWASM2(hub, config, getWorker) {
|
|
|
153
133
|
console.log("[machine-starter] Call MixExplain() for explaining debug levels, and MixSetMask(m) for changing these")
|
|
154
134
|
};
|
|
155
135
|
last_hub = hub;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (initialMask & DEBUG_STATE) {
|
|
167
|
-
console.debug("[machine-starter] waiting for termination of VM: " + config.vmID);
|
|
168
|
-
};
|
|
169
|
-
await coord.term_promise;
|
|
136
|
+
let channel = await hub.newChannel();
|
|
137
|
+
// injected by either index.js or node.js
|
|
138
|
+
let worker = await getWorker();
|
|
139
|
+
if (workers[config.vmID] || ffiLoops[config.vmID])
|
|
140
|
+
throw new Error("Cannot start VM, the ID is used: " + config.vmID);
|
|
141
|
+
workers[config.vmID] = worker;
|
|
142
|
+
if (config.topicPrefix != undefined && config.topicPrefix != "") {
|
|
143
|
+
worker_topics[config.vmID] = config.topicPrefix + "/vm/" + config.vmID;
|
|
144
|
+
} else {
|
|
145
|
+
worker_topics[config.vmID] = "/org/" + config.org + "/ws/" + config.workspace + "/vm/" + config.vmID;
|
|
170
146
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
147
|
+
let starterFFIs = config.localFFIs || {};
|
|
148
|
+
// from now on, the "local" FFIs are called "starter" FFIs, because this
|
|
149
|
+
// distinguishes these from other locally defined FFIs
|
|
150
|
+
let mixcore = await createStarterMixcore(config.mixcore);
|
|
151
|
+
if (mixcore) {
|
|
152
|
+
// merge the ffis and store them back into the config so sub vms also get them
|
|
153
|
+
config.localFFIs = Object.assign(starterFFIs, await mixcoreStarterFFIs(mixcore));
|
|
154
|
+
// delete the mixcore config to avoid being handled further by the worker
|
|
155
|
+
delete config.mixcore;
|
|
174
156
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// injected by either index.js or node.js
|
|
182
|
-
let worker = await getWorker();
|
|
183
|
-
workers[config.vmID] = worker;
|
|
184
|
-
if (config.topicPrefix != undefined && config.topicPrefix != "") {
|
|
185
|
-
worker_topics[config.vmID] = config.topicPrefix + "/vm/" + config.vmID;
|
|
157
|
+
let starterFFIkind = {};
|
|
158
|
+
let starterFFIfuns = {};
|
|
159
|
+
for (const [k, v] of Object.entries(starterFFIs)) {
|
|
160
|
+
starterFFIfuns[k] = {...v};
|
|
161
|
+
if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
|
|
162
|
+
console.error("A raw, starter FFI must neither be failing nor use the JSON decoder: " + k);
|
|
186
163
|
} else {
|
|
187
|
-
|
|
164
|
+
starterFFIkind[k] = {...v};
|
|
165
|
+
delete starterFFIkind[k].run;
|
|
188
166
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
167
|
+
};
|
|
168
|
+
let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
|
|
169
|
+
starterFFIkind["$vm_start"] = vm_kind;
|
|
170
|
+
starterFFIfuns["$vm_start"] = (conn, args) => ffi_vm_start(conn, args, getWorker);
|
|
171
|
+
starterFFIkind["$vm_stop"] = vm_kind;
|
|
172
|
+
starterFFIfuns["$vm_stop"] = ffi_vm_stop;
|
|
173
|
+
let mixrtCode = config.mixrtCode;
|
|
174
|
+
if (typeof(mixrtCode) == "string" && mixrtCode.startsWith("remix://")) {
|
|
175
|
+
// for the desktop only: precompile the mixrt module to get faster
|
|
176
|
+
// startup times
|
|
177
|
+
if (globalThis.mixrtCodeModule && globalThis.mixrtCodeURL == mixrtCode) {
|
|
178
|
+
console.log("[machine-starter] reusing mixrt");
|
|
179
|
+
mixrtCode = globalThis.mixrtCodeModule;
|
|
180
|
+
} else {
|
|
181
|
+
let url = mixrtCode;
|
|
182
|
+
console.log("[machine-starter] pre-compiling mixrt");
|
|
183
|
+
mixrtCode = await WebAssembly.compileStreaming(fetch(url));
|
|
184
|
+
globalThis.mixrtCodeURL = url;
|
|
185
|
+
globalThis.mixrtCodeModule = mixrtCode;
|
|
198
186
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
let url = mixrtCode;
|
|
224
|
-
console.log("[machine-starter] pre-compiling mixrt");
|
|
225
|
-
mixrtCode = await WebAssembly.compileStreaming(fetch(url));
|
|
226
|
-
globalThis.mixrtCodeURL = url;
|
|
227
|
-
globalThis.mixrtCodeModule = mixrtCode;
|
|
228
|
-
}
|
|
187
|
+
};
|
|
188
|
+
ffiLoops[config.vmID] = setupStarterFFIs(hub, config, starterFFIfuns);
|
|
189
|
+
blobsLoops[config.vmID] = setupBlobs(hub, config);
|
|
190
|
+
let config_msg =
|
|
191
|
+
{ "_rmx_type": "msg_vm_configure",
|
|
192
|
+
"baseURL": config.baseURL,
|
|
193
|
+
"org": config.org,
|
|
194
|
+
"workspace": config.workspace,
|
|
195
|
+
"topicPrefix": config.topicPrefix,
|
|
196
|
+
"vmID": config.vmID,
|
|
197
|
+
"user": config.user,
|
|
198
|
+
"token": config.token,
|
|
199
|
+
"hub": channel.port,
|
|
200
|
+
"outputViaMQTT": !(config.noOutputViaMQTT),
|
|
201
|
+
"machType": config.machType,
|
|
202
|
+
"debugMask": initialMask,
|
|
203
|
+
"starterFFIs": starterFFIkind,
|
|
204
|
+
"allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
|
|
205
|
+
"interceptFFI": config.interceptFFI,
|
|
206
|
+
"interceptDynloadFFI": config.interceptDynloadFFI,
|
|
207
|
+
"mixcore": config.mixcore,
|
|
208
|
+
"mixrtCode": mixrtCode
|
|
209
|
+
// can be: base64-encoded string, Uint8Array, or a URL as string
|
|
210
|
+
// (http, https, data)
|
|
229
211
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
let config_msg =
|
|
233
|
-
{ "_rmx_type": "msg_vm_configure",
|
|
234
|
-
"baseURL": config.baseURL,
|
|
235
|
-
"org": config.org,
|
|
236
|
-
"workspace": config.workspace,
|
|
237
|
-
"topicPrefix": config.topicPrefix,
|
|
238
|
-
"vmID": config.vmID,
|
|
239
|
-
"user": config.user,
|
|
240
|
-
"token": config.token,
|
|
241
|
-
"hub": channel.port,
|
|
242
|
-
"outputViaMQTT": !(config.noOutputViaMQTT),
|
|
243
|
-
"machType": config.machType,
|
|
244
|
-
"debugMask": initialMask,
|
|
245
|
-
"starterFFIs": starterFFIkind,
|
|
246
|
-
"allowInsecureHttp": globalThis.GROOVEBOX_ALLOW_INSECURE_HTTP,
|
|
247
|
-
"interceptFFI": config.interceptFFI,
|
|
248
|
-
"interceptDynloadFFI": config.interceptDynloadFFI,
|
|
249
|
-
"mixcore": config.mixcore,
|
|
250
|
-
"mixrtCode": mixrtCode
|
|
251
|
-
// can be: base64-encoded string, Uint8Array, or a URL as string
|
|
252
|
-
// (http, https, data)
|
|
253
|
-
};
|
|
254
|
-
worker.postMessage(config_msg, [ channel.port ]);
|
|
255
|
-
return worker;
|
|
256
|
-
} finally {
|
|
257
|
-
coord.start_promise = null;
|
|
258
|
-
start_done();
|
|
259
|
-
}
|
|
212
|
+
worker.postMessage(config_msg, [ channel.port ]);
|
|
213
|
+
return worker;
|
|
260
214
|
}
|
|
261
215
|
|
|
262
216
|
async function mixcoreStarterFFIs(mixcore) {
|
|
@@ -433,7 +387,7 @@ async function starterFFIsMessageLoop(hub, config, starterFFIs, terminate) {
|
|
|
433
387
|
sub.next().then((msg) => ({msg})),
|
|
434
388
|
terminate.then(() => ({terminated: true})),
|
|
435
389
|
]);
|
|
436
|
-
if (terminated
|
|
390
|
+
if (terminated) {
|
|
437
391
|
// console.log("[machine-starter] terminate FFI loop", vmID);
|
|
438
392
|
return;
|
|
439
393
|
}
|
|
@@ -493,7 +447,7 @@ async function blobsMessageLoop(hub, config, terminate) {
|
|
|
493
447
|
sub.next().then((msg) => ({msg})),
|
|
494
448
|
terminate.then(() => ({terminated: true})),
|
|
495
449
|
]);
|
|
496
|
-
if (terminated
|
|
450
|
+
if (terminated) {
|
|
497
451
|
// console.log("[machine-starter] terminate blobs loop", vmID);
|
|
498
452
|
return;
|
|
499
453
|
}
|
package/groovebox_build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GROOVEBOX_BUILD = "
|
|
1
|
+
var GROOVEBOX_BUILD = "12943";
|
|
2
2
|
export { GROOVEBOX_BUILD }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix_labs/machine-starter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12943.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": "2.
|
|
14
|
+
"@remix_labs/hub-client": "2.12943.0-dev",
|
|
15
15
|
"nanoid": "^5.0.2",
|
|
16
16
|
"web-worker": "^1.2.0"
|
|
17
17
|
},
|