@camera.ui/sdk / plugin / BasePlugin
Abstract Class: BasePlugin<T>
Defined in: plugin/interfaces.ts:113
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.
Lifecycle order: the host calls configureCameras() once at startup with every camera already assigned to this plugin, then calls 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
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();
this.state.delete(cameraId);
}
}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:114
Parameters
logger
api
storage
Returns
BasePlugin<T>
Properties
api
api:
PluginAPI
Defined in: plugin/interfaces.ts:116
logger
logger:
LoggerService
Defined in: plugin/interfaces.ts:115
storage
storage:
DeviceStorage<T>
Defined in: plugin/interfaces.ts:117
Accessors
storageSchema
Get Signature
get storageSchema():
JsonSchema[]
Defined in: plugin/interfaces.ts:124
Override to register a JSON schema for the plugin-level settings form rendered in the UI. Default: no schema.
Returns
Methods
configureCameras()
abstractconfigureCameras(cameras):Promise<void>
Defined in: plugin/interfaces.ts:135
Called once on startup with every camera that is already assigned to this plugin. The plugin should attach handlers, open vendor sessions, and warm up models. A rejection aborts plugin startup.
Parameters
cameras
Cameras already assigned to this plugin.
Returns
Promise<void>
onCameraAdded()
abstractonCameraAdded(camera):Promise<void>
Defined in: plugin/interfaces.ts:145
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 in the UI. The plugin should set up the same per-camera state as in configureCameras().
Parameters
camera
The camera device that was added.
Returns
Promise<void>
onCameraReleased()
abstractonCameraReleased(cameraId):Promise<void>
Defined in: plugin/interfaces.ts:154
Called when a camera is unassigned from this plugin or deleted from the system. The plugin must release per-camera resources (sessions, timers, decoders) before resolving.
Parameters
cameraId
string
ID of the camera that was released.
Returns
Promise<void>