Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix automatic snapshot refresh for two cameras on same station #83

Merged
merged 4 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homebridge-ui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class UiServer extends HomebridgePluginUiServer {
fs.mkdirSync(this.storagePath);
}

const logfileStream = fs.createWriteStream(this.storagePath + '/config_ui_log', { flags: 'w' });

this.log = bunyan.createLogger({
name: '[' + plugin.version + ']',
hostname: '',
Expand All @@ -33,6 +35,7 @@ class UiServer extends HomebridgePluginUiServer {
showProcess: false,
showPid: false,
showDate: false,
out: logfileStream,
}),
}],
serializers: bunyanDebugStream.serializers,
Expand Down
2 changes: 2 additions & 0 deletions src/accessories/LocalLivestreamManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export class LocalLivestreamManager extends EventEmitter {
if (!this.livestreamIsStarting) { // prevent multiple stream starts from eufy station
this.livestreamIsStarting = true;
this.platform.eufyClient.startStationLivestream(this.device.getSerial());
} else {
this.log.debug(this.device.getName(), 'stream is already starting. waiting...');
}

if (this.connectionTimeout) {
Expand Down
18 changes: 13 additions & 5 deletions src/accessories/SnapshotManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { rejects } from 'node:assert';

const SnapshotBlackPath = require.resolve('../../media/Snapshot-black.png');

let MINUTES_TO_WAIT_FOR_AUTOMATIC_REFRESH_TO_BEGIN = 1; // should be incremented by 1 for every device

type Snapshot = {
timestamp: number;
image: Buffer;
Expand Down Expand Up @@ -97,10 +99,11 @@ export class SnapshotManager extends EventEmitter {
this.cameraConfig.refreshSnapshotIntervalMinutes = 5;
}
// eslint-disable-next-line max-len
this.log.info(this.device.getName(), 'Setting up automatic snapshot refresh every ' + this.cameraConfig.refreshSnapshotIntervalMinutes + ' minutes. This may decrease battery life dramatically.');
this.log.info(this.device.getName(), 'Setting up automatic snapshot refresh every ' + this.cameraConfig.refreshSnapshotIntervalMinutes + ' minutes. This may decrease battery life dramatically. The refresh process for ' + this.device.getName() + ' should begin in ' + MINUTES_TO_WAIT_FOR_AUTOMATIC_REFRESH_TO_BEGIN + ' minutes.');
setTimeout(() => { // give homebridge some time to start up
this.automaticSnapshotRefresh();
}, 60 * 1000);
}, MINUTES_TO_WAIT_FOR_AUTOMATIC_REFRESH_TO_BEGIN * 60 * 1000);
MINUTES_TO_WAIT_FOR_AUTOMATIC_REFRESH_TO_BEGIN++;
}

if (this.cameraConfig.snapshotHandlingMethod === 1) {
Expand Down Expand Up @@ -430,10 +433,11 @@ export class SnapshotManager extends EventEmitter {
private async getCurrentCameraSnapshot(): Promise<Buffer> {
const source = await this.getCameraSource();

if (!source) {
return Promise.reject('No camera source detected.');
}

return new Promise((resolve, reject) => {
if (!source) {
return;
}

const url = '-i ' + source.url;
const ffmpegArgs = (this.cameraConfig.videoConfig!.stillImageSource || url) + // Still
Expand All @@ -452,6 +456,10 @@ export class SnapshotManager extends EventEmitter {
const ffmpeg = spawn(this.videoProcessor, ffmpegArgs.split(/\s+/), { env: process.env });

const ffmpegTimeout = setTimeout(() => {
if (source.livestreamId) {
this.livestreamManager.stopProxyStream(source.livestreamId);
}

reject('ffmpeg process timed out');
}, 15000);

Expand Down