Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Dec 30, 2024
1 parent e2e947d commit 8267ce2
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Converter } from './Converter';
import { GetParametersResponse } from './GetParametersResponse';

export class GetParametersRequest extends DeviceRequest {
private readonly parameterGroups: string[];

constructor(connection: Connection, ...parameterGroups: string[]) {
super(connection);
this.parameterGroups = parameterGroups;
}

private readonly parameterGroups: string[];

public async send(): Promise<GetParametersResponse> {
const response = await this.get(this.relativePath);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { DeviceResponse } from 'axis-core';

export class GetParametersResponse extends DeviceResponse {
constructor(response: string) {
super(response);
}

// A parameter has the following format:
// [NAME]=[VALUE]
private static readonly ParameterSuccessResponse = /(?:root\.)?(\S*)\s*=\s*(.*)\s*$/;

// An error is described in the following format:
// # Error: Error -1 getting param in group '[PARAMETER]'
private static readonly ErrorResponse = /# Error:/;

constructor(response: string) {
super(response);
}

public assertSuccess(): void {
// No errors are reported in the response body, thus no action is needed here
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Connection, DeviceRequest } from 'axis-core';
import { UpdateParametersResponse } from './UpdateParametersResponse';

export class UpdateParametersRequest extends DeviceRequest {
private readonly parameters: { [name: string]: string };

constructor(connection: Connection, parameters: { [name: string]: string }) {
super(connection);
this.parameters = parameters;
}

private readonly parameters: { [name: string]: string };

public async send(): Promise<UpdateParametersResponse> {
const response = await this.get(this.relativePath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { DeviceResponse } from 'axis-core';
import { UpdateParametersError } from '../..';

export class UpdateParametersResponse extends DeviceResponse {
constructor(response: string) {
super(response);
}

// A success is described by the following response:
// OK
private static readonly SuccessResponse = /OK/;

// An error is described in the following format:
// # Error: Error setting '[PARAMETER]' to '[VALUE]'!
private static readonly ParameterErrorResponse = /# Error: Error setting '(.*)' to '(.*)'!/;

constructor(response: string) {
super(response);
}

public assertSuccess(): void {
if (UpdateParametersResponse.SuccessResponse.test(this.response)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { DeviceResponse, UnknownError } from 'axis-core';
import { UserAlreadyExistsError } from '../..';

export class AddUserResponse extends DeviceResponse {
private static readonly SuccessResponse = /Created account .*\./;
private static readonly UserAlreadyExistsResponse = /Error: this user name already exists, consult the system log file/;

constructor(response: string) {
super(response);
}

private static readonly SuccessResponse = /Created account .*\./;
private static readonly UserAlreadyExistsResponse = /Error: this user name already exists, consult the system log file/;

public assertSuccess(): void {
const body: string | null = this.body;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { DeviceResponse } from 'axis-core';
import { AccessRights, User } from '../..';

export class GetUsersResponse extends DeviceResponse {
constructor(response: string) {
super(response);
}

// A parameter has the following format:
// [NAME]="[VALUE1],[VALUE2]..."
private static readonly ParameterSuccessResponse = /\s*(\S*)\s*=\s*"(\S*)"\s*/;

private parsedUsers?: User[];

constructor(response: string) {
super(response);
}

public assertSuccess(): void {
// No errors are reported in the response body, thus no action is needed here
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DeviceResponse, UnknownError } from 'axis-core';

export class RemoveUserResponse extends DeviceResponse {
private static readonly SuccessResponse = /Removed account .*\./;

constructor(response: string) {
super(response);
}

private static readonly SuccessResponse = /Removed account .*\./;

public assertSuccess(): void {
const body: string | null = this.body;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DeviceResponse, UnknownError } from 'axis-core';

export class UpdateUserResponse extends DeviceResponse {
private static readonly SuccessResponse = /Modified account .*\./;

constructor(response: string) {
super(response);
}

private static readonly SuccessResponse = /Modified account .*\./;

public assertSuccess(): void {
const body: string | null = this.body;

Expand Down
8 changes: 4 additions & 4 deletions packages/axis-discovery-ssdp/src/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ interface Events {
* Class responsible for discovering Axis cameras on the network.
*/
export class Discovery implements EventEmitter {
private readonly eventEmitter = new EventEmitter();
private readonly options: IOptions;
private sockets?: SocketBase[];

/**
* Initializes a new instance of the class.
* @param options The SSDP discovery options.
Expand All @@ -31,6 +27,10 @@ export class Discovery implements EventEmitter {
this.options = options || {};
}

private readonly eventEmitter = new EventEmitter();
private readonly options: IOptions;
private sockets?: SocketBase[];

/**
* Start listen for device advertisements on all network interface
* addresses.
Expand Down
9 changes: 6 additions & 3 deletions packages/axis-discovery-ssdp/src/sockets/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
* Class describing a received SSDP message.
*/
export class Message {
private readonly headers: { [name: string]: string } = {};

constructor(readonly remoteAddress: string, message: Buffer) {
constructor(
readonly remoteAddress: string,
message: Buffer,
) {
this.parseHeaders(message);
}

private readonly headers: { [name: string]: string } = {};

/**
* Gets the HTTP method.
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/axis-discovery/src/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ interface Events {
* Class responsible for discovering Axis cameras on the network.
*/
export class Discovery implements EventEmitter {
private readonly eventEmitter = new EventEmitter();
private readonly discoveryProtocols: IDiscoveryProtocol[] = [];
private readonly deviceCache = new DeviceCache();

/**
* Initializes a new instance of the class.
*/
Expand All @@ -28,6 +24,10 @@ export class Discovery implements EventEmitter {
this.setup(new Ssdp());
}

private readonly eventEmitter = new EventEmitter();
private readonly discoveryProtocols: IDiscoveryProtocol[] = [];
private readonly deviceCache = new DeviceCache();

/**
* Start listen for device advertisements on all network interface
* addresses.
Expand Down
4 changes: 2 additions & 2 deletions packages/axis-discovery/src/caches/DeviceCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Device } from '../Device';
import { log } from '../logging';

export class DeviceCache {
private readonly devices: { [macAddress: string]: Device } = {};

constructor(...devices: Device[]) {
for (const device of devices) {
this.devices[device.macAddress] = device;
}
}

private readonly devices: { [macAddress: string]: Device } = {};

public update(device: Device): Device {
expect.toExist(device.macAddress, `MAC address of device with address ${device.address} is expected`);

Expand Down
6 changes: 3 additions & 3 deletions packages/axis-discovery/src/discovery-protocols/Bonjour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { log } from '../logging';
import { IDiscoveryProtocol } from './IDiscoveryProtocol';

export class Bonjour implements IDiscoveryProtocol {
private readonly discovery: bonjour.Discovery;

constructor() {
this.discovery = new bonjour.Discovery();
}

private readonly discovery: bonjour.Discovery;

public start(): Promise<void> {
return new Promise((resolve, reject) => {
try {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class Bonjour implements IDiscoveryProtocol {
undefined,
undefined,
undefined,
undefined
undefined,
);
}
}
6 changes: 3 additions & 3 deletions packages/axis-discovery/src/discovery-protocols/Ssdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { log } from '../logging';
import { IDiscoveryProtocol } from './IDiscoveryProtocol';

export class Ssdp implements IDiscoveryProtocol {
private readonly discovery: ssdp.Discovery;

constructor() {
this.discovery = new ssdp.Discovery();
}

private readonly discovery: ssdp.Discovery;

public async start(): Promise<void> {
try {
await this.discovery.start();
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Ssdp implements IDiscoveryProtocol {
ssdpDevice.modelName,
ssdpDevice.modelDescription,
ssdpDevice.modelNumber,
ssdpDevice.presentationURL
ssdpDevice.presentationURL,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { DeviceResponse, UnknownError } from 'axis-core';
import { FactoryDefaultType } from './FactoryDefaultType';

export class FactoryDefaultResponse extends DeviceResponse {
private static readonly SuccessResponsePartialType = /factoryMessage/i;
private static readonly SuccessResponseHardType = /factoryMessage2/i;

constructor(response: string, private readonly type: FactoryDefaultType) {
constructor(
response: string,
private readonly type: FactoryDefaultType,
) {
super(response);
}

private static readonly SuccessResponsePartialType = /factoryMessage/i;
private static readonly SuccessResponseHardType = /factoryMessage2/i;

public assertSuccess(): void {
if (this.type === FactoryDefaultType.Partial) {
this.assertPartialTypeSuccess();
Expand Down
6 changes: 3 additions & 3 deletions packages/axis-maintenance/src/restart/RestartResponse.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DeviceResponse, UnknownError } from "axis-core";
import { DeviceResponse, UnknownError } from 'axis-core';

export class RestartResponse extends DeviceResponse {
private static readonly SuccessResponse = /restartMessage/i;

constructor(response: string) {
super(response);
}

private static readonly SuccessResponse = /restartMessage/i;

public assertSuccess(): void {
if (RestartResponse.SuccessResponse.test(this.response)) {
return;
Expand Down

0 comments on commit 8267ce2

Please sign in to comment.