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

Add steinel cam #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/src/Tabs/Cameras.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import RTSPImageConfig from '../Types/RTSPImage';
import RTSPReolinkE1Config from '../Types/RTSPReolinkE1';
import RTSPEufyConfig from '../Types/RTSPEufy';
import RTSPHiKamConfig from '../Types/RTSPHiKam';
import RTSPSteinel from '../Types/RTSPSteinel';

const TYPES = {
url: { Config: URLImage, name: 'URL' },
Expand All @@ -43,6 +44,7 @@ const TYPES = {
reolinkE1: { Config: RTSPReolinkE1Config, name: 'Reolink E1 Snapshot' },
eufy: { Config: RTSPEufyConfig, name: 'Eufy Security' },
hikam: { Config: RTSPHiKamConfig, name: 'HiKam / WiWiCam' },
steinel: { Config: RTSPSteinel, name: 'Steinel Cam' },
};

const styles = {
Expand Down
69 changes: 69 additions & 0 deletions src/src/Types/RTSPSteinel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { getRtspSnapshot, getRtspURL } = require('./rtsp');
const path = require('path');

function init(adapter, cam) {
adapter.__urlCameras = adapter.__urlCameras || {};
adapter.__urlCameras[cam.name] = true;

// check parameters
if (!cam.ip || typeof cam.ip !== 'string') {
return Promise.reject(`Invalid IP: "${cam.ip}"`);
}

cam.decodedPassword = cam.password ? adapter.decrypt(cam.password) : '';

// Construct the RTSP URL
cam.settings = JSON.parse(JSON.stringify(cam));
cam.settings.port = 554;
cam.settings.urlPath = `user=${cam.username || 'admin'}&password=${cam.decodedPassword || ''}&channel=1&stream=${cam.quality === 'high' ? '0' : '1'}.sdp?`;
cam.settings.timeout = parseInt(cam.timeout || adapter.config.defaultTimeout, 10) || 2000;

return Promise.resolve();
}

function unload(adapter, cam) {
if (adapter.__urlCameras[cam.name]) {
delete adapter.__urlCameras[cam.name];
}
// after last unload, all the resources must be cleared too
if (Object.keys(adapter.__urlCameras)) {
// unload
}

// do nothing
return Promise.resolve();
}

function process(adapter, cam) {
if (cam.runningRequest) {
return cam.runningRequest;
}

adapter.log.debug(`Requesting Steinel Cam from ${cam.ip}...`);

const outputFileName = path.normalize(`${adapter.config.tempPath}/${cam.ip.replace(/[.:]/g, '_')}.jpg`);

if (!cam.settings) {
return Promise.reject(`Invalid settings for ${JSON.stringify(cam)}`);
}

cam.runningRequest = getRtspSnapshot(adapter.config.ffmpegPath, cam.settings, outputFileName, adapter)
.then(body => {
cam.runningRequest = null;
adapter.log.debug(`Steinel Cam from ${cam.ip}. Done!`);

return {
body,
contentType: 'image/jpeg',
};
});

return cam.runningRequest;
}

module.exports = {
init,
process,
unload,
getRtspURL,
};