# Plugin

`class` in `gateway` · v0.5.1

<https://docs.seedcord.org/packages/gateway/0.5.1/classes/plugin>

Base class for a gateway plugin, binding `this.core` to the gateway [`Core`](/packages/gateway/0.5.1/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, in `ShutdownPhase.Disconnect` by default. seedcord skips it when `init()` has thrown.

When `init()` outlasts its timeout, seedcord calls this once that `init()` resolves, outside any shutdown phase. The process must still be alive for that call to happen.

### init

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

Runs in `StartupPhase.Configuration` by default. Move it to a different phase with the [`PluginLifecycleSpec`](/packages/core/0.7.0/interfaces/plugin-lifecycle-spec).

### 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 Ready phase, after every attached plugin's `init()` has resolved. The other Ready tasks run alongside it, including the http server binding its port.

Override it when your work needs a logged-in client or a resolved application id.

### 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.
