mixin fixups

This commit is contained in:
Koushik Dutta
2021-09-01 15:29:09 -07:00
parent b498a2fa45
commit b09024f14f
10 changed files with 85 additions and 26 deletions

View File

@@ -0,0 +1,47 @@
import { Settings, Setting, MixinDeviceBase, ScryptedInterface } from "@scrypted/sdk";
export interface SettingsMixinDeviceOptions {
providerNativeId: string;
mixinDeviceInterfaces: ScryptedInterface[];
group: string;
groupKey: string;
}
export abstract class SettingsMixinDeviceBase<T> extends MixinDeviceBase<T & Settings> implements Settings {
settingsGroup: string;
settingsGroupKey: string;
constructor(mixinDevice: any, mixinDeviceState: { [key: string]: any }, options: SettingsMixinDeviceOptions) {
super(mixinDevice, options.mixinDeviceInterfaces, mixinDeviceState, options.providerNativeId);
this.settingsGroup = options.group;
this.settingsGroupKey = options.groupKey;
}
abstract getMixinSettings(): Promise<Setting[]>;
abstract putMixinSetting(key: string, value: string | number | boolean): Promise<void>;
async getSettings(): Promise<Setting[]> {
const settings = this.mixinDeviceInterfaces.includes(ScryptedInterface.Settings) ?
await this.mixinDevice.getSettings() : [];
const mixinSettings = await this.getMixinSettings();
for (const setting of mixinSettings) {
setting.group = setting.group || this.settingsGroup;
setting.key = this.settingsGroupKey + ':' + setting.key;
}
settings.push(...mixinSettings);
return settings;
}
async putSetting(key: string, value: string | number | boolean) {
const prefix = this.settingsGroupKey + ':';
if (!key?.startsWith(prefix)) {
return this.mixinDevice.putSetting(key, value);
}
return this.putMixinSetting(key.substring(prefix.length), value)
}
}

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/core",
"version": "0.0.57",
"version": "0.0.58",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/core",
"version": "0.0.57",
"version": "0.0.58",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/sdk": "file:../../sdk",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/core",
"version": "0.0.57",
"version": "0.0.58",
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/homekit",
"version": "0.0.16",
"version": "0.0.17",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/homekit",
"version": "0.0.16",
"version": "0.0.17",
"dependencies": {
"axios": "^0.21.1",
"hap-nodejs": "file:../HAP-NodeJS",

View File

@@ -36,5 +36,5 @@
"@types/node": "^14.17.9",
"@types/url-parse": "^1.4.3"
},
"version": "0.0.16"
"version": "0.0.17"
}

View File

