Class PlayerPlugin<EventMap>Abstract

Abstract base class for Player plugins Plugins can extend the player functionality and add custom events

Example

class MyPlugin extends PlayerPlugin<{
customEvent: [data: string];
}> {
readonly name = "my-plugin";

init(player: Player) {
player.on("trackStart", () => {
this.emit("customEvent", "track started");
});
}

// Example of a toJSON method, assuming it's meant to be part of the plugin class
// and not inside the player.on callback.
// The instruction "Improving toJSON return type" suggests this method might exist elsewhere
// or is being added.
toJSON(): Record<string, unknown> {
return {
name: this.name,
// ... other plugin properties
};
}
}

Type Parameters

  • EventMap extends Record<string, unknown[]> = Record<string, unknown[]>

Hierarchy (view full)

Constructors

Properties

Methods

Constructors

Properties

Type helper for event map - not used at runtime

name: string

Unique name for the plugin - must be readonly Used to identify and access the plugin from player.plugins

Methods

  • Initialize the plugin with the player instance Called once when the player is initialized

    Parameters

    • player: Player<QueueContext, []>

      The player instance to attach to

    Returns void