@homebridge/hap-nodejs 2.3.1-beta.0 → 2.3.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/accessories/types.d.ts +0 -1
- package/dist/hap.d.ts +1 -1
- package/dist/hap.js +6 -4
- package/dist/hap.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +6 -7
- package/dist/internal-types.js +1 -5
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +49 -25
- package/dist/lib/Accessory.js +275 -171
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +37 -18
- package/dist/lib/Advertiser.js +143 -62
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -2
- package/dist/lib/Bridge.js +1 -1
- package/dist/lib/Characteristic.d.ts +40 -21
- package/dist/lib/Characteristic.js +207 -153
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +19 -13
- package/dist/lib/HAPServer.js +266 -220
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +16 -12
- package/dist/lib/Service.js +58 -37
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +5 -5
- package/dist/lib/camera/RTPProxy.js +48 -23
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +18 -13
- package/dist/lib/camera/RTPStreamManagement.js +247 -216
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +13 -13
- package/dist/lib/camera/RecordingManagement.js +115 -110
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +0 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +41 -36
- package/dist/lib/controller/AdaptiveLightingController.js +126 -113
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +17 -17
- package/dist/lib/controller/CameraController.js +30 -26
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +15 -12
- package/dist/lib/controller/Controller.js +0 -1
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +6 -6
- package/dist/lib/controller/DoorbellController.js +10 -3
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +46 -27
- package/dist/lib/controller/RemoteController.js +268 -178
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +0 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +6 -6
- package/dist/lib/datastream/DataStreamManagement.js +30 -26
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +25 -8
- package/dist/lib/datastream/DataStreamParser.js +124 -105
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +47 -23
- package/dist/lib/datastream/DataStreamServer.js +285 -143
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +0 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +35 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +649 -568
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +7 -1
- package/dist/lib/definitions/ServiceDefinitions.js +16 -1
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +0 -1
- package/dist/lib/gen/HomeKit.d.ts +0 -1
- package/dist/lib/model/AccessoryInfo.d.ts +5 -6
- package/dist/lib/model/AccessoryInfo.js +23 -19
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +11 -5
- package/dist/lib/model/ControllerStorage.js +34 -8
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts +20 -2
- package/dist/lib/model/HAPFileStorage.js +59 -10
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +0 -1
- package/dist/lib/model/HAPStorage.js +6 -3
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +2 -3
- package/dist/lib/model/IdentifierCache.js +26 -13
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -7
- package/dist/lib/tv/AccessControlManagement.js +13 -19
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +1 -2
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts +0 -1
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -2
- package/dist/lib/util/color-utils.js +1 -1
- package/dist/lib/util/errors.d.ts +4 -0
- package/dist/lib/util/errors.js +15 -0
- package/dist/lib/util/errors.js.map +1 -0
- package/dist/lib/util/eventedhttp.d.ts +63 -19
- package/dist/lib/util/eventedhttp.js +170 -48
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +1 -2
- package/dist/lib/util/hapCrypto.js +6 -7
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +0 -1
- package/dist/lib/util/hapStatusError.js +1 -1
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts +1 -2
- package/dist/lib/util/net-utils.js +6 -7
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts +0 -1
- package/dist/lib/util/promise-utils.d.ts +1 -2
- package/dist/lib/util/promise-utils.js +2 -1
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +4 -4
- package/dist/lib/util/request-util.js +29 -28
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -2
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +4 -4
- package/dist/lib/util/tlv.js +16 -5
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +5 -2
- package/dist/lib/util/uuid.js +6 -0
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +20 -17
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -14
- package/dist/accessories/AirConditioner_accessory.d.ts +0 -2
- package/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
- package/dist/accessories/AirConditioner_accessory.js +0 -126
- package/dist/accessories/AirConditioner_accessory.js.map +0 -1
- package/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
- package/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
- package/dist/accessories/AppleTVRemote_accessory.js +0 -146
- package/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
- package/dist/accessories/Camera_accessory.d.ts +0 -2
- package/dist/accessories/Camera_accessory.d.ts.map +0 -1
- package/dist/accessories/Camera_accessory.js +0 -562
- package/dist/accessories/Camera_accessory.js.map +0 -1
- package/dist/accessories/Fan_accessory.d.ts +0 -2
- package/dist/accessories/Fan_accessory.d.ts.map +0 -1
- package/dist/accessories/Fan_accessory.js +0 -71
- package/dist/accessories/Fan_accessory.js.map +0 -1
- package/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
- package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +0 -76
- package/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -103
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
- package/dist/accessories/Light_accessory.d.ts +0 -2
- package/dist/accessories/Light_accessory.d.ts.map +0 -1
- package/dist/accessories/Light_accessory.js +0 -143
- package/dist/accessories/Light_accessory.js.map +0 -1
- package/dist/accessories/Lock_accessory.d.ts +0 -2
- package/dist/accessories/Lock_accessory.d.ts.map +0 -1
- package/dist/accessories/Lock_accessory.js +0 -74
- package/dist/accessories/Lock_accessory.js.map +0 -1
- package/dist/accessories/MotionSensor_accessory.d.ts +0 -2
- package/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
- package/dist/accessories/MotionSensor_accessory.js +0 -43
- package/dist/accessories/MotionSensor_accessory.js.map +0 -1
- package/dist/accessories/Outlet_accessory.d.ts +0 -2
- package/dist/accessories/Outlet_accessory.d.ts.map +0 -1
- package/dist/accessories/Outlet_accessory.js +0 -77
- package/dist/accessories/Outlet_accessory.js.map +0 -1
- package/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
- package/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
- package/dist/accessories/SmartSpeaker_accessory.js +0 -42
- package/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
- package/dist/accessories/Sprinkler_accessory.d.ts +0 -2
- package/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
- package/dist/accessories/Sprinkler_accessory.js +0 -126
- package/dist/accessories/Sprinkler_accessory.js.map +0 -1
- package/dist/accessories/TV_accessory.d.ts +0 -2
- package/dist/accessories/TV_accessory.d.ts.map +0 -1
- package/dist/accessories/TV_accessory.js +0 -99
- package/dist/accessories/TV_accessory.js.map +0 -1
- package/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
- package/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
- package/dist/accessories/TemperatureSensor_accessory.js +0 -42
- package/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +0 -14
- package/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +0 -16
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
- package/dist/accessories/gstreamer-audioProducer.js +0 -145
- package/dist/accessories/gstreamer-audioProducer.js.map +0 -1
- package/dist/accessories/types.d.ts.map +0 -1
- package/dist/hap.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/internal-types.d.ts.map +0 -1
- package/dist/lib/Accessory.d.ts.map +0 -1
- package/dist/lib/Advertiser.d.ts.map +0 -1
- package/dist/lib/Bridge.d.ts.map +0 -1
- package/dist/lib/Characteristic.d.ts.map +0 -1
- package/dist/lib/HAPServer.d.ts.map +0 -1
- package/dist/lib/Service.d.ts.map +0 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +0 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
- package/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
- package/dist/lib/camera/index.d.ts.map +0 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
- package/dist/lib/controller/CameraController.d.ts.map +0 -1
- package/dist/lib/controller/Controller.d.ts.map +0 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +0 -1
- package/dist/lib/controller/RemoteController.d.ts.map +0 -1
- package/dist/lib/controller/index.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
- package/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
- package/dist/lib/datastream/index.d.ts.map +0 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
- package/dist/lib/definitions/generate-definitions.d.ts +0 -34
- package/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
- package/dist/lib/definitions/generate-definitions.js +0 -624
- package/dist/lib/definitions/generate-definitions.js.map +0 -1
- package/dist/lib/definitions/generator-configuration.d.ts +0 -22
- package/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
- package/dist/lib/definitions/generator-configuration.js +0 -674
- package/dist/lib/definitions/generator-configuration.js.map +0 -1
- package/dist/lib/definitions/index.d.ts.map +0 -1
- package/dist/lib/gen/HomeKit.d.ts.map +0 -1
- package/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
- package/dist/lib/model/ControllerStorage.d.ts.map +0 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
- package/dist/lib/model/HAPStorage.d.ts.map +0 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +0 -1
- package/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
- package/dist/lib/util/checkName.d.ts.map +0 -1
- package/dist/lib/util/clone.d.ts.map +0 -1
- package/dist/lib/util/color-utils.d.ts.map +0 -1
- package/dist/lib/util/eventedhttp.d.ts.map +0 -1
- package/dist/lib/util/hapCrypto.d.ts.map +0 -1
- package/dist/lib/util/hapStatusError.d.ts.map +0 -1
- package/dist/lib/util/net-utils.d.ts.map +0 -1
- package/dist/lib/util/once.d.ts.map +0 -1
- package/dist/lib/util/promise-utils.d.ts.map +0 -1
- package/dist/lib/util/request-util.d.ts.map +0 -1
- package/dist/lib/util/time.d.ts.map +0 -1
- package/dist/lib/util/tlv.d.ts.map +0 -1
- package/dist/lib/util/uuid.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -3,12 +3,14 @@ import { Buffer } from 'node:buffer';
|
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
import createDebug from 'debug';
|
|
6
|
-
import { Characteristic } from '../Characteristic.js';
|
|
7
|
-
import { DataStreamManagement, HDSConnectionError, HDSProtocolError, HDSProtocolSpecificErrorReason, HDSStatus, } from '../datastream/index.js';
|
|
6
|
+
import { Access, Characteristic, CharacteristicEventTypes } from '../Characteristic.js';
|
|
7
|
+
import { DataStreamConnectionEvent, DataStreamManagement, HDSConnectionError, HDSConnectionErrorType, HDSProtocolError, HDSProtocolSpecificErrorReason, HDSStatus, Protocols, Topics, } from '../datastream/index.js';
|
|
8
8
|
import { HAPStatus } from '../HAPServer.js';
|
|
9
9
|
import { Service } from '../Service.js';
|
|
10
|
+
import { errorMessage, errorStack } from '../util/errors.js';
|
|
10
11
|
import { HapStatusError } from '../util/hapStatusError.js';
|
|
11
12
|
import * as tlv from '../util/tlv.js';
|
|
13
|
+
import { AudioBitrate } from './index.js';
|
|
12
14
|
const debug = createDebug('HAP-NodeJS:Camera:RecordingManagement');
|
|
13
15
|
const hksvDebug = createDebug('HAP-NodeJS:HKSV');
|
|
14
16
|
/**
|
|
@@ -16,7 +18,6 @@ const hksvDebug = createDebug('HAP-NodeJS:HKSV');
|
|
|
16
18
|
*
|
|
17
19
|
* @group Camera
|
|
18
20
|
*/
|
|
19
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
20
21
|
export var EventTriggerOption;
|
|
21
22
|
(function (EventTriggerOption) {
|
|
22
23
|
/**
|
|
@@ -36,19 +37,16 @@ export var EventTriggerOption;
|
|
|
36
37
|
/**
|
|
37
38
|
* @group Camera
|
|
38
39
|
*/
|
|
39
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
40
40
|
export var MediaContainerType;
|
|
41
41
|
(function (MediaContainerType) {
|
|
42
42
|
MediaContainerType[MediaContainerType["FRAGMENTED_MP4"] = 0] = "FRAGMENTED_MP4";
|
|
43
43
|
})(MediaContainerType || (MediaContainerType = {}));
|
|
44
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
45
44
|
var VideoCodecConfigurationTypes;
|
|
46
45
|
(function (VideoCodecConfigurationTypes) {
|
|
47
46
|
VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
|
|
48
47
|
VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["CODEC_PARAMETERS"] = 2] = "CODEC_PARAMETERS";
|
|
49
48
|
VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["ATTRIBUTES"] = 3] = "ATTRIBUTES";
|
|
50
49
|
})(VideoCodecConfigurationTypes || (VideoCodecConfigurationTypes = {}));
|
|
51
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
52
50
|
var VideoCodecParametersTypes;
|
|
53
51
|
(function (VideoCodecParametersTypes) {
|
|
54
52
|
VideoCodecParametersTypes[VideoCodecParametersTypes["PROFILE_ID"] = 1] = "PROFILE_ID";
|
|
@@ -56,14 +54,12 @@ var VideoCodecParametersTypes;
|
|
|
56
54
|
VideoCodecParametersTypes[VideoCodecParametersTypes["BITRATE"] = 3] = "BITRATE";
|
|
57
55
|
VideoCodecParametersTypes[VideoCodecParametersTypes["IFRAME_INTERVAL"] = 4] = "IFRAME_INTERVAL";
|
|
58
56
|
})(VideoCodecParametersTypes || (VideoCodecParametersTypes = {}));
|
|
59
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
60
57
|
var VideoAttributesTypes;
|
|
61
58
|
(function (VideoAttributesTypes) {
|
|
62
59
|
VideoAttributesTypes[VideoAttributesTypes["IMAGE_WIDTH"] = 1] = "IMAGE_WIDTH";
|
|
63
60
|
VideoAttributesTypes[VideoAttributesTypes["IMAGE_HEIGHT"] = 2] = "IMAGE_HEIGHT";
|
|
64
61
|
VideoAttributesTypes[VideoAttributesTypes["FRAME_RATE"] = 3] = "FRAME_RATE";
|
|
65
62
|
})(VideoAttributesTypes || (VideoAttributesTypes = {}));
|
|
66
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
67
63
|
var SelectedCameraRecordingConfigurationTypes;
|
|
68
64
|
(function (SelectedCameraRecordingConfigurationTypes) {
|
|
69
65
|
SelectedCameraRecordingConfigurationTypes[SelectedCameraRecordingConfigurationTypes["SELECTED_RECORDING_CONFIGURATION"] = 1] = "SELECTED_RECORDING_CONFIGURATION";
|
|
@@ -73,7 +69,6 @@ var SelectedCameraRecordingConfigurationTypes;
|
|
|
73
69
|
/**
|
|
74
70
|
* @group Camera
|
|
75
71
|
*/
|
|
76
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
77
72
|
export var AudioRecordingCodecType;
|
|
78
73
|
(function (AudioRecordingCodecType) {
|
|
79
74
|
AudioRecordingCodecType[AudioRecordingCodecType["AAC_LC"] = 0] = "AAC_LC";
|
|
@@ -82,7 +77,6 @@ export var AudioRecordingCodecType;
|
|
|
82
77
|
/**
|
|
83
78
|
* @group Camera
|
|
84
79
|
*/
|
|
85
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
86
80
|
export var AudioRecordingSamplerate;
|
|
87
81
|
(function (AudioRecordingSamplerate) {
|
|
88
82
|
AudioRecordingSamplerate[AudioRecordingSamplerate["KHZ_8"] = 0] = "KHZ_8";
|
|
@@ -92,30 +86,25 @@ export var AudioRecordingSamplerate;
|
|
|
92
86
|
AudioRecordingSamplerate[AudioRecordingSamplerate["KHZ_44_1"] = 4] = "KHZ_44_1";
|
|
93
87
|
AudioRecordingSamplerate[AudioRecordingSamplerate["KHZ_48"] = 5] = "KHZ_48";
|
|
94
88
|
})(AudioRecordingSamplerate || (AudioRecordingSamplerate = {}));
|
|
95
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
96
89
|
var SupportedVideoRecordingConfigurationTypes;
|
|
97
90
|
(function (SupportedVideoRecordingConfigurationTypes) {
|
|
98
91
|
SupportedVideoRecordingConfigurationTypes[SupportedVideoRecordingConfigurationTypes["VIDEO_CODEC_CONFIGURATION"] = 1] = "VIDEO_CODEC_CONFIGURATION";
|
|
99
92
|
})(SupportedVideoRecordingConfigurationTypes || (SupportedVideoRecordingConfigurationTypes = {}));
|
|
100
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
101
93
|
var SupportedCameraRecordingConfigurationTypes;
|
|
102
94
|
(function (SupportedCameraRecordingConfigurationTypes) {
|
|
103
95
|
SupportedCameraRecordingConfigurationTypes[SupportedCameraRecordingConfigurationTypes["PREBUFFER_LENGTH"] = 1] = "PREBUFFER_LENGTH";
|
|
104
96
|
SupportedCameraRecordingConfigurationTypes[SupportedCameraRecordingConfigurationTypes["EVENT_TRIGGER_OPTIONS"] = 2] = "EVENT_TRIGGER_OPTIONS";
|
|
105
97
|
SupportedCameraRecordingConfigurationTypes[SupportedCameraRecordingConfigurationTypes["MEDIA_CONTAINER_CONFIGURATIONS"] = 3] = "MEDIA_CONTAINER_CONFIGURATIONS";
|
|
106
98
|
})(SupportedCameraRecordingConfigurationTypes || (SupportedCameraRecordingConfigurationTypes = {}));
|
|
107
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
108
99
|
var MediaContainerConfigurationTypes;
|
|
109
100
|
(function (MediaContainerConfigurationTypes) {
|
|
110
101
|
MediaContainerConfigurationTypes[MediaContainerConfigurationTypes["MEDIA_CONTAINER_TYPE"] = 1] = "MEDIA_CONTAINER_TYPE";
|
|
111
102
|
MediaContainerConfigurationTypes[MediaContainerConfigurationTypes["MEDIA_CONTAINER_PARAMETERS"] = 2] = "MEDIA_CONTAINER_PARAMETERS";
|
|
112
103
|
})(MediaContainerConfigurationTypes || (MediaContainerConfigurationTypes = {}));
|
|
113
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
114
104
|
var MediaContainerParameterTypes;
|
|
115
105
|
(function (MediaContainerParameterTypes) {
|
|
116
106
|
MediaContainerParameterTypes[MediaContainerParameterTypes["FRAGMENT_LENGTH"] = 1] = "FRAGMENT_LENGTH";
|
|
117
107
|
})(MediaContainerParameterTypes || (MediaContainerParameterTypes = {}));
|
|
118
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
119
108
|
var AudioCodecParametersTypes;
|
|
120
109
|
(function (AudioCodecParametersTypes) {
|
|
121
110
|
AudioCodecParametersTypes[AudioCodecParametersTypes["CHANNEL"] = 1] = "CHANNEL";
|
|
@@ -123,13 +112,11 @@ var AudioCodecParametersTypes;
|
|
|
123
112
|
AudioCodecParametersTypes[AudioCodecParametersTypes["SAMPLE_RATE"] = 3] = "SAMPLE_RATE";
|
|
124
113
|
AudioCodecParametersTypes[AudioCodecParametersTypes["MAX_AUDIO_BITRATE"] = 4] = "MAX_AUDIO_BITRATE";
|
|
125
114
|
})(AudioCodecParametersTypes || (AudioCodecParametersTypes = {}));
|
|
126
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
127
115
|
var AudioCodecConfigurationTypes;
|
|
128
116
|
(function (AudioCodecConfigurationTypes) {
|
|
129
117
|
AudioCodecConfigurationTypes[AudioCodecConfigurationTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
|
|
130
118
|
AudioCodecConfigurationTypes[AudioCodecConfigurationTypes["CODEC_PARAMETERS"] = 2] = "CODEC_PARAMETERS";
|
|
131
119
|
})(AudioCodecConfigurationTypes || (AudioCodecConfigurationTypes = {}));
|
|
132
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
133
120
|
var SupportedAudioRecordingConfigurationTypes;
|
|
134
121
|
(function (SupportedAudioRecordingConfigurationTypes) {
|
|
135
122
|
SupportedAudioRecordingConfigurationTypes[SupportedAudioRecordingConfigurationTypes["AUDIO_CODEC_CONFIGURATION"] = 1] = "AUDIO_CODEC_CONFIGURATION";
|
|
@@ -137,7 +124,6 @@ var SupportedAudioRecordingConfigurationTypes;
|
|
|
137
124
|
/**
|
|
138
125
|
* @group Camera
|
|
139
126
|
*/
|
|
140
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
141
127
|
export var PacketDataType;
|
|
142
128
|
(function (PacketDataType) {
|
|
143
129
|
/**
|
|
@@ -176,7 +162,7 @@ export class RecordingManagement {
|
|
|
176
162
|
* Array of sensor services (e.g. {@link Service.MotionSensor} or {@link Service.OccupancySensor}).
|
|
177
163
|
* Any service in this array owns a {@link Characteristic.StatusActive} characteristic.
|
|
178
164
|
* The value of the {@link Characteristic.HomeKitCameraActive} is mirrored towards the {@link Characteristic.StatusActive} characteristic.
|
|
179
|
-
* The array is initialized
|
|
165
|
+
* The array is initialized by the caller shortly after calling the constructor.
|
|
180
166
|
*/
|
|
181
167
|
sensorServices = [];
|
|
182
168
|
/**
|
|
@@ -225,7 +211,7 @@ export class RecordingManagement {
|
|
|
225
211
|
.onGet(this.handleSelectedCameraRecordingConfigurationRead.bind(this))
|
|
226
212
|
.onSet(this.handleSelectedCameraRecordingConfigurationWrite.bind(this))
|
|
227
213
|
.setProps({
|
|
228
|
-
adminOnlyAccess: [
|
|
214
|
+
adminOnlyAccess: [Access.WRITE],
|
|
229
215
|
});
|
|
230
216
|
this.recordingManagementService.getCharacteristic(Characteristic.Active)
|
|
231
217
|
.onSet((value) => {
|
|
@@ -236,14 +222,14 @@ export class RecordingManagement {
|
|
|
236
222
|
hksvDebug('Active onSet: recordingActive -> %s', this.recordingActive);
|
|
237
223
|
this.delegate.updateRecordingActive(this.recordingActive);
|
|
238
224
|
})
|
|
239
|
-
.on(
|
|
225
|
+
.on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.())
|
|
240
226
|
.setProps({
|
|
241
|
-
adminOnlyAccess: [
|
|
227
|
+
adminOnlyAccess: [Access.WRITE],
|
|
242
228
|
});
|
|
243
229
|
this.recordingManagementService.getCharacteristic(Characteristic.RecordingAudioActive)
|
|
244
|
-
.on(
|
|
230
|
+
.on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.());
|
|
245
231
|
this.operatingModeService.getCharacteristic(Characteristic.HomeKitCameraActive)
|
|
246
|
-
.on(
|
|
232
|
+
.on(CharacteristicEventTypes.CHANGE, (change) => {
|
|
247
233
|
for (const service of this.sensorServices) {
|
|
248
234
|
service.setCharacteristic(Characteristic.StatusActive, !!change.newValue);
|
|
249
235
|
}
|
|
@@ -253,44 +239,52 @@ export class RecordingManagement {
|
|
|
253
239
|
this.stateChangeDelegate?.();
|
|
254
240
|
})
|
|
255
241
|
.setProps({
|
|
256
|
-
adminOnlyAccess: [
|
|
242
|
+
adminOnlyAccess: [Access.WRITE],
|
|
257
243
|
});
|
|
258
244
|
this.operatingModeService.getCharacteristic(Characteristic.EventSnapshotsActive)
|
|
259
|
-
.on(
|
|
245
|
+
.on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.())
|
|
260
246
|
.setProps({
|
|
261
|
-
adminOnlyAccess: [
|
|
247
|
+
adminOnlyAccess: [Access.WRITE],
|
|
262
248
|
});
|
|
263
249
|
this.operatingModeService.getCharacteristic(Characteristic.PeriodicSnapshotsActive)
|
|
264
|
-
.on(
|
|
250
|
+
.on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.())
|
|
265
251
|
.setProps({
|
|
266
|
-
adminOnlyAccess: [
|
|
252
|
+
adminOnlyAccess: [Access.WRITE],
|
|
267
253
|
});
|
|
268
254
|
this.dataStreamManagement
|
|
269
|
-
.onRequestMessage(
|
|
255
|
+
.onRequestMessage(Protocols.DATA_SEND, Topics.OPEN, this.handleDataSendOpen.bind(this));
|
|
270
256
|
}
|
|
271
257
|
handleDataSendOpen(connection, id, message) {
|
|
272
258
|
// for message fields see https://github.com/Supereg/secure-video-specification#41-start
|
|
259
|
+
// the message is sent by the controller, so no field is known to have the expected type before it is checked
|
|
273
260
|
const streamId = message.streamId;
|
|
274
261
|
const type = message.type;
|
|
275
262
|
const target = message.target;
|
|
276
263
|
const reason = message.reason;
|
|
264
|
+
if (typeof streamId !== 'number') {
|
|
265
|
+
debug('[HDS %s] Received data send without a numeric streamId: %o. Rejecting...', connection.remoteAddress, streamId);
|
|
266
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
267
|
+
status: HDSProtocolSpecificErrorReason.UNEXPECTED_FAILURE,
|
|
268
|
+
});
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
277
271
|
if (target !== 'controller' || type !== 'ipcamera.recording') {
|
|
278
272
|
debug('[HDS %s] Received data send with unexpected target: %s or type: %d. Rejecting...', connection.remoteAddress, target, type);
|
|
279
|
-
connection.sendResponse(
|
|
273
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
280
274
|
status: HDSProtocolSpecificErrorReason.UNEXPECTED_FAILURE,
|
|
281
275
|
});
|
|
282
276
|
return;
|
|
283
277
|
}
|
|
284
278
|
if (!this.recordingActive) {
|
|
285
279
|
hksvDebug('[HDS %s] rejecting DATA_SEND OPEN: recordingActive=false', connection.remoteAddress);
|
|
286
|
-
connection.sendResponse(
|
|
280
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
287
281
|
status: HDSProtocolSpecificErrorReason.NOT_ALLOWED,
|
|
288
282
|
});
|
|
289
283
|
return;
|
|
290
284
|
}
|
|
291
285
|
if (!this.operatingModeService.getCharacteristic(Characteristic.HomeKitCameraActive).value) {
|
|
292
286
|
hksvDebug('[HDS %s] rejecting DATA_SEND OPEN: HomeKitCameraActive=false', connection.remoteAddress);
|
|
293
|
-
connection.sendResponse(
|
|
287
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
294
288
|
status: HDSProtocolSpecificErrorReason.NOT_ALLOWED,
|
|
295
289
|
});
|
|
296
290
|
return;
|
|
@@ -298,14 +292,14 @@ export class RecordingManagement {
|
|
|
298
292
|
if (this.recordingStream) {
|
|
299
293
|
debug('[HDS %s] Rejecting DATA_SEND OPEN as another stream (%s) is already recording with streamId %d!', connection.remoteAddress, this.recordingStream.connection.remoteAddress, this.recordingStream.streamId);
|
|
300
294
|
// there is already a recording stream running.
|
|
301
|
-
connection.sendResponse(
|
|
295
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
302
296
|
status: HDSProtocolSpecificErrorReason.BUSY,
|
|
303
297
|
});
|
|
304
298
|
return;
|
|
305
299
|
}
|
|
306
300
|
if (!this.selectedConfiguration) {
|
|
307
301
|
hksvDebug('[HDS %s] rejecting DATA_SEND OPEN: no selectedConfiguration (homebridge#3928)', connection.remoteAddress);
|
|
308
|
-
connection.sendResponse(
|
|
302
|
+
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
|
|
309
303
|
status: HDSProtocolSpecificErrorReason.INVALID_CONFIGURATION,
|
|
310
304
|
});
|
|
311
305
|
return;
|
|
@@ -313,8 +307,8 @@ export class RecordingManagement {
|
|
|
313
307
|
debug('[HDS %s] HDS DATA_SEND Open with reason \'%s\'.', connection.remoteAddress, reason);
|
|
314
308
|
// eslint-disable-next-line ts/no-use-before-define
|
|
315
309
|
this.recordingStream = new CameraRecordingStream(connection, this.delegate, id, streamId);
|
|
316
|
-
this.recordingStream.on(
|
|
317
|
-
debug('[HDS %s] Removing active
|
|
310
|
+
this.recordingStream.on(CameraRecordingStreamEvents.CLOSED, () => {
|
|
311
|
+
debug('[HDS %s] Removing active recording session from recording management!', connection.remoteAddress);
|
|
318
312
|
this.recordingStream = undefined;
|
|
319
313
|
});
|
|
320
314
|
this.recordingStream.startStreaming();
|
|
@@ -326,11 +320,12 @@ export class RecordingManagement {
|
|
|
326
320
|
return this.selectedConfiguration.base64;
|
|
327
321
|
}
|
|
328
322
|
handleSelectedCameraRecordingConfigurationWrite(value) {
|
|
323
|
+
if (typeof value !== 'string') {
|
|
324
|
+
throw new HapStatusError(HAPStatus.INVALID_VALUE_IN_REQUEST);
|
|
325
|
+
}
|
|
329
326
|
const configuration = this.parseSelectedConfiguration(value);
|
|
330
327
|
const changed = this.selectedConfiguration?.base64 !== value;
|
|
331
|
-
hksvDebug('SelectedRecordingConfiguration write: changed=%s hasStateChangeDelegate=%s base64Len=%d', changed, !!this.stateChangeDelegate,
|
|
332
|
-
? value.length
|
|
333
|
-
: -1);
|
|
328
|
+
hksvDebug('SelectedRecordingConfiguration write: changed=%s hasStateChangeDelegate=%s base64Len=%d', changed, !!this.stateChangeDelegate, value.length);
|
|
334
329
|
this.selectedConfiguration = {
|
|
335
330
|
parsed: configuration,
|
|
336
331
|
base64: value,
|
|
@@ -343,35 +338,35 @@ export class RecordingManagement {
|
|
|
343
338
|
}
|
|
344
339
|
parseSelectedConfiguration(value) {
|
|
345
340
|
const decoded = tlv.decode(Buffer.from(value, 'base64'));
|
|
346
|
-
const recording = tlv.decode(decoded[
|
|
347
|
-
const video = tlv.decode(decoded[
|
|
348
|
-
const audio = tlv.decode(decoded[
|
|
349
|
-
const prebufferLength = recording[
|
|
350
|
-
let eventTriggerOptions = recording[
|
|
351
|
-
const mediaContainerConfiguration = tlv.decode(recording[
|
|
352
|
-
const containerType = mediaContainerConfiguration[
|
|
353
|
-
const mediaContainerParameters = tlv.decode(mediaContainerConfiguration[
|
|
354
|
-
const fragmentLength = mediaContainerParameters[
|
|
355
|
-
const videoCodec = video[
|
|
356
|
-
const videoParameters = tlv.decode(video[
|
|
357
|
-
const videoAttributes = tlv.decode(video[
|
|
358
|
-
const profile = videoParameters[
|
|
359
|
-
const level = videoParameters[
|
|
360
|
-
const videoBitrate = videoParameters[
|
|
361
|
-
const iFrameInterval = videoParameters[
|
|
362
|
-
const width = videoAttributes[
|
|
363
|
-
const height = videoAttributes[
|
|
364
|
-
const framerate = videoAttributes[
|
|
365
|
-
const audioCodec = audio[
|
|
366
|
-
const audioParameters = tlv.decode(audio[
|
|
367
|
-
const audioChannels = audioParameters[
|
|
368
|
-
const samplerate = audioParameters[
|
|
369
|
-
const audioBitrateMode = audioParameters[
|
|
370
|
-
const audioBitrate = audioParameters[
|
|
341
|
+
const recording = tlv.decode(decoded[SelectedCameraRecordingConfigurationTypes.SELECTED_RECORDING_CONFIGURATION]);
|
|
342
|
+
const video = tlv.decode(decoded[SelectedCameraRecordingConfigurationTypes.SELECTED_VIDEO_CONFIGURATION]);
|
|
343
|
+
const audio = tlv.decode(decoded[SelectedCameraRecordingConfigurationTypes.SELECTED_AUDIO_CONFIGURATION]);
|
|
344
|
+
const prebufferLength = recording[SupportedCameraRecordingConfigurationTypes.PREBUFFER_LENGTH].readInt32LE(0);
|
|
345
|
+
let eventTriggerOptions = recording[SupportedCameraRecordingConfigurationTypes.EVENT_TRIGGER_OPTIONS].readInt32LE(0);
|
|
346
|
+
const mediaContainerConfiguration = tlv.decode(recording[SupportedCameraRecordingConfigurationTypes.MEDIA_CONTAINER_CONFIGURATIONS]);
|
|
347
|
+
const containerType = mediaContainerConfiguration[MediaContainerConfigurationTypes.MEDIA_CONTAINER_TYPE][0];
|
|
348
|
+
const mediaContainerParameters = tlv.decode(mediaContainerConfiguration[MediaContainerConfigurationTypes.MEDIA_CONTAINER_PARAMETERS]);
|
|
349
|
+
const fragmentLength = mediaContainerParameters[MediaContainerParameterTypes.FRAGMENT_LENGTH].readInt32LE(0);
|
|
350
|
+
const videoCodec = video[VideoCodecConfigurationTypes.CODEC_TYPE][0];
|
|
351
|
+
const videoParameters = tlv.decode(video[VideoCodecConfigurationTypes.CODEC_PARAMETERS]);
|
|
352
|
+
const videoAttributes = tlv.decode(video[VideoCodecConfigurationTypes.ATTRIBUTES]);
|
|
353
|
+
const profile = videoParameters[VideoCodecParametersTypes.PROFILE_ID][0];
|
|
354
|
+
const level = videoParameters[VideoCodecParametersTypes.LEVEL][0];
|
|
355
|
+
const videoBitrate = videoParameters[VideoCodecParametersTypes.BITRATE].readInt32LE(0);
|
|
356
|
+
const iFrameInterval = videoParameters[VideoCodecParametersTypes.IFRAME_INTERVAL].readInt32LE(0);
|
|
357
|
+
const width = videoAttributes[VideoAttributesTypes.IMAGE_WIDTH].readInt16LE(0);
|
|
358
|
+
const height = videoAttributes[VideoAttributesTypes.IMAGE_HEIGHT].readInt16LE(0);
|
|
359
|
+
const framerate = videoAttributes[VideoAttributesTypes.FRAME_RATE][0];
|
|
360
|
+
const audioCodec = audio[AudioCodecConfigurationTypes.CODEC_TYPE][0];
|
|
361
|
+
const audioParameters = tlv.decode(audio[AudioCodecConfigurationTypes.CODEC_PARAMETERS]);
|
|
362
|
+
const audioChannels = audioParameters[AudioCodecParametersTypes.CHANNEL][0];
|
|
363
|
+
const samplerate = audioParameters[AudioCodecParametersTypes.SAMPLE_RATE][0];
|
|
364
|
+
const audioBitrateMode = audioParameters[AudioCodecParametersTypes.BIT_RATE][0];
|
|
365
|
+
const audioBitrate = audioParameters[AudioCodecParametersTypes.MAX_AUDIO_BITRATE].readUInt32LE(0);
|
|
371
366
|
const typedEventTriggers = [];
|
|
372
367
|
let bit_index = 0;
|
|
373
368
|
while (eventTriggerOptions > 0) {
|
|
374
|
-
if (eventTriggerOptions & 0x01) { //
|
|
369
|
+
if (eventTriggerOptions & 0x01) { // if the lowest bit is set, add the next event trigger option
|
|
375
370
|
typedEventTriggers.push(1 << bit_index);
|
|
376
371
|
}
|
|
377
372
|
eventTriggerOptions = eventTriggerOptions >> 1; // shift to right till we reach zero.
|
|
@@ -411,10 +406,10 @@ export class RecordingManagement {
|
|
|
411
406
|
const eventTriggerOptions = Buffer.alloc(8);
|
|
412
407
|
prebufferLength.writeInt32LE(options.prebufferLength, 0);
|
|
413
408
|
eventTriggerOptions.writeInt32LE(this.eventTriggerOptions, 0);
|
|
414
|
-
return tlv.encode(
|
|
409
|
+
return tlv.encode(SupportedCameraRecordingConfigurationTypes.PREBUFFER_LENGTH, prebufferLength, SupportedCameraRecordingConfigurationTypes.EVENT_TRIGGER_OPTIONS, eventTriggerOptions, SupportedCameraRecordingConfigurationTypes.MEDIA_CONTAINER_CONFIGURATIONS, mediaContainers.map((config) => {
|
|
415
410
|
const fragmentLength = Buffer.alloc(4);
|
|
416
411
|
fragmentLength.writeInt32LE(config.fragmentLength, 0);
|
|
417
|
-
return tlv.encode(
|
|
412
|
+
return tlv.encode(MediaContainerConfigurationTypes.MEDIA_CONTAINER_TYPE, config.type, MediaContainerConfigurationTypes.MEDIA_CONTAINER_PARAMETERS, tlv.encode(MediaContainerParameterTypes.FRAGMENT_LENGTH, fragmentLength));
|
|
418
413
|
})).toString('base64');
|
|
419
414
|
}
|
|
420
415
|
_supportedVideoRecordingConfiguration(videoOptions) {
|
|
@@ -424,8 +419,8 @@ export class RecordingManagement {
|
|
|
424
419
|
if (!videoOptions.resolutions) {
|
|
425
420
|
throw new Error('Video resolutions cannot be undefined');
|
|
426
421
|
}
|
|
427
|
-
const codecParameters = tlv.encode(
|
|
428
|
-
const videoStreamConfiguration = tlv.encode(
|
|
422
|
+
const codecParameters = tlv.encode(VideoCodecParametersTypes.PROFILE_ID, videoOptions.parameters.profiles, VideoCodecParametersTypes.LEVEL, videoOptions.parameters.levels);
|
|
423
|
+
const videoStreamConfiguration = tlv.encode(VideoCodecConfigurationTypes.CODEC_TYPE, videoOptions.type, VideoCodecConfigurationTypes.CODEC_PARAMETERS, codecParameters, VideoCodecConfigurationTypes.ATTRIBUTES, videoOptions.resolutions.map((resolution) => {
|
|
429
424
|
if (resolution.length !== 3) {
|
|
430
425
|
throw new Error('Unexpected video resolution');
|
|
431
426
|
}
|
|
@@ -435,9 +430,9 @@ export class RecordingManagement {
|
|
|
435
430
|
width.writeUInt16LE(resolution[0], 0);
|
|
436
431
|
height.writeUInt16LE(resolution[1], 0);
|
|
437
432
|
frameRate.writeUInt8(resolution[2], 0);
|
|
438
|
-
return tlv.encode(
|
|
433
|
+
return tlv.encode(VideoAttributesTypes.IMAGE_WIDTH, width, VideoAttributesTypes.IMAGE_HEIGHT, height, VideoAttributesTypes.FRAME_RATE, frameRate);
|
|
439
434
|
}));
|
|
440
|
-
return tlv.encode(
|
|
435
|
+
return tlv.encode(SupportedVideoRecordingConfigurationTypes.VIDEO_CODEC_CONFIGURATION, videoStreamConfiguration).toString('base64');
|
|
441
436
|
}
|
|
442
437
|
_supportedAudioStreamConfiguration(audioOptions) {
|
|
443
438
|
const audioCodecs = Array.isArray(audioOptions.codecs)
|
|
@@ -453,10 +448,10 @@ export class RecordingManagement {
|
|
|
453
448
|
if (providedSamplerates.length === 0) {
|
|
454
449
|
throw new Error('CameraRecordingOptions.audio.codecs: Audio samplerate cannot be empty!');
|
|
455
450
|
}
|
|
456
|
-
const audioParameters = tlv.encode(
|
|
457
|
-
return tlv.encode(
|
|
451
|
+
const audioParameters = tlv.encode(AudioCodecParametersTypes.CHANNEL, Math.max(1, codec.audioChannels || 1), AudioCodecParametersTypes.BIT_RATE, codec.bitrateMode || AudioBitrate.VARIABLE, AudioCodecParametersTypes.SAMPLE_RATE, providedSamplerates);
|
|
452
|
+
return tlv.encode(AudioCodecConfigurationTypes.CODEC_TYPE, codec.type, AudioCodecConfigurationTypes.CODEC_PARAMETERS, audioParameters);
|
|
458
453
|
});
|
|
459
|
-
return tlv.encode(
|
|
454
|
+
return tlv.encode(SupportedAudioRecordingConfigurationTypes.AUDIO_CODEC_CONFIGURATION, codecConfigurations).toString('base64');
|
|
460
455
|
}
|
|
461
456
|
computeConfigurationHash(algorithm = 'sha256') {
|
|
462
457
|
const configurationHash = crypto.createHash(algorithm);
|
|
@@ -524,7 +519,7 @@ export class RecordingManagement {
|
|
|
524
519
|
}
|
|
525
520
|
}
|
|
526
521
|
catch (error) {
|
|
527
|
-
console.error(`Failed to properly initialize CameraRecordingDelegate from persistent storage: ${error
|
|
522
|
+
console.error(`Failed to properly initialize CameraRecordingDelegate from persistent storage: ${errorStack(error) ?? errorMessage(error)}`);
|
|
528
523
|
}
|
|
529
524
|
if (changedState) {
|
|
530
525
|
this.stateChangeDelegate?.();
|
|
@@ -542,6 +537,7 @@ export class RecordingManagement {
|
|
|
542
537
|
handleFactoryReset() {
|
|
543
538
|
hksvDebug('handleFactoryReset: clearing selectedConfiguration and resetting recording state');
|
|
544
539
|
this.selectedConfiguration = undefined;
|
|
540
|
+
this.recordingActive = false; // updateCharacteristic below does not run the set handler which keeps this in step
|
|
545
541
|
this.recordingManagementService.updateCharacteristic(Characteristic.Active, false);
|
|
546
542
|
this.recordingManagementService.updateCharacteristic(Characteristic.RecordingAudioActive, false);
|
|
547
543
|
this.operatingModeService.updateCharacteristic(Characteristic.EventSnapshotsActive, true);
|
|
@@ -556,14 +552,13 @@ export class RecordingManagement {
|
|
|
556
552
|
this.delegate.updateRecordingConfiguration(undefined);
|
|
557
553
|
}
|
|
558
554
|
catch (error) {
|
|
559
|
-
console.error(`CameraRecordingDelegate failed to update state after handleFactoryReset: ${error
|
|
555
|
+
console.error(`CameraRecordingDelegate failed to update state after handleFactoryReset: ${errorStack(error) ?? errorMessage(error)}`);
|
|
560
556
|
}
|
|
561
557
|
}
|
|
562
558
|
}
|
|
563
559
|
/**
|
|
564
560
|
* @group Camera
|
|
565
561
|
*/
|
|
566
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
567
562
|
var CameraRecordingStreamEvents;
|
|
568
563
|
(function (CameraRecordingStreamEvents) {
|
|
569
564
|
/**
|
|
@@ -579,7 +574,6 @@ var CameraRecordingStreamEvents;
|
|
|
579
574
|
*
|
|
580
575
|
* @group Camera
|
|
581
576
|
*/
|
|
582
|
-
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
583
577
|
class CameraRecordingStream extends EventEmitter {
|
|
584
578
|
connection;
|
|
585
579
|
delegate;
|
|
@@ -588,15 +582,15 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
588
582
|
abortController;
|
|
589
583
|
closed = false;
|
|
590
584
|
eventHandler = {
|
|
591
|
-
[
|
|
592
|
-
[
|
|
585
|
+
[Topics.CLOSE]: this.handleDataSendClose.bind(this),
|
|
586
|
+
[Topics.ACK]: this.handleDataSendAck.bind(this),
|
|
593
587
|
};
|
|
594
588
|
requestHandler = undefined;
|
|
595
589
|
closeListener;
|
|
596
590
|
generator;
|
|
597
591
|
/**
|
|
598
592
|
* This timeout is used to detect non-returning generators.
|
|
599
|
-
* When we signal the delegate that it is being closed its generator must return
|
|
593
|
+
* When we signal the delegate that it is being closed its generator must return within 10s.
|
|
600
594
|
*/
|
|
601
595
|
generatorTimeout;
|
|
602
596
|
/**
|
|
@@ -611,18 +605,14 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
611
605
|
this.delegate = delegate;
|
|
612
606
|
this.hdsRequestId = requestId;
|
|
613
607
|
this.streamId = streamId;
|
|
614
|
-
this.connection.on(
|
|
615
|
-
this.connection.addProtocolHandler(
|
|
608
|
+
this.connection.on(DataStreamConnectionEvent.CLOSED, this.closeListener = this.handleDataStreamConnectionClosed.bind(this));
|
|
609
|
+
this.connection.addProtocolHandler(Protocols.DATA_SEND, this);
|
|
616
610
|
}
|
|
617
611
|
startStreaming() {
|
|
618
612
|
// noinspection JSIgnoredPromiseFromCall
|
|
619
613
|
this._startStreaming();
|
|
620
614
|
}
|
|
621
615
|
async _startStreaming() {
|
|
622
|
-
debug('[HDS %s] Sending DATA_SEND OPEN response for streamId %d', this.connection.remoteAddress, this.streamId);
|
|
623
|
-
this.connection.sendResponse("dataSend" /* Protocols.DATA_SEND */, "open" /* Topics.OPEN */, this.hdsRequestId, HDSStatus.SUCCESS, {
|
|
624
|
-
status: HDSStatus.SUCCESS,
|
|
625
|
-
});
|
|
626
616
|
// 256 KiB (1KiB to 900 KiB)
|
|
627
617
|
const maxChunk = 0x40000;
|
|
628
618
|
// The first buffer which we receive from the generator is always the `mediaInitialization` packet (mp4 `moov` box).
|
|
@@ -631,6 +621,12 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
631
621
|
// tracks if the last received RecordingPacket was yielded with `isLast=true`.
|
|
632
622
|
let lastFragmentWasMarkedLast = false;
|
|
633
623
|
try {
|
|
624
|
+
// Inside the try: nobody waits for this method, so an error thrown here (e.g. the connection is
|
|
625
|
+
// closing already) would be an unhandled rejection, and the stream would be left marked as recording.
|
|
626
|
+
debug('[HDS %s] Sending DATA_SEND OPEN response for streamId %d', this.connection.remoteAddress, this.streamId);
|
|
627
|
+
this.connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, this.hdsRequestId, HDSStatus.SUCCESS, {
|
|
628
|
+
status: HDSStatus.SUCCESS,
|
|
629
|
+
});
|
|
634
630
|
this.abortController = new AbortController();
|
|
635
631
|
this.generator = this.delegate.handleRecordingStreamRequest(this.streamId, this.abortController.signal);
|
|
636
632
|
for await (const packet of this.generator) {
|
|
@@ -638,14 +634,14 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
638
634
|
debug('[HDS %s] Delegate yielded fragment after stream %d was already closed.', this.connection.remoteAddress, this.streamId);
|
|
639
635
|
break;
|
|
640
636
|
}
|
|
641
|
-
if (lastFragmentWasMarkedLast) {
|
|
642
|
-
console.error(`[HDS ${this.connection.remoteAddress}] Delegate yielded fragment for stream ${this.streamId} after already signaling end of stream!`);
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
637
|
const fragment = packet.data;
|
|
638
|
+
if (fragment.length === 0 && !packet.isLast) {
|
|
639
|
+
continue; // nothing to send, and no sequence number is used up
|
|
640
|
+
}
|
|
646
641
|
let offset = 0;
|
|
647
642
|
let dataChunkSequenceNumber = 1;
|
|
648
|
-
|
|
643
|
+
// at least once: a last packet without data still has to tell the controller that the stream has ended
|
|
644
|
+
do {
|
|
649
645
|
if (this.closed) {
|
|
650
646
|
break;
|
|
651
647
|
}
|
|
@@ -658,7 +654,7 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
658
654
|
{
|
|
659
655
|
data,
|
|
660
656
|
metadata: {
|
|
661
|
-
dataType: initialization ?
|
|
657
|
+
dataType: initialization ? PacketDataType.MEDIA_INITIALIZATION : PacketDataType.MEDIA_FRAGMENT,
|
|
662
658
|
dataSequenceNumber,
|
|
663
659
|
dataChunkSequenceNumber,
|
|
664
660
|
isLastDataChunk: offset >= fragment.length,
|
|
@@ -673,10 +669,10 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
673
669
|
: undefined,
|
|
674
670
|
};
|
|
675
671
|
debug('[HDS %s] Sending DATA_SEND DATA for stream %d with metadata: %o and length %d; EoS: %s', this.connection.remoteAddress, this.streamId, event.packets[0].metadata, data.length, event.endOfStream);
|
|
676
|
-
this.connection.sendEvent(
|
|
672
|
+
this.connection.sendEvent(Protocols.DATA_SEND, Topics.DATA, event);
|
|
677
673
|
dataChunkSequenceNumber++;
|
|
678
674
|
initialization = false;
|
|
679
|
-
}
|
|
675
|
+
} while (offset < fragment.length);
|
|
680
676
|
lastFragmentWasMarkedLast = packet.isLast;
|
|
681
677
|
if (packet.isLast) {
|
|
682
678
|
break;
|
|
@@ -691,7 +687,7 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
691
687
|
}
|
|
692
688
|
catch (error) {
|
|
693
689
|
if (this.closed) {
|
|
694
|
-
console.warn(`[HDS ${this.connection.remoteAddress}] Encountered unexpected error on already closed recording stream ${this.streamId}: ${error
|
|
690
|
+
console.warn(`[HDS ${this.connection.remoteAddress}] Encountered unexpected error on already closed recording stream ${this.streamId}: ${errorStack(error) ?? errorMessage(error)}`);
|
|
695
691
|
}
|
|
696
692
|
else {
|
|
697
693
|
let closeReason = HDSProtocolSpecificErrorReason.UNEXPECTED_FAILURE;
|
|
@@ -699,13 +695,13 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
699
695
|
closeReason = error.reason;
|
|
700
696
|
debug('[HDS %s] Delegate signaled to close the recording stream %d.', this.connection.remoteAddress, this.streamId);
|
|
701
697
|
}
|
|
702
|
-
else if (error instanceof HDSConnectionError && error.type ===
|
|
698
|
+
else if (error instanceof HDSConnectionError && error.type === HDSConnectionErrorType.CLOSED_SOCKET) {
|
|
703
699
|
// we are probably on a shutdown or just late. Connection is dead. End the stream!
|
|
704
700
|
debug('[HDS %s] Exited recording stream due to closed HDS socket: stream id %d.', this.connection.remoteAddress, this.streamId);
|
|
705
701
|
return; // execute finally and then exit (we want to skip the `sendEvent` below)
|
|
706
702
|
}
|
|
707
703
|
else {
|
|
708
|
-
console.error(`[HDS ${this.connection.remoteAddress}] Encountered unexpected error for recording stream ${this.streamId}: ${error
|
|
704
|
+
console.error(`[HDS ${this.connection.remoteAddress}] Encountered unexpected error for recording stream ${this.streamId}: ${errorStack(error) ?? errorMessage(error)}`);
|
|
709
705
|
}
|
|
710
706
|
// call close to go through standard close routine!
|
|
711
707
|
this.close(closeReason);
|
|
@@ -730,20 +726,28 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
730
726
|
handleDataSendAck(message) {
|
|
731
727
|
const streamId = message.streamId;
|
|
732
728
|
const endOfStream = message.endOfStream;
|
|
729
|
+
if (streamId !== this.streamId) {
|
|
730
|
+
return; // an acknowledgment for another stream, like handleDataSendClose checks
|
|
731
|
+
}
|
|
733
732
|
// The HomeKit Controller will send a DATA_SEND ACK if we set the `endOfStream` flag in the last packet
|
|
734
733
|
// of our DATA_SEND DATA packet.
|
|
735
|
-
//
|
|
734
|
+
// In my testing the session is then considered complete and the HomeKit controller will close the HDS Connection after 5 seconds.
|
|
736
735
|
debug('[HDS %s] Received DATA_SEND ACK packet for streamId %s. Acknowledged %s.', this.connection.remoteAddress, streamId, endOfStream);
|
|
737
736
|
this.handleClosed(() => this.delegate.acknowledgeStream?.(this.streamId));
|
|
738
737
|
}
|
|
739
738
|
handleDataSendClose(message) {
|
|
740
739
|
// see https://github.com/Supereg/secure-video-specification#43-close
|
|
741
740
|
const streamId = message.streamId;
|
|
742
|
-
|
|
741
|
+
// a reason which is not a number is handled like a missing one
|
|
742
|
+
const reason = typeof message.reason === 'number'
|
|
743
|
+
? message.reason
|
|
744
|
+
: undefined;
|
|
743
745
|
if (streamId !== this.streamId) {
|
|
744
746
|
return;
|
|
745
747
|
}
|
|
746
|
-
debug('[HDS %s] Received DATA_SEND CLOSE for streamId %d with reason %s', this.connection.remoteAddress, streamId,
|
|
748
|
+
debug('[HDS %s] Received DATA_SEND CLOSE for streamId %d with reason %s', this.connection.remoteAddress, streamId, reason !== undefined
|
|
749
|
+
? HDSProtocolSpecificErrorReason[reason]
|
|
750
|
+
: reason);
|
|
747
751
|
this.handleClosed(() => this.delegate.closeRecordingStream(streamId, reason));
|
|
748
752
|
}
|
|
749
753
|
handleDataStreamConnectionClosed() {
|
|
@@ -762,29 +766,29 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
762
766
|
clearTimeout(this.closingTimeout);
|
|
763
767
|
this.closingTimeout = undefined;
|
|
764
768
|
}
|
|
765
|
-
this.connection.removeProtocolHandler(
|
|
766
|
-
this.connection.removeListener(
|
|
769
|
+
this.connection.removeProtocolHandler(Protocols.DATA_SEND, this);
|
|
770
|
+
this.connection.removeListener(DataStreamConnectionEvent.CLOSED, this.closeListener);
|
|
767
771
|
if (this.generator) {
|
|
768
772
|
// Signal the generator to terminate via the async generator protocol. The return is queued and takes effect
|
|
769
773
|
// after the generator's current await completes. Combined with the AbortSignal above, this ensures the
|
|
770
774
|
// generator terminates promptly even if the delegate doesn't check the signal. We catch rejections
|
|
771
775
|
// to prevent unhandled promise warnings if the generator's cleanup throws.
|
|
772
|
-
|
|
773
|
-
void this.generator.return().catch((error) => debug('[HDS %s] Error while closing recording generator for stream %d: %s', this.connection.remoteAddress, this.streamId, error.stack ?? String(error)));
|
|
776
|
+
void this.generator.return(undefined).catch((error) => debug('[HDS %s] Error while closing recording generator for stream %d: %s', this.connection.remoteAddress, this.streamId, error.stack ?? String(error)));
|
|
774
777
|
// when this variable is defined, the generator hasn't returned yet.
|
|
775
778
|
// we start a timeout to uncover potential programming mistakes where we await forever and can't free resources.
|
|
776
779
|
this.generatorTimeout = setTimeout(() => {
|
|
777
780
|
console.error('[HDS %s] Recording download stream %d is still awaiting generator although stream was closed 10s ago! '
|
|
778
781
|
+ 'This is a programming mistake by the camera implementation which prevents freeing up resources.', this.connection.remoteAddress, this.streamId);
|
|
779
782
|
}, 10000);
|
|
783
|
+
this.generatorTimeout.unref(); // only reports a mistake, so it must not keep the process alive
|
|
780
784
|
}
|
|
781
785
|
try {
|
|
782
786
|
closure();
|
|
783
787
|
}
|
|
784
788
|
catch (error) {
|
|
785
|
-
console.error(`[HDS ${this.connection.remoteAddress}]
|
|
789
|
+
console.error(`[HDS ${this.connection.remoteAddress}] CameraRecordingDelegate failed to handle closing the stream ${this.streamId}: ${errorStack(error) ?? errorMessage(error)}`);
|
|
786
790
|
}
|
|
787
|
-
this.emit(
|
|
791
|
+
this.emit(CameraRecordingStreamEvents.CLOSED);
|
|
788
792
|
}
|
|
789
793
|
/**
|
|
790
794
|
* This method can be used to close a recording session from the outside.
|
|
@@ -795,9 +799,9 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
795
799
|
return;
|
|
796
800
|
}
|
|
797
801
|
debug('[HDS %s] Recording stream %d was closed manually with reason %s.', this.connection.remoteAddress, this.streamId, reason ? HDSProtocolSpecificErrorReason[reason] : 'CLOSED');
|
|
798
|
-
// the `isConsideredClosed` check just ensures that
|
|
802
|
+
// the `isConsideredClosed` check just ensures that we won't ever throw here and that `handledClosed` is always executed.
|
|
799
803
|
if (!this.connection.isConsideredClosed()) {
|
|
800
|
-
this.connection.sendEvent(
|
|
804
|
+
this.connection.sendEvent(Protocols.DATA_SEND, Topics.CLOSE, {
|
|
801
805
|
streamId: this.streamId,
|
|
802
806
|
reason,
|
|
803
807
|
});
|
|
@@ -815,6 +819,7 @@ class CameraRecordingStream extends EventEmitter {
|
|
|
815
819
|
debug('[HDS %s] Recording stream %d took longer than expected to fully close. Force closing now!', this.connection.remoteAddress, this.streamId);
|
|
816
820
|
this.close(HDSProtocolSpecificErrorReason.CANCELLED);
|
|
817
821
|
}, 12000);
|
|
822
|
+
this.closingTimeout.unref();
|
|
818
823
|
}
|
|
819
824
|
}
|
|
820
825
|
//# sourceMappingURL=RecordingManagement.js.map
|