mirror of
https://github.com/koush/scrypted.git
synced 2026-02-03 14:13:28 +00:00
homekit: autopopulate bridge addresses from recording requests.
This commit is contained in:
2
external/HAP-NodeJS
vendored
2
external/HAP-NodeJS
vendored
Submodule external/HAP-NodeJS updated: 4b9f639a93...a400094fc3
4
plugins/homekit/package-lock.json
generated
4
plugins/homekit/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/homekit",
|
||||
"version": "0.0.133",
|
||||
"version": "0.0.134",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/homekit",
|
||||
"version": "0.0.133",
|
||||
"version": "0.0.134",
|
||||
"dependencies": {
|
||||
"hap-nodejs": "file:../../external/HAP-NodeJS",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -40,5 +40,5 @@
|
||||
"@types/qrcode": "^1.4.1",
|
||||
"@types/url-parse": "^1.4.3"
|
||||
},
|
||||
"version": "0.0.133"
|
||||
"version": "0.0.134"
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface SnapshotThrottle {
|
||||
export interface HomeKitSession {
|
||||
snapshotThrottles: Map<string, SnapshotThrottle>;
|
||||
isHomeKitHub(ip: string): boolean;
|
||||
detectedHomeKitHub(ip: string): void;
|
||||
}
|
||||
|
||||
interface SupportedType {
|
||||
|
||||
@@ -44,14 +44,6 @@ class HomeKit extends ScryptedDeviceBase implements MixinProvider, Settings, Hom
|
||||
return username;
|
||||
}
|
||||
|
||||
getHomeKitHubs(): string[] {
|
||||
try {
|
||||
return JSON.parse(this.storage.getItem('homekitHubs'));
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
async getSettings(): Promise<Setting[]> {
|
||||
const addresses = Object.entries(os.networkInterfaces()).filter(([iface]) => iface.startsWith('en') || iface.startsWith('eth') || iface.startsWith('wlan')).map(([_, addr]) => addr).flat().map(info => info.address).filter(address => address);
|
||||
return [
|
||||
@@ -292,10 +284,44 @@ class HomeKit extends ScryptedDeviceBase implements MixinProvider, Settings, Hom
|
||||
return parseInt(this.storage.getItem('portOverride')) || 0;
|
||||
}
|
||||
|
||||
getHomeKitHubs(): string[] {
|
||||
try {
|
||||
return JSON.parse(this.storage.getItem('homekitHubs'));
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
getAutoHomeKitHubs(): string[] {
|
||||
try {
|
||||
return JSON.parse(this.storage.getItem('autoHomekitHubs'));
|
||||
}
|
||||
catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
isHomeKitHub(address: string) {
|
||||
return !!this.getHomeKitHubs()?.find(check => check.endsWith(address));
|
||||
}
|
||||
|
||||
detectedHomeKitHub(ip: string) {
|
||||
try {
|
||||
const homekitHubs = this.getHomeKitHubs();
|
||||
if (homekitHubs?.includes(ip))
|
||||
return;
|
||||
const autoHomekitHubs = this.getAutoHomeKitHubs();
|
||||
if (autoHomekitHubs.includes(ip))
|
||||
return;
|
||||
autoHomekitHubs.push(ip);
|
||||
homekitHubs.push(ip);
|
||||
this.storage.setItem('autoHomekitHubs', JSON.stringify(autoHomekitHubs));
|
||||
this.storage.setItem('homekitHubs', JSON.stringify(homekitHubs));
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
async canMixin(type: ScryptedDeviceType, interfaces: string[]) {
|
||||
const supportedType = supportedTypes[type];
|
||||
if (!supportedType?.probe({
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Active, ContactSensor } from 'hap-nodejs/src/lib/definitions';
|
||||
import { handleFragmentsRequests, iframeIntervalSeconds } from './camera/camera-recording';
|
||||
import { createSnapshotHandler } from './camera/camera-snapshot';
|
||||
import { evalRequest } from './camera/camera-transcode';
|
||||
import { CharacteristicEventTypes, Service, WithUUID } from 'hap-nodejs/src';
|
||||
import { CharacteristicEventTypes, DataStreamConnection, Service, WithUUID } from 'hap-nodejs/src';
|
||||
import { RecordingManagement } from 'hap-nodejs/src/lib/camera';
|
||||
import { defaultObjectDetectionContactSensorTimeout } from '../camera-mixin';
|
||||
|
||||
@@ -446,7 +446,8 @@ addSupportedType({
|
||||
|
||||
if (linkedMotionSensor || device.interfaces.includes(ScryptedInterface.MotionSensor) || needAudioMotionService) {
|
||||
recordingDelegate = {
|
||||
handleFragmentsRequests(): AsyncGenerator<Buffer, void, unknown> {
|
||||
handleFragmentsRequests(connection: DataStreamConnection): AsyncGenerator<Buffer, void, unknown> {
|
||||
homekitSession.detectedHomeKitHub(connection.remoteAddress);
|
||||
const configuration = RecordingManagement.parseSelectedConfiguration(storage.getItem(storageKeySelectedRecordingConfiguration))
|
||||
return handleFragmentsRequests(device, configuration, console)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user