Skip to content

Commit

Permalink
Fixed wired doorbell p2p livestream (should fix also indoor, floodlig…
Browse files Browse the repository at this point in the history
…ht and solo cameras)

Fixed issue that treats known push notifications as unknown
Fixed relative path for state last_event_pic_url
Updated versions of the package dependencies
  • Loading branch information
Patrick Broetto committed Feb 18, 2021
1 parent a027d44 commit 5f2a9ae
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 120 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ Best is to set the adapter to Debug log mode (Instances -> Expert mode -> Column

## Changelog

### 0.2.3 (2021-02-17)
* (bropat) Fixed wired doorbell p2p livestream (should fix also indoor, floodlight and solo cameras)
* (bropat) Fixed issue that treats known push notifications as unknown
* (bropat) Fixed relative path for state last_event_pic_url
* (bropat) Updated versions of the package dependencies

### 0.2.2 (2021-02-16)
* (bropat) Fixed web extension settings for serving videos and pictures (issue [#79](https://github.com/bropat/ioBroker.eufy-security/issues/78))

Expand Down
7 changes: 3 additions & 4 deletions build/lib/eufy-security/eufy-security.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class EufySecurity extends tiny_typed_emitter_1.TypedEmitter {
}
getStationDevice(station_sn, channel) {
for (const device of Object.values(this.devices)) {
if (device.getStationSerial() === station_sn && device.getChannel() === channel) {
if ((device.getStationSerial() === station_sn && device.getChannel() === channel) || (device.getStationSerial() === station_sn && device.getSerial() === station_sn)) {
return device;
}
}
Expand Down Expand Up @@ -423,7 +423,7 @@ class EufySecurity extends tiny_typed_emitter_1.TypedEmitter {
try {
const device = this.getStationDevice(station.getSerial(), channel);
try {
yield utils_1.removeFiles(this.adapter.namespace, station.getSerial(), types_2.DataLocation.TEMP, device.getSerial());
yield utils_1.removeFiles(this.adapter.namespace, station.getSerial(), types_2.DataLocation.TEMP, device.getSerial()).catch();
const file_path = utils_1.getDataFilePath(this.adapter.namespace, station.getSerial(), types_2.DataLocation.TEMP, `${device.getSerial()}${types_2.STREAM_FILE_NAME_EXT}`);
video_1.ffmpegStreamToHls(this.adapter.namespace, metadata, videostream, audiostream, file_path, this.log)
.then(() => {
Expand Down Expand Up @@ -477,9 +477,8 @@ class EufySecurity extends tiny_typed_emitter_1.TypedEmitter {
try {
const device = this.getStationDevice(station.getSerial(), channel);
try {
const device = this.getStationDevice(station.getSerial(), channel);
const file_path = utils_1.getDataFilePath(this.adapter.namespace, station.getSerial(), types_2.DataLocation.LIVESTREAM, `${device.getSerial()}${types_2.STREAM_FILE_NAME_EXT}`);
yield utils_1.removeFiles(this.adapter.namespace, station.getSerial(), types_2.DataLocation.LIVESTREAM, device.getSerial());
yield utils_1.removeFiles(this.adapter.namespace, station.getSerial(), types_2.DataLocation.LIVESTREAM, device.getSerial()).catch();
video_1.ffmpegStreamToHls(this.adapter.namespace, metadata, videostream, audiostream, file_path, this.log)
.then(() => {
return utils_1.removeFiles(this.adapter.namespace, station.getSerial(), types_2.DataLocation.LAST_LIVESTREAM, device.getSerial());
Expand Down
33 changes: 16 additions & 17 deletions build/lib/eufy-security/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.lowestUnusedNumber = exports.moveFiles = exports.removeFiles = exports.getDataFilePath = exports.saveImageStates = exports.setStateWithTimestamp = exports.setStateChangedWithTimestamp = exports.saveImage = exports.getImageAsHTML = exports.getImage = exports.getState = exports.isEmpty = exports.setStateChangedAsync = exports.md5 = exports.generateSerialnumber = exports.generateUDID = exports.decrypt = void 0;
exports.lowestUnusedNumber = exports.moveFiles = exports.removeFiles = exports.saveImageStates = exports.setStateWithTimestamp = exports.setStateChangedWithTimestamp = exports.saveImage = exports.getDataFilePath = exports.getImageAsHTML = exports.getImage = exports.getState = exports.isEmpty = exports.setStateChangedAsync = exports.md5 = exports.generateSerialnumber = exports.generateUDID = exports.decrypt = void 0;
const crypto = __importStar(require("crypto"));
const read_bigint_1 = require("read-bigint");
const axios_1 = __importDefault(require("axios"));
Expand Down Expand Up @@ -114,7 +114,16 @@ const getImageAsHTML = function (data) {
return "";
};
exports.getImageAsHTML = getImageAsHTML;
const saveImage = function (adapter, url, filename_without_extension) {
const getDataFilePath = function (namespace, stationSerial, folderName, fileName) {
const root_path = `${utils.getAbsoluteDefaultDataDir()}files${path_1.default.sep}${namespace}`;
const dir_path = `${root_path}${path_1.default.sep}${stationSerial}${path_1.default.sep}${folderName}`;
if (!fs_extra_1.default.existsSync(dir_path)) {
fs_extra_1.default.mkdirSync(dir_path, { mode: 0o775, recursive: true });
}
return `${dir_path}${path_1.default.sep}${fileName}`;
};
exports.getDataFilePath = getDataFilePath;
const saveImage = function (adapter, url, station_sn, device_sn, location) {
return __awaiter(this, void 0, void 0, function* () {
const result = {
status: 0,
Expand All @@ -128,10 +137,9 @@ const saveImage = function (adapter, url, filename_without_extension) {
result.status = response.status;
result.statusText = response.statusText;
if (response.status === 200) {
const filename = `${filename_without_extension}.jpg`;
const data = Buffer.from(response.data);
yield adapter.writeFileAsync(`${adapter.name}.${adapter.instance}`, filename, data).then(() => {
result.imageUrl = `/${adapter.name}.${adapter.instance}/${filename}`;
yield adapter.writeFileAsync(adapter.namespace, `${station_sn}/${location}/${device_sn}${types_1.IMAGE_FILE_JPEG_EXT}`, data).then(() => {
result.imageUrl = `/${adapter.namespace}/${station_sn}/${location}/${device_sn}${types_1.IMAGE_FILE_JPEG_EXT}`;
result.imageHtml = exports.getImageAsHTML(data);
}).catch(error => {
adapter.log.error(`saveImage(): writeFile Error: ${error} - url: ${url}`);
Expand Down Expand Up @@ -189,14 +197,14 @@ const setStateWithTimestamp = function (adapter, state_id, common_name, value, t
});
};
exports.setStateWithTimestamp = setStateWithTimestamp;
const saveImageStates = function (adapter, url, timestamp, serial_number, url_state_id, html_state_id, prefix_common_name, filename_prefix = "", retry = 1) {
const saveImageStates = function (adapter, url, timestamp, station_sn, device_sn, location, url_state_id, html_state_id, prefix_common_name, retry = 1) {
return __awaiter(this, void 0, void 0, function* () {
const image_data = yield exports.saveImage(adapter, url, `${filename_prefix}${serial_number}`);
const image_data = yield exports.saveImage(adapter, url, station_sn, device_sn, location);
if (image_data.status === 404) {
if (retry < 6) {
adapter.log.info(`Retry get image in ${5 * retry} seconds from url: ${url} (retry_count: ${retry} error: ${image_data.statusText} message: ${image_data.statusText})...`);
setTimeout(() => {
exports.saveImageStates(adapter, url, timestamp, serial_number, url_state_id, html_state_id, prefix_common_name, filename_prefix, ++retry);
exports.saveImageStates(adapter, url, timestamp, station_sn, device_sn, location, url_state_id, html_state_id, prefix_common_name, ++retry);
}, 5 * 1000 * retry);
}
else {
Expand All @@ -209,15 +217,6 @@ const saveImageStates = function (adapter, url, timestamp, serial_number, url_st
});
};
exports.saveImageStates = saveImageStates;
const getDataFilePath = function (namespace, stationSerial, folderName, fileName) {
const root_path = `${utils.getAbsoluteDefaultDataDir()}files${path_1.default.sep}${namespace}`;
const dir_path = `${root_path}${path_1.default.sep}${stationSerial}${path_1.default.sep}${folderName}`;
if (!fs_extra_1.default.existsSync(dir_path)) {
fs_extra_1.default.mkdirSync(dir_path, { mode: 0o775, recursive: true });
}
return `${dir_path}${path_1.default.sep}${fileName}`;
};
exports.getDataFilePath = getDataFilePath;
const removeFiles = function (namespace, stationSerial, folderName, device_sn) {
return new Promise((resolve, reject) => {
try {
Expand Down
Loading

0 comments on commit 5f2a9ae

Please sign in to comment.