AbstractPlugin

client. AbstractPlugin

Base class to extend for implementing a new plugin.

A plugin should always be provided wrapped in a factory function to allow for dynamically extend this class and avoid circular dependencies.

Constructor

new AbstractPlugin(client, name)

Source:
Example
function myPluginFactory(AbstractPlugin) {
  class MyPlugin extends AbstractPlugin {
    constructor(client, name, options) {
      super(client, name);
      // ...
    }

    async start() {
      await ...
      this.started();
      await ...
      this.ready();
    }
  }

  return MyPlugin;
}
// then register the factory
client.pluginManager.register('my-plugin', myPluginFactory, { options }, []);
Parameters:
Name Type Description
client client.Client

instance of the soundworks Client

name String

user defined name of the plugin

Members

client :String

Source:
See:

Instance of the soundworks client

Type:
  • String

name :String

Source:

Name of the plugin, as defined on registration.

Type:
  • String

options :Object

Source:

Options of the plugin.

Type:
  • Object

Methods

configure()

Source:

Helper function to merge default options and user-defined options.

Example
this.options = this.configure(defaults, options);

ready()

Source:
See:

Lifecyle method to call in the client.AbstractPlugin#start method when the plugin has completely finished its initialization should be considered as ready. Calling this method notify soundworks that the initialization process can continue or that the application can start safely (cf. client.AbstractExperience#start)

Example
class MyDelayPlugin extends AbstractPlugin {
  // ...
  async start() {
    this.state = await this.client.stateManager.attach(`s:${this.name}`);
    this.started();
    // do [async] stuff
    setTimeout(() => this.ready(), 3000);
  }
}

start()

Source:
See:

Interface method to override when implementing child class.

Important: the derived class MUST call client.AbstractPlugin#started and client.AbstractPlugin#ready to notify soundworks about the state of the plugin

Example
class MyDelayPlugin extends AbstractPlugin {
  // ...
  async start() {
    this.state = await this.client.stateManager.attach(`s:${this.name}`);
    this.started();
    // do [async] stuff
    setTimeout(() => this.ready(), 3000);
  }
}

started()

Source:
See:

Lifecyle method to call in the client.AbstractPlugin#start method when the plugin is effectively started, as it may have to do some asynchonous job at start (e.g. creating a shared state, waiting for user input, etc.).

Must be called between before client.AbstractPlugin#ready.

Example
class MyDelayPlugin extends AbstractPlugin {
  // start() is executed when the `start` signal pass to `true`
  async start() {
    this.state = await this.client.stateManager.attach(`s:${this.name}`);
    this.started();
    // do [async] stuff
    setTimeout(() => this.ready(), 3000);
  }
}