homekit: autopopulate bridge addresses from recording requests.

This commit is contained in:
Koushik Dutta
2021-12-12 11:18:14 -08:00
parent d5ce7a5ee9
commit bd045ffb48
6 changed files with 42 additions and 14 deletions

View File

@@ -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",

View File

@@ -40,5 +40,5 @@
"@types/qrcode": "^1.4.1",
"@types/url-parse": "^1.4.3"
},
"version": "0.0.133"
"version": "0.0.134"
}

View File

@@ -15,6 +15,7 @@ export interface SnapshotThrottle {
export interface HomeKitSession {
snapshotThrottles: Map<string, SnapshotThrottle>;
isHomeKitHub(ip: string): boolean;
detectedHomeKitHub(ip: string): void;
}
interface SupportedType {

View File

@@ -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({

View File

@@ -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)
}