Extends
Members
[undefined]
- Description:
#private
- Source:
- Overrides:
#private
status :'idle'|'inited'|'started'|'errored'
- Description:
Status of the plugin manager
- Source:
- Overrides:
Status of the plugin manager
Type:
- 'idle' | 'inited' | 'started' | 'errored'
Methods
addDependency()
- Description:
Manually add a dependency to a given plugin.
Usefull to require a plugin within a plugin
- Source:
- Overrides:
(async) get(id) → {ServerPlugin}
- Description:
Retrieve a fully started instance of a registered plugin.
Be aware that the
get
method resolves only when the plugin is fully 'started', which is what we want 99.99% of the time. As such, and to prevent the application to be stuck in some kind of Promise dead lock, this method will throw if used beforeserver.init()
(orserver.start()
).To handle the remaining 0.01% cases and access plugin instances during their initialization (e.g. to display initialization screen, etc.), you should rely on the
onStateChange
method.Note: the async API is designed to enable the dynamic creation of plugins (hopefully without brealing changes) in a future release.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
id |
ServerPlugin#id | Id of the plugin as defined when registered. |
Returns:
- Type
- ServerPlugin
getRegisteredPlugins() → {Array.<string>}
- Description:
Returns the list of the registered plugins ids
- Source:
- Overrides:
Returns:
- Type
- Array.<string>
(async) getUnsafe()
- Description:
Retrieve an fully started instance of a registered plugin without checking that the pluginManager is started.
This method is required for starting the plugin manager itself and to require a plugin from within another plugin.
Warning: Unless you are developing your own plugins, you should not have to use this method
- Source:
- Overrides:
onStateChange(callback) → {pluginManagerDeleteOnStateChangeCallback}
- Description:
Propagate a notification each time a plugin is updated (status or inner state). The callback will receive the list of all plugins as first parameter, and the plugin instance that initiated the state change event as second parameter.
In most cases, you should not have to rely on this method.
- Source:
- Overrides:
Example
const unsubscribe = client.pluginManager.onStateChange(pluginList, initiator => {
// log the current status of all plugins
for (let name in pluginList) {
console.log(name, pluginList[name].status);
}
// if the change was initiated by a plugin, log its status and state
if (initiator !== null) {
. console.log(initiator.name, initiator.status, initiator.state);
}
});
// stop listening for updates later
unsubscribe();
Parameters:
Name | Type | Description |
---|---|---|
callback |
pluginManagerOnStateChangeCallback | Callback to execute on state change |
Returns:
- Clear the subscription when executed
register(id, factory, optionsopt, depsopt)
- Description:
Register a plugin into the manager.
A plugin must always be registered both on client-side and on server-side
Refer to the plugin documentation to check its options and proper way of registering it.
- Source:
- Overrides:
- See:
Example
// client-side
client.pluginManager.register('user-defined-id', pluginFactory);
// server-side
server.pluginManager.register('user-defined-id', pluginFactory);
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
id |
string | Unique id of the plugin. Enables the registration of the same plugin factory under different ids. |
||
factory |
function |
null
|
Factory function that returns the Plugin class. |
|
options |
object |
<optional> |
{}
|
Options to configure the plugin. |
deps |
array |
<optional> |
[]
|
List of plugins' names the plugin depends on, i.e. the plugin initialization will start only after the plugins it depends on are fully started themselves. |