@@ -1,15 +1,20 @@
import { MixinDeviceBase, VideoCamera, Settings, Setting, ScryptedInterface } from "@scrypted/sdk";
import { VideoCamera, Settings, Setting, ScryptedInterface } from "@scrypted/sdk";
import { SettingsMixinDeviceBase } from "../../../common/src/settings-mixin";
export class CameraMixin extends MixinDeviceBase<VideoCamera & Settings> implements Settings {
export class CameraMixin extends SettingsMixinDeviceBase<VideoCamera & Settings> implements Settings {
constructor(mixinDevice: VideoCamera & Settings, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }, providerNativeId: string) {
super(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, providerNativeId);
super(mixinDevice, mixinDeviceState, {
providerNativeId,
mixinDeviceInterfaces,
group: "HomeKit Settings",
groupKey: "homekit",
});
}
async getSettings(): Promise<Setting[]> {
const settings = this.mixinDeviceInterfaces.includes(ScryptedInterface.Settings) ?
await this.mixinDevice.getSettings() : [];
async getMixinSettings(): Promise<Setting[]> {
const settings: Setting[] = [];
settings.push({
group: 'HomeKit Settings',
title: 'Transcode Streaming',
type: 'boolean',
key: 'transcodeStreaming',
@@ -19,7 +24,6 @@ export class CameraMixin extends MixinDeviceBase<VideoCamera & Settings> impleme
if (this.interfaces.includes(ScryptedInterface.MotionSensor)) {
settings.push({
group: 'HomeKit Settings',
title: 'Transcode Recording',
key: 'transcodeRecording',
type: 'boolean',
@@ -30,7 +34,8 @@ export class CameraMixin extends MixinDeviceBase<VideoCamera & Settings> impleme
return settings;
}
async putSetting(key: string, value: string | number | boolean) {
async putMixinSetting(key: string, value: string | number | boolean) {
this.storage.setItem(key, value.toString());
}
}

View File

@@ -138,14 +138,15 @@ class HomeKit extends ScryptedDeviceBase implements MixinProvider, Settings {
return null;
}
if (type === ScryptedDeviceType.Camera) {
if ((type === ScryptedDeviceType.Camera || type === ScryptedDeviceType.Doorbell)
&& interfaces.includes(ScryptedInterface.VideoCamera)) {
return [ScryptedInterface.Settings];
}
return [];
}
getMixin(mixinDevice: any, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }) {
if ((mixinDeviceState.type === ScryptedDeviceType.Camera || mixinDeviceState.type === ScryptedDeviceType.Doorbell)
&& mixinDeviceInterfaces.includes(ScryptedInterface.Camera)) {
&& mixinDeviceInterfaces.includes(ScryptedInterface.VideoCamera)) {
return new CameraMixin(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, this.nativeId);
}
return mixinDevice;

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.1.29",
"version": "0.1.30",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/prebuffer-mixin",
"version": "0.1.29",
"version": "0.1.30",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/prebuffer-mixin",
"version": "0.1.29",
"version": "0.1.30",
"description": "Prebuffer mixin for VideoCamera devices.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -5,6 +5,7 @@ import { FFMpegFragmentedMP4Session, MP4Atom, startFFMPegFragmetedMP4Session } f
import { Server } from 'net';
import { listenZeroCluster } from '@scrypted/common/src/listen-cluster';
import EventEmitter from 'events';
import { SettingsMixinDeviceBase } from "../../../common/src/settings-mixin";
const { mediaManager, log } = sdk;
@@ -16,7 +17,7 @@ interface Prebuffer {
time: number;
}
class PrebufferMixin extends MixinDeviceBase<VideoCamera & Settings> implements VideoCamera, Settings {
class PrebufferMixin extends SettingsMixinDeviceBase<VideoCamera> implements VideoCamera, Settings {
prebufferSession: Promise<FFMpegFragmentedMP4Session>;
prebuffer: Prebuffer[] = [];
ftyp: MP4Atom;
@@ -25,16 +26,20 @@ class PrebufferMixin extends MixinDeviceBase<VideoCamera & Settings> implements
released = false;
constructor(mixinDevice: VideoCamera & Settings, mixinDeviceInterfaces: ScryptedInterface[], mixinDeviceState: { [key: string]: any }, providerNativeId: string) {
super(mixinDevice, mixinDeviceInterfaces, mixinDeviceState, providerNativeId);
super(mixinDevice, mixinDeviceState, {
providerNativeId,
mixinDeviceInterfaces,
group: "Prebuffer Settings",
groupKey: "prebuffer",
});
// to prevent noisy startup/reload/shutdown, delay the prebuffer starting.
log.i(`${this.name} prebuffer session starting in 10 seconds`);
setTimeout(() => this.ensurePrebufferSession(), 10000);
}
async getSettings(): Promise<Setting[]> {
const settings = this.interfaces.includes(ScryptedInterface.Settings) ?
await this.mixinDevice.getSettings() : [];
async getMixinSettings(): Promise<Setting[]> {
const settings: Setting[] = [];
settings.push(
{
@@ -47,7 +52,8 @@ class PrebufferMixin extends MixinDeviceBase<VideoCamera & Settings> implements
);
return settings;
}
async putSetting(key: string, value: string | number | boolean): Promise<void> {
async putMixinSetting(key: string, value: string | number | boolean): Promise<void> {
this.storage.setItem(key, value.toString());
}