Overview
Plugin registration methods manage the full plugin lifecycle: queuing before setup, inline registration after setup, dependency / version checks, same-id swap via static replaces, cascade removal, and translation merging.
addPlugin(PluginClass, opts?)
Register a plugin with the player. Returns the player for chaining.
Pre-setup or mid-setup (idle / setup phase): the plugin is queued and registered during the pluginsRegistering pipeline stage.
Ordering within the queue follows registration order; dependency checks are evaluated at registration time across both registered and queued plugins so pre-setup ordering does not matter.
Post-setup: registration runs inline (fire-and-forget).
Listen for plugin:installed or plugin:failed to know when it settled.
| Parameter | Type | Description |
|---|---|---|
PluginClass | PluginCtorWithId | A class with static readonly id: string |
opts | P['opts'] | Typed options, inferred from the plugin class |
Returns: this (the player instance)
Throws:
| Code | Cause |
|---|---|
core:lifecycle/use-plugin-after-dispose | Called after dispose() |
core:plugin/duplicate-id | A plugin with the same id is already registered or queued |
core:plugin/missing-dep | static requires lists a plugin that is not registered (and not optional) |
core:plugin/version-mismatch | A required dependency’s version is below minVersion |
core:plugin/incompatible-core-version | static minCoreVersion exceeds the running core version |
import { EqualizerPlugin } from '@nomercy-entertainment/nomercy-player-core';
player
.setup({ ... })
.addPlugin(EqualizerPlugin, { preset: 'flat' });
getPlugin(PluginClass)
Look up a registered plugin instance by class.
Returns the instance typed as the class’s instance type, or undefined when not registered.
Prefer this over getPluginById when the class is in scope.
Returns: P | undefined
const eq = player.getPlugin(EqualizerPlugin);
eq?.band(250, 6); // set 250 Hz band to +6 dB, fully typed
getPluginById(id)
Look up a registered plugin instance by string id. Use when the class is not in scope (e.g. cross-plugin discovery).
Returns: P | undefined (generic, defaults to object)
removePlugin(PluginClass, opts?)
Remove a plugin by class.
Disposes its instance, drops its lifecycle resources, removes its translations, and emits plugin:disposed.
Cascade behaviour: when other plugins depend on the one being removed, they are removed first (recursively).
Pass { cascade: false } to opt out, and the call will throw core:plugin/has-dependents instead.
Returns: void
removePluginById(id, opts?)
String-id version of removePlugin.
Also clears any pending queue entry so a queued-then-removed plugin won’t register later.
plugins()
All registered plugin instances in registration order (both enabled and disabled). Returns a fresh array, so mutating it does not affect the player’s internal list.
Returns: ReadonlyArray<Plugin>
enabledPlugins()
Registered plugins that are currently enabled, ordered by static priority descending.
Ties break by registration order.
Used internally for before* dispatch chains.
Returns: ReadonlyArray<Plugin>
Plugin static contract
| Static field | Type | Description |
|---|---|---|
id | string | Required. Unique identifier ('vendor:name' convention) |
version | string | Semver string for dependency checks |
priority | number | Higher = earlier in dispatch order |
requires | RequireSpec[] | Dependency declarations (class or { plugin, optional, minVersion }) |
replaces | string | Id of the plugin this one replaces |
minCoreVersion | string | Minimum core version required |
advisories | PluginAdvisory[] | Mutation advisory declarations |
translations | Translations | Translation bundle (eager or lazy via translationsFromGlob) |
See also
- Built-in Core Plugins: shipped plugins
- Events Reference:
plugin:installed,plugin:failed,plugin:disposed