From de44217f651d94c2e5c82b9638c9ee03a3c19077 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 31 Jul 2024 21:06:22 -0700 Subject: [PATCH] core: Fix notificaiton automation --- plugins/core/package-lock.json | 4 ++-- plugins/core/package.json | 2 +- plugins/core/src/automation-actions.ts | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/plugins/core/package-lock.json b/plugins/core/package-lock.json index 30da55784..2d087a999 100644 --- a/plugins/core/package-lock.json +++ b/plugins/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/core", - "version": "0.3.61", + "version": "0.3.62", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/core", - "version": "0.3.61", + "version": "0.3.62", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/core/package.json b/plugins/core/package.json index 1547859a1..d2331aa47 100644 --- a/plugins/core/package.json +++ b/plugins/core/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/core", - "version": "0.3.61", + "version": "0.3.62", "description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/core/src/automation-actions.ts b/plugins/core/src/automation-actions.ts index b35dac812..136b1e980 100644 --- a/plugins/core/src/automation-actions.ts +++ b/plugins/core/src/automation-actions.ts @@ -1,5 +1,6 @@ -import { Brightness, Lock, LockState, Notifier, OnOff, Program, ScryptedDevice, ScryptedInterface, StartStop } from "@scrypted/sdk"; +import { Brightness, Camera, Lock, LockState, Notifier, OnOff, Program, ScryptedDevice, ScryptedInterface, StartStop, VideoCamera } from "@scrypted/sdk"; import { StorageSettingsDict } from "@scrypted/sdk/storage-settings"; +import sdk from '@scrypted/sdk'; interface InvokeStorage { settings: StorageSettingsDict; @@ -81,7 +82,23 @@ addAction(ScryptedInterface.Notifier, { deviceFilter: `deviceInterface === '${ScryptedInterface.VideoCamera}' || deviceInterface === '${ScryptedInterface.Camera}'`, }, }, async function invoke(device: ScryptedDevice & Notifier, storageSettings) { + let { notificationMediaUrl } = storageSettings; + if (notificationMediaUrl && !notificationMediaUrl?.includes('://')) { + const [id,iface] = notificationMediaUrl.split('#'); + if (iface === ScryptedInterface.Camera) { + const mediaDevice = sdk.systemManager.getDeviceById(id); + notificationMediaUrl = await mediaDevice.takePicture({ + reason: 'event', + }); + } + else { + const mediaDevice = sdk.systemManager.getDeviceById(id); + notificationMediaUrl = mediaDevice.getVideoStream(); + } + + } + return device.sendNotification(storageSettings.notificationTitle as string, { body: storageSettings.notificationBody as string, - }); + }, notificationMediaUrl); }); \ No newline at end of file