Skip to content

@camera.ui/sdk / plugin / BasePlugin

Abstract Class: BasePlugin<T>

Defined in: plugin/interfaces.ts:132

Base class every plugin extends. It wires up the three dependencies the host injects (logger, PluginAPI, DeviceStorage) and declares the lifecycle methods the host calls on the plugin.

The host calls configureCameras() once at startup with every camera already assigned to this plugin, then onCameraAdded() / onCameraReleased() as the user adds or removes cameras at runtime. The generic T types storage.values so plugin code gets autocompletion for its own settings shape.

Example

typescript
export default class MyPlugin extends BasePlugin<MyStorage> {
  private state = new Map<string, MyState>();

  async configureCameras(cameras: CameraDevice[]): Promise<void> {
    for (const camera of cameras) await this.onCameraAdded(camera);
  }

  async onCameraAdded(camera: CameraDevice): Promise<void> {
    this.state.set(camera.id, await this.attach(camera));
  }

  async onCameraReleased(cameraId: string): Promise<void> {
    this.state.get(cameraId)?.dispose();
  }
}

Type Parameters

T

T extends Record<string, any> = Record<string, any>

Constructors

Constructor

new BasePlugin<T>(logger, api, storage): BasePlugin<T>

Defined in: plugin/interfaces.ts:133

Parameters

logger

LoggerService

api

PluginAPI

storage

DeviceStorage<T>

Returns

BasePlugin<T>

Properties

api

api: PluginAPI

Defined in: plugin/interfaces.ts:135


logger

logger: LoggerService

Defined in: plugin/interfaces.ts:134


storage

storage: DeviceStorage<T>

Defined in: plugin/interfaces.ts:136

Accessors

storageSchema

Get Signature

get storageSchema(): JsonSchema[]

Defined in: plugin/interfaces.ts:140

Override to register a JSON schema for the plugin-level settings form rendered in the UI. Default: no schema.

Returns

JsonSchema[]

Methods

configureCameras()

abstract configureCameras(cameras): Promise<void>

Defined in: plugin/interfaces.ts:151

Called once on startup with every camera that is already assigned to this plugin. Attach handlers, open vendor sessions, warm up models here. A rejection aborts plugin startup.

Parameters

cameras

CameraDevice[]

Cameras already assigned to this plugin.

Returns

Promise<void>


configureSensors()?

optional configureSensors(sensors): Promise<void>

Defined in: plugin/interfaces.ts:181

Called once on startup with every sensor this plugin may consume: sensors whose type is listed in contract.consumes and that are exposed. Each sensor carries type, assignedCameraIds, assignmentLocked and connected, so consumers decide rendering purely from that data. Optional, only bridge plugins implement it.

Parameters

sensors

SensorLike[]

Consumable sensors known at startup.

Returns

Promise<void>


onCameraAdded()

abstract onCameraAdded(camera): Promise<void>

Defined in: plugin/interfaces.ts:161

Called whenever a camera is assigned to this plugin at runtime, after a discovery adoption (DiscoveryProvider.onAdoptCamera) or after the user re-assigns an existing camera. Set up the same per-camera state as in configureCameras().

Parameters

camera

CameraDevice

The camera device that was added.

Returns

Promise<void>


onCameraReleased()

abstract onCameraReleased(cameraId): Promise<void>

Defined in: plugin/interfaces.ts:170

Called when a camera is unassigned from this plugin or deleted from the system. Release per-camera resources (sessions, timers, decoders) before resolving.

Parameters

cameraId

string

ID of the camera that was released.

Returns

Promise<void>


onSensorAdded()?

optional onSensorAdded(sensor): Promise<void>

Defined in: plugin/interfaces.ts:189

Called when a sensor enters this plugin's consumable view at runtime: it was created, became exposed, or its type became consumable.

Parameters

sensor

SensorLike

The sensor that appeared.

Returns

Promise<void>


onSensorReleased()?

optional onSensorReleased(sensorId): Promise<void>

Defined in: plugin/interfaces.ts:198

Called when a sensor permanently leaves the consumable view: it was deleted or unexposed. Plugin connectivity does NOT fire this, watch sensor.onConnectedChanged for that.

Parameters

sensorId

string

Persistent id of the sensor that left.

Returns

Promise<void>