@homebridge/hap-nodejs 2.2.4-beta.7 → 2.3.0-beta.1
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 +14 -17
- package/dist/accessories/AirConditioner_accessory.js +27 -29
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +63 -76
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +151 -134
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +18 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +33 -35
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +41 -44
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +32 -34
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +24 -26
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +13 -15
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +20 -22
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +18 -20
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +36 -38
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +43 -45
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +12 -14
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +9 -12
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +11 -14
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +3 -3
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +38 -38
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.d.ts +63 -63
- package/dist/accessories/types.d.ts.map +1 -1
- package/dist/accessories/types.js +83 -87
- package/dist/accessories/types.js.map +1 -1
- package/dist/hap.d.ts +50 -0
- package/dist/hap.d.ts.map +1 -0
- package/dist/hap.js +49 -0
- package/dist/hap.js.map +1 -0
- package/dist/index.d.ts +3 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -53
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +19 -19
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +37 -37
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +286 -280
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +6 -6
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +143 -139
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -6
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +40 -41
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +290 -240
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +31 -30
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +245 -247
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +21 -22
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +60 -68
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +2 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +35 -37
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +34 -33
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +184 -137
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +18 -17
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +189 -164
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +3 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +3 -6
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +8 -8
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +112 -99
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +21 -20
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +92 -89
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +1 -1
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +5 -8
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +4 -4
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +9 -13
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +40 -39
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +213 -186
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +5 -5
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.js +5 -8
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +2 -2
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +36 -35
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +1 -0
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +53 -69
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +24 -23
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +151 -154
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.d.ts.map +1 -1
- package/dist/lib/datastream/index.js +3 -6
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1103 -1288
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +644 -722
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +2 -2
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +241 -241
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +572 -309
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +2 -2
- package/dist/lib/definitions/index.d.ts.map +1 -1
- package/dist/lib/definitions/index.js +2 -5
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/gen/HomeKit.js +1 -2
- package/dist/lib/gen/HomeKit.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +4 -3
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +53 -56
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -3
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +31 -30
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPFileStorage.js +71 -50
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +1 -1
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +11 -14
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +23 -27
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -6
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +23 -24
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -2
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +8 -14
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +1 -5
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +1608 -410
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +23 -22
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +127 -122
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +2 -1
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +72 -59
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +1 -1
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +5 -9
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +13 -19
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -6
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +1 -1
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +9 -11
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +3 -3
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +14 -23
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -0
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +6 -11
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +1 -0
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +38 -44
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +1 -0
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +26 -38
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/package.json +49 -42
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const debug = (0, debug_1.default)("HAP-NodeJS:Remote:Controller");
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import createDebug from 'debug';
|
|
5
|
+
import { Characteristic, } from '../Characteristic.js';
|
|
6
|
+
import { DataStreamManagement, Float32, HDSProtocolSpecificErrorReason, HDSStatus, Int64, } from '../datastream/index.js';
|
|
7
|
+
import { HAPStatus } from '../HAPServer.js';
|
|
8
|
+
import { Service } from '../Service.js';
|
|
9
|
+
import * as tlv from '../util/tlv.js';
|
|
10
|
+
const debug = createDebug('HAP-NodeJS:Remote:Controller');
|
|
11
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
13
12
|
var TargetControlCommands;
|
|
14
13
|
(function (TargetControlCommands) {
|
|
15
14
|
TargetControlCommands[TargetControlCommands["MAXIMUM_TARGETS"] = 1] = "MAXIMUM_TARGETS";
|
|
@@ -17,6 +16,7 @@ var TargetControlCommands;
|
|
|
17
16
|
TargetControlCommands[TargetControlCommands["SUPPORTED_BUTTON_CONFIGURATION"] = 3] = "SUPPORTED_BUTTON_CONFIGURATION";
|
|
18
17
|
TargetControlCommands[TargetControlCommands["TYPE"] = 4] = "TYPE";
|
|
19
18
|
})(TargetControlCommands || (TargetControlCommands = {}));
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
20
|
var SupportedButtonConfigurationTypes;
|
|
21
21
|
(function (SupportedButtonConfigurationTypes) {
|
|
22
22
|
SupportedButtonConfigurationTypes[SupportedButtonConfigurationTypes["BUTTON_ID"] = 1] = "BUTTON_ID";
|
|
@@ -25,7 +25,7 @@ var SupportedButtonConfigurationTypes;
|
|
|
25
25
|
/**
|
|
26
26
|
* @group Apple TV Remote
|
|
27
27
|
*/
|
|
28
|
-
var ButtonType;
|
|
28
|
+
export var ButtonType;
|
|
29
29
|
(function (ButtonType) {
|
|
30
30
|
// noinspection JSUnusedGlobalSymbols
|
|
31
31
|
ButtonType[ButtonType["UNDEFINED"] = 0] = "UNDEFINED";
|
|
@@ -42,7 +42,8 @@ var ButtonType;
|
|
|
42
42
|
ButtonType[ButtonType["SIRI"] = 11] = "SIRI";
|
|
43
43
|
ButtonType[ButtonType["POWER"] = 12] = "POWER";
|
|
44
44
|
ButtonType[ButtonType["GENERIC"] = 13] = "GENERIC";
|
|
45
|
-
})(ButtonType || (
|
|
45
|
+
})(ButtonType || (ButtonType = {}));
|
|
46
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
46
47
|
var TargetControlList;
|
|
47
48
|
(function (TargetControlList) {
|
|
48
49
|
TargetControlList[TargetControlList["OPERATION"] = 1] = "OPERATION";
|
|
@@ -58,6 +59,7 @@ var Operation;
|
|
|
58
59
|
Operation[Operation["RESET"] = 4] = "RESET";
|
|
59
60
|
Operation[Operation["UPDATE"] = 5] = "UPDATE";
|
|
60
61
|
})(Operation || (Operation = {}));
|
|
62
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
61
63
|
var TargetConfigurationTypes;
|
|
62
64
|
(function (TargetConfigurationTypes) {
|
|
63
65
|
TargetConfigurationTypes[TargetConfigurationTypes["TARGET_IDENTIFIER"] = 1] = "TARGET_IDENTIFIER";
|
|
@@ -68,18 +70,21 @@ var TargetConfigurationTypes;
|
|
|
68
70
|
/**
|
|
69
71
|
* @group Apple TV Remote
|
|
70
72
|
*/
|
|
71
|
-
|
|
73
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
74
|
+
export var TargetCategory;
|
|
72
75
|
(function (TargetCategory) {
|
|
73
76
|
// noinspection JSUnusedGlobalSymbols
|
|
74
77
|
TargetCategory[TargetCategory["UNDEFINED"] = 0] = "UNDEFINED";
|
|
75
78
|
TargetCategory[TargetCategory["APPLE_TV"] = 24] = "APPLE_TV";
|
|
76
|
-
})(TargetCategory || (
|
|
79
|
+
})(TargetCategory || (TargetCategory = {}));
|
|
80
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
77
81
|
var ButtonConfigurationTypes;
|
|
78
82
|
(function (ButtonConfigurationTypes) {
|
|
79
83
|
ButtonConfigurationTypes[ButtonConfigurationTypes["BUTTON_ID"] = 1] = "BUTTON_ID";
|
|
80
84
|
ButtonConfigurationTypes[ButtonConfigurationTypes["BUTTON_TYPE"] = 2] = "BUTTON_TYPE";
|
|
81
85
|
ButtonConfigurationTypes[ButtonConfigurationTypes["BUTTON_NAME"] = 3] = "BUTTON_NAME";
|
|
82
86
|
})(ButtonConfigurationTypes || (ButtonConfigurationTypes = {}));
|
|
87
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
83
88
|
var ButtonEvent;
|
|
84
89
|
(function (ButtonEvent) {
|
|
85
90
|
ButtonEvent[ButtonEvent["BUTTON_ID"] = 1] = "BUTTON_ID";
|
|
@@ -90,22 +95,25 @@ var ButtonEvent;
|
|
|
90
95
|
/**
|
|
91
96
|
* @group Apple TV Remote
|
|
92
97
|
*/
|
|
93
|
-
var ButtonState;
|
|
98
|
+
export var ButtonState;
|
|
94
99
|
(function (ButtonState) {
|
|
95
100
|
ButtonState[ButtonState["UP"] = 0] = "UP";
|
|
96
101
|
ButtonState[ButtonState["DOWN"] = 1] = "DOWN";
|
|
97
|
-
})(ButtonState || (
|
|
102
|
+
})(ButtonState || (ButtonState = {}));
|
|
103
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
98
104
|
var SelectedAudioInputStreamConfigurationTypes;
|
|
99
105
|
(function (SelectedAudioInputStreamConfigurationTypes) {
|
|
100
106
|
SelectedAudioInputStreamConfigurationTypes[SelectedAudioInputStreamConfigurationTypes["SELECTED_AUDIO_INPUT_STREAM_CONFIGURATION"] = 1] = "SELECTED_AUDIO_INPUT_STREAM_CONFIGURATION";
|
|
101
107
|
})(SelectedAudioInputStreamConfigurationTypes || (SelectedAudioInputStreamConfigurationTypes = {}));
|
|
102
108
|
// ----------
|
|
109
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
103
110
|
var SupportedAudioStreamConfigurationTypes;
|
|
104
111
|
(function (SupportedAudioStreamConfigurationTypes) {
|
|
105
112
|
// noinspection JSUnusedGlobalSymbols
|
|
106
113
|
SupportedAudioStreamConfigurationTypes[SupportedAudioStreamConfigurationTypes["AUDIO_CODEC_CONFIGURATION"] = 1] = "AUDIO_CODEC_CONFIGURATION";
|
|
107
114
|
SupportedAudioStreamConfigurationTypes[SupportedAudioStreamConfigurationTypes["COMFORT_NOISE_SUPPORT"] = 2] = "COMFORT_NOISE_SUPPORT";
|
|
108
115
|
})(SupportedAudioStreamConfigurationTypes || (SupportedAudioStreamConfigurationTypes = {}));
|
|
116
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
109
117
|
var AudioCodecConfigurationTypes;
|
|
110
118
|
(function (AudioCodecConfigurationTypes) {
|
|
111
119
|
AudioCodecConfigurationTypes[AudioCodecConfigurationTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
|
|
@@ -114,7 +122,8 @@ var AudioCodecConfigurationTypes;
|
|
|
114
122
|
/**
|
|
115
123
|
* @group Camera
|
|
116
124
|
*/
|
|
117
|
-
|
|
125
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
126
|
+
export var AudioCodecTypes;
|
|
118
127
|
(function (AudioCodecTypes) {
|
|
119
128
|
// noinspection JSUnusedGlobalSymbols
|
|
120
129
|
AudioCodecTypes[AudioCodecTypes["PCMU"] = 0] = "PCMU";
|
|
@@ -124,14 +133,16 @@ var AudioCodecTypes;
|
|
|
124
133
|
AudioCodecTypes[AudioCodecTypes["MSBC"] = 4] = "MSBC";
|
|
125
134
|
AudioCodecTypes[AudioCodecTypes["AMR"] = 5] = "AMR";
|
|
126
135
|
AudioCodecTypes[AudioCodecTypes["AMR_WB"] = 6] = "AMR_WB";
|
|
127
|
-
})(AudioCodecTypes || (
|
|
136
|
+
})(AudioCodecTypes || (AudioCodecTypes = {}));
|
|
137
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
128
138
|
var AudioCodecParametersTypes;
|
|
129
139
|
(function (AudioCodecParametersTypes) {
|
|
130
140
|
AudioCodecParametersTypes[AudioCodecParametersTypes["CHANNEL"] = 1] = "CHANNEL";
|
|
131
141
|
AudioCodecParametersTypes[AudioCodecParametersTypes["BIT_RATE"] = 2] = "BIT_RATE";
|
|
132
142
|
AudioCodecParametersTypes[AudioCodecParametersTypes["SAMPLE_RATE"] = 3] = "SAMPLE_RATE";
|
|
133
|
-
AudioCodecParametersTypes[AudioCodecParametersTypes["PACKET_TIME"] = 4] = "PACKET_TIME";
|
|
143
|
+
AudioCodecParametersTypes[AudioCodecParametersTypes["PACKET_TIME"] = 4] = "PACKET_TIME";
|
|
134
144
|
})(AudioCodecParametersTypes || (AudioCodecParametersTypes = {}));
|
|
145
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
135
146
|
var SiriAudioSessionState;
|
|
136
147
|
(function (SiriAudioSessionState) {
|
|
137
148
|
SiriAudioSessionState[SiriAudioSessionState["STARTING"] = 0] = "STARTING";
|
|
@@ -142,17 +153,19 @@ var SiriAudioSessionState;
|
|
|
142
153
|
/**
|
|
143
154
|
* @group Apple TV Remote
|
|
144
155
|
*/
|
|
145
|
-
|
|
156
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
157
|
+
export var TargetUpdates;
|
|
146
158
|
(function (TargetUpdates) {
|
|
147
159
|
TargetUpdates[TargetUpdates["NAME"] = 0] = "NAME";
|
|
148
160
|
TargetUpdates[TargetUpdates["CATEGORY"] = 1] = "CATEGORY";
|
|
149
161
|
TargetUpdates[TargetUpdates["UPDATED_BUTTONS"] = 2] = "UPDATED_BUTTONS";
|
|
150
162
|
TargetUpdates[TargetUpdates["REMOVED_BUTTONS"] = 3] = "REMOVED_BUTTONS";
|
|
151
|
-
})(TargetUpdates || (
|
|
163
|
+
})(TargetUpdates || (TargetUpdates = {}));
|
|
152
164
|
/**
|
|
153
165
|
* @group Apple TV Remote
|
|
154
166
|
*/
|
|
155
|
-
|
|
167
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
168
|
+
export var RemoteControllerEvents;
|
|
156
169
|
(function (RemoteControllerEvents) {
|
|
157
170
|
/**
|
|
158
171
|
* This event is emitted when the active state of the remote has changed.
|
|
@@ -186,18 +199,17 @@ var RemoteControllerEvents;
|
|
|
186
199
|
* when the accessory gets unpaired.
|
|
187
200
|
*/
|
|
188
201
|
RemoteControllerEvents["TARGETS_RESET"] = "targets-reset";
|
|
189
|
-
})(RemoteControllerEvents || (
|
|
202
|
+
})(RemoteControllerEvents || (RemoteControllerEvents = {}));
|
|
190
203
|
/**
|
|
191
204
|
* Handles everything needed to implement a fully working HomeKit remote controller.
|
|
192
205
|
*
|
|
193
206
|
* @group Apple TV Remote
|
|
194
207
|
*/
|
|
195
|
-
// eslint-disable-next-line
|
|
196
|
-
class RemoteController extends
|
|
208
|
+
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
209
|
+
export class RemoteController extends EventEmitter {
|
|
197
210
|
stateChangeDelegate;
|
|
198
211
|
audioSupported;
|
|
199
212
|
audioProducerConstructor;
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
213
|
audioProducerOptions;
|
|
202
214
|
targetControlManagementService;
|
|
203
215
|
targetControlService;
|
|
@@ -207,8 +219,8 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
207
219
|
buttons = {}; // internal mapping of buttonId to buttonType for supported buttons
|
|
208
220
|
supportedConfiguration;
|
|
209
221
|
targetConfigurations = new Map();
|
|
210
|
-
targetConfigurationsString =
|
|
211
|
-
lastButtonEvent =
|
|
222
|
+
targetConfigurationsString = '';
|
|
223
|
+
lastButtonEvent = '';
|
|
212
224
|
activeIdentifier = 0; // id of 0 means no device selected
|
|
213
225
|
activeConnection; // session which marked this remote as active and listens for events and siri
|
|
214
226
|
activeConnectionDisconnectListener;
|
|
@@ -235,9 +247,9 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
235
247
|
*
|
|
236
248
|
* @param audioProducerConstructor - constructor for a SiriAudioStreamProducer
|
|
237
249
|
* @param producerOptions - if supplied this argument will be supplied as third argument of the SiriAudioStreamProducer
|
|
238
|
-
*
|
|
250
|
+
* constructor. This should be used to supply configurations to the stream producer.
|
|
239
251
|
*/
|
|
240
|
-
// eslint-disable-next-line
|
|
252
|
+
// eslint-disable-next-line ts/explicit-module-boundary-types
|
|
241
253
|
constructor(audioProducerConstructor, producerOptions) {
|
|
242
254
|
super();
|
|
243
255
|
this.audioSupported = audioProducerConstructor !== undefined;
|
|
@@ -276,11 +288,11 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
276
288
|
return;
|
|
277
289
|
}
|
|
278
290
|
if (activeIdentifier !== 0 && !this.targetConfigurations.has(activeIdentifier)) {
|
|
279
|
-
throw Error(
|
|
291
|
+
throw new Error('Tried setting unconfigured targetIdentifier to active');
|
|
280
292
|
}
|
|
281
|
-
debug(
|
|
293
|
+
debug('%d is now the active target', activeIdentifier);
|
|
282
294
|
this.activeIdentifier = activeIdentifier;
|
|
283
|
-
this.targetControlService.getCharacteristic(
|
|
295
|
+
this.targetControlService.getCharacteristic(Characteristic.ActiveIdentifier).updateValue(activeIdentifier);
|
|
284
296
|
if (this.activeAudioSession) {
|
|
285
297
|
this.handleSiriAudioStop();
|
|
286
298
|
}
|
|
@@ -321,7 +333,7 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
321
333
|
* @param button - button to be pressed
|
|
322
334
|
*/
|
|
323
335
|
pushButton(button) {
|
|
324
|
-
this.sendButtonEvent(button,
|
|
336
|
+
this.sendButtonEvent(button, ButtonState.DOWN);
|
|
325
337
|
}
|
|
326
338
|
/**
|
|
327
339
|
* Sends a button event that the supplied button was released.
|
|
@@ -329,7 +341,7 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
329
341
|
* @param button - button which was released
|
|
330
342
|
*/
|
|
331
343
|
releaseButton(button) {
|
|
332
|
-
this.sendButtonEvent(button,
|
|
344
|
+
this.sendButtonEvent(button, ButtonState.UP);
|
|
333
345
|
}
|
|
334
346
|
/**
|
|
335
347
|
* Presses a supplied button for a given time.
|
|
@@ -345,7 +357,7 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
345
357
|
}
|
|
346
358
|
catch (error) {
|
|
347
359
|
// e.g. the remote was set inactive in the meantime; throwing inside the timer would crash the process
|
|
348
|
-
debug(
|
|
360
|
+
debug('Failed to release button %d: %s', button, error.message);
|
|
349
361
|
}
|
|
350
362
|
}, time);
|
|
351
363
|
}
|
|
@@ -359,14 +371,23 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
359
371
|
hardwareImplemented: this.audioSupported, // siri is only allowed for hardware implemented remotes
|
|
360
372
|
};
|
|
361
373
|
const supportedButtons = [
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
ButtonType.MENU,
|
|
375
|
+
ButtonType.PLAY_PAUSE,
|
|
376
|
+
ButtonType.TV_HOME,
|
|
377
|
+
ButtonType.SELECT,
|
|
378
|
+
ButtonType.ARROW_UP,
|
|
379
|
+
ButtonType.ARROW_RIGHT,
|
|
380
|
+
ButtonType.ARROW_DOWN,
|
|
381
|
+
ButtonType.ARROW_LEFT,
|
|
382
|
+
ButtonType.VOLUME_UP,
|
|
383
|
+
ButtonType.VOLUME_DOWN,
|
|
384
|
+
ButtonType.POWER,
|
|
385
|
+
ButtonType.GENERIC,
|
|
365
386
|
];
|
|
366
387
|
if (this.audioSupported) { // add siri button if this remote supports it
|
|
367
|
-
supportedButtons.push(
|
|
388
|
+
supportedButtons.push(ButtonType.SIRI);
|
|
368
389
|
}
|
|
369
|
-
supportedButtons.forEach(button => {
|
|
390
|
+
supportedButtons.forEach((button) => {
|
|
370
391
|
const buttonConfiguration = {
|
|
371
392
|
buttonID: 100 + button,
|
|
372
393
|
buttonType: button,
|
|
@@ -390,16 +411,15 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
390
411
|
};
|
|
391
412
|
}
|
|
392
413
|
// --------------------------------- TARGET CONTROL ----------------------------------
|
|
393
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
394
414
|
handleTargetControlWrite(value, callback) {
|
|
395
|
-
const data = Buffer.from(value,
|
|
415
|
+
const data = Buffer.from(value, 'base64');
|
|
396
416
|
const objects = tlv.decode(data);
|
|
397
417
|
const operation = objects[1 /* TargetControlList.OPERATION */][0];
|
|
398
|
-
let targetConfiguration
|
|
418
|
+
let targetConfiguration;
|
|
399
419
|
if (objects[2 /* TargetControlList.TARGET_CONFIGURATION */]) { // if target configuration was sent, parse it
|
|
400
420
|
targetConfiguration = this.parseTargetConfigurationTLV(objects[2 /* TargetControlList.TARGET_CONFIGURATION */]);
|
|
401
421
|
}
|
|
402
|
-
debug(
|
|
422
|
+
debug('Received TargetControl write operation %s', Operation[operation]);
|
|
403
423
|
let handler;
|
|
404
424
|
switch (operation) {
|
|
405
425
|
case Operation.ADD:
|
|
@@ -418,56 +438,56 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
418
438
|
handler = this.handleListTargets.bind(this);
|
|
419
439
|
break;
|
|
420
440
|
default:
|
|
421
|
-
callback(
|
|
441
|
+
callback(HAPStatus.INVALID_VALUE_IN_REQUEST, undefined);
|
|
422
442
|
return;
|
|
423
443
|
}
|
|
424
444
|
const status = handler(targetConfiguration);
|
|
425
|
-
if (status ===
|
|
445
|
+
if (status === HAPStatus.SUCCESS) {
|
|
426
446
|
callback(undefined, this.targetConfigurationsString); // passing value for write response
|
|
427
447
|
if (operation === Operation.ADD && this.activeIdentifier === 0) {
|
|
428
448
|
this.setActiveIdentifier(targetConfiguration.targetIdentifier);
|
|
429
449
|
}
|
|
430
450
|
}
|
|
431
451
|
else {
|
|
432
|
-
callback(new Error(status
|
|
452
|
+
callback(new Error(`${status}`));
|
|
433
453
|
}
|
|
434
454
|
}
|
|
435
455
|
handleAddTarget(targetConfiguration) {
|
|
436
456
|
if (!targetConfiguration) {
|
|
437
|
-
return
|
|
457
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
438
458
|
}
|
|
439
459
|
this.targetConfigurations.set(targetConfiguration.targetIdentifier, targetConfiguration);
|
|
440
|
-
debug(
|
|
460
|
+
debug(`Configured new target '${targetConfiguration.targetName}' with targetIdentifier '${targetConfiguration.targetIdentifier}'`);
|
|
441
461
|
setTimeout(() => this.emit("target-add" /* RemoteControllerEvents.TARGET_ADDED */, targetConfiguration), 0);
|
|
442
462
|
this.updatedTargetConfiguration(); // set response
|
|
443
|
-
return
|
|
463
|
+
return HAPStatus.SUCCESS;
|
|
444
464
|
}
|
|
445
465
|
handleUpdateTarget(targetConfiguration) {
|
|
446
466
|
if (!targetConfiguration) {
|
|
447
|
-
return
|
|
467
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
448
468
|
}
|
|
449
469
|
const updates = [];
|
|
450
470
|
const configuredTarget = this.targetConfigurations.get(targetConfiguration.targetIdentifier);
|
|
451
471
|
if (!configuredTarget) {
|
|
452
|
-
return
|
|
472
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
453
473
|
}
|
|
454
474
|
if (targetConfiguration.targetName) {
|
|
455
|
-
debug(
|
|
475
|
+
debug('Target name was updated \'%s\' => \'%s\' (%d)', configuredTarget.targetName, targetConfiguration.targetName, configuredTarget.targetIdentifier);
|
|
456
476
|
configuredTarget.targetName = targetConfiguration.targetName;
|
|
457
477
|
updates.push(0 /* TargetUpdates.NAME */);
|
|
458
478
|
}
|
|
459
479
|
if (targetConfiguration.targetCategory) {
|
|
460
|
-
debug(
|
|
480
|
+
debug('Target category was updated \'%d\' => \'%d\' for target \'%s\' (%d)', configuredTarget.targetCategory, targetConfiguration.targetCategory, configuredTarget.targetName, configuredTarget.targetIdentifier);
|
|
461
481
|
configuredTarget.targetCategory = targetConfiguration.targetCategory;
|
|
462
482
|
updates.push(1 /* TargetUpdates.CATEGORY */);
|
|
463
483
|
}
|
|
464
484
|
// the parsed buttonConfiguration is an empty object when the request didn't contain any buttons
|
|
465
485
|
if (Object.keys(targetConfiguration.buttonConfiguration).length > 0) {
|
|
466
|
-
debug(
|
|
486
|
+
debug('%d button configurations were updated for target \'%s\' (%d)', Object.keys(targetConfiguration.buttonConfiguration).length, configuredTarget.targetName, configuredTarget.targetIdentifier);
|
|
467
487
|
for (const configuration of Object.values(targetConfiguration.buttonConfiguration)) {
|
|
468
488
|
const savedConfiguration = configuredTarget.buttonConfiguration[configuration.buttonID];
|
|
469
489
|
if (!savedConfiguration) {
|
|
470
|
-
debug(
|
|
490
|
+
debug('Ignoring update for unknown button %d of target \'%s\' (%d)', configuration.buttonID, configuredTarget.targetName, configuredTarget.targetIdentifier);
|
|
471
491
|
continue;
|
|
472
492
|
}
|
|
473
493
|
savedConfiguration.buttonType = configuration.buttonType;
|
|
@@ -477,29 +497,29 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
477
497
|
}
|
|
478
498
|
setTimeout(() => this.emit("target-update" /* RemoteControllerEvents.TARGET_UPDATED */, targetConfiguration, updates), 0);
|
|
479
499
|
this.updatedTargetConfiguration(); // set response
|
|
480
|
-
return
|
|
500
|
+
return HAPStatus.SUCCESS;
|
|
481
501
|
}
|
|
482
502
|
handleRemoveTarget(targetConfiguration) {
|
|
483
503
|
if (!targetConfiguration) {
|
|
484
|
-
return
|
|
504
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
485
505
|
}
|
|
486
506
|
const configuredTarget = this.targetConfigurations.get(targetConfiguration.targetIdentifier);
|
|
487
507
|
if (!configuredTarget) {
|
|
488
|
-
return
|
|
508
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
489
509
|
}
|
|
490
510
|
// the parsed buttonConfiguration is an empty object when the request didn't contain any buttons
|
|
491
511
|
if (Object.keys(targetConfiguration.buttonConfiguration).length > 0) {
|
|
492
512
|
for (const key in targetConfiguration.buttonConfiguration) {
|
|
493
|
-
if (Object.
|
|
513
|
+
if (Object.hasOwn(targetConfiguration.buttonConfiguration, key)) {
|
|
494
514
|
delete configuredTarget.buttonConfiguration[key];
|
|
495
515
|
}
|
|
496
516
|
}
|
|
497
|
-
debug(
|
|
517
|
+
debug('Removed %d button configurations of target \'%s\' (%d)', Object.keys(targetConfiguration.buttonConfiguration).length, configuredTarget.targetName, configuredTarget.targetIdentifier);
|
|
498
518
|
setTimeout(() => this.emit("target-update" /* RemoteControllerEvents.TARGET_UPDATED */, configuredTarget, [3 /* TargetUpdates.REMOVED_BUTTONS */]), 0);
|
|
499
519
|
}
|
|
500
520
|
else {
|
|
501
521
|
this.targetConfigurations.delete(targetConfiguration.targetIdentifier);
|
|
502
|
-
debug(
|
|
522
|
+
debug('Target \'%s\' (%d) was removed', configuredTarget.targetName, configuredTarget.targetIdentifier);
|
|
503
523
|
setTimeout(() => this.emit("target-remove" /* RemoteControllerEvents.TARGET_REMOVED */, targetConfiguration.targetIdentifier), 0);
|
|
504
524
|
if (this.activeIdentifier === targetConfiguration.targetIdentifier) {
|
|
505
525
|
// switch to next available remote
|
|
@@ -507,31 +527,31 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
507
527
|
}
|
|
508
528
|
}
|
|
509
529
|
this.updatedTargetConfiguration(); // set response
|
|
510
|
-
return
|
|
530
|
+
return HAPStatus.SUCCESS;
|
|
511
531
|
}
|
|
512
532
|
handleResetTargets(targetConfiguration) {
|
|
513
533
|
if (targetConfiguration) {
|
|
514
|
-
return
|
|
534
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
515
535
|
}
|
|
516
|
-
debug(
|
|
536
|
+
debug('Resetting all target configurations');
|
|
517
537
|
this.targetConfigurations = new Map();
|
|
518
538
|
this.updatedTargetConfiguration(); // set response
|
|
519
539
|
setTimeout(() => this.emit("targets-reset" /* RemoteControllerEvents.TARGETS_RESET */), 0);
|
|
520
540
|
this.setActiveIdentifier(0); // resetting active identifier (also sets active to false)
|
|
521
|
-
return
|
|
541
|
+
return HAPStatus.SUCCESS;
|
|
522
542
|
}
|
|
523
543
|
handleListTargets(targetConfiguration) {
|
|
524
544
|
if (targetConfiguration) {
|
|
525
|
-
return
|
|
545
|
+
return HAPStatus.INVALID_VALUE_IN_REQUEST;
|
|
526
546
|
}
|
|
527
547
|
// this.targetConfigurationsString is updated after each change, so we basically don't need to do anything here
|
|
528
|
-
debug(
|
|
529
|
-
return
|
|
548
|
+
debug(`Returning ${this.targetConfigurations.size} target configurations`);
|
|
549
|
+
return HAPStatus.SUCCESS;
|
|
530
550
|
}
|
|
531
551
|
handleActiveWrite(value, callback, connection) {
|
|
532
552
|
if (this.activeIdentifier === 0) {
|
|
533
|
-
debug(
|
|
534
|
-
callback(
|
|
553
|
+
debug('Tried to change active state. There is no active target set though');
|
|
554
|
+
callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
|
|
535
555
|
return;
|
|
536
556
|
}
|
|
537
557
|
if (this.activeConnection) {
|
|
@@ -546,10 +566,10 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
546
566
|
}
|
|
547
567
|
const activeTarget = this.targetConfigurations.get(this.activeIdentifier);
|
|
548
568
|
if (!activeTarget) {
|
|
549
|
-
callback(
|
|
569
|
+
callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
|
|
550
570
|
return;
|
|
551
571
|
}
|
|
552
|
-
debug(
|
|
572
|
+
debug('Remote with activeTarget \'%s\' (%d) was set to %s', activeTarget.targetName, this.activeIdentifier, value ? 'ACTIVE' : 'INACTIVE');
|
|
553
573
|
callback();
|
|
554
574
|
this.emit("active-change" /* RemoteControllerEvents.ACTIVE_CHANGE */, value);
|
|
555
575
|
}
|
|
@@ -560,61 +580,64 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
560
580
|
this.activeConnection.removeListener("closed" /* HAPConnectionEvent.CLOSED */, this.activeConnectionDisconnectListener);
|
|
561
581
|
this.activeConnection = undefined;
|
|
562
582
|
this.activeConnectionDisconnectListener = undefined;
|
|
563
|
-
this.targetControlService.getCharacteristic(
|
|
564
|
-
debug(
|
|
583
|
+
this.targetControlService.getCharacteristic(Characteristic.Active).updateValue(false);
|
|
584
|
+
debug('Remote was set to INACTIVE');
|
|
565
585
|
setTimeout(() => this.emit("active-change" /* RemoteControllerEvents.ACTIVE_CHANGE */, false), 0);
|
|
566
586
|
}
|
|
567
587
|
handleActiveSessionDisconnected(connection) {
|
|
568
588
|
if (connection !== this.activeConnection) {
|
|
569
589
|
return;
|
|
570
590
|
}
|
|
571
|
-
debug(
|
|
591
|
+
debug('Active hap session disconnected!');
|
|
572
592
|
this.setInactive();
|
|
573
593
|
}
|
|
574
594
|
sendButtonEvent(button, buttonState) {
|
|
575
595
|
const buttonID = this.buttons[button];
|
|
576
596
|
if (buttonID === undefined || buttonID === 0) {
|
|
577
|
-
throw new Error(
|
|
597
|
+
throw new Error(`Tried sending button event for unsupported button (${button})`);
|
|
578
598
|
}
|
|
579
599
|
if (this.activeIdentifier === 0) { // cannot press button if no device is selected
|
|
580
|
-
throw new Error(
|
|
600
|
+
throw new Error('Tried sending button event although no target was selected');
|
|
581
601
|
}
|
|
582
602
|
if (!this.isActive()) { // cannot press button if device is not active (aka no Apple TV is listening)
|
|
583
|
-
throw new Error(
|
|
603
|
+
throw new Error('Tried sending button event although target was not marked as active');
|
|
584
604
|
}
|
|
585
|
-
if (button ===
|
|
586
|
-
if (buttonState ===
|
|
605
|
+
if (button === ButtonType.SIRI && this.audioSupported) {
|
|
606
|
+
if (buttonState === ButtonState.DOWN) { // start streaming session
|
|
587
607
|
this.handleSiriAudioStart();
|
|
588
608
|
}
|
|
589
|
-
else if (buttonState ===
|
|
609
|
+
else if (buttonState === ButtonState.UP) { // stop streaming session
|
|
590
610
|
this.handleSiriAudioStop();
|
|
591
611
|
}
|
|
592
612
|
return;
|
|
593
613
|
}
|
|
594
614
|
const buttonIdTlv = tlv.encode(1 /* ButtonEvent.BUTTON_ID */, buttonID);
|
|
595
615
|
const buttonStateTlv = tlv.encode(2 /* ButtonEvent.BUTTON_STATE */, buttonState);
|
|
596
|
-
const timestampTlv = tlv.encode(3 /* ButtonEvent.TIMESTAMP */, tlv.writeVariableUIntLE(
|
|
616
|
+
const timestampTlv = tlv.encode(3 /* ButtonEvent.TIMESTAMP */, tlv.writeVariableUIntLE(Date.now()));
|
|
597
617
|
const activeIdentifierTlv = tlv.encode(4 /* ButtonEvent.ACTIVE_IDENTIFIER */, tlv.writeUInt32(this.activeIdentifier));
|
|
598
618
|
this.lastButtonEvent = Buffer.concat([
|
|
599
|
-
buttonIdTlv,
|
|
600
|
-
|
|
601
|
-
|
|
619
|
+
buttonIdTlv,
|
|
620
|
+
buttonStateTlv,
|
|
621
|
+
timestampTlv,
|
|
622
|
+
activeIdentifierTlv,
|
|
623
|
+
]).toString('base64');
|
|
624
|
+
this.targetControlService.getCharacteristic(Characteristic.ButtonEvent).sendEventNotification(this.lastButtonEvent);
|
|
602
625
|
}
|
|
603
626
|
parseTargetConfigurationTLV(data) {
|
|
604
627
|
const configTLV = tlv.decode(data);
|
|
605
628
|
const identifier = tlv.readUInt32(configTLV[1 /* TargetConfigurationTypes.TARGET_IDENTIFIER */]);
|
|
606
|
-
let name
|
|
629
|
+
let name;
|
|
607
630
|
if (configTLV[2 /* TargetConfigurationTypes.TARGET_NAME */]) {
|
|
608
631
|
name = configTLV[2 /* TargetConfigurationTypes.TARGET_NAME */].toString();
|
|
609
632
|
}
|
|
610
|
-
let category
|
|
633
|
+
let category;
|
|
611
634
|
if (configTLV[3 /* TargetConfigurationTypes.TARGET_CATEGORY */]) {
|
|
612
635
|
category = tlv.readUInt16(configTLV[3 /* TargetConfigurationTypes.TARGET_CATEGORY */]);
|
|
613
636
|
}
|
|
614
637
|
const buttonConfiguration = {};
|
|
615
638
|
if (configTLV[4 /* TargetConfigurationTypes.BUTTON_CONFIGURATION */]) {
|
|
616
639
|
const buttonConfigurationTLV = tlv.decodeList(configTLV[4 /* TargetConfigurationTypes.BUTTON_CONFIGURATION */], 1 /* ButtonConfigurationTypes.BUTTON_ID */);
|
|
617
|
-
buttonConfigurationTLV.forEach(entry => {
|
|
640
|
+
buttonConfigurationTLV.forEach((entry) => {
|
|
618
641
|
const buttonId = entry[1 /* ButtonConfigurationTypes.BUTTON_ID */][0];
|
|
619
642
|
const buttonType = tlv.readUInt16(entry[2 /* ButtonConfigurationTypes.BUTTON_TYPE */]);
|
|
620
643
|
let buttonName;
|
|
@@ -622,13 +645,12 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
622
645
|
buttonName = entry[3 /* ButtonConfigurationTypes.BUTTON_NAME */].toString();
|
|
623
646
|
}
|
|
624
647
|
else {
|
|
625
|
-
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
626
648
|
buttonName = ButtonType[buttonType];
|
|
627
649
|
}
|
|
628
650
|
buttonConfiguration[buttonId] = {
|
|
629
651
|
buttonID: buttonId,
|
|
630
|
-
buttonType
|
|
631
|
-
buttonName
|
|
652
|
+
buttonType,
|
|
653
|
+
buttonName,
|
|
632
654
|
};
|
|
633
655
|
});
|
|
634
656
|
}
|
|
@@ -636,7 +658,7 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
636
658
|
targetIdentifier: identifier,
|
|
637
659
|
targetName: name,
|
|
638
660
|
targetCategory: category,
|
|
639
|
-
buttonConfiguration
|
|
661
|
+
buttonConfiguration,
|
|
640
662
|
};
|
|
641
663
|
}
|
|
642
664
|
updatedTargetConfiguration() {
|
|
@@ -657,55 +679,64 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
657
679
|
buttonConfigurationBuffers.push(tlvBuffer);
|
|
658
680
|
}
|
|
659
681
|
const buttonConfiguration = tlv.encode(4 /* TargetConfigurationTypes.BUTTON_CONFIGURATION */, Buffer.concat(buttonConfigurationBuffers));
|
|
660
|
-
const targetConfiguration = Buffer.concat([
|
|
682
|
+
const targetConfiguration = Buffer.concat([
|
|
683
|
+
targetIdentifier,
|
|
684
|
+
targetName,
|
|
685
|
+
targetCategory,
|
|
686
|
+
buttonConfiguration,
|
|
687
|
+
]);
|
|
661
688
|
bufferList.push(targetConfiguration);
|
|
662
689
|
}
|
|
663
690
|
// targets are a tlv list, thus every entry is separated by an empty tlv
|
|
664
691
|
this.targetConfigurationsString = bufferList.length === 0
|
|
665
|
-
?
|
|
666
|
-
: tlv.encode(2 /* TargetControlList.TARGET_CONFIGURATION */, bufferList).toString(
|
|
692
|
+
? ''
|
|
693
|
+
: tlv.encode(2 /* TargetControlList.TARGET_CONFIGURATION */, bufferList).toString('base64');
|
|
667
694
|
this.stateChangeDelegate?.();
|
|
668
695
|
}
|
|
669
696
|
buildTargetControlSupportedConfigurationTLV(configuration) {
|
|
670
697
|
const maximumTargets = tlv.encode(1 /* TargetControlCommands.MAXIMUM_TARGETS */, configuration.maximumTargets);
|
|
671
698
|
const ticksPerSecond = tlv.encode(2 /* TargetControlCommands.TICKS_PER_SECOND */, tlv.writeVariableUIntLE(configuration.ticksPerSecond));
|
|
672
699
|
const supportedButtonConfigurationBuffers = [];
|
|
673
|
-
configuration.supportedButtonConfiguration.forEach(value => {
|
|
700
|
+
configuration.supportedButtonConfiguration.forEach((value) => {
|
|
674
701
|
const tlvBuffer = tlv.encode(1 /* SupportedButtonConfigurationTypes.BUTTON_ID */, value.buttonID, 2 /* SupportedButtonConfigurationTypes.BUTTON_TYPE */, tlv.writeUInt16(value.buttonType));
|
|
675
702
|
supportedButtonConfigurationBuffers.push(tlvBuffer);
|
|
676
703
|
});
|
|
677
704
|
const supportedButtonConfiguration = tlv.encode(3 /* TargetControlCommands.SUPPORTED_BUTTON_CONFIGURATION */, Buffer.concat(supportedButtonConfigurationBuffers));
|
|
678
705
|
const type = tlv.encode(4 /* TargetControlCommands.TYPE */, configuration.hardwareImplemented ? 1 : 0);
|
|
679
|
-
return Buffer.concat([
|
|
706
|
+
return Buffer.concat([
|
|
707
|
+
maximumTargets,
|
|
708
|
+
ticksPerSecond,
|
|
709
|
+
supportedButtonConfiguration,
|
|
710
|
+
type,
|
|
711
|
+
]).toString('base64');
|
|
680
712
|
}
|
|
681
713
|
// --------------------------------- SIRI/DATA STREAM --------------------------------
|
|
682
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
683
714
|
handleTargetControlWhoAmI(connection, message) {
|
|
684
715
|
const targetIdentifier = message.identifier;
|
|
685
716
|
this.dataStreamConnections.set(targetIdentifier, connection);
|
|
686
|
-
debug(
|
|
717
|
+
debug('Discovered HDS connection for targetIdentifier %s', targetIdentifier);
|
|
687
718
|
connection.addProtocolHandler("dataSend" /* Protocols.DATA_SEND */, this);
|
|
688
719
|
}
|
|
689
720
|
handleSiriAudioStart() {
|
|
690
721
|
if (!this.audioSupported) {
|
|
691
|
-
throw new Error(
|
|
722
|
+
throw new Error('Cannot start siri stream on remote where siri is not supported');
|
|
692
723
|
}
|
|
693
724
|
if (!this.isActive()) {
|
|
694
|
-
debug(
|
|
725
|
+
debug('Tried opening Siri audio stream, however no controller is connected!');
|
|
695
726
|
return;
|
|
696
727
|
}
|
|
697
728
|
if (this.activeAudioSession && (!this.activeAudioSession.isClosing() || this.nextAudioSession)) {
|
|
698
729
|
// there is already a session running, which is not in closing state and/or there is even already a
|
|
699
730
|
// nextAudioSession running. ignoring start request
|
|
700
|
-
debug(
|
|
731
|
+
debug('Tried opening Siri audio stream, however there is already one in progress');
|
|
701
732
|
return;
|
|
702
733
|
}
|
|
703
734
|
const connection = this.dataStreamConnections.get(this.activeIdentifier); // get connection for current target
|
|
704
735
|
if (connection === undefined) { // target seems not connected, ignore it
|
|
705
|
-
debug(
|
|
736
|
+
debug('Tried opening Siri audio stream however target is not connected via HDS');
|
|
706
737
|
return;
|
|
707
738
|
}
|
|
708
|
-
// eslint-disable-next-line
|
|
739
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
709
740
|
const audioSession = new SiriAudioSession(connection, this.selectedAudioConfiguration, this.audioProducerConstructor, this.audioProducerOptions);
|
|
710
741
|
if (!this.activeAudioSession) {
|
|
711
742
|
this.activeAudioSession = audioSession;
|
|
@@ -729,9 +760,8 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
729
760
|
return;
|
|
730
761
|
}
|
|
731
762
|
}
|
|
732
|
-
debug(
|
|
763
|
+
debug('handleSiriAudioStop called although no audio session was started');
|
|
733
764
|
}
|
|
734
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
735
765
|
handleDataSendAckEvent(message) {
|
|
736
766
|
const streamId = message.streamId;
|
|
737
767
|
const endOfStream = message.endOfStream;
|
|
@@ -742,10 +772,9 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
742
772
|
this.nextAudioSession.handleDataSendAckEvent(endOfStream);
|
|
743
773
|
}
|
|
744
774
|
else {
|
|
745
|
-
debug(
|
|
775
|
+
debug('Received dataSend acknowledgment event for unknown streamId \'%s\'', streamId);
|
|
746
776
|
}
|
|
747
777
|
}
|
|
748
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
749
778
|
handleDataSendCloseEvent(message) {
|
|
750
779
|
const streamId = message.streamId;
|
|
751
780
|
const reason = message.reason;
|
|
@@ -756,7 +785,7 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
756
785
|
this.nextAudioSession.handleDataSendCloseEvent(reason);
|
|
757
786
|
}
|
|
758
787
|
else {
|
|
759
|
-
debug(
|
|
788
|
+
debug('Received dataSend close event for unknown streamId \'%s\'', streamId);
|
|
760
789
|
}
|
|
761
790
|
}
|
|
762
791
|
handleSiriAudioSessionClosed(session) {
|
|
@@ -771,16 +800,15 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
771
800
|
handleDataStreamConnectionClosed(connection) {
|
|
772
801
|
for (const [targetIdentifier, connection0] of this.dataStreamConnections) {
|
|
773
802
|
if (connection === connection0) {
|
|
774
|
-
debug(
|
|
803
|
+
debug('HDS connection disconnected for targetIdentifier %s', targetIdentifier);
|
|
775
804
|
this.dataStreamConnections.delete(targetIdentifier);
|
|
776
805
|
break;
|
|
777
806
|
}
|
|
778
807
|
}
|
|
779
808
|
}
|
|
780
809
|
// ------------------------------- AUDIO CONFIGURATION -------------------------------
|
|
781
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
782
810
|
handleSelectedAudioConfigurationWrite(value, callback) {
|
|
783
|
-
const data = Buffer.from(value,
|
|
811
|
+
const data = Buffer.from(value, 'base64');
|
|
784
812
|
const objects = tlv.decode(data);
|
|
785
813
|
const selectedAudioStreamConfiguration = tlv.decode(objects[1 /* SelectedAudioInputStreamConfigurationTypes.SELECTED_AUDIO_INPUT_STREAM_CONFIGURATION */]);
|
|
786
814
|
const codec = selectedAudioStreamConfiguration[1 /* AudioCodecConfigurationTypes.CODEC_TYPE */][0];
|
|
@@ -791,9 +819,9 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
791
819
|
this.selectedAudioConfiguration = {
|
|
792
820
|
codecType: codec,
|
|
793
821
|
parameters: {
|
|
794
|
-
channels
|
|
795
|
-
bitrate
|
|
796
|
-
samplerate
|
|
822
|
+
channels,
|
|
823
|
+
bitrate,
|
|
824
|
+
samplerate,
|
|
797
825
|
rtpTime: 20,
|
|
798
826
|
},
|
|
799
827
|
};
|
|
@@ -805,12 +833,12 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
805
833
|
static buildSupportedAudioConfigurationTLV(configuration) {
|
|
806
834
|
const codecConfigurationTLV = RemoteController.buildCodecConfigurationTLV(configuration.audioCodecConfiguration);
|
|
807
835
|
const supportedAudioStreamConfiguration = tlv.encode(1 /* SupportedAudioStreamConfigurationTypes.AUDIO_CODEC_CONFIGURATION */, codecConfigurationTLV);
|
|
808
|
-
return supportedAudioStreamConfiguration.toString(
|
|
836
|
+
return supportedAudioStreamConfiguration.toString('base64');
|
|
809
837
|
}
|
|
810
838
|
static buildSelectedAudioConfigurationTLV(configuration) {
|
|
811
839
|
const codecConfigurationTLV = RemoteController.buildCodecConfigurationTLV(configuration.audioCodecConfiguration);
|
|
812
840
|
const supportedAudioStreamConfiguration = tlv.encode(1 /* SelectedAudioInputStreamConfigurationTypes.SELECTED_AUDIO_INPUT_STREAM_CONFIGURATION */, codecConfigurationTLV);
|
|
813
|
-
return supportedAudioStreamConfiguration.toString(
|
|
841
|
+
return supportedAudioStreamConfiguration.toString('base64');
|
|
814
842
|
}
|
|
815
843
|
static buildCodecConfigurationTLV(codecConfiguration) {
|
|
816
844
|
const parameters = codecConfiguration.parameters;
|
|
@@ -828,23 +856,23 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
828
856
|
* @private
|
|
829
857
|
*/
|
|
830
858
|
constructServices() {
|
|
831
|
-
this.targetControlManagementService = new
|
|
832
|
-
this.targetControlManagementService.setCharacteristic(
|
|
833
|
-
this.targetControlManagementService.setCharacteristic(
|
|
859
|
+
this.targetControlManagementService = new Service.TargetControlManagement('', '');
|
|
860
|
+
this.targetControlManagementService.setCharacteristic(Characteristic.TargetControlSupportedConfiguration, this.supportedConfiguration);
|
|
861
|
+
this.targetControlManagementService.setCharacteristic(Characteristic.TargetControlList, this.targetConfigurationsString);
|
|
834
862
|
this.targetControlManagementService.setPrimaryService();
|
|
835
863
|
// you can also expose multiple TargetControl services to control multiple apple tvs simultaneously.
|
|
836
864
|
// should we extend this class to support multiple TargetControl services or should users just create a second accessory?
|
|
837
|
-
this.targetControlService = new
|
|
838
|
-
this.targetControlService.setCharacteristic(
|
|
839
|
-
this.targetControlService.setCharacteristic(
|
|
840
|
-
this.targetControlService.setCharacteristic(
|
|
865
|
+
this.targetControlService = new Service.TargetControl('', '');
|
|
866
|
+
this.targetControlService.setCharacteristic(Characteristic.ActiveIdentifier, 0);
|
|
867
|
+
this.targetControlService.setCharacteristic(Characteristic.Active, false);
|
|
868
|
+
this.targetControlService.setCharacteristic(Characteristic.ButtonEvent, this.lastButtonEvent);
|
|
841
869
|
if (this.audioSupported) {
|
|
842
|
-
this.siriService = new
|
|
843
|
-
this.siriService.setCharacteristic(
|
|
844
|
-
this.audioStreamManagementService = new
|
|
845
|
-
this.audioStreamManagementService.setCharacteristic(
|
|
846
|
-
this.audioStreamManagementService.setCharacteristic(
|
|
847
|
-
this.dataStreamManagement = new
|
|
870
|
+
this.siriService = new Service.Siri('', '');
|
|
871
|
+
this.siriService.setCharacteristic(Characteristic.SiriInputType, Characteristic.SiriInputType.PUSH_BUTTON_TRIGGERED_APPLE_TV);
|
|
872
|
+
this.audioStreamManagementService = new Service.AudioStreamManagement('', '');
|
|
873
|
+
this.audioStreamManagementService.setCharacteristic(Characteristic.SupportedAudioStreamConfiguration, this.supportedAudioConfiguration);
|
|
874
|
+
this.audioStreamManagementService.setCharacteristic(Characteristic.SelectedAudioStreamConfiguration, this.selectedAudioConfigurationString);
|
|
875
|
+
this.dataStreamManagement = new DataStreamManagement();
|
|
848
876
|
this.siriService.addLinkedService(this.dataStreamManagement.getService());
|
|
849
877
|
this.siriService.addLinkedService(this.audioStreamManagementService);
|
|
850
878
|
}
|
|
@@ -864,43 +892,43 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
864
892
|
this.targetControlService = serviceMap.targetControl;
|
|
865
893
|
this.siriService = serviceMap.siri;
|
|
866
894
|
this.audioStreamManagementService = serviceMap.audioStreamManagement;
|
|
867
|
-
this.dataStreamManagement = new
|
|
895
|
+
this.dataStreamManagement = new DataStreamManagement(serviceMap.dataStreamTransportManagement);
|
|
868
896
|
}
|
|
869
897
|
/**
|
|
870
898
|
* @private
|
|
871
899
|
*/
|
|
872
900
|
configureServices() {
|
|
873
901
|
if (!this.targetControlManagementService || !this.targetControlService) {
|
|
874
|
-
throw new Error(
|
|
902
|
+
throw new Error('Unexpected state: Services not configured!'); // playing it save
|
|
875
903
|
}
|
|
876
|
-
this.targetControlManagementService.getCharacteristic(
|
|
877
|
-
.on("get" /* CharacteristicEventTypes.GET */, callback => {
|
|
904
|
+
this.targetControlManagementService.getCharacteristic(Characteristic.TargetControlList)
|
|
905
|
+
.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
|
|
878
906
|
callback(null, this.targetConfigurationsString);
|
|
879
907
|
})
|
|
880
908
|
.on("set" /* CharacteristicEventTypes.SET */, this.handleTargetControlWrite.bind(this));
|
|
881
|
-
this.targetControlService.getCharacteristic(
|
|
882
|
-
.on("get" /* CharacteristicEventTypes.GET */, callback => {
|
|
909
|
+
this.targetControlService.getCharacteristic(Characteristic.ActiveIdentifier)
|
|
910
|
+
.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
|
|
883
911
|
callback(undefined, this.activeIdentifier);
|
|
884
912
|
});
|
|
885
|
-
this.targetControlService.getCharacteristic(
|
|
886
|
-
.on("get" /* CharacteristicEventTypes.GET */, callback => {
|
|
913
|
+
this.targetControlService.getCharacteristic(Characteristic.Active)
|
|
914
|
+
.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
|
|
887
915
|
callback(undefined, this.isActive());
|
|
888
916
|
})
|
|
889
917
|
.on("set" /* CharacteristicEventTypes.SET */, (value, callback, context, connection) => {
|
|
890
918
|
if (!connection) {
|
|
891
|
-
debug(
|
|
892
|
-
callback(
|
|
919
|
+
debug('Set event handler for Remote.Active cannot be called from plugin. Connection undefined!');
|
|
920
|
+
callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
|
|
893
921
|
return;
|
|
894
922
|
}
|
|
895
923
|
this.handleActiveWrite(value, callback, connection);
|
|
896
924
|
});
|
|
897
|
-
this.targetControlService.getCharacteristic(
|
|
925
|
+
this.targetControlService.getCharacteristic(Characteristic.ButtonEvent)
|
|
898
926
|
.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
|
|
899
927
|
callback(undefined, this.lastButtonEvent);
|
|
900
928
|
});
|
|
901
929
|
if (this.audioSupported) {
|
|
902
|
-
this.audioStreamManagementService.getCharacteristic(
|
|
903
|
-
.on("get" /* CharacteristicEventTypes.GET */, callback => {
|
|
930
|
+
this.audioStreamManagementService.getCharacteristic(Characteristic.SelectedAudioStreamConfiguration)
|
|
931
|
+
.on("get" /* CharacteristicEventTypes.GET */, (callback) => {
|
|
904
932
|
callback(null, this.selectedAudioConfigurationString);
|
|
905
933
|
})
|
|
906
934
|
.on("set" /* CharacteristicEventTypes.SET */, this.handleSelectedAudioConfigurationWrite.bind(this))
|
|
@@ -935,9 +963,9 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
935
963
|
* @private
|
|
936
964
|
*/
|
|
937
965
|
handleFactoryReset() {
|
|
938
|
-
debug(
|
|
966
|
+
debug('Running factory reset. Resetting targets...');
|
|
939
967
|
this.handleResetTargets(undefined);
|
|
940
|
-
this.lastButtonEvent =
|
|
968
|
+
this.lastButtonEvent = '';
|
|
941
969
|
}
|
|
942
970
|
/**
|
|
943
971
|
* @private
|
|
@@ -973,27 +1001,27 @@ class RemoteController extends events_1.EventEmitter {
|
|
|
973
1001
|
this.stateChangeDelegate = delegate;
|
|
974
1002
|
}
|
|
975
1003
|
}
|
|
976
|
-
exports.RemoteController = RemoteController;
|
|
977
1004
|
/**
|
|
978
1005
|
* @group Apple TV Remote
|
|
979
1006
|
*/
|
|
980
|
-
|
|
1007
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
1008
|
+
export var SiriAudioSessionEvents;
|
|
981
1009
|
(function (SiriAudioSessionEvents) {
|
|
982
1010
|
SiriAudioSessionEvents["CLOSE"] = "close";
|
|
983
|
-
})(SiriAudioSessionEvents || (
|
|
1011
|
+
})(SiriAudioSessionEvents || (SiriAudioSessionEvents = {}));
|
|
984
1012
|
/**
|
|
985
1013
|
* Represents an ongoing audio transmission
|
|
986
1014
|
* @group Apple TV Remote
|
|
987
1015
|
*/
|
|
988
|
-
// eslint-disable-next-line
|
|
989
|
-
class SiriAudioSession extends
|
|
1016
|
+
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
1017
|
+
export class SiriAudioSession extends EventEmitter {
|
|
990
1018
|
connection;
|
|
991
1019
|
selectedAudioConfiguration;
|
|
992
1020
|
producer;
|
|
993
1021
|
producerRunning = false; // indicates if the producer is running
|
|
994
1022
|
producerTimer; // producer has a 3s timeout to produce the first frame, otherwise transmission will be cancelled
|
|
995
1023
|
/**
|
|
996
|
-
* @private
|
|
1024
|
+
* @private
|
|
997
1025
|
*/
|
|
998
1026
|
state = 0 /* SiriAudioSessionState.STARTING */;
|
|
999
1027
|
streamId; // present when state >= SENDING
|
|
@@ -1003,7 +1031,7 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1003
1031
|
sequenceNumber = 0;
|
|
1004
1032
|
closeListener;
|
|
1005
1033
|
constructor(connection, selectedAudioConfiguration, producerConstructor,
|
|
1006
|
-
// eslint-disable-next-line
|
|
1034
|
+
// eslint-disable-next-line ts/explicit-module-boundary-types
|
|
1007
1035
|
producerOptions) {
|
|
1008
1036
|
super();
|
|
1009
1037
|
this.connection = connection;
|
|
@@ -1015,24 +1043,24 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1015
1043
|
* Called when siri button is pressed
|
|
1016
1044
|
*/
|
|
1017
1045
|
start() {
|
|
1018
|
-
debug(
|
|
1046
|
+
debug('Sending request to start siri audio stream');
|
|
1019
1047
|
// opening dataSend
|
|
1020
1048
|
this.connection.sendRequest("dataSend" /* Protocols.DATA_SEND */, "open" /* Topics.OPEN */, {
|
|
1021
|
-
target:
|
|
1022
|
-
type:
|
|
1049
|
+
target: 'controller',
|
|
1050
|
+
type: 'audio.siri',
|
|
1023
1051
|
}, (error, status, message) => {
|
|
1024
1052
|
if (this.state === 3 /* SiriAudioSessionState.CLOSED */) {
|
|
1025
|
-
debug(
|
|
1053
|
+
debug('Ignoring dataSend open response as the session is already closed');
|
|
1026
1054
|
return;
|
|
1027
1055
|
}
|
|
1028
|
-
|
|
1056
|
+
assert.strictEqual(this.state, 0 /* SiriAudioSessionState.STARTING */);
|
|
1029
1057
|
this.state = 1 /* SiriAudioSessionState.SENDING */;
|
|
1030
1058
|
if (error || status) {
|
|
1031
1059
|
if (error) { // errors get produced by hap-nodejs
|
|
1032
|
-
debug(
|
|
1060
|
+
debug('Error occurred trying to start siri audio stream: %s', error.message);
|
|
1033
1061
|
}
|
|
1034
1062
|
else if (status) { // status codes are those returned by the hds response
|
|
1035
|
-
debug(
|
|
1063
|
+
debug('Controller responded with non-zero status code: %s', HDSStatus[status]);
|
|
1036
1064
|
}
|
|
1037
1065
|
if (this.producerRunning) {
|
|
1038
1066
|
this.stopAudioProducer();
|
|
@@ -1042,10 +1070,10 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1042
1070
|
else {
|
|
1043
1071
|
this.streamId = message.streamId;
|
|
1044
1072
|
if (!this.producerRunning) { // audio producer errored in the meantime
|
|
1045
|
-
this.sendDataSendCloseEvent(
|
|
1073
|
+
this.sendDataSendCloseEvent(HDSProtocolSpecificErrorReason.CANCELLED);
|
|
1046
1074
|
}
|
|
1047
1075
|
else {
|
|
1048
|
-
debug(
|
|
1076
|
+
debug('Successfully setup siri audio stream with streamId %d', this.streamId);
|
|
1049
1077
|
}
|
|
1050
1078
|
}
|
|
1051
1079
|
});
|
|
@@ -1061,8 +1089,8 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1061
1089
|
* Called when siri button is released (or active identifier is changed to another device)
|
|
1062
1090
|
*/
|
|
1063
1091
|
stop() {
|
|
1064
|
-
(
|
|
1065
|
-
debug(
|
|
1092
|
+
assert(this.state <= 1 /* SiriAudioSessionState.SENDING */, 'state was higher than SENDING');
|
|
1093
|
+
debug('Stopping siri audio stream with streamId %d', this.streamId);
|
|
1066
1094
|
this.endOfStream = true; // mark as endOfStream
|
|
1067
1095
|
this.stopAudioProducer();
|
|
1068
1096
|
if (this.state === 1 /* SiriAudioSessionState.SENDING */) {
|
|
@@ -1077,9 +1105,9 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1077
1105
|
this.producer.startAudioProduction(this.selectedAudioConfiguration);
|
|
1078
1106
|
this.producerRunning = true;
|
|
1079
1107
|
this.producerTimer = setTimeout(() => {
|
|
1080
|
-
debug(
|
|
1108
|
+
debug('Didn\'t receive any frames from audio producer for stream with streamId %s. Canceling the stream now.', this.streamId);
|
|
1081
1109
|
this.producerTimer = undefined;
|
|
1082
|
-
this.handleProducerError(
|
|
1110
|
+
this.handleProducerError(HDSProtocolSpecificErrorReason.CANCELLED);
|
|
1083
1111
|
}, 3000);
|
|
1084
1112
|
this.producerTimer.unref();
|
|
1085
1113
|
}
|
|
@@ -1106,28 +1134,29 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1106
1134
|
return;
|
|
1107
1135
|
}
|
|
1108
1136
|
let queued;
|
|
1137
|
+
// eslint-disable-next-line no-cond-assign
|
|
1109
1138
|
while ((queued = this.popSome()) !== null) { // send packets
|
|
1110
1139
|
const packets = [];
|
|
1111
|
-
queued.forEach(frame => {
|
|
1140
|
+
queued.forEach((frame) => {
|
|
1112
1141
|
const packetData = {
|
|
1113
1142
|
data: frame.data,
|
|
1114
1143
|
metadata: {
|
|
1115
|
-
rms: new
|
|
1116
|
-
sequenceNumber: new
|
|
1144
|
+
rms: new Float32(frame.rms),
|
|
1145
|
+
sequenceNumber: new Int64(this.sequenceNumber++),
|
|
1117
1146
|
},
|
|
1118
1147
|
};
|
|
1119
1148
|
packets.push(packetData);
|
|
1120
1149
|
});
|
|
1121
1150
|
const message = {
|
|
1122
|
-
packets
|
|
1123
|
-
streamId: new
|
|
1151
|
+
packets,
|
|
1152
|
+
streamId: new Int64(this.streamId),
|
|
1124
1153
|
endOfStream: this.endOfStream,
|
|
1125
1154
|
};
|
|
1126
1155
|
try {
|
|
1127
1156
|
this.connection.sendEvent("dataSend" /* Protocols.DATA_SEND */, "data" /* Topics.DATA */, message);
|
|
1128
1157
|
}
|
|
1129
1158
|
catch (error) {
|
|
1130
|
-
debug(
|
|
1159
|
+
debug('Error occurred when trying to send audio frame of hds connection: %s', error.message);
|
|
1131
1160
|
this.stopAudioProducer();
|
|
1132
1161
|
this.closed();
|
|
1133
1162
|
}
|
|
@@ -1146,29 +1175,28 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1146
1175
|
}
|
|
1147
1176
|
}
|
|
1148
1177
|
handleDataSendAckEvent(endOfStream) {
|
|
1149
|
-
|
|
1150
|
-
debug(
|
|
1151
|
-
this.sendDataSendCloseEvent(
|
|
1178
|
+
assert.strictEqual(endOfStream, true);
|
|
1179
|
+
debug('Received acknowledgment for siri audio stream with streamId %s, closing it now', this.streamId);
|
|
1180
|
+
this.sendDataSendCloseEvent(HDSProtocolSpecificErrorReason.NORMAL);
|
|
1152
1181
|
}
|
|
1153
1182
|
handleDataSendCloseEvent(reason) {
|
|
1154
|
-
|
|
1155
|
-
debug("Received close event from controller with reason %s for stream with streamId %s", datastream_1.HDSProtocolSpecificErrorReason[reason], this.streamId);
|
|
1183
|
+
debug('Received close event from controller with reason %s for stream with streamId %s', HDSProtocolSpecificErrorReason[reason], this.streamId);
|
|
1156
1184
|
if (this.state <= 1 /* SiriAudioSessionState.SENDING */) {
|
|
1157
1185
|
this.stopAudioProducer();
|
|
1158
1186
|
}
|
|
1159
1187
|
this.closed();
|
|
1160
1188
|
}
|
|
1161
1189
|
sendDataSendCloseEvent(reason) {
|
|
1162
|
-
(
|
|
1163
|
-
(
|
|
1190
|
+
assert(this.state >= 1 /* SiriAudioSessionState.SENDING */, 'state was less than SENDING');
|
|
1191
|
+
assert(this.state <= 2 /* SiriAudioSessionState.CLOSING */, 'state was higher than CLOSING');
|
|
1164
1192
|
this.connection.sendEvent("dataSend" /* Protocols.DATA_SEND */, "close" /* Topics.CLOSE */, {
|
|
1165
|
-
streamId: new
|
|
1166
|
-
reason: new
|
|
1193
|
+
streamId: new Int64(this.streamId),
|
|
1194
|
+
reason: new Int64(reason),
|
|
1167
1195
|
});
|
|
1168
1196
|
this.closed();
|
|
1169
1197
|
}
|
|
1170
1198
|
handleDataStreamConnectionClosed() {
|
|
1171
|
-
debug(
|
|
1199
|
+
debug('Closing audio session with streamId %d', this.streamId);
|
|
1172
1200
|
if (this.state <= 1 /* SiriAudioSessionState.SENDING */) {
|
|
1173
1201
|
this.stopAudioProducer();
|
|
1174
1202
|
}
|
|
@@ -1196,5 +1224,4 @@ class SiriAudioSession extends events_1.EventEmitter {
|
|
|
1196
1224
|
return result;
|
|
1197
1225
|
}
|
|
1198
1226
|
}
|
|
1199
|
-
exports.SiriAudioSession = SiriAudioSession;
|
|
1200
1227
|
//# sourceMappingURL=RemoteController.js.map
|