PluginManager

client. PluginManager

The PluginManager allows to register and retrieve soundworks plugins.

Plugins should always be registered both client-side and server-side, and before client.Client#start or server.Server#start to be properly initialized.

In some sitautions, you might want to register the same plugin factory several times using different ids (e.g. for watching several parts of the file system, etc.).

Refer to the plugins' documentation for more precise examples, and the specific API they expose. See https://soundworks.dev/guide/ecosystem for more informations on the available plugins.

See client.Client#pluginManager

// client-side
import { Client } from '@soundworks/core/client.js';
import syncPlugin from '@soundworks/plugin-sync/client.js';

const client = new Client(config);
// register the plugin before `client.start()`
client.pluginManager.register('sync', syncPlugin);

await client.start();

const sync = await client.pluginManager.get('sync');

setInterval(() => {
  // log the estimated global synced clock alongside the local clock.
  console.log(sync.getSyncTime(), sync.getLocalTime());
}, 1000);
// server-side
import { Server } from '@soundworks/core/server.js';
import syncPlugin from '@soundworks/plugin-sync/server.js';

const server = new Server(config);
// register the plugin before `server.start()`
server.pluginManager.register('sync', syncPlugin);

await server.start();

const sync = await server.pluginManager.get('sync');

setInterval(() => {
  // log the estimated global synced clock alongside the local clock.
  console.log(sync.getSyncTime(), sync.getLocalTime());
}, 1000);

Extends

Methods

addDependency()

Description:
  • Manually add a dependency to a given plugin. Usefull to require a plugin within a plugin

Source:
Overrides:

getRegisteredPlugins() → {Array.<string>}

Description:
  • Returns the list of the registered plugins ids

Source:
Overrides:
Returns:
Type
Array.<string>

onStateChange(callback, Function)

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 client.PluginManager~onStateChangeCallback | server.PluginManager~onStateChangeCallback

Callback to be executed on state change

Function client.PluginManager~deleteOnStateChangeCallback | client.PluginManager~deleteOnStateChangeCallback

to execute to listening for changes.

register(id, factory, optionsopt, depsopt)

Description:
  • Register a plugin into soundworks.

    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

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.

Type Definitions

deleteOnStateChangeCallback()

Description:
Source:

onStateChangeCallback(fullState, initiator)

Description:
  • Callback executed when a plugin internal state is updated.

Source:
Parameters:
Name Type Description
fullState object.<client.Plugin#id, client.Plugin>

List of all plugins.

initiator client.Plugin | null

Plugin that initiated the update or null if the change was initiated by the state manager (i.e. when the initialization of the plugins starts).