Plugins
Overview
When designing a multi app project, sometimes you may need to execute initial system logic - initialize data providers (like search providers), register Interop methods, or even modify the behavior of the @interopio/browser-platform
library (see Interception). In a desktop app this is usually handled by auto starting hidden apps. In a web project, however, it isn't possible to create a hidden browser window that will execute the required initial logic. The solution is to define a Plugin in the configuration object for the Main app. The Plugin will be initialized on platform startup and will simulate using a hidden service app in your project.
Usage
Plugins in the context of io.Connect Browser are user-defined functions that will be executed upon startup of the Main app. You can also specify whether the initialization of the @interopio/browser-platform
library must wait for the Plugin to be executed. The Plugin receives as a first argument an object containing the fully initialized io.Connect library, which allows you to perform io.Connect operations before the Main app or any of the Browser Client apps has been initialized. As a second argument, the Plugin receives a user-defined configuration object, and as a third - an object that can be used for finer system control (see Interception).
Use the plugins
property of the configuration object when initializing the @interopio/browser-platform
library in the Main app to define Plugins:
import IOBrowserPlatform from "@interopio/browser-platform";
const myPlugin = async (io, config) => {
let meaning;
if (config.io === 42) {
meaning = config.io;
} else {
meaning = undefined;
};
await io.interop.register("MyMethod", () => `Currently, the meaning of life is ${meaning}.`);
};
const config = {
licenseKey: "my-license-key",
plugins: {
// Plugin definitions.
definitions: [
{
name: "my-plugin",
config: { io: 42 },
start: myPlugin,
critical: true
}
]
}
};
const { io } = await IOBrowserPlatform(config);
The Plugin definition object has the following properties:
Property | Type | Description |
---|---|---|
name |
string |
Required. Name for the Plugin. |
start |
function |
Required. Function that will receive as arguments a fully initialized io object, the config object specified in the definition and a platform object (see Interception) that can be used for handling low-level system messages and logging. |
version |
string |
Version of the Plugin. |
config |
object |
Configuration that will be passed to the Plugin. |
critical |
boolean |
If true , the @interopio/browser-platform library will wait for the Plugin to be executed before completing its initialization. |