homebridge#SnapshotRequestCallback TypeScript Examples
The following examples show how to use
homebridge#SnapshotRequestCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: streaming-delegate.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
private getOfflineImage(callback: SnapshotRequestCallback): void {
const log = this.log;
readFile(join(__dirname, `../images/offline.jpg`), (err, data) => {
if (err) {
log.error(err.message);
callback(err);
} else {
callback(undefined, data);
}
});
}
Example #2
Source File: streaming-delegate.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
handleSnapshotRequest(request: SnapshotRequest, callback: SnapshotRequestCallback): void {
if (this.camera.info.properties['streaming.enabled']) {
this.camera
.getSnapshot(request.height)
.then((snapshot) => {
callback(undefined, snapshot);
})
.catch((error) => {
handleError(this.log, error, `Error fetching snapshot for ${this.camera.info.name}`);
callback(error);
});
} else {
this.getOfflineImage(callback);
}
}
Example #3
Source File: streamingDelegate.ts From homebridge-eufy-security with Apache License 2.0 | 6 votes |
async handleSnapshotRequest(request: SnapshotRequest, callback: SnapshotRequestCallback): Promise<void> {
const resolution = this.determineResolution(request, true);
try {
const cachedSnapshot = !!this.snapshotPromise;
this.log.debug('Snapshot requested: ' + request.width + ' x ' + request.height,
this.cameraName, this.videoConfig.debug);
const snapshot = await (this.snapshotPromise || this.fetchSnapshot(resolution.snapFilter));
this.log.debug('Sending snapshot: ' + (resolution.width > 0 ? resolution.width : 'native') + ' x ' +
(resolution.height > 0 ? resolution.height : 'native') +
(cachedSnapshot ? ' (cached)' : ''), this.cameraName, this.videoConfig.debug);
const resized = await this.resizeSnapshot(snapshot, resolution.resizeFilter);
callback(undefined, resized);
} catch (Error) {
this.log.error(Error as string, this.cameraName);
callback(Error as Error);
}
}
Example #4
Source File: new-streaming-delegate.ts From homebridge-plugin-eufy-security with Apache License 2.0 | 5 votes |
handleSnapshotRequest(
request: SnapshotRequest,
callback: SnapshotRequestCallback,
): void {
const resolution = this.determineResolution(request, true);
this.log.debug(
'Snapshot requested: ' + request.width + ' x ' + request.height,
this.cameraName,
this.debug,
);
this.log.debug(
'Sending snapshot: ' +
(resolution.width > 0 ? resolution.width : 'native') +
' x ' +
(resolution.height > 0 ? resolution.height : 'native'),
this.cameraName,
this.debug,
);
// get device info
this.platform.httpService
.listDevices({
device_sn: this.device.device_sn,
})
.then(([device]) => {
// let ffmpegArgs = this.videoConfig.stillImageSource || this.videoConfig.source;
let ffmpegArgs = `-i ${device.cover_path}`;
ffmpegArgs += // Still
' -frames:v 1' +
(resolution.videoFilter
? ' -filter:v ' + resolution.videoFilter
: '') +
' -f image2 -';
try {
const ffmpeg = spawn(this.videoProcessor, ffmpegArgs.split(/\s+/), {
env: process.env,
});
let imageBuffer = Buffer.alloc(0);
this.log.debug(
'Snapshot command: ' + this.videoProcessor + ' ' + ffmpegArgs,
this.cameraName,
this.debug,
);
ffmpeg.stdout.on('data', (data: Uint8Array) => {
imageBuffer = Buffer.concat([imageBuffer, data]);
});
const log = this.log;
ffmpeg.on('error', (error: string) => {
log.error(
'An error occurred while making snapshot request: ' + error,
this.cameraName,
);
});
ffmpeg.on('close', () => {
callback(undefined, imageBuffer);
});
} catch (err) {
this.log.error(err, this.cameraName);
callback(err);
}
});
}