Working on linux host
This commit is contained in:
parent
ddf37d6f18
commit
3d73ddf4d5
@ -18,7 +18,6 @@
|
||||
#restart service
|
||||
ssh -t
|
||||
ssh -t $remote_user@$remote_server "sudo systemctl restart homebridge.service"
|
||||
ssh -t $remote_user@$remote_server "sudo systemctl status homebridge.service"
|
||||
|
||||
echo done
|
||||
exit
|
@ -15,35 +15,49 @@ export const getFaceDetectorOptions = (net: faceapi.NeuralNetwork<any>) => {
|
||||
: new faceapi.TinyFaceDetectorOptions({ inputSize, scoreThreshold });
|
||||
};
|
||||
|
||||
export function saveFile(
|
||||
export const saveFile = async (
|
||||
basePath: string,
|
||||
fileName: string,
|
||||
buf: Buffer
|
||||
): Promise<void> {
|
||||
const writeFile = (): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(path.resolve(basePath, fileName), buf, "base64", (err) => {
|
||||
if (err) {
|
||||
): Promise<void> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
//Create directory if it does not exist
|
||||
await makeDirectory(basePath);
|
||||
} catch (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
//Write file to directory
|
||||
try {
|
||||
const asdf = fs.writeFileSync(
|
||||
path.join(basePath, fileName),
|
||||
buf,
|
||||
"base64"
|
||||
);
|
||||
} catch (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve();
|
||||
});
|
||||
};
|
||||
|
||||
export const makeDirectory = (path: string): Promise<void> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!fs.existsSync(basePath)) {
|
||||
fs.mkdir(basePath, async (err) => {
|
||||
if (!fs.existsSync(path)) {
|
||||
fs.mkdir(path, async (err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve(await writeFile());
|
||||
});
|
||||
} else {
|
||||
resolve(await writeFile());
|
||||
}
|
||||
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
return resolve();
|
||||
});
|
||||
};
|
||||
|
||||
export const delay = (ms: number): Promise<void> => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
|
@ -175,7 +175,7 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
if (!mimeType || !mimeType.startsWith("image")) {
|
||||
return;
|
||||
}
|
||||
console.log(path.join(this.config.refImageDirectory, dir, file));
|
||||
this.log.info(path.join(this.config.refImageDirectory, dir, file));
|
||||
|
||||
try {
|
||||
const referenceImage = (await canvas.loadImage(
|
||||
@ -193,7 +193,7 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
const faceDescriptors = [descriptor.descriptor];
|
||||
return new faceapi.LabeledFaceDescriptors(dir, faceDescriptors);
|
||||
} catch (err) {
|
||||
console.log(
|
||||
this.log.info(
|
||||
"An error occurred loading image at path: " +
|
||||
path.join(this.config.refImageDirectory, dir, file)
|
||||
);
|
||||
@ -217,10 +217,10 @@ export class HomeLocationPlatform implements DynamicPlatformPlugin {
|
||||
"utf8",
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.log(`An error occurred while writing data model to file`);
|
||||
this.log.info(`An error occurred while writing data model to file`);
|
||||
}
|
||||
|
||||
console.log(`Successfully wrote data model to file`);
|
||||
this.log.info(`Successfully wrote data model to file`);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -155,7 +155,6 @@ export class Monitor {
|
||||
if (this._config.writeOutput) {
|
||||
await saveFile(this._config.outputDirectory, room + ".jpg", args.data);
|
||||
}
|
||||
|
||||
for (const res of resultsQuery) {
|
||||
const bestMatch = this._matcher.matchDescriptor(res.descriptor);
|
||||
const old = this._state[bestMatch.label];
|
||||
@ -183,6 +182,8 @@ export class Monitor {
|
||||
connectionString: connectionString,
|
||||
};
|
||||
|
||||
connectionString = this.getRedactedConnectionString(connectionString);
|
||||
|
||||
//Subscribe to rtsp events
|
||||
stream.rtsp.dataEvent.push((sender: Rtsp, args: IStreamEventArgs) =>
|
||||
this.onData(roomName, stream, args)
|
||||
@ -223,4 +224,13 @@ export class Monitor {
|
||||
);
|
||||
stream.rtsp.start();
|
||||
};
|
||||
|
||||
private getRedactedConnectionString(connectionString: string) {
|
||||
const pwSepIdx = connectionString.lastIndexOf(":") + 1;
|
||||
const pwEndIdx = connectionString.indexOf("@");
|
||||
return (
|
||||
connectionString.substring(0, pwSepIdx) +
|
||||
connectionString.substring(pwEndIdx)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -93,11 +93,20 @@ export class Rtsp {
|
||||
}
|
||||
|
||||
this._childProcess.stdout?.on("data", this.onData);
|
||||
this._childProcess.stdout?.on("error", (err) =>
|
||||
console.log("And error occurred" + err)
|
||||
|
||||
this._childProcess.stdout?.on("error", (error: Error) =>
|
||||
this._errorEvent.fire(this, { err: error })
|
||||
);
|
||||
this._childProcess.stdout?.on("close", () =>
|
||||
this._closeEvent.fire(this, {
|
||||
message: "Stream closed",
|
||||
})
|
||||
);
|
||||
this._childProcess.stdout?.on("end", () =>
|
||||
this._closeEvent.fire(this, {
|
||||
message: "Stream ended",
|
||||
})
|
||||
);
|
||||
this._childProcess.stdout?.on("close", () => console.log("Stream closed"));
|
||||
this._childProcess.stdout?.on("end", () => console.log("Stream ended"));
|
||||
|
||||
//Only register this event if there are subscribers
|
||||
if (this._childProcess.stderr && this._messageEvent.length > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user