mirror of
https://github.com/koush/scrypted.git
synced 2026-02-09 00:39:56 +00:00
sdk: listener management
This commit is contained in:
4
sdk/index.d.ts
vendored
4
sdk/index.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
export * from './types';
|
||||
import { DeviceBase } from './types';
|
||||
import type { ScryptedNativeId } from './types';
|
||||
import type { ScryptedNativeId, EventListenerRegister } from './types';
|
||||
import type { ScryptedInterface, ScryptedStatic, Logger, DeviceState } from './types';
|
||||
export declare class ScryptedDeviceBase extends DeviceBase {
|
||||
nativeId?: string;
|
||||
@@ -26,6 +26,7 @@ export declare class MixinDeviceBase<T> extends DeviceBase implements DeviceStat
|
||||
private _log;
|
||||
private _console;
|
||||
private _deviceState;
|
||||
private _listeners;
|
||||
constructor(mixinDevice: T, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: DeviceState, mixinProviderNativeId: ScryptedNativeId);
|
||||
get storage(): Storage;
|
||||
get console(): Console;
|
||||
@@ -34,6 +35,7 @@ export declare class MixinDeviceBase<T> extends DeviceBase implements DeviceStat
|
||||
*/
|
||||
onDeviceEvent(eventInterface: string, eventData: any): Promise<void>;
|
||||
_lazyLoadDeviceState(): void;
|
||||
manageListener(listener: EventListenerRegister): void;
|
||||
release(): void;
|
||||
}
|
||||
declare let sdk: ScryptedStatic;
|
||||
|
||||
@@ -60,6 +60,7 @@ class MixinDeviceBase extends types_1.DeviceBase {
|
||||
this.mixinDevice = mixinDevice;
|
||||
this.mixinDeviceInterfaces = mixinDeviceInterfaces;
|
||||
this.mixinProviderNativeId = mixinProviderNativeId;
|
||||
this._listeners = new Set();
|
||||
this._deviceState = mixinDeviceState;
|
||||
}
|
||||
get storage() {
|
||||
@@ -85,7 +86,13 @@ class MixinDeviceBase extends types_1.DeviceBase {
|
||||
}
|
||||
_lazyLoadDeviceState() {
|
||||
}
|
||||
manageListener(listener) {
|
||||
this._listeners.add(listener);
|
||||
}
|
||||
release() {
|
||||
for (const l of this._listeners) {
|
||||
l.removeListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.MixinDeviceBase = MixinDeviceBase;
|
||||
|
||||
10
sdk/index.ts
10
sdk/index.ts
@@ -1,6 +1,6 @@
|
||||
export * from './types'
|
||||
import { ScryptedInterfaceProperty, DeviceBase } from './types';
|
||||
import type { ScryptedNativeId, DeviceManager, SystemManager, MediaManager, EndpointManager } from './types';
|
||||
import type { ScryptedNativeId, DeviceManager, SystemManager, MediaManager, EndpointManager, EventListenerRegister } from './types';
|
||||
import type { ScryptedInterface, ScryptedStatic, Logger, DeviceState } from './types';
|
||||
|
||||
export class ScryptedDeviceBase extends DeviceBase {
|
||||
@@ -60,6 +60,7 @@ export class MixinDeviceBase<T> extends DeviceBase implements DeviceState {
|
||||
private _log: Logger;
|
||||
private _console: Console;
|
||||
private _deviceState: DeviceState;
|
||||
private _listeners = new Set<EventListenerRegister>();
|
||||
|
||||
constructor(public mixinDevice: T, public mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: DeviceState, public mixinProviderNativeId: ScryptedNativeId) {
|
||||
super();
|
||||
@@ -95,7 +96,14 @@ export class MixinDeviceBase<T> extends DeviceBase implements DeviceState {
|
||||
_lazyLoadDeviceState() {
|
||||
}
|
||||
|
||||
manageListener(listener: EventListenerRegister) {
|
||||
this._listeners.add(listener);
|
||||
}
|
||||
|
||||
release() {
|
||||
for (const l of this._listeners) {
|
||||
l.removeListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user