Skip to content

Commit

Permalink
Updated dependency eufy-security-client to 2.0.1
Browse files Browse the repository at this point in the history
Updated dependency ws to 8.6.0
  • Loading branch information
bropat committed May 3, 2022
1 parent 6012a57 commit df25474
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 130 deletions.
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/eufy-security-ws.png)

# eufy-security-ws <small>0.9.0</small>
# eufy-security-ws <small>0.9.1</small>

> A small server wrapper around [eufy-security-client](https://github.com/bropat/eufy-security-client) library to access it via a WebSocket
Expand Down
192 changes: 96 additions & 96 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eufy-security-ws",
"version": "0.9.0",
"version": "0.9.1",
"description": "Node WebSocket server implementation to integrate Eufy Security devices",
"main": "dist/lib/index.js",
"bin": {
Expand Down Expand Up @@ -45,19 +45,19 @@
"dependencies": {
"ansi-colors": "^4.1.1",
"commander": "^9.2.0",
"eufy-security-client": "^2.0.0",
"eufy-security-client": "^2.0.1",
"fs-extra": "^10.1.0",
"promptly": "^3.2.0",
"tslog": "^3.3.3",
"ws": "^8.5.0"
"ws": "^8.6.0"
},
"devDependencies": {
"@types/node": "^16.11.32",
"@types/node-rsa": "^1.1.1",
"@types/promptly": "^3.0.2",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/message_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DeviceMessageHandler {
static async handle(message: IncomingMessageDevice, driver: EufySecurity, client: Client): Promise<DeviceResultTypes[DeviceCommand]> {
const { serialNumber, command } = message;

const device = driver.getDevice(serialNumber);
const device = await driver.getDevice(serialNumber);
const station = driver.getStation(device.getStationSerial());

switch (command) {
Expand Down
42 changes: 23 additions & 19 deletions src/lib/forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export class EventForwarder {
this.setupStation(station);
});

this.clients.driver.getDevices().forEach(device => {
this.setupDevice(device);
});
this.clients.driver.getDevices().then((devices: Device[]) => {
devices.forEach(device => {
this.setupDevice(device);
});
}).catch();

this.clients.driver.on("station livestream start", (station: Station, device: Device, metadata: StreamMetadata, videostream: Readable, audiostream: Readable) => {
const serialNumber = device.getSerial();
Expand Down Expand Up @@ -379,13 +381,14 @@ export class EventForwarder {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
station.on("rtsp url", (station: Station, channel:number, value: string) => {
const device = this.clients.driver.getStationDevice(station.getSerial(), channel);
this.forwardEvent({
source: "device",
event: DeviceEvent.gotRtspUrl,
serialNumber: device.getSerial(),
rtspUrl: value,
}, 0);
this.clients.driver.getStationDevice(station.getSerial(), channel).then((device: Device) => {
this.forwardEvent({
source: "device",
event: DeviceEvent.gotRtspUrl,
serialNumber: device.getSerial(),
rtspUrl: value,
}, 0);
}).catch();
});

station.on("command result", (station: Station, result: CommandResult) => {
Expand Down Expand Up @@ -478,15 +481,16 @@ export class EventForwarder {
break;
}
if (command !== undefined) {
const device = this.clients.driver.getStationDevice(station.getSerial(), result.channel);
this.forwardEvent({
source: "device",
event: DeviceEvent.commandResult,
serialNumber: device.getSerial(),
command: command.split(".")[1],
returnCode: result.return_code,
returnCodeName: ErrorCode[result.return_code] !== undefined ? ErrorCode[result.return_code] : "UNKNOWN",
}, 0);
this.clients.driver.getStationDevice(station.getSerial(), result.channel).then((device: Device) => {
this.forwardEvent({
source: "device",
event: DeviceEvent.commandResult,
serialNumber: device.getSerial(),
command: command?.split(".")[1],
returnCode: result.return_code,
returnCodeName: ErrorCode[result.return_code] !== undefined ? ErrorCode[result.return_code] : "UNKNOWN",
}, 0);
}).catch();
}
}
});
Expand Down
11 changes: 5 additions & 6 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebSocketServer } from "ws"
import { Logger } from "tslog";
import { EventEmitter, once } from "events";
import { Server as HttpServer, createServer, IncomingMessage as HttpIncomingMessage } from "http";
import { DeviceNotFoundError, EufySecurity, InvalidCountryCodeError, InvalidLanguageCodeError, InvalidPropertyValueError, libVersion, NotSupportedError, ReadOnlyPropertyError, StationNotFoundError, WrongStationError, PropertyNotSupportedError, InvalidPropertyError, InvalidCommandValueError } from "eufy-security-client";
import { DeviceNotFoundError, EufySecurity, InvalidCountryCodeError, InvalidLanguageCodeError, InvalidPropertyValueError, libVersion, NotSupportedError, ReadOnlyPropertyError, StationNotFoundError, WrongStationError, PropertyNotSupportedError, InvalidPropertyError, InvalidCommandValueError, Device } from "eufy-security-client";

import { EventForwarder } from "./forward";
import type * as OutgoingMessages from "./outgoing_message";
Expand Down Expand Up @@ -90,7 +90,7 @@ export class Client {

if (msg.command === ServerCommand.startListening) {
this.sendResultSuccess(msg.messageId, {
state: dumpState(this.driver, this.schemaVersion),
state: await dumpState(this.driver, this.schemaVersion),
});
this.receiveEvents = true;
return;
Expand Down Expand Up @@ -304,8 +304,7 @@ export class ClientsController {

disconnectedClients.forEach(client => {
Object.keys(client.receiveLivestream).forEach(serialNumber => {
try {
const device = this.driver.getDevice(serialNumber);
this.driver.getDevice(serialNumber).then((device: Device) => {
const station = this.driver.getStation(device.getStationSerial());
const streamingDevices = DeviceMessageHandler.getStreamingDevices(station.getSerial());

Expand All @@ -316,9 +315,9 @@ export class ClientsController {

client.receiveLivestream[device.getSerial()] = false;
DeviceMessageHandler.removeStreamingDevice(station.getSerial(), client);
} catch(error) {
}).catch((error) => {
this.logger.error(`Error doing cleanup of client`, error);
}
});
});
});
this.cleanupLoggingEventForwarder();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export type EufySecurityState =
| EufySecurityStateSchema0;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const dumpState = (driver: EufySecurity, schemaVersion: number): EufySecurityState => {
export const dumpState = async (driver: EufySecurity, schemaVersion: number): Promise<EufySecurityState> => {
const base: Partial<EufySecurityStateSchema0> = {
driver: dumpDriver(driver, schemaVersion),
stations: Array.from(driver.getStations(), (station) =>
dumpStation(station, schemaVersion)
),
devices: Array.from(driver.getDevices(), (device) =>
devices: Array.from(await driver.getDevices(), (device) =>
dumpDevice(device, schemaVersion)
),
};
Expand Down

0 comments on commit df25474

Please sign in to comment.