# Plugin

`class` in `gateway` · v0.2.1-next.0

<https://docs.seedcord.org/packages/gateway/0.2.1-next.0/classes/plugin>

Base class for a gateway plugin, binding `this.core` to the gateway [`Core`](/packages/gateway/0.2.1-next.0/interfaces/core).

A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose `this.core` is typed to the shared members only.

```ts
abstract class Plugin<
    Opts extends GatewayPluginOptions = { transport: "gateway"; runtime: "server" }
> extends Plugin<Opts, Core>
```

## Constructors

### constructor

```ts
Plugin(host: CoreBase, spec?: PluginLifecycleSpec)
```

Constructs a new instance of the `Plugin` class

## Properties

### core

```ts
protected core: TCore
```

The host, typed to the transport whose `Plugin` base this class extends.

### logger

```ts
protected readonly logger: Logger
```

Logs under the plugin's class name, on the channel its attach key sets.

## Methods

### dispose

```ts
async dispose(): Promise<void>
```

Runs during teardown, only when `init()` resolved.

### init

```ts
abstract async init(): Promise<void>
```

### onHmr

```ts
async onHmr(_event: HmrUpdateEvent): Promise<void>
```

Override to reload plugin state on an HMR update.

### ready

```ts
async ready(): Promise<void>
```

Runs in the startup Ready phase, after `init()`. The gateway client is logged in by this phase, and the http host binds its server in the same phase.

### registerCriticalFiles

```ts
protected registerCriticalFiles(
    patterns: string[]
): void
```

Registers critical file patterns that should trigger a full restart when changed in Dev HMR.

### rejectOptions

```ts
protected rejectOptions(reason: string): never
```

Throws a `SeedcordError` that contains the plugin class name and the reason.
