From 245c6e3006c82245361c366f5328440c839a2bf2 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 11 Jan 2024 19:29:15 -0800 Subject: [PATCH] doorbird: remove axios digest auth --- plugins/doorbird/package-lock.json | 48 ++++++++---------------------- plugins/doorbird/package.json | 1 - plugins/doorbird/src/main.ts | 31 +++++++++---------- 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/plugins/doorbird/package-lock.json b/plugins/doorbird/package-lock.json index af1cc4e6a8..13a1072e57 100644 --- a/plugins/doorbird/package-lock.json +++ b/plugins/doorbird/package-lock.json @@ -8,7 +8,6 @@ "name": "@scrypted/doorbird", "version": "0.0.2", "dependencies": { - "@koush/axios-digest-auth": "^0.8.5", "doorbird": "^2.1.2" }, "devDependencies": { @@ -26,23 +25,24 @@ "dependencies": { "@scrypted/sdk": "file:../sdk", "@scrypted/server": "file:../server", - "http-auth-utils": "^3.0.2", + "http-auth-utils": "^5.0.1", "node-fetch-commonjs": "^3.1.1", - "typescript": "^4.4.3" + "typescript": "^5.3.3" }, "devDependencies": { - "@types/node": "^16.9.0" + "@types/node": "^20.10.8", + "ts-node": "^10.9.2" } }, "../../sdk": { "name": "@scrypted/sdk", - "version": "0.2.103", + "version": "0.3.4", "dev": true, "license": "ISC", "dependencies": { "@babel/preset-typescript": "^7.18.6", "adm-zip": "^0.4.13", - "axios": "^0.21.4", + "axios": "^1.6.5", "babel-loader": "^9.1.0", "babel-plugin-const-enum": "^1.1.0", "esbuild": "^0.15.9", @@ -72,23 +72,6 @@ "typedoc": "^0.23.21" } }, - "node_modules/@koush/axios-digest-auth": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/@koush/axios-digest-auth/-/axios-digest-auth-0.8.5.tgz", - "integrity": "sha512-EZMM0gMJ3hMUD4EuUqSwP6UGt5Vmw2TZtY7Ypec55AnxkExSXM0ySgPtqkAcnL43g1R27yAg/dQL7dRTLMqO3Q==", - "dependencies": { - "auth-header": "^1.0.0", - "axios": "^0.21.4" - } - }, - "node_modules/@koush/axios-digest-auth/node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", - "dependencies": { - "follow-redirects": "^1.14.0" - } - }, "node_modules/@scrypted/common": { "resolved": "../../common", "link": true @@ -108,17 +91,12 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, - "node_modules/auth-header": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/auth-header/-/auth-header-1.0.0.tgz", - "integrity": "sha512-CPPazq09YVDUNNVWo4oSPTQmtwIzHusZhQmahCKvIsk0/xH6U3QsMAv3sM+7+Q0B1K2KJ/Q38OND317uXs4NHA==" - }, "node_modules/axios": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.5.tgz", - "integrity": "sha512-glL/PvG/E+xCWwV8S6nCHcrfg1exGx7vxyUIivIA1iL7BIh6bePylCfVHwp6k13ao7SATxB6imau2kqY+I67kw==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", + "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.4", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -199,9 +177,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "funding": [ { "type": "individual", diff --git a/plugins/doorbird/package.json b/plugins/doorbird/package.json index ccef2ea5fd..20c796dff2 100644 --- a/plugins/doorbird/package.json +++ b/plugins/doorbird/package.json @@ -33,7 +33,6 @@ ] }, "dependencies": { - "@koush/axios-digest-auth": "^0.8.5", "doorbird": "^2.1.2" }, "devDependencies": { diff --git a/plugins/doorbird/src/main.ts b/plugins/doorbird/src/main.ts index e7eda579df..25dac91609 100644 --- a/plugins/doorbird/src/main.ts +++ b/plugins/doorbird/src/main.ts @@ -5,8 +5,8 @@ import { ffmpegLogInitialOutput, safePrintFFmpegArguments } from "@scrypted/comm import net from 'net'; import { randomBytes } from 'crypto'; import { PassThrough, Readable } from "stream"; -import AxiosDigestAuth from '@koush/axios-digest-auth'; import { readLength } from "@scrypted/common/src/read-stream"; +import { authHttpFetch } from "@scrypted/common/src/http-auth-fetch"; import { ApiRingEvent, ApiMotionEvent, DoorbirdAPI } from "./doorbird-api"; const { deviceManager, mediaManager } = sdk; @@ -27,7 +27,7 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid this.binaryState = false; this.doorbellAudioActive = false; - this.updateDeviceInfo(); + this.updateDeviceInfo(); } getDoorbirdApi() { @@ -49,8 +49,8 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid this.console?.log("Time:", event.timestamp); this.triggerMotionSensor(); }); - this.getDoorbirdApi()?.startEventSocket(); - } + this.getDoorbirdApi()?.startEventSocket(); + } return this.doorbirdApi; } @@ -157,7 +157,7 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid this.stopAudioTransmitter(); this.stopAudioReceiver(); } - + async startAudioTransmitter(media: MediaObject): Promise { const ffmpegInput: FFmpegInput = JSON.parse((await mediaManager.convertMediaObjectToBuffer(media, ScryptedMimeTypes.FFmpegInput)).toString()); @@ -194,13 +194,13 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid this.console.log('Doorbird: audio transmitter started.'); const passthrough = new PassThrough(); - const digestAuth = new AxiosDigestAuth({ - username, - password - }); - digestAuth.request({ + authHttpFetch({ method: 'POST', url: audioTxUrl, + credential: { + username, + password, + }, headers: { 'Content-Type': 'audio/basic', 'Content-Length': '9999999' @@ -293,7 +293,8 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid // this is a hint to let homekit, et al, know that it's OPUS audio and does not need transcoding. codec: 'pcm_mulaw', } - }]; } + }]; + } async getVideoStream(options?: ResponseMediaStreamOptions): Promise { @@ -327,7 +328,7 @@ class DoorbirdCamera extends ScryptedDeviceBase implements Intercom, Camera, Vid if (this.audioSilenceProcess) return; - this.console.log('Doorbird: starting audio silence generator...') + this.console.log('Doorbird: starting audio silence generator...') const ffmpegPath = await mediaManager.getFFmpegPath(); const ffmpegArgs = [ @@ -552,10 +553,10 @@ export class DoorbirdCamProvider extends ScryptedDeviceBase implements DevicePro } async releaseDevice(id: string, nativeId: string): Promise { - if( this.devices.delete( nativeId ) ) { - this.console.log("Doorbird: Removed device from list: " + id + " / " + nativeId ) + if (this.devices.delete(nativeId)) { + this.console.log("Doorbird: Removed device from list: " + id + " / " + nativeId) } - } + } createCamera(nativeId: string): DoorbirdCamera { return new DoorbirdCamera(nativeId, this);