From 93e8bd63cec2b7aaf65eaac11c3da583a0777593 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 1 Jun 2022 22:29:42 -0700 Subject: [PATCH] amcrest/unifi: add device management urls --- plugins/amcrest/src/main.ts | 15 +++++++++++++++ plugins/unifi-protect/src/camera.ts | 9 +++++++-- plugins/unifi-protect/src/main.ts | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/plugins/amcrest/src/main.ts b/plugins/amcrest/src/main.ts index 7f6b88dab..e6e30faf8 100644 --- a/plugins/amcrest/src/main.ts +++ b/plugins/amcrest/src/main.ts @@ -39,6 +39,19 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration, } this.updateDeviceInfo(); + this.updateManagementUrl(); + } + + updateManagementUrl() { + const ip = this.storage.getItem('ip'); + if (!ip) + return; + const info = this.info || {}; + const managementUrl = `http://${ip}`; + if (info.managementUrl !== managementUrl) { + info.managementUrl = managementUrl; + this.info = info; + } } getRecordingStreamThumbnail(time: number): Promise { @@ -412,6 +425,8 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration, if (continuousRecording) interfaces.push(ScryptedInterface.VideoRecorder); provider.updateDevice(this.nativeId, this.name, interfaces, type); + + this.updateManagementUrl(); } async startIntercom(media: MediaObject): Promise { diff --git a/plugins/unifi-protect/src/camera.ts b/plugins/unifi-protect/src/camera.ts index 826acadd0..42cda6017 100644 --- a/plugins/unifi-protect/src/camera.ts +++ b/plugins/unifi-protect/src/camera.ts @@ -3,8 +3,6 @@ import { ProtectCameraChannelConfig, ProtectCameraConfigInterface, ProtectCamera import child_process, { ChildProcess } from 'child_process'; import { ffmpegLogInitialOutput, safeKillFFmpeg } from '@scrypted/common/src/media-helpers'; import { fitHeightToWidth } from "@scrypted/common/src/resolution-utils"; -import { listenZero } from "@scrypted/common/src/listen-cluster"; -import net from 'net'; import WS from 'ws'; import { once } from "events"; import { FeatureFlagsShim } from "./shim"; @@ -57,6 +55,13 @@ export class UnifiCamera extends ScryptedDeviceBase implements Notifier, Interco } this.updateState(protectCamera); + + const info = this.info || {}; + const managementUrl = `https://192.168.2.1/protect/devices/${protectCamera.id}`; + if (info?.managementUrl !== managementUrl) { + info.managementUrl = managementUrl; + this.info = info; + } } async setStatusLight(on: boolean) { diff --git a/plugins/unifi-protect/src/main.ts b/plugins/unifi-protect/src/main.ts index f798b181b..2e8f7ebcb 100644 --- a/plugins/unifi-protect/src/main.ts +++ b/plugins/unifi-protect/src/main.ts @@ -40,6 +40,8 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device super(nativeId); this.startup = this.discoverDevices(0) + + this.updateManagementUrl(); } handleUpdatePacket(packet: any) { @@ -536,6 +538,19 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device } return ret; } + + updateManagementUrl() { + const ip = this.storage.getItem('ip'); + if (!ip) + return; + const info = this.info || {}; + const managementUrl = `https://${ip}/protect/dashboard`; + if (info.managementUrl !== managementUrl) { + info.managementUrl = managementUrl; + this.info = info; + } + } + async putSetting(key: string, value: string | number) { if (key === 'instance-mode') { if (value === 'MIGRATE') { @@ -543,8 +558,11 @@ export class UnifiProtect extends ScryptedDeviceBase implements Settings, Device } return; } + this.storage.setItem(key, value.toString()); this.discoverDevices(0); + + this.updateManagementUrl(); } }