Using events from common lib
This commit is contained in:
@ -7,6 +7,7 @@ export interface IConfig extends PlatformConfig {
|
||||
trainOnStartup: boolean;
|
||||
rooms: Array<IRoom>;
|
||||
detectionTimeout: number;
|
||||
debug: boolean;
|
||||
}
|
||||
|
||||
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 { nets } from "@vladmandic/face-api";
|
||||
import { Logger } from "homebridge";
|
||||
import { Event } from "./events/event";
|
||||
import { Event } from "common/events";
|
||||
const { Canvas, Image, ImageData } = canvas;
|
||||
|
||||
export type MonitorState = { [label: string]: string | null };
|
||||
@ -25,7 +25,8 @@ export class Monitor {
|
||||
constructor(
|
||||
private _rooms: Array<IRoom>,
|
||||
private _matcher: FaceMatcher,
|
||||
private _logger: Logger
|
||||
private _logger: Logger,
|
||||
private _isDebug: boolean
|
||||
) {
|
||||
this._stateChangedEvent = new Event();
|
||||
|
||||
@ -34,13 +35,14 @@ export class Monitor {
|
||||
this._streamsByRoom[room.name] = [
|
||||
...room.rtspConnectionStrings.map((connectionString) => {
|
||||
return new Rtsp(connectionString, {
|
||||
rate: 0.5,
|
||||
rate: 1,
|
||||
image: true,
|
||||
})
|
||||
.on("data", async (data: Buffer) => this.onData(room.name, data))
|
||||
.on("error", async (error: string) =>
|
||||
.on("data", (data: Buffer) => this.onData(room.name, data))
|
||||
.on("error", (error: string) =>
|
||||
this.onError(error, connectionString)
|
||||
);
|
||||
)
|
||||
.on("exit", () => this.onExit(connectionString));
|
||||
}),
|
||||
];
|
||||
|
||||
@ -112,22 +114,24 @@ export class Monitor {
|
||||
.detectAllFaces(out, getFaceDetectorOptions(this._faceDetectionNet))
|
||||
.withFaceLandmarks()
|
||||
.withFaceDescriptors();
|
||||
switch (room) {
|
||||
case "Kitchen": {
|
||||
saveFile(
|
||||
"/Users/brandonwatson/Documents/Git/Gitea/homebridge-face-location/out",
|
||||
"Kitchen.jpg",
|
||||
data
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "LivingRoom": {
|
||||
saveFile(
|
||||
"/Users/brandonwatson/Documents/Git/Gitea/homebridge-face-location/out",
|
||||
"LivingRoom.jpg",
|
||||
data
|
||||
);
|
||||
break;
|
||||
if (this._isDebug) {
|
||||
switch (room) {
|
||||
case "Kitchen": {
|
||||
saveFile(
|
||||
"/Users/brandonwatson/Documents/Git/Gitea/homebridge-face-location/out",
|
||||
"Kitchen.jpg",
|
||||
data
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "LivingRoom": {
|
||||
saveFile(
|
||||
"/Users/brandonwatson/Documents/Git/Gitea/homebridge-face-location/out",
|
||||
"LivingRoom.jpg",
|
||||
data
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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}`);
|
||||
};
|
||||
private onExit = (streamName: string) => {
|
||||
this._logger.info(`[${streamName}] Stream has exited`);
|
||||
};
|
||||
}
|
||||
|
@ -103,7 +103,8 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
const locationMonitor = new Monitor(
|
||||
this.config.rooms,
|
||||
faceMatcher,
|
||||
this.log
|
||||
this.log,
|
||||
this.config.debug
|
||||
);
|
||||
|
||||
locationMonitor.startStreams();
|
||||
|
Reference in New Issue
Block a user