Class PluginLoader

Service for the worker node to import plugins & load them globally or into specific rooms.

An "imported plugin" is a plugin which has actually been loaded into memory with require(), and a "loaded plugin" is a plugin which is enabled on a room or globally.

Hierarchy

  • PluginLoader

Methods

  • Check whether some object is a Hindenburg plugin.

    Returns

    Whether someObject is a Hindenburg plugin.

    Example

    console.log(this.worker.pluginLoader.isHindenburgPlugin({})); // false
    

    Example

    class MyPlugin extends WorkerPlugin {}

    console.log(this.worker.pluginLoader.isHindenburgPlugin(MyPlugin)); // true

    Parameters

    • someObject: any

      The object to check.

    Returns boolean

  • Check whether an imported Hindenburg plugin is a room plugin to be loaded into rooms, extending RoomPlugin.

    Returns

    Whether pluginCtr is a room plugin.

    Example

    .@HindenburgPlugin("hbplugin-fun-things")
    class MyPlugin extends RoomPlugin {}

    console.log(this.worker.pluginLoad.isRoomPlugin(MyPlugin)); // true

    Example

    .@HindenburgPlugin("hbplugin-fun-things")
    class MyPlugin extends WorkerPlugin {}

    console.log(this.worker.pluginLoad.isRoomPlugin(MyPlugin)); // false

    Parameters

    Returns pluginCtr is typeof RoomPlugin

  • Check whether an imported Hindenburg plugin is a worker plugin to be loaded globally, extending WorkerPlugin.

    Returns

    Whether pluginCtr is a global worker plugin.

    Example

    .@HindenburgPlugin("hbplugin-fun-things")
    class MyPlugin extends RoomPlugin {}

    console.log(this.worker.pluginLoad.isWorkerPlugin(MyPlugin)); // false

    Example

    .@HindenburgPlugin("hbplugin-fun-things")
    class MyPlugin extends WorkerPlugin {}

    console.log(this.worker.pluginLoad.isWorkerPlugin(MyPlugin)); // true

    Parameters

    Returns pluginCtr is typeof WorkerPlugin

  • Generate a random plugin ID that has not been taken by any other plugins.

    Returns

    A random plugin ID that can safely be used.

    Returns string

  • Import a plugin via its ID, checking both installed NPM plugins and also local plugin folders.

    Returns

    The loaded plugin, or 'undefined' if unsuccessful (e.g. the module could not be found, or it was loaded but it was not a Hindenburg plugin).

    Example

    const pluginCtr = await this.worker.pluginLoader.importFromId("hbplugin-fun-things");

    if (!pluginCtr) {
    console.log("Failed to load my plugin.");
    return;
    }

    Parameters

    • id: string

      The ID of the plugin to import.

    Returns Promise<undefined | ImportedPlugin<typeof WorkerPlugin | typeof RoomPlugin>>

  • Import a plugin from its absolute path on the filesystem.

    Returns

    The imported plugin constructor, or false if the plugin failed to be imported or was not a Hindenburg plugin.

    Example

    const pluginCtr = await this.worker.pluginLoader.importPlugin("/home/user/hindenburg/plugins/hbplugin-fun-things");

    if (!pluginCtr) {
    console.log("Failed to load my plugin!");
    return;
    }x

    Parameters

    • pluginPath: string

      The path of the plugin to import.

    Returns Promise<false | ImportedPlugin<typeof WorkerPlugin | typeof RoomPlugin>>

  • Load all imported room plugins into a room, checking PluginLoader.isEnabled.

    Example

    ts await this.worker.pluginLoader.loadAllWorkerPlugins(); 7

    Parameters

    Returns Promise<void>

  • Load all imported worker plugins into the worker, checking PluginLoader.isEnabled.

    Example

    await this.worker.pluginLoader.loadAllWorkerPlugins();
    

    Returns Promise<void>

  • Load a global worker plugin into the worker, does not regard PluginLoader.isEnabled, waits for onPluginLoad to be finish.

    Returns

    The plugin instance that was loaded.

    Throws

    If there was an attempt to load a plugin that isn't imported, or if the server tries load a worker plugin onto a room.

    Example

    const importedPlugin = await this.worker.workerPlugins.get("hbplugin-fun-things");
    await this.worker.pluginLoader.loadPlugin(importedPlugin);

    Example

    const importedPlugin = await this.worker.workerPlugins.get("hbplugin-fun-things");
    await this.worker.pluginLoader.loadPlugin(importedPlugin, this.room); // !! Attempted to load a worker plugin on a room or other non-worker object

    Example

    await this.worker.pluginLoader.loadPlugin("hbplugin-what-the-hell"); // !! Plugin with ID 'hbplugin-what-the-hell' not imported
    

    Parameters

    Returns Promise<WorkerPlugin>

  • Load a room plugin into a room, does not regard PluginLoader.isEnabled, waits for onPluginLoad to be finish.

    Returns

    The plugin instance that was loaded.

    Throws

    If there was an attempt to load a plugin that isn't imported, or if the server tries load a room plugin onto the worker.

    Example

    const importedPlugin = await this.worker.roomPlugins.get("hbplugin-fun-things");
    await this.worker.pluginLoader.loadPlugin(importedPlugin, this.room);

    Example

    const importedPlugin = await this.worker.roomPlugins.get("hbplugin-fun-things");
    await this.worker.pluginLoader.loadPlugin(importedPlugin); // !! Attempted to load a room plugin on a worker or other non-room object

    Example

    await this.worker.pluginLoader.loadPlugin("hbplugin-what-the-hell", this.room); // !! Plugin with ID 'hbplugin-what-the-hell' not imported
    

    Parameters

    Returns Promise<RoomPlugin>

  • Unload a global worker plugin from the worker, calls but doesn't wait for onPluginUnload to finish.

    Throws

    If there was an attempt to unload a plugin that isn't loaded.

    Example

    this.worker.pluginLoader.unloadPlugin("hbplugin-fun-things");
    

    Example

    this.worker.pluginLoader.unloadPlugin("hbplugin-what-the-hell"); // !! Plugin with id 'hbplugin-what-the-hell' not loaded
    

    Parameters

    Returns void

  • Unload a room plugin from a room, calls but doesn't wait for onPluginUnload to finish.

    Throws

    If there was an attempt to unload a plugin that isn't loaded.

    Example

    this.worker.pluginLoader.unloadPlugin("hbplugin-fun-things");
    

    Example

    this.worker.pluginLoader.unloadPlugin("hbplugin-what-the-hell"); // !! Plugin with id 'hbplugin-what-the-hell' not loaded
    

    Parameters

    • pluginCtr: string | typeof RoomPlugin | RoomPlugin

      The plugin ID, class, or instance to unload.

    • room: Room

      The room to unload the plugin from.

    Returns void

Constructors

  • Create a plugin loader. Note that the worker instantiates one itself, see pluginLoader.

    Example

    const pluginLoader = new PluginLoader(this.worker, "/home/user/hindenburg/plugins");
    

    Parameters

    • worker: Worker

      The worker that the plugin loader is for.

    • pluginDirectories: string[]

      The base directory for installed plugins.

    Returns PluginLoader

Properties

importedPlugins: Map<string, ImportedPlugin<typeof WorkerPlugin | typeof RoomPlugin>>

A map of every worker and room plugin that has been imported.

pluginDirectories: string[]

The base directory for installed plugins.

worker: Worker

The worker that this plugin loader is for.

Generated using TypeDoc