mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
more scaffolding
This commit is contained in:
parent
431600342f
commit
6c74e84e11
@ -48,6 +48,7 @@ const config = {
|
||||
generatorWorker: './example/generator/generatorWorker.js',
|
||||
couchDBChangesFeed: './src/plugins/persistence/couch/CouchChangesFeed.js',
|
||||
inMemorySearchWorker: './src/api/objects/InMemorySearchWorker.js',
|
||||
compsMathWorker: './src/plugins/comps/CompsMathWorker.js',
|
||||
espressoTheme: './src/plugins/themes/espresso-theme.scss',
|
||||
snowTheme: './src/plugins/themes/snow-theme.scss',
|
||||
darkmatterTheme: './src/plugins/themes/darkmatter-theme.scss'
|
||||
@ -91,7 +92,7 @@ const config = {
|
||||
__OPENMCT_BUILD_BRANCH__: `'${gitBranch}'`,
|
||||
__VUE_OPTIONS_API__: true, // enable/disable Options API support, default: true
|
||||
__VUE_PROD_DEVTOOLS__: false, // enable/disable devtools support in production, default: false
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false', // enable/disable hydration mismatch details in production, default: false
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, // enable/disable hydration mismatch details in production, default: false
|
||||
}),
|
||||
new VueLoaderPlugin(),
|
||||
new CopyWebpackPlugin({
|
||||
|
26
src/plugins/comps/CompsMathWorker.js
Normal file
26
src/plugins/comps/CompsMathWorker.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { evaluate } from 'mathjs';
|
||||
|
||||
onconnect = function (e) {
|
||||
const port = e.ports[0];
|
||||
console.debug('🧮 Comps Math Worker connected');
|
||||
|
||||
port.onmessage = function (event) {
|
||||
console.debug('🧮 Comps Math Worker message:', event);
|
||||
const { type, id, data, expression } = event.data;
|
||||
if (type === 'calculate') {
|
||||
try {
|
||||
const result = data.map((point) => {
|
||||
// Using Math.js to evaluate the expression against the data
|
||||
return { ...point, value: evaluate(expression, point) };
|
||||
});
|
||||
port.postMessage({ type: 'response', id, result });
|
||||
} catch (error) {
|
||||
port.postMessage({ type: 'error', id, error: error.message });
|
||||
}
|
||||
} else if (type === 'init') {
|
||||
port.postMessage({ type: 'ready' });
|
||||
} else {
|
||||
port.postMessage({ type: 'error', id, error: 'Invalid message type' });
|
||||
}
|
||||
};
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
export default class ConditionSetTelemetryProvider {
|
||||
constructor(openmct) {
|
||||
this.openmct = openmct;
|
||||
this.#startSharedWorker();
|
||||
}
|
||||
|
||||
isTelemetryObject(domainObject) {
|
||||
@ -37,13 +38,46 @@ export default class ConditionSetTelemetryProvider {
|
||||
return domainObject.type === 'comps';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
async request(domainObject, options) {
|
||||
// TODO: do some math in a worker
|
||||
return { value: 0};
|
||||
return { value: 0 };
|
||||
}
|
||||
|
||||
subscribe(domainObject, callback) {
|
||||
// TODO: add to listener list and return a function to remove it
|
||||
return () => {};
|
||||
}
|
||||
|
||||
#startSharedWorker() {
|
||||
// eslint-disable-next-line no-undef
|
||||
const sharedWorkerURL = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}compsMathWorker.js`;
|
||||
|
||||
const sharedWorker = new SharedWorker(sharedWorkerURL, `Comps Math Worker`);
|
||||
sharedWorker.port.onmessage = this.onSharedWorkerMessage.bind(this);
|
||||
sharedWorker.port.onmessageerror = this.onSharedWorkerMessageError.bind(this);
|
||||
sharedWorker.port.start();
|
||||
|
||||
// send an initial message to the worker
|
||||
sharedWorker.port.postMessage({ type: 'init' });
|
||||
|
||||
// for testing, try a message adding two numbers
|
||||
sharedWorker.port.postMessage({
|
||||
type: 'calculate',
|
||||
data: [{ a: 1, b: 2 }],
|
||||
expression: 'a + b'
|
||||
});
|
||||
|
||||
this.openmct.on('destroy', () => {
|
||||
sharedWorker.port.close();
|
||||
});
|
||||
}
|
||||
|
||||
onSharedWorkerMessage(event) {
|
||||
console.log('📝 Shared worker message:', event.data);
|
||||
}
|
||||
|
||||
onSharedWorkerMessageError(event) {
|
||||
console.error('❌ Shared worker message error:', event);
|
||||
}
|
||||
}
|
||||
|
@ -31,14 +31,13 @@ export default function CompsPlugin() {
|
||||
creatable: true,
|
||||
cssClass: 'icon-telemetry',
|
||||
initialize: function (domainObject) {
|
||||
domainObject.configuration = {
|
||||
};
|
||||
domainObject.configuration = {};
|
||||
domainObject.composition = [];
|
||||
domainObject.telemetry = {};
|
||||
}
|
||||
});
|
||||
openmct.composition.addPolicy((parent, child) => {
|
||||
return openmct.telemetry.isTelemetryObject(child);
|
||||
return openmct.telemetry.isTelemetryObject(child);
|
||||
});
|
||||
openmct.telemetry.addProvider(new CompsTelemetryProvider(openmct));
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user