Using events from common lib
This commit is contained in:
parent
65f11bec09
commit
0792147dc4
4
package-lock.json
generated
4
package-lock.json
generated
@ -1200,6 +1200,10 @@
|
|||||||
"sax": "^1.2.4"
|
"sax": "^1.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node-common": {
|
||||||
|
"version": "git+ssh://git@thebword.ddns.net:3122/watsonb8/node-common.git#3ee1400be94851335e822916861ea2eddb9e344f",
|
||||||
|
"from": "git+ssh://git@thebword.ddns.net:3122/watsonb8/node-common.git"
|
||||||
|
},
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.1",
|
"version": "2.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
"dotenv-extended": "^2.9.0",
|
"dotenv-extended": "^2.9.0",
|
||||||
"mime-types": "^2.1.27",
|
"mime-types": "^2.1.27",
|
||||||
"rtsp-stream": "file:../rtsp-stream",
|
"rtsp-stream": "file:../rtsp-stream",
|
||||||
|
"node-common": "git+ssh://git@thebword.ddns.net:3122/watsonb8/node-common.git",
|
||||||
"tsyringe": "^4.4.0"
|
"tsyringe": "^4.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -7,6 +7,7 @@ export interface IConfig extends PlatformConfig {
|
|||||||
trainOnStartup: boolean;
|
trainOnStartup: boolean;
|
||||||
rooms: Array<IRoom>;
|
rooms: Array<IRoom>;
|
||||||
detectionTimeout: number;
|
detectionTimeout: number;
|
||||||
|
debug: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRoom {
|
export interface IRoom {
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { EventDelegate } from "./eventDelegate";
|
|
||||||
|
|
||||||
export class Event<T, K> extends Array<EventDelegate<T, K>> {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
public fire = (source: T, args: K) => {
|
|
||||||
for (const delegate of this) {
|
|
||||||
delegate(source, args);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
export type EventDelegate<T, K> = (sender: T, args: K) => void;
|
|
@ -6,7 +6,7 @@ import * as faceapi from "@vladmandic/face-api";
|
|||||||
import { getFaceDetectorOptions, saveFile } from "./common";
|
import { getFaceDetectorOptions, saveFile } from "./common";
|
||||||
import { nets } from "@vladmandic/face-api";
|
import { nets } from "@vladmandic/face-api";
|
||||||
import { Logger } from "homebridge";
|
import { Logger } from "homebridge";
|
||||||
import { Event } from "./events/event";
|
import { Event } from "common/events";
|
||||||
const { Canvas, Image, ImageData } = canvas;
|
const { Canvas, Image, ImageData } = canvas;
|
||||||
|
|
||||||
export type MonitorState = { [label: string]: string | null };
|
export type MonitorState = { [label: string]: string | null };
|
||||||
@ -25,7 +25,8 @@ export class Monitor {
|
|||||||
constructor(
|
constructor(
|
||||||
private _rooms: Array<IRoom>,
|
private _rooms: Array<IRoom>,
|
||||||
private _matcher: FaceMatcher,
|
private _matcher: FaceMatcher,
|
||||||
private _logger: Logger
|
private _logger: Logger,
|
||||||
|
private _isDebug: boolean
|
||||||
) {
|
) {
|
||||||
this._stateChangedEvent = new Event();
|
this._stateChangedEvent = new Event();
|
||||||
|
|
||||||
@ -34,13 +35,14 @@ export class Monitor {
|
|||||||
this._streamsByRoom[room.name] = [
|
this._streamsByRoom[room.name] = [
|
||||||
...room.rtspConnectionStrings.map((connectionString) => {
|
...room.rtspConnectionStrings.map((connectionString) => {
|
||||||
return new Rtsp(connectionString, {
|
return new Rtsp(connectionString, {
|
||||||
rate: 0.5,
|
rate: 1,
|
||||||
image: true,
|
image: true,
|
||||||
})
|
})
|
||||||
.on("data", async (data: Buffer) => this.onData(room.name, data))
|
.on("data", (data: Buffer) => this.onData(room.name, data))
|
||||||
.on("error", async (error: string) =>
|
.on("error", (error: string) =>
|
||||||
this.onError(error, connectionString)
|
this.onError(error, connectionString)
|
||||||
);
|
)
|
||||||
|
.on("exit", () => this.onExit(connectionString));
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -112,6 +114,7 @@ export class Monitor {
|
|||||||
.detectAllFaces(out, getFaceDetectorOptions(this._faceDetectionNet))
|
.detectAllFaces(out, getFaceDetectorOptions(this._faceDetectionNet))
|
||||||
.withFaceLandmarks()
|
.withFaceLandmarks()
|
||||||
.withFaceDescriptors();
|
.withFaceDescriptors();
|
||||||
|
if (this._isDebug) {
|
||||||
switch (room) {
|
switch (room) {
|
||||||
case "Kitchen": {
|
case "Kitchen": {
|
||||||
saveFile(
|
saveFile(
|
||||||
@ -130,6 +133,7 @@ export class Monitor {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const res of resultsQuery) {
|
for (const res of resultsQuery) {
|
||||||
const bestMatch = this._matcher.matchDescriptor(res.descriptor);
|
const bestMatch = this._matcher.matchDescriptor(res.descriptor);
|
||||||
@ -145,7 +149,10 @@ export class Monitor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private onError = async (error: string, streamName: string) => {
|
private onError = (error: string, streamName: string) => {
|
||||||
this._logger.info(`[${streamName}] ${error}`);
|
this._logger.info(`[${streamName}] ${error}`);
|
||||||
};
|
};
|
||||||
|
private onExit = (streamName: string) => {
|
||||||
|
this._logger.info(`[${streamName}] Stream has exited`);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,8 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
|||||||
const locationMonitor = new Monitor(
|
const locationMonitor = new Monitor(
|
||||||
this.config.rooms,
|
this.config.rooms,
|
||||||
faceMatcher,
|
faceMatcher,
|
||||||
this.log
|
this.log,
|
||||||
|
this.config.debug
|
||||||
);
|
);
|
||||||
|
|
||||||
locationMonitor.startStreams();
|
locationMonitor.startStreams();
|
||||||
|
@ -39,7 +39,8 @@
|
|||||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
|
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
|
||||||
"paths": {
|
"paths": {
|
||||||
"rtsp/*": ["./node_modules/rtsp-stream/lib/*"]
|
"rtsp/*": ["./node_modules/rtsp-stream/lib/*"],
|
||||||
|
"common/*": ["./node_modules/node-common/lib/*"]
|
||||||
} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
|
} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
@ -65,6 +66,9 @@
|
|||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
"path": "./node_modules/rtsp-stream/tsconfig.json"
|
"path": "./node_modules/rtsp-stream/tsconfig.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./node_modules/node-common/tsconfig.json"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user