From f45d8707fcf35e907dc36bd600fdd7fed05ea94a Mon Sep 17 00:00:00 2001 From: "Jared.K" <3268576+jaredkotoff@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:45:40 -0700 Subject: [PATCH 1/2] run prettier --- .github/workflows/restyled.yml | 2 +- .prettierignore | 10 ++++++ .prettierrc | 1 + eslint.config.mjs | 54 +++++++++++++++-------------- package-lock.json | 39 +++++++++++++++++++++ package.json | 3 ++ src/camera.test.ts | 24 ++++++------- src/camera.ts | 14 ++++---- src/handlers/apiHandler.ts | 30 ++++++++-------- src/handlers/baseApiHandler.ts | 34 +++++++++---------- src/handlers/restHandler.ts | 12 +++---- src/index.ts | 2 +- src/interfaces/CommandData.ts | 30 ++++++++-------- src/mixins/alarm.ts | 12 +++---- src/mixins/device.ts | 24 ++++++------- src/mixins/display.ts | 26 +++++++------- src/mixins/download.ts | 10 +++--- src/mixins/image.ts | 22 ++++++------ src/mixins/motion.ts | 22 ++++++------ src/mixins/network.ts | 62 +++++++++++++++++----------------- src/mixins/nvrdownload.ts | 10 +++--- src/mixins/ptz.ts | 54 ++++++++++++++--------------- src/mixins/record.ts | 22 ++++++------ src/mixins/stream.ts | 24 ++++++------- src/mixins/system.ts | 24 ++++++------- src/mixins/user.ts | 32 +++++++++--------- src/mixins/zoom.ts | 20 +++++------ src/utils/rtspClient.ts | 26 +++++++------- tsconfig.json | 38 +++++---------------- vitest.config.mjs | 4 +-- 30 files changed, 361 insertions(+), 326 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.github/workflows/restyled.yml b/.github/workflows/restyled.yml index af95c10..9680cf4 100644 --- a/.github/workflows/restyled.yml +++ b/.github/workflows/restyled.yml @@ -31,6 +31,6 @@ jobs: branch: ${{ steps.restyler.outputs.restyled-head }} title: ${{ steps.restyler.outputs.restyled-title }} body: ${{ steps.restyler.outputs.restyled-body }} - labels: 'restyled' + labels: "restyled" reviewers: ${{ github.event.pull_request.user.login }} delete-branch: true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..3b7a596 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +# Ignore artifacts: +build +coverage + +node_modules +tmp +package.json +package-lock.json +LICENSE.md +.vscode diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/eslint.config.mjs b/eslint.config.mjs index 6b141f5..2d5f8ab 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,8 +1,9 @@ -import { FlatCompat } from '@eslint/eslintrc'; -import js from '@eslint/js'; -import tsParser from '@typescript-eslint/parser'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { FlatCompat } from "@eslint/eslintrc"; +import js from "@eslint/js"; +import tsParser from "@typescript-eslint/parser"; +import eslintConfigPrettier from "eslint-config-prettier"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -13,26 +14,26 @@ const compat = new FlatCompat({ }); export default [ - ...compat.extends('plugin:@typescript-eslint/recommended'), + ...compat.extends("plugin:@typescript-eslint/recommended"), { plugins: {}, languageOptions: { parser: tsParser, - ecmaVersion: 'latest', - sourceType: 'module', + ecmaVersion: "latest", + sourceType: "module", parserOptions: { - project: './tsconfig.json', + project: "./tsconfig.json", }, }, rules: { - '@typescript-eslint/no-parameter-properties': 'off', - '@typescript-eslint/no-explicit-any': 'off', + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-explicit-any": "off", - '@typescript-eslint/no-use-before-define': [ - 'error', + "@typescript-eslint/no-use-before-define": [ + "error", { functions: false, typedefs: false, @@ -40,35 +41,36 @@ export default [ }, ], - '@typescript-eslint/no-unused-vars': [ - 'error', + "@typescript-eslint/no-unused-vars": [ + "error", { ignoreRestSiblings: true, - argsIgnorePattern: '^_', + argsIgnorePattern: "^_", }, ], - '@typescript-eslint/explicit-function-return-type': [ - 'warn', + "@typescript-eslint/explicit-function-return-type": [ + "warn", { allowExpressions: true, allowTypedFunctionExpressions: true, }, ], - '@typescript-eslint/no-object-literal-type-assertion': 'off', - '@typescript-eslint/interface-name-prefix': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - 'no-var': 'error', - 'prefer-const': 'error', - 'no-trailing-spaces': 'error', + "@typescript-eslint/no-object-literal-type-assertion": "off", + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "no-var": "error", + "prefer-const": "error", + "no-trailing-spaces": "error", }, }, { - files: ['**/*.test.ts'], + files: ["**/*.test.ts"], rules: { - '@typescript-eslint/explicit-function-return-type': 'off', + "@typescript-eslint/explicit-function-return-type": "off", }, }, + eslintConfigPrettier, ]; diff --git a/package-lock.json b/package-lock.json index c58fb3a..6801229 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,12 +19,15 @@ "@eslint/js": "^9.12.0", "@types/eslint__eslintrc": "^2.1.2", "@types/eslint__js": "^8.42.3", + "@types/eslint-config-prettier": "^6.11.3", "@types/node": "^22.7.5", "@typescript-eslint/eslint-plugin": "^8.9.0", "@typescript-eslint/parser": "^8.9.0", "dotenv": "^16.4.5", "eslint": "^9.12.0", + "eslint-config-prettier": "^9.1.0", "mkdirp": "^3.0.1", + "prettier": "3.3.3", "typescript": "^5.6.3", "vite-tsconfig-paths": "^5.0.1", "vitest": "^2.1.3" @@ -1460,6 +1463,13 @@ "@types/eslint": "*" } }, + "node_modules/@types/eslint-config-prettier": { + "version": "6.11.3", + "resolved": "https://registry.npmjs.org/@types/eslint-config-prettier/-/eslint-config-prettier-6.11.3.tgz", + "integrity": "sha512-3wXCiM8croUnhg9LdtZUJQwNcQYGWxxdOWDjPe1ykCqJFPVpzAKfs/2dgSoCtAvdPeaponcWPI7mPcGGp9dkKQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", @@ -2422,6 +2432,19 @@ } } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-scope": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", @@ -3767,6 +3790,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/proc-log": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-4.2.0.tgz", diff --git a/package.json b/package.json index ffcb3d7..c8a7f3f 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,15 @@ "@eslint/js": "^9.12.0", "@types/eslint__eslintrc": "^2.1.2", "@types/eslint__js": "^8.42.3", + "@types/eslint-config-prettier": "^6.11.3", "@types/node": "^22.7.5", "@typescript-eslint/eslint-plugin": "^8.9.0", "@typescript-eslint/parser": "^8.9.0", "dotenv": "^16.4.5", "eslint": "^9.12.0", + "eslint-config-prettier": "^9.1.0", "mkdirp": "^3.0.1", + "prettier": "3.3.3", "typescript": "^5.6.3", "vite-tsconfig-paths": "^5.0.1", "vitest": "^2.1.3" diff --git a/src/camera.test.ts b/src/camera.test.ts index 9809d24..4a6b213 100644 --- a/src/camera.test.ts +++ b/src/camera.test.ts @@ -1,8 +1,8 @@ -import 'dotenv/config'; -import { existsSync } from 'fs'; -import { mkdirp } from 'mkdirp'; -import { beforeAll, beforeEach, describe, expect, test } from 'vitest'; -import Camera from './camera'; +import "dotenv/config"; +import { existsSync } from "fs"; +import { mkdirp } from "mkdirp"; +import { beforeAll, beforeEach, describe, expect, test } from "vitest"; +import Camera from "./camera"; interface CameraConfig { camera: { @@ -13,7 +13,7 @@ interface CameraConfig { }; } -describe('Camera', () => { +describe("Camera", () => { let config: CameraConfig; let cam: Camera; @@ -23,7 +23,7 @@ describe('Camera', () => { ip: process.env.CAMERA_IP, username: process.env.CAMERA_USERNAME, password: process.env.CAMERA_PASSWORD, - https: process.env.CAMERA_HTTPS === 'true' ? true : false, + https: process.env.CAMERA_HTTPS === "true" ? true : false, }, } as CameraConfig; }); @@ -37,16 +37,16 @@ describe('Camera', () => { ); }); - test('camera connects and gets a token', () => { - expect(cam['ip']).toBe(config.camera.ip); - expect(cam['token']).not.toBe(''); + test("camera connects and gets a token", () => { + expect(cam["ip"]).toBe(config.camera.ip); + expect(cam["token"]).not.toBe(""); }); - test('snapshot functionality', async () => { + test("snapshot functionality", async () => { const img = await cam.getSnap(); // Ensure the directory exists - const outputPath = '../tmp/snaps/'; + const outputPath = "../tmp/snaps/"; await mkdirp(outputPath); const outputFilePath = `${outputPath}camera.jpg`; diff --git a/src/camera.ts b/src/camera.ts index d31b433..df8c655 100644 --- a/src/camera.ts +++ b/src/camera.ts @@ -1,19 +1,19 @@ -import APIHandler from '@handlers/apiHandler'; -import { AxiosInstance, AxiosRequestConfig } from 'axios'; +import APIHandler from "@handlers/apiHandler"; +import { AxiosInstance, AxiosRequestConfig } from "axios"; class Camera extends APIHandler { protected profile: string; constructor( ip: string, - username: string = 'admin', - password: string = '', + username: string = "admin", + password: string = "", https: boolean = false, deferLogin: boolean = false, - profile: string = 'main', - options?: { proxy?: AxiosRequestConfig['proxy']; session?: AxiosInstance }, + profile: string = "main", + options?: { proxy?: AxiosRequestConfig["proxy"]; session?: AxiosInstance }, ) { - if (!['main', 'sub'].includes(profile)) { + if (!["main", "sub"].includes(profile)) { throw new Error('Profile argument must be either "main" or "sub"'); } super(ip, username, password, https, options); diff --git a/src/handlers/apiHandler.ts b/src/handlers/apiHandler.ts index 4cb5ddf..5a1656f 100644 --- a/src/handlers/apiHandler.ts +++ b/src/handlers/apiHandler.ts @@ -1,18 +1,18 @@ -import AlarmAPIMixin from '@mixins/alarm'; -import DeviceAPIMixin from '@mixins/device'; -import DisplayAPIMixin from '@mixins/display'; -import DownloadAPIMixin from '@mixins/download'; -import ImageAPIMixin from '@mixins/image'; -import MotionAPIMixin from '@mixins/motion'; -import NetworkAPIMixin from '@mixins/network'; -import NvrDownloadAPIMixin from '@mixins/nvrdownload'; -import PtzAPIMixin from '@mixins/ptz'; -import RecordAPIMixin from '@mixins/record'; -import StreamAPIMixin from '@mixins/stream'; -import SystemAPIMixin from '@mixins/system'; -import UserAPIMixin from '@mixins/user'; -import ZoomAPIMixin from '@mixins/zoom'; -import { Mixin } from 'ts-mixer'; +import AlarmAPIMixin from "@mixins/alarm"; +import DeviceAPIMixin from "@mixins/device"; +import DisplayAPIMixin from "@mixins/display"; +import DownloadAPIMixin from "@mixins/download"; +import ImageAPIMixin from "@mixins/image"; +import MotionAPIMixin from "@mixins/motion"; +import NetworkAPIMixin from "@mixins/network"; +import NvrDownloadAPIMixin from "@mixins/nvrdownload"; +import PtzAPIMixin from "@mixins/ptz"; +import RecordAPIMixin from "@mixins/record"; +import StreamAPIMixin from "@mixins/stream"; +import SystemAPIMixin from "@mixins/system"; +import UserAPIMixin from "@mixins/user"; +import ZoomAPIMixin from "@mixins/zoom"; +import { Mixin } from "ts-mixer"; class _APIHandler extends Mixin( AlarmAPIMixin, diff --git a/src/handlers/baseApiHandler.ts b/src/handlers/baseApiHandler.ts index 3b20a01..2dcd884 100644 --- a/src/handlers/baseApiHandler.ts +++ b/src/handlers/baseApiHandler.ts @@ -1,7 +1,7 @@ -import CommandData from '@interfaces/CommandData'; -import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; -import fs from 'fs'; -import Request from './restHandler'; +import CommandData from "@interfaces/CommandData"; +import axios, { AxiosInstance, AxiosRequestConfig } from "axios"; +import fs from "fs"; +import Request from "./restHandler"; interface LoginResponse { code: string; @@ -24,9 +24,9 @@ class BaseAPIHandler { username: string, password: string, https: boolean = false, - options?: { proxy?: AxiosRequestConfig['proxy']; session?: AxiosInstance }, + options?: { proxy?: AxiosRequestConfig["proxy"]; session?: AxiosInstance }, ) { - const scheme = https ? 'https' : 'http'; + const scheme = https ? "https" : "http"; this.url = `${scheme}://${ip}/cgi-bin/api.cgi`; this.ip = ip; this.username = username; @@ -39,7 +39,7 @@ class BaseAPIHandler { try { const body: CommandData[] = [ { - cmd: 'Login', + cmd: "Login", action: 0, param: { User: { @@ -50,32 +50,32 @@ class BaseAPIHandler { }, ]; - const param = { cmd: 'Login', token: 'null' }; + const param = { cmd: "Login", token: "null" }; const response = await Request.post(this.url, body, param); const data: LoginResponse = response?.data[0]; if (parseInt(data.code) === 0) { this.token = data.value.Token.name; - console.log('Login success'); + console.log("Login success"); return true; } else { - console.log('Failed to login'); + console.log("Failed to login"); return false; } } catch (error) { - console.error('Error during login:', error); + console.error("Error during login:", error); return false; } } async logout(): Promise { try { - const data: CommandData[] = [{ cmd: 'Logout', action: 0 }]; - await this.executeCommand('Logout', data); + const data: CommandData[] = [{ cmd: "Logout", action: 0 }]; + await this.executeCommand("Logout", data); return true; } catch (error) { - console.error('Error during logout:', error); + console.error("Error during logout:", error); return false; } } @@ -86,7 +86,7 @@ class BaseAPIHandler { multi: boolean = false, ): Promise { if (!this.token) { - throw new Error('Login first'); + throw new Error("Login first"); } const params: any = { token: this.token, cmd: command }; @@ -95,11 +95,11 @@ class BaseAPIHandler { } try { - if (command === 'Download') { + if (command === "Download") { const tgtFilePath = data[0].filepath; const response = await axios.get(this.url, { params, - responseType: 'stream', + responseType: "stream", proxy: Request.proxies, }); diff --git a/src/handlers/restHandler.ts b/src/handlers/restHandler.ts index 5fa73df..351ef45 100644 --- a/src/handlers/restHandler.ts +++ b/src/handlers/restHandler.ts @@ -1,12 +1,12 @@ -import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; -import https from 'https'; +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import https from "https"; interface RequestParams { [key: string]: string | number | undefined; } class Request { - static proxies: AxiosRequestConfig['proxy'] = undefined; + static proxies: AxiosRequestConfig["proxy"] = undefined; static session: AxiosInstance | undefined = undefined; private static getSession(): AxiosInstance { @@ -19,7 +19,7 @@ class Request { params: RequestParams = {}, ): Promise { try { - const headers = { 'Content-Type': 'application/json' }; + const headers = { "Content-Type": "application/json" }; const response = await Request.getSession().post(url, data, { headers, params, @@ -33,7 +33,7 @@ class Request { throw new Error(`HTTP Request had non-200 Status: ${response.status}`); } } catch (error) { - console.error('Post Error\n', error); + console.error("Post Error\n", error); throw error; } } @@ -53,7 +53,7 @@ class Request { return response; } catch (error) { - console.error('Get Error\n', error); + console.error("Get Error\n", error); throw error; } } diff --git a/src/index.ts b/src/index.ts index a7ed3d3..69973ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export { default as Camera } from './camera'; +export { default as Camera } from "./camera"; diff --git a/src/interfaces/CommandData.ts b/src/interfaces/CommandData.ts index 37ab968..6b6be6d 100644 --- a/src/interfaces/CommandData.ts +++ b/src/interfaces/CommandData.ts @@ -1,16 +1,16 @@ -import { AlarmAPIMixinParams } from '../mixins/alarm'; -import { DeviceAPIMixinParams } from '../mixins/device'; -import { SetOsdParams } from '../mixins/display'; -import { SetImageParams, SetIspParams } from '../mixins/image'; -import { SearchParams } from '../mixins/motion'; +import { AlarmAPIMixinParams } from "../mixins/alarm"; +import { DeviceAPIMixinParams } from "../mixins/device"; +import { SetOsdParams } from "../mixins/display"; +import { SetImageParams, SetIspParams } from "../mixins/image"; +import { SearchParams } from "../mixins/motion"; import { SetLocalLinkParams, SetNetPortParams, SetWifiParams, -} from '../mixins/network'; -import { NvrDownloadParams } from '../mixins/nvrdownload'; -import { SetEncParams } from '../mixins/record'; -import { DelUserParams } from '../mixins/user'; +} from "../mixins/network"; +import { NvrDownloadParams } from "../mixins/nvrdownload"; +import { SetEncParams } from "../mixins/record"; +import { DelUserParams } from "../mixins/user"; type CommandDataParam = { channel?: number; @@ -48,10 +48,10 @@ export default interface CommandData { } export enum OsdPos { - 'Upper Left', - 'Top Center', - 'Upper Right', - 'Lower Left', - 'Bottom Center', - 'Lower Right', + "Upper Left", + "Top Center", + "Upper Right", + "Lower Left", + "Bottom Center", + "Lower Right", } diff --git a/src/mixins/alarm.ts b/src/mixins/alarm.ts index 8c2eda7..4495237 100644 --- a/src/mixins/alarm.ts +++ b/src/mixins/alarm.ts @@ -1,6 +1,6 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; -import { Mixin } from 'ts-mixer'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; +import { Mixin } from "ts-mixer"; interface AlarmResponse { // Define the structure of the response if known, use any if the structure is dynamic @@ -23,17 +23,17 @@ export default class AlarmAPIMixin extends Mixin(BaseAPIHandler) { */ const body: CommandData[] = [ { - cmd: 'GetAlarm', + cmd: "GetAlarm", action: 1, param: { Alarm: { channel: 0, - type: 'md', // 'md' indicates motion detection + type: "md", // 'md' indicates motion detection }, }, }, ]; - return this.executeCommand('GetAlarm', body); + return this.executeCommand("GetAlarm", body); } } diff --git a/src/mixins/device.ts b/src/mixins/device.ts index 5e9d067..57a42f5 100644 --- a/src/mixins/device.ts +++ b/src/mixins/device.ts @@ -1,6 +1,6 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; -import { Mixin } from 'ts-mixer'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; +import { Mixin } from "ts-mixer"; export interface DeviceAPIMixinParams { DevName?: { name: string }; @@ -12,36 +12,36 @@ export default class DeviceAPIMixin extends Mixin(BaseAPIHandler) { async setDeviceName(name: string): Promise { const body: CommandData[] = [ - { cmd: 'SetDevName', action: 0, param: { DevName: { name } } }, + { cmd: "SetDevName", action: 0, param: { DevName: { name } } }, ]; - await this.executeCommand('SetDevName', body); + await this.executeCommand("SetDevName", body); console.log(`Successfully set device name to: ${name}`); return true; } getDeviceName(): Promise { - const body: CommandData[] = [{ cmd: 'GetDevName', action: 0, param: {} }]; - return this.executeCommand('GetDevName', body); + const body: CommandData[] = [{ cmd: "GetDevName", action: 0, param: {} }]; + return this.executeCommand("GetDevName", body); } getHddInfo(): Promise { - const body: CommandData[] = [{ cmd: 'GetHddInfo', action: 0, param: {} }]; - return this.executeCommand('GetHddInfo', body); + const body: CommandData[] = [{ cmd: "GetHddInfo", action: 0, param: {} }]; + return this.executeCommand("GetHddInfo", body); } async formatHdd( hddId: number[] = DeviceAPIMixin.DEFAULT_HDD_ID, ): Promise { const body: CommandData[] = [ - { cmd: 'Format', action: 0, param: { HddInfo: { id: hddId } } }, + { cmd: "Format", action: 0, param: { HddInfo: { id: hddId } } }, ]; - const response = await this.executeCommand('Format', body); + const response = await this.executeCommand("Format", body); const rData = response[0]; if (rData.value.rspCode === 200) { return true; } else { console.log( - 'Could not format HDD/SD. Camera responded with:', + "Could not format HDD/SD. Camera responded with:", rData.value, ); return false; diff --git a/src/mixins/display.ts b/src/mixins/display.ts index a0aa4ed..c8e62b1 100644 --- a/src/mixins/display.ts +++ b/src/mixins/display.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData, { OsdPos } from '../interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData, { OsdPos } from "../interfaces/CommandData"; export interface SetOsdParams { Osd: { @@ -27,9 +27,9 @@ class DisplayAPIMixin extends BaseAPIHandler { * @returns response json */ const body: CommandData[] = [ - { cmd: 'GetOsd', action: 1, param: { channel: 0 } }, + { cmd: "GetOsd", action: 1, param: { channel: 0 } }, ]; - return this.executeCommand('GetOsd', body); + return this.executeCommand("GetOsd", body); } public async getMask(): Promise { @@ -39,19 +39,19 @@ class DisplayAPIMixin extends BaseAPIHandler { * @returns response json */ const body: CommandData[] = [ - { cmd: 'GetMask', action: 1, param: { channel: 0 } }, + { cmd: "GetMask", action: 1, param: { channel: 0 } }, ]; - return this.executeCommand('GetMask', body); + return this.executeCommand("GetMask", body); } public async setOsd( bg_color: boolean = false, channel: number = 0, osd_channel_enabled: boolean = false, - osd_channel_name: string = '', - osd_channel_pos: OsdPos = OsdPos['Lower Right'], + osd_channel_name: string = "", + osd_channel_pos: OsdPos = OsdPos["Lower Right"], osd_time_enabled: boolean = false, - osd_time_pos: OsdPos = OsdPos['Lower Right'], + osd_time_pos: OsdPos = OsdPos["Lower Right"], osd_watermark_enabled: boolean = false, ): Promise { /** @@ -60,7 +60,7 @@ class DisplayAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: 'SetOsd', + cmd: "SetOsd", action: 1, param: { Osd: { @@ -79,18 +79,18 @@ class DisplayAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand('SetOsd', body); + const response = await this.executeCommand("SetOsd", body); const r_data = response[0]; if (r_data?.value?.rspCode === 200) { return true; } console.log( - 'Could not set OSD. Camera responded with status:', + "Could not set OSD. Camera responded with status:", r_data.error, ); return false; } catch (error) { - console.error('Error setting OSD:', error); + console.error("Error setting OSD:", error); return false; } } diff --git a/src/mixins/download.ts b/src/mixins/download.ts index a2951fb..82ff929 100644 --- a/src/mixins/download.ts +++ b/src/mixins/download.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; class DownloadAPIMixin extends BaseAPIHandler { /** @@ -15,7 +15,7 @@ class DownloadAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: 'Download', + cmd: "Download", action: 0, // action is required in CommandData, but not used in the original Python code source: filename, output: filename, @@ -24,10 +24,10 @@ class DownloadAPIMixin extends BaseAPIHandler { ]; try { - const resp = await this.executeCommand('Download', body); + const resp = await this.executeCommand("Download", body); return resp; } catch (error) { - console.error('Error downloading file:', error); + console.error("Error downloading file:", error); return false; } } diff --git a/src/mixins/image.ts b/src/mixins/image.ts index 4226cc8..3e53776 100644 --- a/src/mixins/image.ts +++ b/src/mixins/image.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; export interface SetImageParams { Image: { @@ -37,17 +37,17 @@ class ImageAPIMixin extends BaseAPIHandler { */ public async setAdvImageSettings( - anti_flicker: string = 'Outdoor', - exposure: string = 'Auto', + anti_flicker: string = "Outdoor", + exposure: string = "Auto", gain_min: number = 1, gain_max: number = 62, shutter_min: number = 1, shutter_max: number = 125, blue_gain: number = 128, red_gain: number = 128, - white_balance: string = 'Auto', - day_night: string = 'Auto', - back_light: string = 'DynamicRangeControl', + white_balance: string = "Auto", + day_night: string = "Auto", + back_light: string = "DynamicRangeControl", blc: number = 128, drc: number = 128, rotation: number = 0, @@ -59,7 +59,7 @@ class ImageAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: 'SetIsp', + cmd: "SetIsp", action: 0, param: { Isp: { @@ -82,7 +82,7 @@ class ImageAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand('SetIsp', body); + return this.executeCommand("SetIsp", body); } public async setImageSettings( @@ -97,7 +97,7 @@ class ImageAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: 'SetImage', + cmd: "SetImage", action: 0, param: { Image: { @@ -112,7 +112,7 @@ class ImageAPIMixin extends BaseAPIHandler { }, ]; - return this.executeCommand('SetImage', body); + return this.executeCommand("SetImage", body); } } diff --git a/src/mixins/motion.ts b/src/mixins/motion.ts index 36588f0..02f4724 100644 --- a/src/mixins/motion.ts +++ b/src/mixins/motion.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; export interface SearchParams { Search: { @@ -50,7 +50,7 @@ class MotionAPIMixin extends BaseAPIHandler { public async getMotionFiles( start: Date, end: Date = new Date(), - streamtype: string = 'sub', + streamtype: string = "sub", channel: number = 0, ): Promise { /** @@ -81,11 +81,11 @@ class MotionAPIMixin extends BaseAPIHandler { }; const body: CommandData[] = [ - { cmd: 'Search', action: 1, param: searchParams }, + { cmd: "Search", action: 1, param: searchParams }, ]; try { - const resp = await this.executeCommand('Search', body); + const resp = await this.executeCommand("Search", body); const result = resp[0]?.value?.SearchResult; const files = result?.File || []; if (files.length > 0) { @@ -93,7 +93,7 @@ class MotionAPIMixin extends BaseAPIHandler { } return []; } catch (error) { - console.error('Error getting motion files:', error); + console.error("Error getting motion files:", error); return []; } } @@ -105,14 +105,14 @@ class MotionAPIMixin extends BaseAPIHandler { */ const processedMotions: ProcessedMotionList = []; const replaceFields: { [key: string]: string } = { - mon: 'month', - sec: 'second', - min: 'minute', + mon: "month", + sec: "second", + min: "minute", }; for (const file of motion_files) { const timeRange: { [key: string]: Date } = {}; - for (const x of ['Start', 'End']) { + for (const x of ["Start", "End"]) { const raw = { ...file[`${x}Time`] }; for (const [k, v] of Object.entries(replaceFields)) { if (k in raw) { @@ -121,7 +121,7 @@ class MotionAPIMixin extends BaseAPIHandler { } } // Adjust for JavaScript's 0-indexed months - if ('month' in raw) { + if ("month" in raw) { raw.month -= 1; } timeRange[x.toLowerCase()] = new Date( diff --git a/src/mixins/network.ts b/src/mixins/network.ts index a9c2794..be4ffcb 100644 --- a/src/mixins/network.ts +++ b/src/mixins/network.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; export interface SetLocalLinkParams { LocalLink: { @@ -52,7 +52,7 @@ class NetworkAPIMixin extends BaseAPIHandler { ): Promise { const body: CommandData[] = [ { - cmd: 'SetLocalLink', + cmd: "SetLocalLink", action: 0, param: { LocalLink: { @@ -67,14 +67,14 @@ class NetworkAPIMixin extends BaseAPIHandler { ip: ip, mask: mask, }, - type: useDhcp ? 'DHCP' : 'Static', + type: useDhcp ? "DHCP" : "Static", }, }, }, ]; - const result = await this.executeCommand('SetLocalLink', body); - console.log('Successfully Set Network Settings'); + const result = await this.executeCommand("SetLocalLink", body); + console.log("Successfully Set Network Settings"); return result; } @@ -88,7 +88,7 @@ class NetworkAPIMixin extends BaseAPIHandler { ): Promise { const body: CommandData[] = [ { - cmd: 'SetNetPort', + cmd: "SetNetPort", action: 0, param: { NetPort: { @@ -102,15 +102,15 @@ class NetworkAPIMixin extends BaseAPIHandler { }, }, ]; - await this.executeCommand('SetNetPort', body, true); - console.log('Successfully Set Network Ports'); + await this.executeCommand("SetNetPort", body, true); + console.log("Successfully Set Network Ports"); return true; } public async setWifi(ssid: string, password: string): Promise { const body: CommandData[] = [ { - cmd: 'SetWifi', + cmd: "SetWifi", action: 0, param: { Wifi: { @@ -120,56 +120,56 @@ class NetworkAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand('SetWifi', body); + return this.executeCommand("SetWifi", body); } public async getNetPorts(): Promise { const body: CommandData[] = [ - { cmd: 'GetNetPort', action: 1, param: {} }, - { cmd: 'GetUpnp', action: 0, param: {} }, - { cmd: 'GetP2p', action: 0, param: {} }, + { cmd: "GetNetPort", action: 1, param: {} }, + { cmd: "GetUpnp", action: 0, param: {} }, + { cmd: "GetP2p", action: 0, param: {} }, ]; - return this.executeCommand('GetNetPort', body, true); + return this.executeCommand("GetNetPort", body, true); } public async getWifi(): Promise { - const body: CommandData[] = [{ cmd: 'GetWifi', action: 1, param: {} }]; - return this.executeCommand('GetWifi', body); + const body: CommandData[] = [{ cmd: "GetWifi", action: 1, param: {} }]; + return this.executeCommand("GetWifi", body); } public async scanWifi(): Promise { - const body: CommandData[] = [{ cmd: 'ScanWifi', action: 1, param: {} }]; - return this.executeCommand('ScanWifi', body); + const body: CommandData[] = [{ cmd: "ScanWifi", action: 1, param: {} }]; + return this.executeCommand("ScanWifi", body); } public async getNetworkGeneral(): Promise { - const body: CommandData[] = [{ cmd: 'GetLocalLink', action: 0, param: {} }]; - return this.executeCommand('GetLocalLink', body); + const body: CommandData[] = [{ cmd: "GetLocalLink", action: 0, param: {} }]; + return this.executeCommand("GetLocalLink", body); } public async getNetworkDdns(): Promise { - const body: CommandData[] = [{ cmd: 'GetDdns', action: 0, param: {} }]; - return this.executeCommand('GetDdns', body); + const body: CommandData[] = [{ cmd: "GetDdns", action: 0, param: {} }]; + return this.executeCommand("GetDdns", body); } public async getNetworkNtp(): Promise { - const body: CommandData[] = [{ cmd: 'GetNtp', action: 0, param: {} }]; - return this.executeCommand('GetNtp', body); + const body: CommandData[] = [{ cmd: "GetNtp", action: 0, param: {} }]; + return this.executeCommand("GetNtp", body); } public async getNetworkEmail(): Promise { - const body: CommandData[] = [{ cmd: 'GetEmail', action: 0, param: {} }]; - return this.executeCommand('GetEmail', body); + const body: CommandData[] = [{ cmd: "GetEmail", action: 0, param: {} }]; + return this.executeCommand("GetEmail", body); } public async getNetworkFtp(): Promise { - const body: CommandData[] = [{ cmd: 'GetFtp', action: 0, param: {} }]; - return this.executeCommand('GetFtp', body); + const body: CommandData[] = [{ cmd: "GetFtp", action: 0, param: {} }]; + return this.executeCommand("GetFtp", body); } public async getNetworkPush(): Promise { - const body: CommandData[] = [{ cmd: 'GetPush', action: 0, param: {} }]; - return this.executeCommand('GetPush', body); + const body: CommandData[] = [{ cmd: "GetPush", action: 0, param: {} }]; + return this.executeCommand("GetPush", body); } public async getNetworkStatus(): Promise { diff --git a/src/mixins/nvrdownload.ts b/src/mixins/nvrdownload.ts index f7b3625..3636b35 100644 --- a/src/mixins/nvrdownload.ts +++ b/src/mixins/nvrdownload.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import CommandData from '@interfaces/CommandData'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import CommandData from "@interfaces/CommandData"; export interface NvrDownloadParams { NvrDownload: { @@ -25,7 +25,7 @@ class NvrDownloadAPIMixin extends BaseAPIHandler { start: Date, end: Date = new Date(), channel: number = 0, - streamType: string = 'sub', + streamType: string = "sub", ): Promise { const searchParams: NvrDownloadParams = { NvrDownload: { @@ -38,11 +38,11 @@ class NvrDownloadAPIMixin extends BaseAPIHandler { }; const body: CommandData[] = [ - { cmd: 'NvrDownload', action: 1, param: searchParams }, + { cmd: "NvrDownload", action: 1, param: searchParams }, ]; try { - const resp = (await this.executeCommand('NvrDownload', body))[0]; + const resp = (await this.executeCommand("NvrDownload", body))[0]; if (!resp.value?.fileList) { return []; } diff --git a/src/mixins/ptz.ts b/src/mixins/ptz.ts index b86de87..b8fe714 100644 --- a/src/mixins/ptz.ts +++ b/src/mixins/ptz.ts @@ -1,21 +1,21 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; +import BaseAPIHandler from "@handlers/baseApiHandler"; class PtzAPIMixin extends BaseAPIHandler { async getPtzCheckState(): Promise> { const body = [ - { cmd: 'GetPtzCheckState', action: 1, param: { channel: 0 } }, + { cmd: "GetPtzCheckState", action: 1, param: { channel: 0 } }, ]; - return this.executeCommand('GetPtzCheckState', body); + return this.executeCommand("GetPtzCheckState", body); } async getPtzPresets(): Promise> { - const body = [{ cmd: 'GetPtzPreset', action: 1, param: { channel: 0 } }]; - return this.executeCommand('GetPtzPreset', body); + const body = [{ cmd: "GetPtzPreset", action: 1, param: { channel: 0 } }]; + return this.executeCommand("GetPtzPreset", body); } async performCalibration(): Promise> { - const data = [{ cmd: 'PtzCheck', action: 0, param: { channel: 0 } }]; - return this.executeCommand('PtzCheck', data); + const data = [{ cmd: "PtzCheck", action: 0, param: { channel: 0 } }]; + return this.executeCommand("PtzCheck", data); } private async sendOperation( @@ -31,93 +31,93 @@ class PtzAPIMixin extends BaseAPIHandler { if (index !== undefined) { param.id = index; } - const data = [{ cmd: 'PtzCtrl', action: 0, param }]; - return this.executeCommand('PtzCtrl', data); + const data = [{ cmd: "PtzCtrl", action: 0, param }]; + return this.executeCommand("PtzCtrl", data); } private async sendNoparmOperation( operation: string, ): Promise> { const data = [ - { cmd: 'PtzCtrl', action: 0, param: { channel: 0, op: operation } }, + { cmd: "PtzCtrl", action: 0, param: { channel: 0, op: operation } }, ]; - return this.executeCommand('PtzCtrl', data); + return this.executeCommand("PtzCtrl", data); } private async sendSetPreset( enable: number, preset: number = 1, - name: string = 'pos1', + name: string = "pos1", ): Promise> { const data = [ { - cmd: 'SetPtzPreset', + cmd: "SetPtzPreset", action: 0, param: { channel: 0, enable, id: preset, name }, }, ]; - return this.executeCommand('PtzCtrl', data); + return this.executeCommand("PtzCtrl", data); } async goToPreset( speed: number = 60, index: number = 1, ): Promise> { - return this.sendOperation('ToPos', speed, index); + return this.sendOperation("ToPos", speed, index); } async addPreset( preset: number = 1, - name: string = 'pos1', + name: string = "pos1", ): Promise> { return this.sendSetPreset(1, preset, name); } async removePreset( preset: number = 1, - name: string = 'pos1', + name: string = "pos1", ): Promise> { return this.sendSetPreset(0, preset, name); } async moveRight(speed: number = 25): Promise> { - return this.sendOperation('Right', speed); + return this.sendOperation("Right", speed); } async moveRightUp(speed: number = 25): Promise> { - return this.sendOperation('RightUp', speed); + return this.sendOperation("RightUp", speed); } async moveRightDown(speed: number = 25): Promise> { - return this.sendOperation('RightDown', speed); + return this.sendOperation("RightDown", speed); } async moveLeft(speed: number = 25): Promise> { - return this.sendOperation('Left', speed); + return this.sendOperation("Left", speed); } async moveLeftUp(speed: number = 25): Promise> { - return this.sendOperation('LeftUp', speed); + return this.sendOperation("LeftUp", speed); } async moveLeftDown(speed: number = 25): Promise> { - return this.sendOperation('LeftDown', speed); + return this.sendOperation("LeftDown", speed); } async moveUp(speed: number = 25): Promise> { - return this.sendOperation('Up', speed); + return this.sendOperation("Up", speed); } async moveDown(speed: number = 25): Promise> { - return this.sendOperation('Down', speed); + return this.sendOperation("Down", speed); } async stopPtz(): Promise> { - return this.sendNoparmOperation('Stop'); + return this.sendNoparmOperation("Stop"); } async autoMovement(speed: number = 25): Promise> { - return this.sendOperation('Auto', speed); + return this.sendOperation("Auto", speed); } } diff --git a/src/mixins/record.ts b/src/mixins/record.ts index 5e83a91..4dcff71 100644 --- a/src/mixins/record.ts +++ b/src/mixins/record.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; +import BaseAPIHandler from "@handlers/baseApiHandler"; export interface SetEncParams { Enc: { @@ -21,29 +21,29 @@ export interface SetEncParams { class RecordAPIMixin extends BaseAPIHandler { async getRecordingEncoding(): Promise> { - const body = [{ cmd: 'GetEnc', action: 1, param: { channel: 0 } }]; - return this.executeCommand('GetEnc', body); + const body = [{ cmd: "GetEnc", action: 1, param: { channel: 0 } }]; + return this.executeCommand("GetEnc", body); } async getRecordingAdvanced(): Promise> { - const body = [{ cmd: 'GetRec', action: 1, param: { channel: 0 } }]; - return this.executeCommand('GetRec', body); + const body = [{ cmd: "GetRec", action: 1, param: { channel: 0 } }]; + return this.executeCommand("GetRec", body); } async setRecordingEncoding( audio: number = 0, mainBitRate: number = 8192, mainFrameRate: number = 8, - mainProfile: string = 'High', - mainSize: string = '2560*1440', + mainProfile: string = "High", + mainSize: string = "2560*1440", subBitRate: number = 160, subFrameRate: number = 7, - subProfile: string = 'High', - subSize: string = '640*480', + subProfile: string = "High", + subSize: string = "640*480", ): Promise> { const body = [ { - cmd: 'SetEnc', + cmd: "SetEnc", action: 0, param: { Enc: { @@ -65,7 +65,7 @@ class RecordAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand('SetEnc', body); + return this.executeCommand("SetEnc", body); } } diff --git a/src/mixins/stream.ts b/src/mixins/stream.ts index 136c415..c9c7b91 100644 --- a/src/mixins/stream.ts +++ b/src/mixins/stream.ts @@ -1,8 +1,8 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; -import { Mat } from '@u4/opencv4nodejs'; -import RtspClient from '@utils/rtspClient'; -import axios from 'axios'; -import sharp from 'sharp'; +import BaseAPIHandler from "@handlers/baseApiHandler"; +import { Mat } from "@u4/opencv4nodejs"; +import RtspClient from "@utils/rtspClient"; +import axios from "axios"; +import sharp from "sharp"; // Type definitions interface ProxyConfig { @@ -24,7 +24,7 @@ interface SnapParams { * API calls for opening a video stream or capturing an image from the camera. */ class StreamAPIMixin extends BaseAPIHandler { - protected profile: string = 'main'; // Add this property if not in BaseAPIHandler + protected profile: string = "main"; // Add this property if not in BaseAPIHandler /** * Generates a random string for request parameters @@ -32,11 +32,11 @@ class StreamAPIMixin extends BaseAPIHandler { * @returns Random string of specified length */ private generateRandomString(length: number): string { - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; return Array.from( { length }, () => characters[Math.floor(Math.random() * characters.length)], - ).join(''); + ).join(""); } /** @@ -73,7 +73,7 @@ class StreamAPIMixin extends BaseAPIHandler { proxies?: ProxyConfig, ): Promise { const params: SnapParams = { - cmd: 'Snap', + cmd: "Snap", channel: 0, rs: this.generateRandomString(10), user: this.username, @@ -85,7 +85,7 @@ class StreamAPIMixin extends BaseAPIHandler { params, proxy: proxies, timeout: timeout * 1000, // Convert to milliseconds - responseType: 'arraybuffer', + responseType: "arraybuffer", }); if (response.status === 200) { @@ -93,12 +93,12 @@ class StreamAPIMixin extends BaseAPIHandler { } console.log( - 'Could not retrieve data from camera successfully. Status:', + "Could not retrieve data from camera successfully. Status:", response.status, ); return null; } catch (error) { - console.error('Could not get Image data\n', error); + console.error("Could not get Image data\n", error); throw error; } } diff --git a/src/mixins/system.ts b/src/mixins/system.ts index 26d9c81..903db53 100644 --- a/src/mixins/system.ts +++ b/src/mixins/system.ts @@ -1,32 +1,32 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; +import BaseAPIHandler from "@handlers/baseApiHandler"; class SystemAPIMixin extends BaseAPIHandler { async getGeneralSystem(): Promise> { const body = [ - { cmd: 'GetTime', action: 1, param: {} }, - { cmd: 'GetNorm', action: 1, param: {} }, + { cmd: "GetTime", action: 1, param: {} }, + { cmd: "GetNorm", action: 1, param: {} }, ]; - return this.executeCommand('get_general_system', body, true); + return this.executeCommand("get_general_system", body, true); } async getPerformance(): Promise> { - const body = [{ cmd: 'GetPerformance', action: 0, param: {} }]; - return this.executeCommand('GetPerformance', body); + const body = [{ cmd: "GetPerformance", action: 0, param: {} }]; + return this.executeCommand("GetPerformance", body); } async getInformation(): Promise> { - const body = [{ cmd: 'GetDevInfo', action: 0, param: {} }]; - return this.executeCommand('GetDevInfo', body); + const body = [{ cmd: "GetDevInfo", action: 0, param: {} }]; + return this.executeCommand("GetDevInfo", body); } async rebootCamera(): Promise> { - const body = [{ cmd: 'Reboot', action: 0, param: {} }]; - return this.executeCommand('Reboot', body); + const body = [{ cmd: "Reboot", action: 0, param: {} }]; + return this.executeCommand("Reboot", body); } async getDst(): Promise> { - const body = [{ cmd: 'GetTime', action: 0, param: {} }]; - return this.executeCommand('GetTime', body); + const body = [{ cmd: "GetTime", action: 0, param: {} }]; + return this.executeCommand("GetTime", body); } } diff --git a/src/mixins/user.ts b/src/mixins/user.ts index 0032361..83f8b9d 100644 --- a/src/mixins/user.ts +++ b/src/mixins/user.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; +import BaseAPIHandler from "@handlers/baseApiHandler"; export interface DelUserParams { User: { @@ -28,8 +28,8 @@ class UserAPIMixin extends BaseAPIHandler { * See examples/response/GetOnline.json for example response data. */ async getOnlineUser(): Promise { - const body = [{ cmd: 'GetOnline', action: 1, param: {} }]; - return this.executeCommand('GetOnline', body); + const body = [{ cmd: "GetOnline", action: 1, param: {} }]; + return this.executeCommand("GetOnline", body); } /** @@ -37,8 +37,8 @@ class UserAPIMixin extends BaseAPIHandler { * See examples/response/GetUser.json for example response data. */ async getUsers(): Promise { - const body = [{ cmd: 'GetUser', action: 1, param: {} }]; - return this.executeCommand('GetUser', body); + const body = [{ cmd: "GetUser", action: 1, param: {} }]; + return this.executeCommand("GetUser", body); } /** @@ -51,11 +51,11 @@ class UserAPIMixin extends BaseAPIHandler { async addUser( username: string, password: string, - level: 'guest' | 'admin' = 'guest', + level: "guest" | "admin" = "guest", ): Promise { const body = [ { - cmd: 'AddUser', + cmd: "AddUser", action: 0, param: { User: { @@ -68,16 +68,16 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand('AddUser', body); + const response = await this.executeCommand("AddUser", body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { return true; } - console.log('Could not add user. Camera responded with:', rData.value); + console.log("Could not add user. Camera responded with:", rData.value); return false; } catch (error) { - console.error('Error adding user:', error); + console.error("Error adding user:", error); return false; } } @@ -91,7 +91,7 @@ class UserAPIMixin extends BaseAPIHandler { async modifyUser(username: string, password: string): Promise { const body = [ { - cmd: 'ModifyUser', + cmd: "ModifyUser", action: 0, param: { User: { @@ -103,7 +103,7 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand('ModifyUser', body); + const response = await this.executeCommand("ModifyUser", body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { @@ -114,7 +114,7 @@ class UserAPIMixin extends BaseAPIHandler { ); return false; } catch (error) { - console.error('Error modifying user:', error); + console.error("Error modifying user:", error); return false; } } @@ -127,7 +127,7 @@ class UserAPIMixin extends BaseAPIHandler { async deleteUser(username: string): Promise { const body = [ { - cmd: 'DelUser', + cmd: "DelUser", action: 0, param: { User: { @@ -138,7 +138,7 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand('DelUser', body); + const response = await this.executeCommand("DelUser", body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { @@ -149,7 +149,7 @@ class UserAPIMixin extends BaseAPIHandler { ); return false; } catch (error) { - console.error('Error deleting user:', error); + console.error("Error deleting user:", error); return false; } } diff --git a/src/mixins/zoom.ts b/src/mixins/zoom.ts index c8d5f76..370bb0c 100644 --- a/src/mixins/zoom.ts +++ b/src/mixins/zoom.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from '@handlers/baseApiHandler'; +import BaseAPIHandler from "@handlers/baseApiHandler"; interface PtzResponse { [key: string]: any; @@ -22,7 +22,7 @@ class ZoomAPIMixin extends BaseAPIHandler { ): Promise { const data = [ { - cmd: 'PtzCtrl', + cmd: "PtzCtrl", action: 0, param: { channel: 0, @@ -31,7 +31,7 @@ class ZoomAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand('PtzCtrl', data); + return this.executeCommand("PtzCtrl", data); } /** @@ -41,15 +41,15 @@ class ZoomAPIMixin extends BaseAPIHandler { private async stopZoomingOrFocusing(): Promise { const data = [ { - cmd: 'PtzCtrl', + cmd: "PtzCtrl", action: 0, param: { channel: 0, - op: 'Stop', + op: "Stop", }, }, ]; - return this.executeCommand('PtzCtrl', data); + return this.executeCommand("PtzCtrl", data); } /** @@ -58,7 +58,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startZoomingIn(speed: number = 60): Promise { - return this.startOperation('ZoomInc', speed); + return this.startOperation("ZoomInc", speed); } /** @@ -67,7 +67,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startZoomingOut(speed: number = 60): Promise { - return this.startOperation('ZoomDec', speed); + return this.startOperation("ZoomDec", speed); } /** @@ -84,7 +84,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startFocusingIn(speed: number = 32): Promise { - return this.startOperation('FocusInc', speed); + return this.startOperation("FocusInc", speed); } /** @@ -93,7 +93,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startFocusingOut(speed: number = 32): Promise { - return this.startOperation('FocusDec', speed); + return this.startOperation("FocusDec", speed); } /** diff --git a/src/utils/rtspClient.ts b/src/utils/rtspClient.ts index 81232ca..e8feaa9 100644 --- a/src/utils/rtspClient.ts +++ b/src/utils/rtspClient.ts @@ -1,5 +1,5 @@ -import cv, { Mat, VideoCapture } from '@u4/opencv4nodejs'; -import EventEmitter from 'events'; +import cv, { Mat, VideoCapture } from "@u4/opencv4nodejs"; +import EventEmitter from "events"; interface RtspConfig { ip: string; @@ -30,7 +30,7 @@ class RtspClient extends EventEmitter { username, password, port = 554, - profile = 'main', + profile = "main", useUdp = true, callback, proxies, @@ -43,7 +43,7 @@ class RtspClient extends EventEmitter { // Set streaming options this.streamOptions = { - OPENCV_FFMPEG_CAPTURE_OPTIONS: `rtsp_transport;${useUdp ? 'udp' : 'tcp'}`, + OPENCV_FFMPEG_CAPTURE_OPTIONS: `rtsp_transport;${useUdp ? "udp" : "tcp"}`, }; // If proxy is configured, set up the environment @@ -70,7 +70,7 @@ class RtspClient extends EventEmitter { // Set buffer size (optional) // this.capture.set(cv.CAP_PROP_BUFFERSIZE, 3); } catch (error) { - console.error('Error opening video capture:', error); + console.error("Error opening video capture:", error); throw error; } } @@ -80,7 +80,7 @@ class RtspClient extends EventEmitter { */ private async *streamBlocking(): AsyncGenerator { if (!this.capture) { - throw new Error('Video capture not initialized'); + throw new Error("Video capture not initialized"); } while (true) { @@ -90,16 +90,16 @@ class RtspClient extends EventEmitter { if (!frame.empty) { yield frame; } else { - console.log('Received empty frame'); + console.log("Received empty frame"); break; } } else { - console.log('Stream closed'); + console.log("Stream closed"); this.capture = null; return; } } catch (error) { - console.error('Error reading frame:', error); + console.error("Error reading frame:", error); this.capture?.release(); this.capture = null; return; @@ -112,7 +112,7 @@ class RtspClient extends EventEmitter { */ private async streamNonBlocking(): Promise { if (!this.callback || !this.capture) { - throw new Error('Callback not set or video capture not initialized'); + throw new Error("Callback not set or video capture not initialized"); } const processFrame = async (): Promise => { @@ -127,11 +127,11 @@ class RtspClient extends EventEmitter { // Schedule next frame processing setImmediate(processFrame); } else { - console.log('Stream is closed'); + console.log("Stream is closed"); this.stopStream(); } } catch (error) { - console.error('Error in non-blocking stream:', error); + console.error("Error in non-blocking stream:", error); this.stopStream(); } }; @@ -161,7 +161,7 @@ class RtspClient extends EventEmitter { this.openVideoCapture(); } - console.log('Opening stream'); + console.log("Opening stream"); this.threadCancelled = false; if (!this.callback) { diff --git a/tsconfig.json b/tsconfig.json index 57993f9..0bb763c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,37 +29,17 @@ // "noUnusedLocals": true, // "noUnusedParameters": true, "target": "ES2022", - "lib": [ - "ES2023", - "DOM" - ], + "lib": ["ES2023", "DOM"], "sourceMap": true, "inlineSourceMap": false, - "types": [ - "vitest/globals" - ], + "types": ["vitest/globals"], "paths": { - "@mixins/*": [ - "./src/mixins/*" - ], - "@handlers/*": [ - "./src/handlers/*" - ], - "@interfaces/*": [ - "./src/interfaces/*" - ], - "@utils/*": [ - "./src/utils/*" - ] + "@mixins/*": ["./src/mixins/*"], + "@handlers/*": ["./src/handlers/*"], + "@interfaces/*": ["./src/interfaces/*"], + "@utils/*": ["./src/utils/*"] } }, - "include": [ - "src/**/*.ts", - "eslint.config.mjs", - "vitest.config.mjs" - ], - "exclude": [ - "build/**", - "node_modules/**" - ] -} \ No newline at end of file + "include": ["src/**/*.ts", "eslint.config.mjs", "vitest.config.mjs"], + "exclude": ["build/**", "node_modules/**"] +} diff --git a/vitest.config.mjs b/vitest.config.mjs index bee75de..cc97433 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -1,5 +1,5 @@ -import tsconfigPaths from 'vite-tsconfig-paths'; -import { defineConfig } from 'vitest/config'; +import tsconfigPaths from "vite-tsconfig-paths"; +import { defineConfig } from "vitest/config"; export default defineConfig({ test: { From e6e01068536e0ec8c8a91506666ff0a4fe0418df Mon Sep 17 00:00:00 2001 From: "Jared.K" <3268576+jaredkotoff@users.noreply.github.com> Date: Tue, 22 Oct 2024 08:54:11 -0700 Subject: [PATCH 2/2] add vscode plugin suggestion --- .github/workflows/restyled.yml | 2 +- .prettierrc | 4 +- .vscode/extensions.json | 3 +- eslint.config.mjs | 54 ++-- examples/response/GetEnc.json | 276 +++------------------ examples/response/GetOsd.json | 2 +- examples/response/GetPtzCheckState.json | 6 +- examples/response/GetRec.json | 6 +- examples/response/GetUser.json | 5 +- examples/response/PtzCheck.json | 2 +- examples/response/PtzCtrl.json | 14 +- examples/response/Reboot.json | 12 +- examples/response/SetAdvImageSettings.json | 15 +- examples/response/SetImageSettings.json | 15 +- examples/response/SetPtzPreset.json | 15 +- src/camera.test.ts | 24 +- src/camera.ts | 14 +- src/handlers/apiHandler.ts | 30 +-- src/handlers/baseApiHandler.ts | 34 +-- src/handlers/restHandler.ts | 12 +- src/index.ts | 2 +- src/interfaces/CommandData.ts | 30 +-- src/mixins/alarm.ts | 12 +- src/mixins/device.ts | 24 +- src/mixins/display.ts | 26 +- src/mixins/download.ts | 10 +- src/mixins/image.ts | 22 +- src/mixins/motion.ts | 22 +- src/mixins/network.ts | 62 ++--- src/mixins/nvrdownload.ts | 10 +- src/mixins/ptz.ts | 54 ++-- src/mixins/record.ts | 22 +- src/mixins/stream.ts | 24 +- src/mixins/system.ts | 24 +- src/mixins/user.ts | 32 +-- src/mixins/zoom.ts | 20 +- src/utils/rtspClient.ts | 26 +- vitest.config.mjs | 4 +- 38 files changed, 372 insertions(+), 599 deletions(-) diff --git a/.github/workflows/restyled.yml b/.github/workflows/restyled.yml index 9680cf4..af95c10 100644 --- a/.github/workflows/restyled.yml +++ b/.github/workflows/restyled.yml @@ -31,6 +31,6 @@ jobs: branch: ${{ steps.restyler.outputs.restyled-head }} title: ${{ steps.restyler.outputs.restyled-title }} body: ${{ steps.restyler.outputs.restyled-body }} - labels: "restyled" + labels: 'restyled' reviewers: ${{ github.event.pull_request.user.login }} delete-branch: true diff --git a/.prettierrc b/.prettierrc index 0967ef4..544138b 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1 +1,3 @@ -{} +{ + "singleQuote": true +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index fd1d9bf..c99c624 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,6 @@ { "recommendations": [ - "dbaeumer.vscode-eslint" + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode" ] } \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index 2d5f8ab..5ae1521 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,9 +1,9 @@ -import { FlatCompat } from "@eslint/eslintrc"; -import js from "@eslint/js"; -import tsParser from "@typescript-eslint/parser"; -import eslintConfigPrettier from "eslint-config-prettier"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; +import { FlatCompat } from '@eslint/eslintrc'; +import js from '@eslint/js'; +import tsParser from '@typescript-eslint/parser'; +import eslintConfigPrettier from 'eslint-config-prettier'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -14,26 +14,26 @@ const compat = new FlatCompat({ }); export default [ - ...compat.extends("plugin:@typescript-eslint/recommended"), + ...compat.extends('plugin:@typescript-eslint/recommended'), { plugins: {}, languageOptions: { parser: tsParser, - ecmaVersion: "latest", - sourceType: "module", + ecmaVersion: 'latest', + sourceType: 'module', parserOptions: { - project: "./tsconfig.json", + project: './tsconfig.json', }, }, rules: { - "@typescript-eslint/no-parameter-properties": "off", - "@typescript-eslint/no-explicit-any": "off", + '@typescript-eslint/no-parameter-properties': 'off', + '@typescript-eslint/no-explicit-any': 'off', - "@typescript-eslint/no-use-before-define": [ - "error", + '@typescript-eslint/no-use-before-define': [ + 'error', { functions: false, typedefs: false, @@ -41,35 +41,35 @@ export default [ }, ], - "@typescript-eslint/no-unused-vars": [ - "error", + '@typescript-eslint/no-unused-vars': [ + 'error', { ignoreRestSiblings: true, - argsIgnorePattern: "^_", + argsIgnorePattern: '^_', }, ], - "@typescript-eslint/explicit-function-return-type": [ - "warn", + '@typescript-eslint/explicit-function-return-type': [ + 'warn', { allowExpressions: true, allowTypedFunctionExpressions: true, }, ], - "@typescript-eslint/no-object-literal-type-assertion": "off", - "@typescript-eslint/interface-name-prefix": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "no-var": "error", - "prefer-const": "error", - "no-trailing-spaces": "error", + '@typescript-eslint/no-object-literal-type-assertion': 'off', + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + 'no-var': 'error', + 'prefer-const': 'error', + 'no-trailing-spaces': 'error', }, }, { - files: ["**/*.test.ts"], + files: ['**/*.test.ts'], rules: { - "@typescript-eslint/explicit-function-return-type": "off", + '@typescript-eslint/explicit-function-return-type': 'off', }, }, eslintConfigPrettier, diff --git a/examples/response/GetEnc.json b/examples/response/GetEnc.json index 547ed6f..721c42f 100644 --- a/examples/response/GetEnc.json +++ b/examples/response/GetEnc.json @@ -25,331 +25,115 @@ { "audio": "boolean", "mainStream": { - "bitRate": [ - 1024, - 1536, - 2048, - 3072, - 4096, - 5120, - 6144, - 7168, - 8192 - ], + "bitRate": [1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192], "default": { "bitRate": 4096, "frameRate": 15 }, - "frameRate": [ - 20, - 18, - 16, - 15, - 12, - 10, - 8, - 6, - 4, - 2 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [20, 18, 16, 15, 12, 10, 8, 6, 4, 2], + "profile": ["Base", "Main", "High"], "size": "3072*1728" }, "subStream": { - "bitRate": [ - 64, - 128, - 160, - 192, - 256, - 384, - 512 - ], + "bitRate": [64, 128, 160, 192, 256, 384, 512], "default": { "bitRate": 160, "frameRate": 7 }, - "frameRate": [ - 15, - 10, - 7, - 4 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [15, 10, 7, 4], + "profile": ["Base", "Main", "High"], "size": "640*360" } }, { "audio": "boolean", "mainStream": { - "bitRate": [ - 1024, - 1536, - 2048, - 3072, - 4096, - 5120, - 6144, - 7168, - 8192 - ], + "bitRate": [1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192], "default": { "bitRate": 4096, "frameRate": 15 }, - "frameRate": [ - 20, - 18, - 16, - 15, - 12, - 10, - 8, - 6, - 4, - 2 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [20, 18, 16, 15, 12, 10, 8, 6, 4, 2], + "profile": ["Base", "Main", "High"], "size": "2592*1944" }, "subStream": { - "bitRate": [ - 64, - 128, - 160, - 192, - 256, - 384, - 512 - ], + "bitRate": [64, 128, 160, 192, 256, 384, 512], "default": { "bitRate": 160, "frameRate": 7 }, - "frameRate": [ - 15, - 10, - 7, - 4 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [15, 10, 7, 4], + "profile": ["Base", "Main", "High"], "size": "640*360" } }, { "audio": "boolean", "mainStream": { - "bitRate": [ - 1024, - 1536, - 2048, - 3072, - 4096, - 5120, - 6144, - 7168, - 8192 - ], + "bitRate": [1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192], "default": { "bitRate": 3072, "frameRate": 15 }, - "frameRate": [ - 30, - 22, - 20, - 18, - 16, - 15, - 12, - 10, - 8, - 6, - 4, - 2 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2], + "profile": ["Base", "Main", "High"], "size": "2560*1440" }, "subStream": { - "bitRate": [ - 64, - 128, - 160, - 192, - 256, - 384, - 512 - ], + "bitRate": [64, 128, 160, 192, 256, 384, 512], "default": { "bitRate": 160, "frameRate": 7 }, - "frameRate": [ - 15, - 10, - 7, - 4 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [15, 10, 7, 4], + "profile": ["Base", "Main", "High"], "size": "640*360" } }, { "audio": "boolean", "mainStream": { - "bitRate": [ - 1024, - 1536, - 2048, - 3072, - 4096, - 5120, - 6144, - 7168, - 8192 - ], + "bitRate": [1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192], "default": { "bitRate": 3072, "frameRate": 15 }, - "frameRate": [ - 30, - 22, - 20, - 18, - 16, - 15, - 12, - 10, - 8, - 6, - 4, - 2 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2], + "profile": ["Base", "Main", "High"], "size": "2048*1536" }, "subStream": { - "bitRate": [ - 64, - 128, - 160, - 192, - 256, - 384, - 512 - ], + "bitRate": [64, 128, 160, 192, 256, 384, 512], "default": { "bitRate": 160, "frameRate": 7 }, - "frameRate": [ - 15, - 10, - 7, - 4 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [15, 10, 7, 4], + "profile": ["Base", "Main", "High"], "size": "640*360" } }, { "audio": "boolean", "mainStream": { - "bitRate": [ - 1024, - 1536, - 2048, - 3072, - 4096, - 5120, - 6144, - 7168, - 8192 - ], + "bitRate": [1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192], "default": { "bitRate": 3072, "frameRate": 15 }, - "frameRate": [ - 30, - 22, - 20, - 18, - 16, - 15, - 12, - 10, - 8, - 6, - 4, - 2 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2], + "profile": ["Base", "Main", "High"], "size": "2304*1296" }, "subStream": { - "bitRate": [ - 64, - 128, - 160, - 192, - 256, - 384, - 512 - ], + "bitRate": [64, 128, 160, 192, 256, 384, 512], "default": { "bitRate": 160, "frameRate": 7 }, - "frameRate": [ - 15, - 10, - 7, - 4 - ], - "profile": [ - "Base", - "Main", - "High" - ], + "frameRate": [15, 10, 7, 4], + "profile": ["Base", "Main", "High"], "size": "640*360" } } diff --git a/examples/response/GetOsd.json b/examples/response/GetOsd.json index e925b90..fb2bbd4 100644 --- a/examples/response/GetOsd.json +++ b/examples/response/GetOsd.json @@ -64,4 +64,4 @@ } } } -] \ No newline at end of file +] diff --git a/examples/response/GetPtzCheckState.json b/examples/response/GetPtzCheckState.json index 55386ec..dee84ec 100644 --- a/examples/response/GetPtzCheckState.json +++ b/examples/response/GetPtzCheckState.json @@ -6,11 +6,7 @@ "PtzCheckState": 2 }, "range": { - "PtzCheckState": [ - 0, - 1, - 2 - ] + "PtzCheckState": [0, 1, 2] }, "value": { "PtzCheckState": 2 diff --git a/examples/response/GetRec.json b/examples/response/GetRec.json index 623c353..c8cac97 100644 --- a/examples/response/GetRec.json +++ b/examples/response/GetRec.json @@ -18,11 +18,7 @@ "Rec": { "channel": 0, "overwrite": "boolean", - "postRec": [ - "15 Seconds", - "30 Seconds", - "1 Minute" - ], + "postRec": ["15 Seconds", "30 Seconds", "1 Minute"], "preRec": "boolean", "schedule": { "enable": "boolean" diff --git a/examples/response/GetUser.json b/examples/response/GetUser.json index d3d77e7..af964ea 100644 --- a/examples/response/GetUser.json +++ b/examples/response/GetUser.json @@ -9,10 +9,7 @@ }, "range": { "User": { - "level": [ - "guest", - "admin" - ], + "level": ["guest", "admin"], "password": { "maxLen": 31, "minLen": 6 diff --git a/examples/response/PtzCheck.json b/examples/response/PtzCheck.json index 8274769..c2e3d48 100644 --- a/examples/response/PtzCheck.json +++ b/examples/response/PtzCheck.json @@ -1 +1 @@ -[{"cmd": "PtzCheck", "code": 0, "value": {"rspCode": 200}}] \ No newline at end of file +[{ "cmd": "PtzCheck", "code": 0, "value": { "rspCode": 200 } }] diff --git a/examples/response/PtzCtrl.json b/examples/response/PtzCtrl.json index fa8e1fb..516838b 100644 --- a/examples/response/PtzCtrl.json +++ b/examples/response/PtzCtrl.json @@ -1,9 +1,9 @@ [ - { - "cmd" : "PtzCtrl", - "code" : 0, - "value" : { - "rspCode" : 200 - } + { + "cmd": "PtzCtrl", + "code": 0, + "value": { + "rspCode": 200 } - ] \ No newline at end of file + } +] diff --git a/examples/response/Reboot.json b/examples/response/Reboot.json index eb10195..0f00c3a 100644 --- a/examples/response/Reboot.json +++ b/examples/response/Reboot.json @@ -1,9 +1,9 @@ [ - { - "cmd": "Reboot", - "code": 0, - "value": { - "rspCode": 200 - } + { + "cmd": "Reboot", + "code": 0, + "value": { + "rspCode": 200 } + } ] diff --git a/examples/response/SetAdvImageSettings.json b/examples/response/SetAdvImageSettings.json index 780adf3..d1d6f0d 100644 --- a/examples/response/SetAdvImageSettings.json +++ b/examples/response/SetAdvImageSettings.json @@ -1,10 +1,9 @@ [ - { - "cmd" : "SetIsp", - "code" : 0, - "value" : { - "rspCode" : 200 - } + { + "cmd": "SetIsp", + "code": 0, + "value": { + "rspCode": 200 } - ] - \ No newline at end of file + } +] diff --git a/examples/response/SetImageSettings.json b/examples/response/SetImageSettings.json index 26ef93d..daa1bba 100644 --- a/examples/response/SetImageSettings.json +++ b/examples/response/SetImageSettings.json @@ -1,10 +1,9 @@ [ - { - "cmd" : "SetImage", - "code" : 0, - "value" : { - "rspCode" : 200 - } + { + "cmd": "SetImage", + "code": 0, + "value": { + "rspCode": 200 } - ] - \ No newline at end of file + } +] diff --git a/examples/response/SetPtzPreset.json b/examples/response/SetPtzPreset.json index 84121bc..781f96e 100644 --- a/examples/response/SetPtzPreset.json +++ b/examples/response/SetPtzPreset.json @@ -1,10 +1,9 @@ [ - { - "cmd" : "SetPtzPreset", - "code" : 0, - "value" : { - "rspCode" : 200 - } + { + "cmd": "SetPtzPreset", + "code": 0, + "value": { + "rspCode": 200 } - ] - \ No newline at end of file + } +] diff --git a/src/camera.test.ts b/src/camera.test.ts index 4a6b213..9809d24 100644 --- a/src/camera.test.ts +++ b/src/camera.test.ts @@ -1,8 +1,8 @@ -import "dotenv/config"; -import { existsSync } from "fs"; -import { mkdirp } from "mkdirp"; -import { beforeAll, beforeEach, describe, expect, test } from "vitest"; -import Camera from "./camera"; +import 'dotenv/config'; +import { existsSync } from 'fs'; +import { mkdirp } from 'mkdirp'; +import { beforeAll, beforeEach, describe, expect, test } from 'vitest'; +import Camera from './camera'; interface CameraConfig { camera: { @@ -13,7 +13,7 @@ interface CameraConfig { }; } -describe("Camera", () => { +describe('Camera', () => { let config: CameraConfig; let cam: Camera; @@ -23,7 +23,7 @@ describe("Camera", () => { ip: process.env.CAMERA_IP, username: process.env.CAMERA_USERNAME, password: process.env.CAMERA_PASSWORD, - https: process.env.CAMERA_HTTPS === "true" ? true : false, + https: process.env.CAMERA_HTTPS === 'true' ? true : false, }, } as CameraConfig; }); @@ -37,16 +37,16 @@ describe("Camera", () => { ); }); - test("camera connects and gets a token", () => { - expect(cam["ip"]).toBe(config.camera.ip); - expect(cam["token"]).not.toBe(""); + test('camera connects and gets a token', () => { + expect(cam['ip']).toBe(config.camera.ip); + expect(cam['token']).not.toBe(''); }); - test("snapshot functionality", async () => { + test('snapshot functionality', async () => { const img = await cam.getSnap(); // Ensure the directory exists - const outputPath = "../tmp/snaps/"; + const outputPath = '../tmp/snaps/'; await mkdirp(outputPath); const outputFilePath = `${outputPath}camera.jpg`; diff --git a/src/camera.ts b/src/camera.ts index df8c655..d31b433 100644 --- a/src/camera.ts +++ b/src/camera.ts @@ -1,19 +1,19 @@ -import APIHandler from "@handlers/apiHandler"; -import { AxiosInstance, AxiosRequestConfig } from "axios"; +import APIHandler from '@handlers/apiHandler'; +import { AxiosInstance, AxiosRequestConfig } from 'axios'; class Camera extends APIHandler { protected profile: string; constructor( ip: string, - username: string = "admin", - password: string = "", + username: string = 'admin', + password: string = '', https: boolean = false, deferLogin: boolean = false, - profile: string = "main", - options?: { proxy?: AxiosRequestConfig["proxy"]; session?: AxiosInstance }, + profile: string = 'main', + options?: { proxy?: AxiosRequestConfig['proxy']; session?: AxiosInstance }, ) { - if (!["main", "sub"].includes(profile)) { + if (!['main', 'sub'].includes(profile)) { throw new Error('Profile argument must be either "main" or "sub"'); } super(ip, username, password, https, options); diff --git a/src/handlers/apiHandler.ts b/src/handlers/apiHandler.ts index 5a1656f..4cb5ddf 100644 --- a/src/handlers/apiHandler.ts +++ b/src/handlers/apiHandler.ts @@ -1,18 +1,18 @@ -import AlarmAPIMixin from "@mixins/alarm"; -import DeviceAPIMixin from "@mixins/device"; -import DisplayAPIMixin from "@mixins/display"; -import DownloadAPIMixin from "@mixins/download"; -import ImageAPIMixin from "@mixins/image"; -import MotionAPIMixin from "@mixins/motion"; -import NetworkAPIMixin from "@mixins/network"; -import NvrDownloadAPIMixin from "@mixins/nvrdownload"; -import PtzAPIMixin from "@mixins/ptz"; -import RecordAPIMixin from "@mixins/record"; -import StreamAPIMixin from "@mixins/stream"; -import SystemAPIMixin from "@mixins/system"; -import UserAPIMixin from "@mixins/user"; -import ZoomAPIMixin from "@mixins/zoom"; -import { Mixin } from "ts-mixer"; +import AlarmAPIMixin from '@mixins/alarm'; +import DeviceAPIMixin from '@mixins/device'; +import DisplayAPIMixin from '@mixins/display'; +import DownloadAPIMixin from '@mixins/download'; +import ImageAPIMixin from '@mixins/image'; +import MotionAPIMixin from '@mixins/motion'; +import NetworkAPIMixin from '@mixins/network'; +import NvrDownloadAPIMixin from '@mixins/nvrdownload'; +import PtzAPIMixin from '@mixins/ptz'; +import RecordAPIMixin from '@mixins/record'; +import StreamAPIMixin from '@mixins/stream'; +import SystemAPIMixin from '@mixins/system'; +import UserAPIMixin from '@mixins/user'; +import ZoomAPIMixin from '@mixins/zoom'; +import { Mixin } from 'ts-mixer'; class _APIHandler extends Mixin( AlarmAPIMixin, diff --git a/src/handlers/baseApiHandler.ts b/src/handlers/baseApiHandler.ts index 2dcd884..3b20a01 100644 --- a/src/handlers/baseApiHandler.ts +++ b/src/handlers/baseApiHandler.ts @@ -1,7 +1,7 @@ -import CommandData from "@interfaces/CommandData"; -import axios, { AxiosInstance, AxiosRequestConfig } from "axios"; -import fs from "fs"; -import Request from "./restHandler"; +import CommandData from '@interfaces/CommandData'; +import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; +import fs from 'fs'; +import Request from './restHandler'; interface LoginResponse { code: string; @@ -24,9 +24,9 @@ class BaseAPIHandler { username: string, password: string, https: boolean = false, - options?: { proxy?: AxiosRequestConfig["proxy"]; session?: AxiosInstance }, + options?: { proxy?: AxiosRequestConfig['proxy']; session?: AxiosInstance }, ) { - const scheme = https ? "https" : "http"; + const scheme = https ? 'https' : 'http'; this.url = `${scheme}://${ip}/cgi-bin/api.cgi`; this.ip = ip; this.username = username; @@ -39,7 +39,7 @@ class BaseAPIHandler { try { const body: CommandData[] = [ { - cmd: "Login", + cmd: 'Login', action: 0, param: { User: { @@ -50,32 +50,32 @@ class BaseAPIHandler { }, ]; - const param = { cmd: "Login", token: "null" }; + const param = { cmd: 'Login', token: 'null' }; const response = await Request.post(this.url, body, param); const data: LoginResponse = response?.data[0]; if (parseInt(data.code) === 0) { this.token = data.value.Token.name; - console.log("Login success"); + console.log('Login success'); return true; } else { - console.log("Failed to login"); + console.log('Failed to login'); return false; } } catch (error) { - console.error("Error during login:", error); + console.error('Error during login:', error); return false; } } async logout(): Promise { try { - const data: CommandData[] = [{ cmd: "Logout", action: 0 }]; - await this.executeCommand("Logout", data); + const data: CommandData[] = [{ cmd: 'Logout', action: 0 }]; + await this.executeCommand('Logout', data); return true; } catch (error) { - console.error("Error during logout:", error); + console.error('Error during logout:', error); return false; } } @@ -86,7 +86,7 @@ class BaseAPIHandler { multi: boolean = false, ): Promise { if (!this.token) { - throw new Error("Login first"); + throw new Error('Login first'); } const params: any = { token: this.token, cmd: command }; @@ -95,11 +95,11 @@ class BaseAPIHandler { } try { - if (command === "Download") { + if (command === 'Download') { const tgtFilePath = data[0].filepath; const response = await axios.get(this.url, { params, - responseType: "stream", + responseType: 'stream', proxy: Request.proxies, }); diff --git a/src/handlers/restHandler.ts b/src/handlers/restHandler.ts index 351ef45..5fa73df 100644 --- a/src/handlers/restHandler.ts +++ b/src/handlers/restHandler.ts @@ -1,12 +1,12 @@ -import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; -import https from "https"; +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; +import https from 'https'; interface RequestParams { [key: string]: string | number | undefined; } class Request { - static proxies: AxiosRequestConfig["proxy"] = undefined; + static proxies: AxiosRequestConfig['proxy'] = undefined; static session: AxiosInstance | undefined = undefined; private static getSession(): AxiosInstance { @@ -19,7 +19,7 @@ class Request { params: RequestParams = {}, ): Promise { try { - const headers = { "Content-Type": "application/json" }; + const headers = { 'Content-Type': 'application/json' }; const response = await Request.getSession().post(url, data, { headers, params, @@ -33,7 +33,7 @@ class Request { throw new Error(`HTTP Request had non-200 Status: ${response.status}`); } } catch (error) { - console.error("Post Error\n", error); + console.error('Post Error\n', error); throw error; } } @@ -53,7 +53,7 @@ class Request { return response; } catch (error) { - console.error("Get Error\n", error); + console.error('Get Error\n', error); throw error; } } diff --git a/src/index.ts b/src/index.ts index 69973ca..a7ed3d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export { default as Camera } from "./camera"; +export { default as Camera } from './camera'; diff --git a/src/interfaces/CommandData.ts b/src/interfaces/CommandData.ts index 6b6be6d..37ab968 100644 --- a/src/interfaces/CommandData.ts +++ b/src/interfaces/CommandData.ts @@ -1,16 +1,16 @@ -import { AlarmAPIMixinParams } from "../mixins/alarm"; -import { DeviceAPIMixinParams } from "../mixins/device"; -import { SetOsdParams } from "../mixins/display"; -import { SetImageParams, SetIspParams } from "../mixins/image"; -import { SearchParams } from "../mixins/motion"; +import { AlarmAPIMixinParams } from '../mixins/alarm'; +import { DeviceAPIMixinParams } from '../mixins/device'; +import { SetOsdParams } from '../mixins/display'; +import { SetImageParams, SetIspParams } from '../mixins/image'; +import { SearchParams } from '../mixins/motion'; import { SetLocalLinkParams, SetNetPortParams, SetWifiParams, -} from "../mixins/network"; -import { NvrDownloadParams } from "../mixins/nvrdownload"; -import { SetEncParams } from "../mixins/record"; -import { DelUserParams } from "../mixins/user"; +} from '../mixins/network'; +import { NvrDownloadParams } from '../mixins/nvrdownload'; +import { SetEncParams } from '../mixins/record'; +import { DelUserParams } from '../mixins/user'; type CommandDataParam = { channel?: number; @@ -48,10 +48,10 @@ export default interface CommandData { } export enum OsdPos { - "Upper Left", - "Top Center", - "Upper Right", - "Lower Left", - "Bottom Center", - "Lower Right", + 'Upper Left', + 'Top Center', + 'Upper Right', + 'Lower Left', + 'Bottom Center', + 'Lower Right', } diff --git a/src/mixins/alarm.ts b/src/mixins/alarm.ts index 4495237..8c2eda7 100644 --- a/src/mixins/alarm.ts +++ b/src/mixins/alarm.ts @@ -1,6 +1,6 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; -import { Mixin } from "ts-mixer"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; +import { Mixin } from 'ts-mixer'; interface AlarmResponse { // Define the structure of the response if known, use any if the structure is dynamic @@ -23,17 +23,17 @@ export default class AlarmAPIMixin extends Mixin(BaseAPIHandler) { */ const body: CommandData[] = [ { - cmd: "GetAlarm", + cmd: 'GetAlarm', action: 1, param: { Alarm: { channel: 0, - type: "md", // 'md' indicates motion detection + type: 'md', // 'md' indicates motion detection }, }, }, ]; - return this.executeCommand("GetAlarm", body); + return this.executeCommand('GetAlarm', body); } } diff --git a/src/mixins/device.ts b/src/mixins/device.ts index 57a42f5..5e9d067 100644 --- a/src/mixins/device.ts +++ b/src/mixins/device.ts @@ -1,6 +1,6 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; -import { Mixin } from "ts-mixer"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; +import { Mixin } from 'ts-mixer'; export interface DeviceAPIMixinParams { DevName?: { name: string }; @@ -12,36 +12,36 @@ export default class DeviceAPIMixin extends Mixin(BaseAPIHandler) { async setDeviceName(name: string): Promise { const body: CommandData[] = [ - { cmd: "SetDevName", action: 0, param: { DevName: { name } } }, + { cmd: 'SetDevName', action: 0, param: { DevName: { name } } }, ]; - await this.executeCommand("SetDevName", body); + await this.executeCommand('SetDevName', body); console.log(`Successfully set device name to: ${name}`); return true; } getDeviceName(): Promise { - const body: CommandData[] = [{ cmd: "GetDevName", action: 0, param: {} }]; - return this.executeCommand("GetDevName", body); + const body: CommandData[] = [{ cmd: 'GetDevName', action: 0, param: {} }]; + return this.executeCommand('GetDevName', body); } getHddInfo(): Promise { - const body: CommandData[] = [{ cmd: "GetHddInfo", action: 0, param: {} }]; - return this.executeCommand("GetHddInfo", body); + const body: CommandData[] = [{ cmd: 'GetHddInfo', action: 0, param: {} }]; + return this.executeCommand('GetHddInfo', body); } async formatHdd( hddId: number[] = DeviceAPIMixin.DEFAULT_HDD_ID, ): Promise { const body: CommandData[] = [ - { cmd: "Format", action: 0, param: { HddInfo: { id: hddId } } }, + { cmd: 'Format', action: 0, param: { HddInfo: { id: hddId } } }, ]; - const response = await this.executeCommand("Format", body); + const response = await this.executeCommand('Format', body); const rData = response[0]; if (rData.value.rspCode === 200) { return true; } else { console.log( - "Could not format HDD/SD. Camera responded with:", + 'Could not format HDD/SD. Camera responded with:', rData.value, ); return false; diff --git a/src/mixins/display.ts b/src/mixins/display.ts index c8e62b1..a0aa4ed 100644 --- a/src/mixins/display.ts +++ b/src/mixins/display.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData, { OsdPos } from "../interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData, { OsdPos } from '../interfaces/CommandData'; export interface SetOsdParams { Osd: { @@ -27,9 +27,9 @@ class DisplayAPIMixin extends BaseAPIHandler { * @returns response json */ const body: CommandData[] = [ - { cmd: "GetOsd", action: 1, param: { channel: 0 } }, + { cmd: 'GetOsd', action: 1, param: { channel: 0 } }, ]; - return this.executeCommand("GetOsd", body); + return this.executeCommand('GetOsd', body); } public async getMask(): Promise { @@ -39,19 +39,19 @@ class DisplayAPIMixin extends BaseAPIHandler { * @returns response json */ const body: CommandData[] = [ - { cmd: "GetMask", action: 1, param: { channel: 0 } }, + { cmd: 'GetMask', action: 1, param: { channel: 0 } }, ]; - return this.executeCommand("GetMask", body); + return this.executeCommand('GetMask', body); } public async setOsd( bg_color: boolean = false, channel: number = 0, osd_channel_enabled: boolean = false, - osd_channel_name: string = "", - osd_channel_pos: OsdPos = OsdPos["Lower Right"], + osd_channel_name: string = '', + osd_channel_pos: OsdPos = OsdPos['Lower Right'], osd_time_enabled: boolean = false, - osd_time_pos: OsdPos = OsdPos["Lower Right"], + osd_time_pos: OsdPos = OsdPos['Lower Right'], osd_watermark_enabled: boolean = false, ): Promise { /** @@ -60,7 +60,7 @@ class DisplayAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: "SetOsd", + cmd: 'SetOsd', action: 1, param: { Osd: { @@ -79,18 +79,18 @@ class DisplayAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand("SetOsd", body); + const response = await this.executeCommand('SetOsd', body); const r_data = response[0]; if (r_data?.value?.rspCode === 200) { return true; } console.log( - "Could not set OSD. Camera responded with status:", + 'Could not set OSD. Camera responded with status:', r_data.error, ); return false; } catch (error) { - console.error("Error setting OSD:", error); + console.error('Error setting OSD:', error); return false; } } diff --git a/src/mixins/download.ts b/src/mixins/download.ts index 82ff929..a2951fb 100644 --- a/src/mixins/download.ts +++ b/src/mixins/download.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; class DownloadAPIMixin extends BaseAPIHandler { /** @@ -15,7 +15,7 @@ class DownloadAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: "Download", + cmd: 'Download', action: 0, // action is required in CommandData, but not used in the original Python code source: filename, output: filename, @@ -24,10 +24,10 @@ class DownloadAPIMixin extends BaseAPIHandler { ]; try { - const resp = await this.executeCommand("Download", body); + const resp = await this.executeCommand('Download', body); return resp; } catch (error) { - console.error("Error downloading file:", error); + console.error('Error downloading file:', error); return false; } } diff --git a/src/mixins/image.ts b/src/mixins/image.ts index 3e53776..4226cc8 100644 --- a/src/mixins/image.ts +++ b/src/mixins/image.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; export interface SetImageParams { Image: { @@ -37,17 +37,17 @@ class ImageAPIMixin extends BaseAPIHandler { */ public async setAdvImageSettings( - anti_flicker: string = "Outdoor", - exposure: string = "Auto", + anti_flicker: string = 'Outdoor', + exposure: string = 'Auto', gain_min: number = 1, gain_max: number = 62, shutter_min: number = 1, shutter_max: number = 125, blue_gain: number = 128, red_gain: number = 128, - white_balance: string = "Auto", - day_night: string = "Auto", - back_light: string = "DynamicRangeControl", + white_balance: string = 'Auto', + day_night: string = 'Auto', + back_light: string = 'DynamicRangeControl', blc: number = 128, drc: number = 128, rotation: number = 0, @@ -59,7 +59,7 @@ class ImageAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: "SetIsp", + cmd: 'SetIsp', action: 0, param: { Isp: { @@ -82,7 +82,7 @@ class ImageAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand("SetIsp", body); + return this.executeCommand('SetIsp', body); } public async setImageSettings( @@ -97,7 +97,7 @@ class ImageAPIMixin extends BaseAPIHandler { */ const body: CommandData[] = [ { - cmd: "SetImage", + cmd: 'SetImage', action: 0, param: { Image: { @@ -112,7 +112,7 @@ class ImageAPIMixin extends BaseAPIHandler { }, ]; - return this.executeCommand("SetImage", body); + return this.executeCommand('SetImage', body); } } diff --git a/src/mixins/motion.ts b/src/mixins/motion.ts index 02f4724..36588f0 100644 --- a/src/mixins/motion.ts +++ b/src/mixins/motion.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; export interface SearchParams { Search: { @@ -50,7 +50,7 @@ class MotionAPIMixin extends BaseAPIHandler { public async getMotionFiles( start: Date, end: Date = new Date(), - streamtype: string = "sub", + streamtype: string = 'sub', channel: number = 0, ): Promise { /** @@ -81,11 +81,11 @@ class MotionAPIMixin extends BaseAPIHandler { }; const body: CommandData[] = [ - { cmd: "Search", action: 1, param: searchParams }, + { cmd: 'Search', action: 1, param: searchParams }, ]; try { - const resp = await this.executeCommand("Search", body); + const resp = await this.executeCommand('Search', body); const result = resp[0]?.value?.SearchResult; const files = result?.File || []; if (files.length > 0) { @@ -93,7 +93,7 @@ class MotionAPIMixin extends BaseAPIHandler { } return []; } catch (error) { - console.error("Error getting motion files:", error); + console.error('Error getting motion files:', error); return []; } } @@ -105,14 +105,14 @@ class MotionAPIMixin extends BaseAPIHandler { */ const processedMotions: ProcessedMotionList = []; const replaceFields: { [key: string]: string } = { - mon: "month", - sec: "second", - min: "minute", + mon: 'month', + sec: 'second', + min: 'minute', }; for (const file of motion_files) { const timeRange: { [key: string]: Date } = {}; - for (const x of ["Start", "End"]) { + for (const x of ['Start', 'End']) { const raw = { ...file[`${x}Time`] }; for (const [k, v] of Object.entries(replaceFields)) { if (k in raw) { @@ -121,7 +121,7 @@ class MotionAPIMixin extends BaseAPIHandler { } } // Adjust for JavaScript's 0-indexed months - if ("month" in raw) { + if ('month' in raw) { raw.month -= 1; } timeRange[x.toLowerCase()] = new Date( diff --git a/src/mixins/network.ts b/src/mixins/network.ts index be4ffcb..a9c2794 100644 --- a/src/mixins/network.ts +++ b/src/mixins/network.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; export interface SetLocalLinkParams { LocalLink: { @@ -52,7 +52,7 @@ class NetworkAPIMixin extends BaseAPIHandler { ): Promise { const body: CommandData[] = [ { - cmd: "SetLocalLink", + cmd: 'SetLocalLink', action: 0, param: { LocalLink: { @@ -67,14 +67,14 @@ class NetworkAPIMixin extends BaseAPIHandler { ip: ip, mask: mask, }, - type: useDhcp ? "DHCP" : "Static", + type: useDhcp ? 'DHCP' : 'Static', }, }, }, ]; - const result = await this.executeCommand("SetLocalLink", body); - console.log("Successfully Set Network Settings"); + const result = await this.executeCommand('SetLocalLink', body); + console.log('Successfully Set Network Settings'); return result; } @@ -88,7 +88,7 @@ class NetworkAPIMixin extends BaseAPIHandler { ): Promise { const body: CommandData[] = [ { - cmd: "SetNetPort", + cmd: 'SetNetPort', action: 0, param: { NetPort: { @@ -102,15 +102,15 @@ class NetworkAPIMixin extends BaseAPIHandler { }, }, ]; - await this.executeCommand("SetNetPort", body, true); - console.log("Successfully Set Network Ports"); + await this.executeCommand('SetNetPort', body, true); + console.log('Successfully Set Network Ports'); return true; } public async setWifi(ssid: string, password: string): Promise { const body: CommandData[] = [ { - cmd: "SetWifi", + cmd: 'SetWifi', action: 0, param: { Wifi: { @@ -120,56 +120,56 @@ class NetworkAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand("SetWifi", body); + return this.executeCommand('SetWifi', body); } public async getNetPorts(): Promise { const body: CommandData[] = [ - { cmd: "GetNetPort", action: 1, param: {} }, - { cmd: "GetUpnp", action: 0, param: {} }, - { cmd: "GetP2p", action: 0, param: {} }, + { cmd: 'GetNetPort', action: 1, param: {} }, + { cmd: 'GetUpnp', action: 0, param: {} }, + { cmd: 'GetP2p', action: 0, param: {} }, ]; - return this.executeCommand("GetNetPort", body, true); + return this.executeCommand('GetNetPort', body, true); } public async getWifi(): Promise { - const body: CommandData[] = [{ cmd: "GetWifi", action: 1, param: {} }]; - return this.executeCommand("GetWifi", body); + const body: CommandData[] = [{ cmd: 'GetWifi', action: 1, param: {} }]; + return this.executeCommand('GetWifi', body); } public async scanWifi(): Promise { - const body: CommandData[] = [{ cmd: "ScanWifi", action: 1, param: {} }]; - return this.executeCommand("ScanWifi", body); + const body: CommandData[] = [{ cmd: 'ScanWifi', action: 1, param: {} }]; + return this.executeCommand('ScanWifi', body); } public async getNetworkGeneral(): Promise { - const body: CommandData[] = [{ cmd: "GetLocalLink", action: 0, param: {} }]; - return this.executeCommand("GetLocalLink", body); + const body: CommandData[] = [{ cmd: 'GetLocalLink', action: 0, param: {} }]; + return this.executeCommand('GetLocalLink', body); } public async getNetworkDdns(): Promise { - const body: CommandData[] = [{ cmd: "GetDdns", action: 0, param: {} }]; - return this.executeCommand("GetDdns", body); + const body: CommandData[] = [{ cmd: 'GetDdns', action: 0, param: {} }]; + return this.executeCommand('GetDdns', body); } public async getNetworkNtp(): Promise { - const body: CommandData[] = [{ cmd: "GetNtp", action: 0, param: {} }]; - return this.executeCommand("GetNtp", body); + const body: CommandData[] = [{ cmd: 'GetNtp', action: 0, param: {} }]; + return this.executeCommand('GetNtp', body); } public async getNetworkEmail(): Promise { - const body: CommandData[] = [{ cmd: "GetEmail", action: 0, param: {} }]; - return this.executeCommand("GetEmail", body); + const body: CommandData[] = [{ cmd: 'GetEmail', action: 0, param: {} }]; + return this.executeCommand('GetEmail', body); } public async getNetworkFtp(): Promise { - const body: CommandData[] = [{ cmd: "GetFtp", action: 0, param: {} }]; - return this.executeCommand("GetFtp", body); + const body: CommandData[] = [{ cmd: 'GetFtp', action: 0, param: {} }]; + return this.executeCommand('GetFtp', body); } public async getNetworkPush(): Promise { - const body: CommandData[] = [{ cmd: "GetPush", action: 0, param: {} }]; - return this.executeCommand("GetPush", body); + const body: CommandData[] = [{ cmd: 'GetPush', action: 0, param: {} }]; + return this.executeCommand('GetPush', body); } public async getNetworkStatus(): Promise { diff --git a/src/mixins/nvrdownload.ts b/src/mixins/nvrdownload.ts index 3636b35..f7b3625 100644 --- a/src/mixins/nvrdownload.ts +++ b/src/mixins/nvrdownload.ts @@ -1,5 +1,5 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import CommandData from "@interfaces/CommandData"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import CommandData from '@interfaces/CommandData'; export interface NvrDownloadParams { NvrDownload: { @@ -25,7 +25,7 @@ class NvrDownloadAPIMixin extends BaseAPIHandler { start: Date, end: Date = new Date(), channel: number = 0, - streamType: string = "sub", + streamType: string = 'sub', ): Promise { const searchParams: NvrDownloadParams = { NvrDownload: { @@ -38,11 +38,11 @@ class NvrDownloadAPIMixin extends BaseAPIHandler { }; const body: CommandData[] = [ - { cmd: "NvrDownload", action: 1, param: searchParams }, + { cmd: 'NvrDownload', action: 1, param: searchParams }, ]; try { - const resp = (await this.executeCommand("NvrDownload", body))[0]; + const resp = (await this.executeCommand('NvrDownload', body))[0]; if (!resp.value?.fileList) { return []; } diff --git a/src/mixins/ptz.ts b/src/mixins/ptz.ts index b8fe714..b86de87 100644 --- a/src/mixins/ptz.ts +++ b/src/mixins/ptz.ts @@ -1,21 +1,21 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; +import BaseAPIHandler from '@handlers/baseApiHandler'; class PtzAPIMixin extends BaseAPIHandler { async getPtzCheckState(): Promise> { const body = [ - { cmd: "GetPtzCheckState", action: 1, param: { channel: 0 } }, + { cmd: 'GetPtzCheckState', action: 1, param: { channel: 0 } }, ]; - return this.executeCommand("GetPtzCheckState", body); + return this.executeCommand('GetPtzCheckState', body); } async getPtzPresets(): Promise> { - const body = [{ cmd: "GetPtzPreset", action: 1, param: { channel: 0 } }]; - return this.executeCommand("GetPtzPreset", body); + const body = [{ cmd: 'GetPtzPreset', action: 1, param: { channel: 0 } }]; + return this.executeCommand('GetPtzPreset', body); } async performCalibration(): Promise> { - const data = [{ cmd: "PtzCheck", action: 0, param: { channel: 0 } }]; - return this.executeCommand("PtzCheck", data); + const data = [{ cmd: 'PtzCheck', action: 0, param: { channel: 0 } }]; + return this.executeCommand('PtzCheck', data); } private async sendOperation( @@ -31,93 +31,93 @@ class PtzAPIMixin extends BaseAPIHandler { if (index !== undefined) { param.id = index; } - const data = [{ cmd: "PtzCtrl", action: 0, param }]; - return this.executeCommand("PtzCtrl", data); + const data = [{ cmd: 'PtzCtrl', action: 0, param }]; + return this.executeCommand('PtzCtrl', data); } private async sendNoparmOperation( operation: string, ): Promise> { const data = [ - { cmd: "PtzCtrl", action: 0, param: { channel: 0, op: operation } }, + { cmd: 'PtzCtrl', action: 0, param: { channel: 0, op: operation } }, ]; - return this.executeCommand("PtzCtrl", data); + return this.executeCommand('PtzCtrl', data); } private async sendSetPreset( enable: number, preset: number = 1, - name: string = "pos1", + name: string = 'pos1', ): Promise> { const data = [ { - cmd: "SetPtzPreset", + cmd: 'SetPtzPreset', action: 0, param: { channel: 0, enable, id: preset, name }, }, ]; - return this.executeCommand("PtzCtrl", data); + return this.executeCommand('PtzCtrl', data); } async goToPreset( speed: number = 60, index: number = 1, ): Promise> { - return this.sendOperation("ToPos", speed, index); + return this.sendOperation('ToPos', speed, index); } async addPreset( preset: number = 1, - name: string = "pos1", + name: string = 'pos1', ): Promise> { return this.sendSetPreset(1, preset, name); } async removePreset( preset: number = 1, - name: string = "pos1", + name: string = 'pos1', ): Promise> { return this.sendSetPreset(0, preset, name); } async moveRight(speed: number = 25): Promise> { - return this.sendOperation("Right", speed); + return this.sendOperation('Right', speed); } async moveRightUp(speed: number = 25): Promise> { - return this.sendOperation("RightUp", speed); + return this.sendOperation('RightUp', speed); } async moveRightDown(speed: number = 25): Promise> { - return this.sendOperation("RightDown", speed); + return this.sendOperation('RightDown', speed); } async moveLeft(speed: number = 25): Promise> { - return this.sendOperation("Left", speed); + return this.sendOperation('Left', speed); } async moveLeftUp(speed: number = 25): Promise> { - return this.sendOperation("LeftUp", speed); + return this.sendOperation('LeftUp', speed); } async moveLeftDown(speed: number = 25): Promise> { - return this.sendOperation("LeftDown", speed); + return this.sendOperation('LeftDown', speed); } async moveUp(speed: number = 25): Promise> { - return this.sendOperation("Up", speed); + return this.sendOperation('Up', speed); } async moveDown(speed: number = 25): Promise> { - return this.sendOperation("Down", speed); + return this.sendOperation('Down', speed); } async stopPtz(): Promise> { - return this.sendNoparmOperation("Stop"); + return this.sendNoparmOperation('Stop'); } async autoMovement(speed: number = 25): Promise> { - return this.sendOperation("Auto", speed); + return this.sendOperation('Auto', speed); } } diff --git a/src/mixins/record.ts b/src/mixins/record.ts index 4dcff71..5e83a91 100644 --- a/src/mixins/record.ts +++ b/src/mixins/record.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; +import BaseAPIHandler from '@handlers/baseApiHandler'; export interface SetEncParams { Enc: { @@ -21,29 +21,29 @@ export interface SetEncParams { class RecordAPIMixin extends BaseAPIHandler { async getRecordingEncoding(): Promise> { - const body = [{ cmd: "GetEnc", action: 1, param: { channel: 0 } }]; - return this.executeCommand("GetEnc", body); + const body = [{ cmd: 'GetEnc', action: 1, param: { channel: 0 } }]; + return this.executeCommand('GetEnc', body); } async getRecordingAdvanced(): Promise> { - const body = [{ cmd: "GetRec", action: 1, param: { channel: 0 } }]; - return this.executeCommand("GetRec", body); + const body = [{ cmd: 'GetRec', action: 1, param: { channel: 0 } }]; + return this.executeCommand('GetRec', body); } async setRecordingEncoding( audio: number = 0, mainBitRate: number = 8192, mainFrameRate: number = 8, - mainProfile: string = "High", - mainSize: string = "2560*1440", + mainProfile: string = 'High', + mainSize: string = '2560*1440', subBitRate: number = 160, subFrameRate: number = 7, - subProfile: string = "High", - subSize: string = "640*480", + subProfile: string = 'High', + subSize: string = '640*480', ): Promise> { const body = [ { - cmd: "SetEnc", + cmd: 'SetEnc', action: 0, param: { Enc: { @@ -65,7 +65,7 @@ class RecordAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand("SetEnc", body); + return this.executeCommand('SetEnc', body); } } diff --git a/src/mixins/stream.ts b/src/mixins/stream.ts index c9c7b91..136c415 100644 --- a/src/mixins/stream.ts +++ b/src/mixins/stream.ts @@ -1,8 +1,8 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; -import { Mat } from "@u4/opencv4nodejs"; -import RtspClient from "@utils/rtspClient"; -import axios from "axios"; -import sharp from "sharp"; +import BaseAPIHandler from '@handlers/baseApiHandler'; +import { Mat } from '@u4/opencv4nodejs'; +import RtspClient from '@utils/rtspClient'; +import axios from 'axios'; +import sharp from 'sharp'; // Type definitions interface ProxyConfig { @@ -24,7 +24,7 @@ interface SnapParams { * API calls for opening a video stream or capturing an image from the camera. */ class StreamAPIMixin extends BaseAPIHandler { - protected profile: string = "main"; // Add this property if not in BaseAPIHandler + protected profile: string = 'main'; // Add this property if not in BaseAPIHandler /** * Generates a random string for request parameters @@ -32,11 +32,11 @@ class StreamAPIMixin extends BaseAPIHandler { * @returns Random string of specified length */ private generateRandomString(length: number): string { - const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; return Array.from( { length }, () => characters[Math.floor(Math.random() * characters.length)], - ).join(""); + ).join(''); } /** @@ -73,7 +73,7 @@ class StreamAPIMixin extends BaseAPIHandler { proxies?: ProxyConfig, ): Promise { const params: SnapParams = { - cmd: "Snap", + cmd: 'Snap', channel: 0, rs: this.generateRandomString(10), user: this.username, @@ -85,7 +85,7 @@ class StreamAPIMixin extends BaseAPIHandler { params, proxy: proxies, timeout: timeout * 1000, // Convert to milliseconds - responseType: "arraybuffer", + responseType: 'arraybuffer', }); if (response.status === 200) { @@ -93,12 +93,12 @@ class StreamAPIMixin extends BaseAPIHandler { } console.log( - "Could not retrieve data from camera successfully. Status:", + 'Could not retrieve data from camera successfully. Status:', response.status, ); return null; } catch (error) { - console.error("Could not get Image data\n", error); + console.error('Could not get Image data\n', error); throw error; } } diff --git a/src/mixins/system.ts b/src/mixins/system.ts index 903db53..26d9c81 100644 --- a/src/mixins/system.ts +++ b/src/mixins/system.ts @@ -1,32 +1,32 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; +import BaseAPIHandler from '@handlers/baseApiHandler'; class SystemAPIMixin extends BaseAPIHandler { async getGeneralSystem(): Promise> { const body = [ - { cmd: "GetTime", action: 1, param: {} }, - { cmd: "GetNorm", action: 1, param: {} }, + { cmd: 'GetTime', action: 1, param: {} }, + { cmd: 'GetNorm', action: 1, param: {} }, ]; - return this.executeCommand("get_general_system", body, true); + return this.executeCommand('get_general_system', body, true); } async getPerformance(): Promise> { - const body = [{ cmd: "GetPerformance", action: 0, param: {} }]; - return this.executeCommand("GetPerformance", body); + const body = [{ cmd: 'GetPerformance', action: 0, param: {} }]; + return this.executeCommand('GetPerformance', body); } async getInformation(): Promise> { - const body = [{ cmd: "GetDevInfo", action: 0, param: {} }]; - return this.executeCommand("GetDevInfo", body); + const body = [{ cmd: 'GetDevInfo', action: 0, param: {} }]; + return this.executeCommand('GetDevInfo', body); } async rebootCamera(): Promise> { - const body = [{ cmd: "Reboot", action: 0, param: {} }]; - return this.executeCommand("Reboot", body); + const body = [{ cmd: 'Reboot', action: 0, param: {} }]; + return this.executeCommand('Reboot', body); } async getDst(): Promise> { - const body = [{ cmd: "GetTime", action: 0, param: {} }]; - return this.executeCommand("GetTime", body); + const body = [{ cmd: 'GetTime', action: 0, param: {} }]; + return this.executeCommand('GetTime', body); } } diff --git a/src/mixins/user.ts b/src/mixins/user.ts index 83f8b9d..0032361 100644 --- a/src/mixins/user.ts +++ b/src/mixins/user.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; +import BaseAPIHandler from '@handlers/baseApiHandler'; export interface DelUserParams { User: { @@ -28,8 +28,8 @@ class UserAPIMixin extends BaseAPIHandler { * See examples/response/GetOnline.json for example response data. */ async getOnlineUser(): Promise { - const body = [{ cmd: "GetOnline", action: 1, param: {} }]; - return this.executeCommand("GetOnline", body); + const body = [{ cmd: 'GetOnline', action: 1, param: {} }]; + return this.executeCommand('GetOnline', body); } /** @@ -37,8 +37,8 @@ class UserAPIMixin extends BaseAPIHandler { * See examples/response/GetUser.json for example response data. */ async getUsers(): Promise { - const body = [{ cmd: "GetUser", action: 1, param: {} }]; - return this.executeCommand("GetUser", body); + const body = [{ cmd: 'GetUser', action: 1, param: {} }]; + return this.executeCommand('GetUser', body); } /** @@ -51,11 +51,11 @@ class UserAPIMixin extends BaseAPIHandler { async addUser( username: string, password: string, - level: "guest" | "admin" = "guest", + level: 'guest' | 'admin' = 'guest', ): Promise { const body = [ { - cmd: "AddUser", + cmd: 'AddUser', action: 0, param: { User: { @@ -68,16 +68,16 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand("AddUser", body); + const response = await this.executeCommand('AddUser', body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { return true; } - console.log("Could not add user. Camera responded with:", rData.value); + console.log('Could not add user. Camera responded with:', rData.value); return false; } catch (error) { - console.error("Error adding user:", error); + console.error('Error adding user:', error); return false; } } @@ -91,7 +91,7 @@ class UserAPIMixin extends BaseAPIHandler { async modifyUser(username: string, password: string): Promise { const body = [ { - cmd: "ModifyUser", + cmd: 'ModifyUser', action: 0, param: { User: { @@ -103,7 +103,7 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand("ModifyUser", body); + const response = await this.executeCommand('ModifyUser', body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { @@ -114,7 +114,7 @@ class UserAPIMixin extends BaseAPIHandler { ); return false; } catch (error) { - console.error("Error modifying user:", error); + console.error('Error modifying user:', error); return false; } } @@ -127,7 +127,7 @@ class UserAPIMixin extends BaseAPIHandler { async deleteUser(username: string): Promise { const body = [ { - cmd: "DelUser", + cmd: 'DelUser', action: 0, param: { User: { @@ -138,7 +138,7 @@ class UserAPIMixin extends BaseAPIHandler { ]; try { - const response = await this.executeCommand("DelUser", body); + const response = await this.executeCommand('DelUser', body); const rData = response[0] as UserResponse; if (rData.value.rspCode === 200) { @@ -149,7 +149,7 @@ class UserAPIMixin extends BaseAPIHandler { ); return false; } catch (error) { - console.error("Error deleting user:", error); + console.error('Error deleting user:', error); return false; } } diff --git a/src/mixins/zoom.ts b/src/mixins/zoom.ts index 370bb0c..c8d5f76 100644 --- a/src/mixins/zoom.ts +++ b/src/mixins/zoom.ts @@ -1,4 +1,4 @@ -import BaseAPIHandler from "@handlers/baseApiHandler"; +import BaseAPIHandler from '@handlers/baseApiHandler'; interface PtzResponse { [key: string]: any; @@ -22,7 +22,7 @@ class ZoomAPIMixin extends BaseAPIHandler { ): Promise { const data = [ { - cmd: "PtzCtrl", + cmd: 'PtzCtrl', action: 0, param: { channel: 0, @@ -31,7 +31,7 @@ class ZoomAPIMixin extends BaseAPIHandler { }, }, ]; - return this.executeCommand("PtzCtrl", data); + return this.executeCommand('PtzCtrl', data); } /** @@ -41,15 +41,15 @@ class ZoomAPIMixin extends BaseAPIHandler { private async stopZoomingOrFocusing(): Promise { const data = [ { - cmd: "PtzCtrl", + cmd: 'PtzCtrl', action: 0, param: { channel: 0, - op: "Stop", + op: 'Stop', }, }, ]; - return this.executeCommand("PtzCtrl", data); + return this.executeCommand('PtzCtrl', data); } /** @@ -58,7 +58,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startZoomingIn(speed: number = 60): Promise { - return this.startOperation("ZoomInc", speed); + return this.startOperation('ZoomInc', speed); } /** @@ -67,7 +67,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startZoomingOut(speed: number = 60): Promise { - return this.startOperation("ZoomDec", speed); + return this.startOperation('ZoomDec', speed); } /** @@ -84,7 +84,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startFocusingIn(speed: number = 32): Promise { - return this.startOperation("FocusInc", speed); + return this.startOperation('FocusInc', speed); } /** @@ -93,7 +93,7 @@ class ZoomAPIMixin extends BaseAPIHandler { * @returns Response from the camera */ async startFocusingOut(speed: number = 32): Promise { - return this.startOperation("FocusDec", speed); + return this.startOperation('FocusDec', speed); } /** diff --git a/src/utils/rtspClient.ts b/src/utils/rtspClient.ts index e8feaa9..81232ca 100644 --- a/src/utils/rtspClient.ts +++ b/src/utils/rtspClient.ts @@ -1,5 +1,5 @@ -import cv, { Mat, VideoCapture } from "@u4/opencv4nodejs"; -import EventEmitter from "events"; +import cv, { Mat, VideoCapture } from '@u4/opencv4nodejs'; +import EventEmitter from 'events'; interface RtspConfig { ip: string; @@ -30,7 +30,7 @@ class RtspClient extends EventEmitter { username, password, port = 554, - profile = "main", + profile = 'main', useUdp = true, callback, proxies, @@ -43,7 +43,7 @@ class RtspClient extends EventEmitter { // Set streaming options this.streamOptions = { - OPENCV_FFMPEG_CAPTURE_OPTIONS: `rtsp_transport;${useUdp ? "udp" : "tcp"}`, + OPENCV_FFMPEG_CAPTURE_OPTIONS: `rtsp_transport;${useUdp ? 'udp' : 'tcp'}`, }; // If proxy is configured, set up the environment @@ -70,7 +70,7 @@ class RtspClient extends EventEmitter { // Set buffer size (optional) // this.capture.set(cv.CAP_PROP_BUFFERSIZE, 3); } catch (error) { - console.error("Error opening video capture:", error); + console.error('Error opening video capture:', error); throw error; } } @@ -80,7 +80,7 @@ class RtspClient extends EventEmitter { */ private async *streamBlocking(): AsyncGenerator { if (!this.capture) { - throw new Error("Video capture not initialized"); + throw new Error('Video capture not initialized'); } while (true) { @@ -90,16 +90,16 @@ class RtspClient extends EventEmitter { if (!frame.empty) { yield frame; } else { - console.log("Received empty frame"); + console.log('Received empty frame'); break; } } else { - console.log("Stream closed"); + console.log('Stream closed'); this.capture = null; return; } } catch (error) { - console.error("Error reading frame:", error); + console.error('Error reading frame:', error); this.capture?.release(); this.capture = null; return; @@ -112,7 +112,7 @@ class RtspClient extends EventEmitter { */ private async streamNonBlocking(): Promise { if (!this.callback || !this.capture) { - throw new Error("Callback not set or video capture not initialized"); + throw new Error('Callback not set or video capture not initialized'); } const processFrame = async (): Promise => { @@ -127,11 +127,11 @@ class RtspClient extends EventEmitter { // Schedule next frame processing setImmediate(processFrame); } else { - console.log("Stream is closed"); + console.log('Stream is closed'); this.stopStream(); } } catch (error) { - console.error("Error in non-blocking stream:", error); + console.error('Error in non-blocking stream:', error); this.stopStream(); } }; @@ -161,7 +161,7 @@ class RtspClient extends EventEmitter { this.openVideoCapture(); } - console.log("Opening stream"); + console.log('Opening stream'); this.threadCancelled = false; if (!this.callback) { diff --git a/vitest.config.mjs b/vitest.config.mjs index cc97433..bee75de 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -1,5 +1,5 @@ -import tsconfigPaths from "vite-tsconfig-paths"; -import { defineConfig } from "vitest/config"; +import tsconfigPaths from 'vite-tsconfig-paths'; +import { defineConfig } from 'vitest/config'; export default defineConfig({ test: {