Plugin

client. Plugin

Base class to extend in order to create the client-side counterpart of a soundworks plugin.

In the soundworks paradigm, a plugin is a component that allows to extend the framework capabilities by encapsulating common and reusable logic in an application wise perspective. For example, plugins are available to handle clock synchronization, to deal with the file system, etc. Plugin should always have both a client-side and a server-side part.

See https://soundworks.dev/guide/ecosystem for more informations on the available plugins.

Creating new plugins should be considered an advanced usage.

Constructor

new Plugin(client, id)

Source:
Parameters:
Name Type Description
client client.Client

The soundworks client instance.

id string

User defined id of the plugin as defined in client.PluginManager#register.

Extends

Members

client :client.Client

Description:
  • Instance of soundworks client.

Source:
See:

Instance of soundworks client.

Type:

(readonly) id :string

Description:
  • User defined ID of the plugin.

Source:
Overrides:
See:

User defined ID of the plugin.

Type:
  • string

options :object

Description:
  • Options of the plugin.

Source:
Overrides:

Options of the plugin.

Type:
  • object

(protected) state :object

Description:
  • Placeholder that stores internal (local) state of the plugin. The state should be modified through the propagateStateChange method to ensure the change to be properly propagated to onStateChange callbacks.

Source:
Overrides:
See:

Placeholder that stores internal (local) state of the plugin. The state should be modified through the propagateStateChange method to ensure the change to be properly propagated to onStateChange callbacks.

Type:
  • object

status :string

Description:
  • Current status of the plugin, i.e. 'idle', 'inited', 'started', 'errored'

Source:
Overrides:

Current status of the plugin, i.e. 'idle', 'inited', 'started', 'errored'

Type:
  • string

(readonly) type :string

Description:
  • Type of the plugin, i.e. the ClassName.

    Usefull to do perform some logic based on certain types of plugins without knowing under which id they have been registered. (e.g. creating some generic views, etc.)

Source:
Overrides:

Type of the plugin, i.e. the ClassName.

Usefull to do perform some logic based on certain types of plugins without knowing under which id they have been registered. (e.g. creating some generic views, etc.)

Type:
  • string

Methods

onStateChange(callback) → {client.Plugin~deleteOnStateChangeCallback|server.Plugin~deleteOnStateChangeCallback}

Description:
  • Listen to the state changes propagated by BasePlugin.propagateStateChange

Source:
Overrides:
See:
Example
const unsubscribe = plugin.onStateChange(pluginState => console.log(pluginState));
// stop listening state changes
unsubscribe();
Parameters:
Name Type Description
callback client.Plugin~onStateChangeCallback | server.Plugin~onStateChangeCallback

Callback to execute when a state change is propagated.

Returns:

Execute the function to delete the listener from the callback list.

Type
client.Plugin~deleteOnStateChangeCallback | server.Plugin~deleteOnStateChangeCallback

propagateStateChange(updates)

Description:
  • Apply updates to the plugin state and propagate the updated state to the onStateChange listeners. The state changes will also be propagated through the PluginManager#onStateChange listeners.

Source:
Overrides:
See:
Parameters:
Name Type Description
updates object

Updates to be merged in the plugin state.

(async) start()

Description:
  • Start the plugin. This method is automatically called during the client or server init() lifecyle step. After start() is fulfilled the plugin should be ready to use.

Source:
Overrides:
Example
// server-side couterpart of a plugin that creates a dedicated global shared
// state on which the server-side part can attach.
class MyPlugin extends Plugin {
  constructor(server, id) {
    super(server, id);

    this.server.stateManager.registerSchema(`my-plugin:${this.id}`, {
      someParam: {
        type: 'boolean',
        default: false,
      },
      // ...
    });
  }

  async start() {
    await super.start()
    this.sharedState = await this.server.stateManager.create(`my-plugin:${this.id}`);
  }

  async stop() {
    await this.sharedState.delete();
  }
}

(async) stop()

Description:
  • Stop the plugin. This method is automatically called during the client or server stop() lifecyle step.

Source:
Overrides:
Example
// server-side couterpart of a plugin that creates a dedicated global shared
// state on which the server-side part can attach.
class MyPlugin extends Plugin {
  constructor(server, id) {
    super(server, id);

    this.server.stateManager.registerSchema(`my-plugin:${this.id}`, {
      someParam: {
        type: 'boolean',
        default: false,
      },
      // ...
    });
  }

  async start() {
    await super.start()
    this.sharedState = await this.server.stateManager.create(`my-plugin:${this.id}`);
    this.sharedState.onUpdate(updates => this.doSomething(updates));
  }

  async stop() {
    await this.sharedState.delete();
  }
}

Type Definitions

deleteOnStateChangeCallback()

Description:
Source:

onStateChangeCallback(state)

Description:
  • Callback executed when the plugin state is updated.

Source:
Parameters:
Name Type Description
state client.Plugin#state

Current state of the plugin.