2020-08-25 22:11:26 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-08-25 23:27:28
|
2020-12-04 18:10:33 +00:00
|
|
|
* @modify date 2020-12-02 08:56:46
|
2020-08-25 22:11:26 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
2020-11-06 13:18:10 +00:00
|
|
|
import { IExportFunctionToDispatcherParameters } from "../decorators/dispatcherDecorators";
|
2020-08-25 22:11:26 +00:00
|
|
|
import { getSingleton } from "../helpers/singletonMethod";
|
2020-11-15 19:11:25 +00:00
|
|
|
import { INopeDispatcherOptions } from "../types/nope/nopeCommunication.interface";
|
2020-11-06 13:18:10 +00:00
|
|
|
import { getDispatcher } from "./getDispatcher";
|
2020-08-25 22:11:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a Dispatcher.
|
2020-12-04 18:10:33 +00:00
|
|
|
* @param options
|
2020-08-25 22:11:26 +00:00
|
|
|
*/
|
2020-11-15 19:11:25 +00:00
|
|
|
export function getLinkedDispatcher(options: INopeDispatcherOptions) {
|
2020-11-12 16:07:05 +00:00
|
|
|
// Create the Dispatcher Instance.
|
2020-11-06 13:18:10 +00:00
|
|
|
const dispatcher = getDispatcher(options);
|
2020-08-25 22:11:26 +00:00
|
|
|
|
2020-11-12 16:07:05 +00:00
|
|
|
// Define a Container, which contains all functions.
|
2020-11-23 06:09:31 +00:00
|
|
|
const container = getSingleton("nopeBackendDispatcher.container", () => {
|
2020-12-04 18:10:33 +00:00
|
|
|
return new Map<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
uri: string;
|
|
|
|
callback: (...args) => Promise<any>;
|
|
|
|
options: IExportFunctionToDispatcherParameters;
|
|
|
|
}
|
|
|
|
>();
|
2020-11-23 06:09:31 +00:00
|
|
|
});
|
2020-11-12 16:07:05 +00:00
|
|
|
|
2020-11-11 17:11:37 +00:00
|
|
|
// If the Dispatcher has been connected, register all functions.
|
2020-12-04 18:10:33 +00:00
|
|
|
dispatcher.ready
|
|
|
|
.waitFor((value) => value === true)
|
|
|
|
.then(() => {
|
|
|
|
if (dispatcher.ready.getContent()) {
|
|
|
|
// Iterate over the Functions
|
|
|
|
for (const [uri, settings] of container.instance.entries()) {
|
|
|
|
dispatcher.registerFunction(settings.callback, {
|
|
|
|
id: uri
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Failed to Setup the Container.
|
2020-11-11 17:11:37 +00:00
|
|
|
}
|
2020-12-04 18:10:33 +00:00
|
|
|
});
|
2020-09-10 16:21:01 +00:00
|
|
|
|
2020-08-25 22:11:26 +00:00
|
|
|
return dispatcher;
|
|
|
|
}
|