matter-all-in-one-addon 2.3.1 → 2.3.13
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 +16 -8
- package/dist/camera/ai/camera-ai-detector.d.ts +0 -2
- package/dist/camera/ai/camera-ai-detector.js +52 -57
- package/dist/camera/ai/camera-ai-detector.js.map +1 -1
- package/dist/camera/browser-preview.d.ts +9 -0
- package/dist/camera/browser-preview.js +135 -0
- package/dist/camera/browser-preview.js.map +1 -0
- package/dist/camera/camera-source-resolver.js +5 -3
- package/dist/camera/camera-source-resolver.js.map +1 -1
- package/dist/camera/camera-types.d.ts +0 -2
- package/dist/camera/cameraui/cameraui-client.js +91 -30
- package/dist/camera/cameraui/cameraui-client.js.map +1 -1
- package/dist/camera/cameraui/cameraui-homekit-bridge.js +13 -4
- package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -1
- package/dist/camera/cameraui/cameraui-storage.js.map +1 -1
- package/dist/camera/cameraui/cameraui-types.d.ts +6 -2
- package/dist/camera/cameraui/ha-camera-entity.js +5 -2
- package/dist/camera/cameraui/ha-camera-entity.js.map +1 -1
- package/dist/camera/homekit/ffmpeg-helper.js +17 -35
- package/dist/camera/homekit/ffmpeg-helper.js.map +1 -1
- package/dist/camera/homekit/hevc/fmp4-hevc.js +3 -1
- package/dist/camera/homekit/hevc/fmp4-hevc.js.map +1 -1
- package/dist/camera/homekit/hevc/hevc-recording.d.ts +0 -2
- package/dist/camera/homekit/hevc/hevc-recording.js +28 -63
- package/dist/camera/homekit/hevc/hevc-recording.js.map +1 -1
- package/dist/camera/homekit/hevc/multi-tier-rtp.d.ts +1 -15
- package/dist/camera/homekit/hevc/multi-tier-rtp.js +70 -228
- package/dist/camera/homekit/hevc/multi-tier-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/sframe-rtp.d.ts +0 -2
- package/dist/camera/homekit/hevc/sframe-rtp.js +0 -25
- package/dist/camera/homekit/hevc/sframe-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/sframe.d.ts +1 -11
- package/dist/camera/homekit/hevc/sframe.js +18 -133
- package/dist/camera/homekit/hevc/sframe.js.map +1 -1
- package/dist/camera/homekit/hevc/types.js +81 -9
- package/dist/camera/homekit/hevc/types.js.map +1 -1
- package/dist/camera/homekit/hevc/webrtc-session.d.ts +3 -17
- package/dist/camera/homekit/hevc/webrtc-session.js +55 -229
- package/dist/camera/homekit/hevc/webrtc-session.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-recording.delegate.d.ts +0 -1
- package/dist/camera/homekit/homekit-camera-recording.delegate.js +115 -43
- package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-stream.delegate.d.ts +4 -7
- package/dist/camera/homekit/homekit-camera-stream.delegate.js +388 -201
- package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera.accessory.d.ts +7 -34
- package/dist/camera/homekit/homekit-camera.accessory.js +207 -169
- package/dist/camera/homekit/homekit-camera.accessory.js.map +1 -1
- package/dist/camera/homekit/live-view-telemetry.d.ts +0 -4
- package/dist/camera/homekit/live-view-telemetry.js.map +1 -1
- package/dist/camera/homekit/tuya-hap-talkback.d.ts +41 -0
- package/dist/camera/homekit/tuya-hap-talkback.js +326 -0
- package/dist/camera/homekit/tuya-hap-talkback.js.map +1 -0
- package/dist/camera/matter/camera-endpoint.builder.js +9 -7
- package/dist/camera/matter/camera-endpoint.builder.js.map +1 -1
- package/dist/camera/matter/camera-session-manager.d.ts +1 -0
- package/dist/camera/matter/camera-session-manager.js +2 -0
- package/dist/camera/matter/camera-session-manager.js.map +1 -1
- package/dist/camera/matter/camera-webrtc-adapter.js +32 -15
- package/dist/camera/matter/camera-webrtc-adapter.js.map +1 -1
- package/dist/camera/motion/ffmpeg-motion-detector.js +28 -14
- package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -1
- package/dist/camera/nest/nest-camera-adapter.js +9 -5
- package/dist/camera/nest/nest-camera-adapter.js.map +1 -1
- package/dist/camera/ptz/ptz-capabilities.js +3 -1
- package/dist/camera/ptz/ptz-capabilities.js.map +1 -1
- package/dist/camera/ptz/ptz-legacy-discovery.js.map +1 -1
- package/dist/camera/ptz/ptz-mqtt-publisher.js +50 -12
- package/dist/camera/ptz/ptz-mqtt-publisher.js.map +1 -1
- package/dist/camera/ptz/ptz-zones-manager.js +6 -1
- package/dist/camera/ptz/ptz-zones-manager.js.map +1 -1
- package/dist/camera/scrypted/scrypted-camera-card.js +3 -1
- package/dist/camera/scrypted/scrypted-camera-card.js.map +1 -1
- package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js +7 -5
- package/dist/camera/scrypted/scrypted-camera-discovery-adapter.js.map +1 -1
- package/dist/camera/scrypted/scrypted-client-discovery-adapter.js.map +1 -1
- package/dist/camera/scrypted/scrypted-client.js +6 -5
- package/dist/camera/scrypted/scrypted-client.js.map +1 -1
- package/dist/camera/scrypted/scrypted-discovery-provider.js.map +1 -1
- package/dist/camera/scrypted/scrypted-homekit-bridge.js +6 -4
- package/dist/camera/scrypted/scrypted-homekit-bridge.js.map +1 -1
- package/dist/camera/scrypted/scrypted-reconnect-manager.js.map +1 -1
- package/dist/camera/scrypted/scrypted-runtime-facade.js +2 -2
- package/dist/camera/scrypted/scrypted-runtime-facade.js.map +1 -1
- package/dist/camera/scrypted/scrypted-runtime-ingest.js +3 -1
- package/dist/camera/scrypted/scrypted-runtime-ingest.js.map +1 -1
- package/dist/camera/scrypted/scrypted-storage.js +12 -6
- package/dist/camera/scrypted/scrypted-storage.js.map +1 -1
- package/dist/camera/scrypted/scrypted-stream-validator.js +25 -7
- package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -1
- package/dist/camera/tuya-webrtc-session.d.ts +53 -0
- package/dist/camera/tuya-webrtc-session.js +261 -0
- package/dist/camera/tuya-webrtc-session.js.map +1 -0
- package/dist/converters/sensor.converter.js +4 -1
- package/dist/converters/sensor.converter.js.map +1 -1
- package/dist/device-profiles.js +3 -1
- package/dist/device-profiles.js.map +1 -1
- package/dist/entities/air_quality.entity.js +3 -1
- package/dist/entities/air_quality.entity.js.map +1 -1
- package/dist/entities/base.entity.js +45 -17
- package/dist/entities/base.entity.js.map +1 -1
- package/dist/entities/camera.entity.d.ts +1 -0
- package/dist/entities/camera.entity.js +24 -2
- package/dist/entities/camera.entity.js.map +1 -1
- package/dist/entities/composite-device.entity.js +37 -13
- package/dist/entities/composite-device.entity.js.map +1 -1
- package/dist/entities/energy_tariff.entity.js.map +1 -1
- package/dist/entities/pet_feeder.entity.d.ts +1 -0
- package/dist/entities/pet_feeder.entity.js +12 -0
- package/dist/entities/pet_feeder.entity.js.map +1 -1
- package/dist/entities/vacuum.entity.js +16 -5
- package/dist/entities/vacuum.entity.js.map +1 -1
- package/dist/frontend/assets/index-1k-iTL-m.js +26 -0
- package/dist/frontend/assets/{index-NrzHqycm.css → index-CJdlkpIy.css} +1 -1
- package/dist/frontend/index.html +2 -2
- package/dist/hap/hap-generic-accessory.d.ts +4 -0
- package/dist/hap/hap-generic-accessory.js +512 -122
- package/dist/hap/hap-generic-accessory.js.map +1 -1
- package/dist/homeAssistant.d.ts +1 -0
- package/dist/homeAssistant.js +23 -5
- package/dist/homeAssistant.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/mqtt/mqtt-client.js.map +1 -1
- package/dist/mqtt/mqtt.entity.js +41 -17
- package/dist/mqtt/mqtt.entity.js.map +1 -1
- package/dist/platform.d.ts +1 -0
- package/dist/platform.js +83 -13
- package/dist/platform.js.map +1 -1
- package/dist/utils/atomic-json-store.js +5 -1
- package/dist/utils/atomic-json-store.js.map +1 -1
- package/dist/utils/ha-state.js +3 -1
- package/dist/utils/ha-state.js.map +1 -1
- package/dist/utils/light-color.js +3 -5
- package/dist/utils/light-color.js.map +1 -1
- package/dist/utils/matter-command-response.js.map +1 -1
- package/dist/utils/matter-firmware.js +1 -2
- package/dist/utils/matter-firmware.js.map +1 -1
- package/dist/utils/matter-protocol.d.ts +1 -0
- package/dist/utils/matter-protocol.js +30 -0
- package/dist/utils/matter-protocol.js.map +1 -0
- package/package.json +27 -19
- package/dist/camera/camera-entity-control.d.ts +0 -12
- package/dist/camera/camera-entity-control.js +0 -24
- package/dist/camera/camera-entity-control.js.map +0 -1
- package/dist/camera/homekit/hevc/bootstrap.d.ts +0 -9
- package/dist/camera/homekit/hevc/bootstrap.js +0 -47
- package/dist/camera/homekit/hevc/bootstrap.js.map +0 -1
- package/dist/camera/homekit/hevc/recording-output.d.ts +0 -2
- package/dist/camera/homekit/hevc/recording-output.js +0 -33
- package/dist/camera/homekit/hevc/recording-output.js.map +0 -1
- package/dist/camera/homekit/media-policy.d.ts +0 -25
- package/dist/camera/homekit/media-policy.js +0 -102
- package/dist/camera/homekit/media-policy.js.map +0 -1
- package/dist/camera/homekit/route-address.d.ts +0 -2
- package/dist/camera/homekit/route-address.js +0 -27
- package/dist/camera/homekit/route-address.js.map +0 -1
- package/dist/camera/homekit/rtp-relay.d.ts +0 -21
- package/dist/camera/homekit/rtp-relay.js +0 -112
- package/dist/camera/homekit/rtp-relay.js.map +0 -1
- package/dist/camera/homekit/startup-timing.d.ts +0 -8
- package/dist/camera/homekit/startup-timing.js +0 -14
- package/dist/camera/homekit/startup-timing.js.map +0 -1
- package/dist/camera/source-adapter.d.ts +0 -132
- package/dist/camera/source-adapter.js +0 -282
- package/dist/camera/source-adapter.js.map +0 -1
- package/dist/frontend/assets/index-Bka3TVAQ.js +0 -21
- package/vendor/hap-nodejs/LICENSE +0 -176
- package/vendor/hap-nodejs/MIAO.md +0 -5
- package/vendor/hap-nodejs/PATCH.md +0 -37
- package/vendor/hap-nodejs/README.md +0 -86
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js +0 -128
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js +0 -159
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js +0 -545
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js +0 -74
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js +0 -78
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -106
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js +0 -145
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js +0 -76
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js +0 -45
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js +0 -79
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js +0 -44
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js +0 -128
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js +0 -101
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js +0 -44
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js +0 -17
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js +0 -19
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js +0 -145
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/types.d.ts +0 -78
- package/vendor/hap-nodejs/dist/accessories/types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/accessories/types.js +0 -88
- package/vendor/hap-nodejs/dist/accessories/types.js.map +0 -1
- package/vendor/hap-nodejs/dist/index.d.ts +0 -50
- package/vendor/hap-nodejs/dist/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/index.js +0 -54
- package/vendor/hap-nodejs/dist/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/internal-types.d.ts +0 -76
- package/vendor/hap-nodejs/dist/internal-types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/internal-types.js +0 -80
- package/vendor/hap-nodejs/dist/internal-types.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts +0 -521
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Accessory.js +0 -1762
- package/vendor/hap-nodejs/dist/lib/Accessory.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts +0 -190
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Advertiser.js +0 -592
- package/vendor/hap-nodejs/dist/lib/Advertiser.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts +0 -12
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Bridge.js +0 -19
- package/vendor/hap-nodejs/dist/lib/Bridge.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts +0 -1768
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Characteristic.js +0 -2532
- package/vendor/hap-nodejs/dist/lib/Characteristic.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts +0 -299
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/HAPServer.js +0 -968
- package/vendor/hap-nodejs/dist/lib/HAPServer.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Service.d.ts +0 -598
- package/vendor/hap-nodejs/dist/lib/Service.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/Service.js +0 -797
- package/vendor/hap-nodejs/dist/lib/Service.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts +0 -102
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js +0 -317
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts +0 -38
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js +0 -174
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts +0 -59
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js +0 -267
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts +0 -379
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js +0 -1021
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts +0 -325
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js +0 -800
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts +0 -20
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js +0 -48
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts +0 -618
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js +0 -911
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/camera/index.js +0 -11
- package/vendor/hap-nodejs/dist/lib/camera/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts +0 -452
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js +0 -868
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts +0 -410
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js +0 -658
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts +0 -197
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js +0 -32
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts +0 -59
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js +0 -102
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts +0 -434
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js +0 -1178
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts +0 -380
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js +0 -947
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/controller/index.js +0 -10
- package/vendor/hap-nodejs/dist/lib/controller/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts +0 -73
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js +0 -205
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts +0 -186
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js +0 -880
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts +0 -351
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js +0 -878
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts +0 -4
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/datastream/index.js +0 -7
- package/vendor/hap-nodejs/dist/lib/datastream/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts +0 -2245
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js +0 -4957
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts +0 -584
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js +0 -1518
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts +0 -34
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js +0 -624
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts +0 -22
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js +0 -734
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts +0 -3
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/definitions/index.js +0 -6
- package/vendor/hap-nodejs/dist/lib/definitions/index.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js +0 -9
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts +0 -91
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js +0 -311
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts +0 -46
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js +0 -277
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts +0 -75
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js +0 -190
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts +0 -26
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js +0 -79
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts +0 -33
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js +0 -114
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts +0 -83
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js +0 -127
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts +0 -8
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/checkName.js +0 -28
- package/vendor/hap-nodejs/dist/lib/util/checkName.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/clone.js +0 -22
- package/vendor/hap-nodejs/dist/lib/util/clone.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts +0 -18
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js +0 -442
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts +0 -251
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js +0 -714
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts +0 -50
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js +0 -185
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts +0 -16
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js +0 -29
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts +0 -21
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js +0 -79
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts +0 -7
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/once.js +0 -22
- package/vendor/hap-nodejs/dist/lib/util/once.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts +0 -14
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js +0 -29
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts +0 -36
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/request-util.js +0 -108
- package/vendor/hap-nodejs/dist/lib/util/request-util.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts +0 -9
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/time.js +0 -23
- package/vendor/hap-nodejs/dist/lib/util/time.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts +0 -90
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/tlv.js +0 -318
- package/vendor/hap-nodejs/dist/lib/util/tlv.js.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts +0 -23
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/lib/util/uuid.js +0 -78
- package/vendor/hap-nodejs/dist/lib/util/uuid.js.map +0 -1
- package/vendor/hap-nodejs/dist/types.d.ts +0 -276
- package/vendor/hap-nodejs/dist/types.d.ts.map +0 -1
- package/vendor/hap-nodejs/dist/types.js +0 -11
- package/vendor/hap-nodejs/dist/types.js.map +0 -1
- package/vendor/hap-nodejs/package.json +0 -53
- package/vendor/hap-nodejs/src/lib/util/hapCrypto.ts +0 -208
|
@@ -1,714 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HAPConnection = exports.HAPConnectionEvent = exports.HAPConnectionState = exports.EventedHTTPServer = exports.EventedHTTPServerEvent = exports.HAPEncryption = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const domain_formatter_1 = require("@homebridge/ciao/lib/util/domain-formatter");
|
|
6
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
8
|
-
const events_1 = require("events");
|
|
9
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
10
|
-
const net_1 = tslib_1.__importDefault(require("net"));
|
|
11
|
-
const os_1 = tslib_1.__importDefault(require("os"));
|
|
12
|
-
const hapCrypto = tslib_1.__importStar(require("./hapCrypto"));
|
|
13
|
-
const net_utils_1 = require("./net-utils");
|
|
14
|
-
const uuid = tslib_1.__importStar(require("./uuid"));
|
|
15
|
-
const debug = (0, debug_1.default)("HAP-NodeJS:EventedHTTPServer");
|
|
16
|
-
const debugCon = (0, debug_1.default)("HAP-NodeJS:EventedHTTPServer:Connection");
|
|
17
|
-
const debugEvents = (0, debug_1.default)("HAP-NodeJS:EventEmitter");
|
|
18
|
-
/**
|
|
19
|
-
* Simple struct to hold vars needed to support HAP encryption.
|
|
20
|
-
*
|
|
21
|
-
* @group Cryptography
|
|
22
|
-
*/
|
|
23
|
-
class HAPEncryption {
|
|
24
|
-
clientPublicKey;
|
|
25
|
-
secretKey;
|
|
26
|
-
publicKey;
|
|
27
|
-
sharedSecret;
|
|
28
|
-
hkdfPairEncryptionKey;
|
|
29
|
-
accessoryToControllerCount = 0;
|
|
30
|
-
controllerToAccessoryCount = 0;
|
|
31
|
-
accessoryToControllerKey;
|
|
32
|
-
controllerToAccessoryKey;
|
|
33
|
-
incompleteFrame;
|
|
34
|
-
constructor(clientPublicKey, secretKey, publicKey, sharedSecret, hkdfPairEncryptionKey) {
|
|
35
|
-
this.clientPublicKey = clientPublicKey;
|
|
36
|
-
this.secretKey = secretKey;
|
|
37
|
-
this.publicKey = publicKey;
|
|
38
|
-
this.sharedSecret = sharedSecret;
|
|
39
|
-
this.hkdfPairEncryptionKey = hkdfPairEncryptionKey;
|
|
40
|
-
this.accessoryToControllerKey = Buffer.alloc(0);
|
|
41
|
-
this.controllerToAccessoryKey = Buffer.alloc(0);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.HAPEncryption = HAPEncryption;
|
|
45
|
-
/**
|
|
46
|
-
* @group HAP Accessory Server
|
|
47
|
-
*/
|
|
48
|
-
var EventedHTTPServerEvent;
|
|
49
|
-
(function (EventedHTTPServerEvent) {
|
|
50
|
-
EventedHTTPServerEvent["LISTENING"] = "listening";
|
|
51
|
-
EventedHTTPServerEvent["CONNECTION_OPENED"] = "connection-opened";
|
|
52
|
-
EventedHTTPServerEvent["REQUEST"] = "request";
|
|
53
|
-
EventedHTTPServerEvent["CONNECTION_CLOSED"] = "connection-closed";
|
|
54
|
-
})(EventedHTTPServerEvent || (exports.EventedHTTPServerEvent = EventedHTTPServerEvent = {}));
|
|
55
|
-
/**
|
|
56
|
-
* EventedHTTPServer provides an HTTP-like server that supports HAP "extensions" for security and events.
|
|
57
|
-
*
|
|
58
|
-
* Implementation
|
|
59
|
-
* --------------
|
|
60
|
-
* In order to implement the "custom HTTP" server required by the HAP protocol (see HAPServer.js) without completely
|
|
61
|
-
* reinventing the wheel, we create both a generic TCP socket server and a standard Node HTTP server.
|
|
62
|
-
* The TCP socket server acts as a proxy, allowing users of this class to transform data (for encryption) as necessary
|
|
63
|
-
* and passing through bytes directly to the HTTP server for processing. This way we get Node to do all
|
|
64
|
-
* the "heavy lifting" of HTTP like parsing headers and formatting responses.
|
|
65
|
-
*
|
|
66
|
-
* Events are sent by simply waiting for current HTTP traffic to subside and then sending a custom response packet
|
|
67
|
-
* directly down the wire via the socket.
|
|
68
|
-
*
|
|
69
|
-
* Each connection to the main TCP server gets its own internal HTTP server, so we can track ongoing requests/responses
|
|
70
|
-
* for safe event insertion.
|
|
71
|
-
*
|
|
72
|
-
* @group HAP Accessory Server
|
|
73
|
-
*/
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
75
|
-
class EventedHTTPServer extends events_1.EventEmitter {
|
|
76
|
-
static CONNECTION_TIMEOUT_LIMIT = 16; // if we have more (or equal) # connections we start the timeout
|
|
77
|
-
static MAX_CONNECTION_IDLE_TIME = 60 * 60 * 1000; // 1h
|
|
78
|
-
tcpServer;
|
|
79
|
-
/**
|
|
80
|
-
* Set of all currently connected HAP connections.
|
|
81
|
-
*/
|
|
82
|
-
connections = new Set();
|
|
83
|
-
/**
|
|
84
|
-
* Session dictionary indexed by username/identifier. The username uniquely identifies every person added to the home.
|
|
85
|
-
* So there can be multiple sessions open for a single username (multiple devices connected to the same Apple ID).
|
|
86
|
-
*/
|
|
87
|
-
connectionsByUsername = new Map();
|
|
88
|
-
connectionIdleTimeout;
|
|
89
|
-
connectionLoggingInterval;
|
|
90
|
-
constructor() {
|
|
91
|
-
super();
|
|
92
|
-
this.tcpServer = net_1.default.createServer();
|
|
93
|
-
}
|
|
94
|
-
scheduleNextConnectionIdleTimeout() {
|
|
95
|
-
this.connectionIdleTimeout = undefined;
|
|
96
|
-
if (!this.tcpServer.listening) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
debug("Running idle timeout timer...");
|
|
100
|
-
const currentTime = new Date().getTime();
|
|
101
|
-
let nextTimeout = -1;
|
|
102
|
-
for (const connection of this.connections) {
|
|
103
|
-
const timeDelta = currentTime - connection.lastSocketOperation;
|
|
104
|
-
if (timeDelta >= EventedHTTPServer.MAX_CONNECTION_IDLE_TIME) {
|
|
105
|
-
debug("[%s] Closing connection as it was inactive for " + timeDelta + "ms");
|
|
106
|
-
connection.close();
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
nextTimeout = Math.max(nextTimeout, EventedHTTPServer.MAX_CONNECTION_IDLE_TIME - timeDelta);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (this.connections.size >= EventedHTTPServer.CONNECTION_TIMEOUT_LIMIT) {
|
|
113
|
-
this.connectionIdleTimeout = setTimeout(this.scheduleNextConnectionIdleTimeout.bind(this), nextTimeout);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
address() {
|
|
117
|
-
return this.tcpServer.address();
|
|
118
|
-
}
|
|
119
|
-
listen(targetPort, hostname) {
|
|
120
|
-
this.tcpServer.listen(targetPort, hostname, () => {
|
|
121
|
-
const address = this.tcpServer.address(); // address() is only a string when listening to unix domain sockets
|
|
122
|
-
debug("Server listening on %s:%s", address.family === "IPv6" ? `[${address.address}]` : address.address, address.port);
|
|
123
|
-
this.connectionLoggingInterval = setInterval(() => {
|
|
124
|
-
const connectionInformation = [...this.connections]
|
|
125
|
-
.map(connection => `${connection.remoteAddress}:${connection.remotePort}`)
|
|
126
|
-
.join(", ");
|
|
127
|
-
debug("Currently %d hap connections open: %s", this.connections.size, connectionInformation);
|
|
128
|
-
}, 60_000);
|
|
129
|
-
this.connectionLoggingInterval.unref();
|
|
130
|
-
this.emit("listening" /* EventedHTTPServerEvent.LISTENING */, address.port, address.address);
|
|
131
|
-
});
|
|
132
|
-
this.tcpServer.on("connection", this.onConnection.bind(this));
|
|
133
|
-
}
|
|
134
|
-
stop() {
|
|
135
|
-
if (this.connectionLoggingInterval != null) {
|
|
136
|
-
clearInterval(this.connectionLoggingInterval);
|
|
137
|
-
this.connectionLoggingInterval = undefined;
|
|
138
|
-
}
|
|
139
|
-
if (this.connectionIdleTimeout != null) {
|
|
140
|
-
clearTimeout(this.connectionIdleTimeout);
|
|
141
|
-
this.connectionIdleTimeout = undefined;
|
|
142
|
-
}
|
|
143
|
-
this.tcpServer.close();
|
|
144
|
-
for (const connection of this.connections) {
|
|
145
|
-
connection.close();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
destroy() {
|
|
149
|
-
this.stop();
|
|
150
|
-
this.removeAllListeners();
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Send an event notification for given characteristic and changed value to all connected clients.
|
|
154
|
-
* If `originator` is specified, the given {@link HAPConnection} will be excluded from the broadcast.
|
|
155
|
-
*
|
|
156
|
-
* @param aid - The accessory id of the updated characteristic.
|
|
157
|
-
* @param iid - The instance id of the updated characteristic.
|
|
158
|
-
* @param value - The newly set value of the characteristic.
|
|
159
|
-
* @param originator - If specified, the connection will not get an event message.
|
|
160
|
-
* @param immediateDelivery - The HAP spec requires some characteristics to be delivery immediately.
|
|
161
|
-
* Namely, for the {@link Characteristic.ButtonEvent} and the {@link Characteristic.ProgrammableSwitchEvent} characteristics.
|
|
162
|
-
*/
|
|
163
|
-
broadcastEvent(aid, iid, value, originator, immediateDelivery) {
|
|
164
|
-
for (const connection of this.connections) {
|
|
165
|
-
if (connection === originator) {
|
|
166
|
-
debug("[%s] Muting event '%s' notification for this connection since it originated here.", connection.remoteAddress, aid + "." + iid);
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
connection.sendEvent(aid, iid, value, immediateDelivery);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
onConnection(socket) {
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
174
|
-
const connection = new HAPConnection(this, socket);
|
|
175
|
-
connection.on("request" /* HAPConnectionEvent.REQUEST */, (request, response) => {
|
|
176
|
-
this.emit("request" /* EventedHTTPServerEvent.REQUEST */, connection, request, response);
|
|
177
|
-
});
|
|
178
|
-
connection.on("authenticated" /* HAPConnectionEvent.AUTHENTICATED */, this.handleConnectionAuthenticated.bind(this, connection));
|
|
179
|
-
connection.on("closed" /* HAPConnectionEvent.CLOSED */, this.handleConnectionClose.bind(this, connection));
|
|
180
|
-
this.connections.add(connection);
|
|
181
|
-
debug("[%s] New connection from client on interface %s (%s)", connection.remoteAddress, connection.networkInterface, connection.localAddress);
|
|
182
|
-
this.emit("connection-opened" /* EventedHTTPServerEvent.CONNECTION_OPENED */, connection);
|
|
183
|
-
if (this.connections.size >= EventedHTTPServer.CONNECTION_TIMEOUT_LIMIT && !this.connectionIdleTimeout) {
|
|
184
|
-
this.scheduleNextConnectionIdleTimeout();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
handleConnectionAuthenticated(connection, username) {
|
|
188
|
-
const connections = this.connectionsByUsername.get(username);
|
|
189
|
-
if (!connections) {
|
|
190
|
-
this.connectionsByUsername.set(username, [connection]);
|
|
191
|
-
}
|
|
192
|
-
else if (!connections.includes(connection)) { // ensure this doesn't get added more than one time
|
|
193
|
-
connections.push(connection);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
handleConnectionClose(connection) {
|
|
197
|
-
this.emit("connection-closed" /* EventedHTTPServerEvent.CONNECTION_CLOSED */, connection);
|
|
198
|
-
this.connections.delete(connection);
|
|
199
|
-
if (connection.username) { // aka connection was authenticated
|
|
200
|
-
const connections = this.connectionsByUsername.get(connection.username);
|
|
201
|
-
if (connections) {
|
|
202
|
-
const index = connections.indexOf(connection);
|
|
203
|
-
if (index !== -1) {
|
|
204
|
-
connections.splice(index, 1);
|
|
205
|
-
}
|
|
206
|
-
if (connections.length === 0) {
|
|
207
|
-
this.connectionsByUsername.delete(connection.username);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* This method is to be called when a given {@link HAPConnection} performs a request that should result in the disconnection
|
|
214
|
-
* of all other {@link HAPConnection} with the same {@link HAPUsername}.
|
|
215
|
-
*
|
|
216
|
-
* The initiator MUST be in the middle of a http request were the response was not served yet.
|
|
217
|
-
* Otherwise, the initiator connection might reside in a state where it isn't disconnected and can't make any further requests.
|
|
218
|
-
*
|
|
219
|
-
* @param initiator - The connection that requested to disconnect all connections of the same username.
|
|
220
|
-
* @param username - The username for which all connections shall be closed.
|
|
221
|
-
*/
|
|
222
|
-
static destroyExistingConnectionsAfterUnpair(initiator, username) {
|
|
223
|
-
const connections = initiator.server.connectionsByUsername.get(username);
|
|
224
|
-
if (connections) {
|
|
225
|
-
for (const connection of connections) {
|
|
226
|
-
connection.closeConnectionAsOfUnpair(initiator);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
exports.EventedHTTPServer = EventedHTTPServer;
|
|
232
|
-
/**
|
|
233
|
-
* @private
|
|
234
|
-
* @group HAP Accessory Server
|
|
235
|
-
*/
|
|
236
|
-
var HAPConnectionState;
|
|
237
|
-
(function (HAPConnectionState) {
|
|
238
|
-
HAPConnectionState[HAPConnectionState["CONNECTING"] = 0] = "CONNECTING";
|
|
239
|
-
HAPConnectionState[HAPConnectionState["FULLY_SET_UP"] = 1] = "FULLY_SET_UP";
|
|
240
|
-
HAPConnectionState[HAPConnectionState["AUTHENTICATED"] = 2] = "AUTHENTICATED";
|
|
241
|
-
// above signals represent an alive connection
|
|
242
|
-
// below states are considered "closed or soon closed"
|
|
243
|
-
HAPConnectionState[HAPConnectionState["TO_BE_TEARED_DOWN"] = 3] = "TO_BE_TEARED_DOWN";
|
|
244
|
-
HAPConnectionState[HAPConnectionState["CLOSING"] = 4] = "CLOSING";
|
|
245
|
-
HAPConnectionState[HAPConnectionState["CLOSED"] = 5] = "CLOSED";
|
|
246
|
-
})(HAPConnectionState || (exports.HAPConnectionState = HAPConnectionState = {}));
|
|
247
|
-
/**
|
|
248
|
-
* @group HAP Accessory Server
|
|
249
|
-
*/
|
|
250
|
-
var HAPConnectionEvent;
|
|
251
|
-
(function (HAPConnectionEvent) {
|
|
252
|
-
HAPConnectionEvent["REQUEST"] = "request";
|
|
253
|
-
HAPConnectionEvent["AUTHENTICATED"] = "authenticated";
|
|
254
|
-
HAPConnectionEvent["CLOSED"] = "closed";
|
|
255
|
-
})(HAPConnectionEvent || (exports.HAPConnectionEvent = HAPConnectionEvent = {}));
|
|
256
|
-
/**
|
|
257
|
-
* Manages a single iOS-initiated HTTP connection during its lifetime.
|
|
258
|
-
* @group HAP Accessory Server
|
|
259
|
-
*/
|
|
260
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
261
|
-
class HAPConnection extends events_1.EventEmitter {
|
|
262
|
-
/**
|
|
263
|
-
* Delay in milliseconds before queued (non-immediate) characteristic event notifications are coalesced and flushed on
|
|
264
|
-
* the connection. HAP batches regular events so a burst of value changes produces a single notification rather than one
|
|
265
|
-
* per change; events flagged for immediate delivery bypass this window entirely.
|
|
266
|
-
*/
|
|
267
|
-
static EVENT_COALESCING_DELAY = 250;
|
|
268
|
-
/**
|
|
269
|
-
* @private file-private API
|
|
270
|
-
*/
|
|
271
|
-
server;
|
|
272
|
-
sessionID; // uuid unique to every HAP connection
|
|
273
|
-
state = 0 /* HAPConnectionState.CONNECTING */;
|
|
274
|
-
localAddress;
|
|
275
|
-
remoteAddress; // cache because it becomes undefined in 'onClientSocketClose'
|
|
276
|
-
remotePort;
|
|
277
|
-
networkInterface;
|
|
278
|
-
tcpSocket;
|
|
279
|
-
internalHttpServer;
|
|
280
|
-
httpSocket; // set when in state FULLY_SET_UP
|
|
281
|
-
internalHttpServerPort;
|
|
282
|
-
internalHttpServerAddress;
|
|
283
|
-
lastSocketOperation = new Date().getTime();
|
|
284
|
-
pendingClientSocketData = Buffer.alloc(0); // data received from client before HTTP proxy is fully setup
|
|
285
|
-
handlingRequest = false; // true while we are composing an HTTP response (so events can wait)
|
|
286
|
-
username; // username is unique to every user in the home, basically identifies an Apple ID
|
|
287
|
-
encryption; // created in handlePairVerifyStepOne
|
|
288
|
-
srpServer;
|
|
289
|
-
_pairSetupState; // TODO ensure those two states are always correctly reset?
|
|
290
|
-
_pairVerifyState;
|
|
291
|
-
registeredEvents = new Set();
|
|
292
|
-
eventsTimer;
|
|
293
|
-
queuedEvents = [];
|
|
294
|
-
/**
|
|
295
|
-
* If true, the above {@link queuedEvents} contains events which are set to be delivered immediately!
|
|
296
|
-
*/
|
|
297
|
-
eventsQueuedForImmediateDelivery = false;
|
|
298
|
-
timedWritePid;
|
|
299
|
-
timedWriteTimeout;
|
|
300
|
-
constructor(server, clientSocket) {
|
|
301
|
-
super();
|
|
302
|
-
this.server = server;
|
|
303
|
-
this.sessionID = uuid.generate(clientSocket.remoteAddress + ":" + clientSocket.remotePort);
|
|
304
|
-
this.localAddress = clientSocket.localAddress;
|
|
305
|
-
this.remoteAddress = clientSocket.remoteAddress; // cache because it becomes undefined in 'onClientSocketClose'
|
|
306
|
-
this.remotePort = clientSocket.remotePort;
|
|
307
|
-
this.networkInterface = HAPConnection.getLocalNetworkInterface(clientSocket);
|
|
308
|
-
// clientSocket is the socket connected to the actual iOS device
|
|
309
|
-
this.tcpSocket = clientSocket;
|
|
310
|
-
this.tcpSocket.on("data", this.onTCPSocketData.bind(this));
|
|
311
|
-
this.tcpSocket.on("close", this.onTCPSocketClose.bind(this));
|
|
312
|
-
// we MUST register for this event, otherwise the error will bubble up to the top and crash the node process entirely.
|
|
313
|
-
this.tcpSocket.on("error", this.onTCPSocketError.bind(this));
|
|
314
|
-
this.tcpSocket.setNoDelay(true); // disable Nagle algorithm
|
|
315
|
-
// "HAP accessory servers must not use keepalive messages, which periodically wake up iOS devices".
|
|
316
|
-
// Thus, we don't configure any tcp keepalive
|
|
317
|
-
// create our internal HTTP server for this connection that we will proxy data to and from
|
|
318
|
-
this.internalHttpServer = http_1.default.createServer();
|
|
319
|
-
this.internalHttpServer.timeout = 0; // clients expect to hold connections open as long as they want
|
|
320
|
-
this.internalHttpServer.keepAliveTimeout = 0; // workaround for https://github.com/nodejs/node/issues/13391
|
|
321
|
-
this.internalHttpServer.on("listening", this.onHttpServerListening.bind(this));
|
|
322
|
-
this.internalHttpServer.on("request", this.handleHttpServerRequest.bind(this));
|
|
323
|
-
this.internalHttpServer.on("error", this.onHttpServerError.bind(this));
|
|
324
|
-
// close event is added later on the "connect" event as possible listen retries would throw unnecessary close events
|
|
325
|
-
this.internalHttpServer.listen(0, this.internalHttpServerAddress = (0, net_utils_1.getOSLoopbackAddressIfAvailable)());
|
|
326
|
-
}
|
|
327
|
-
debugListenerRegistration(event, registration = true, beforeCount = -1) {
|
|
328
|
-
const stackTrace = new Error().stack.split("\n")[3];
|
|
329
|
-
const eventCount = this.listeners(event).length;
|
|
330
|
-
const tabs1 = event === "authenticated" /* HAPConnectionEvent.AUTHENTICATED */ ? "\t" : "\t\t";
|
|
331
|
-
const tabs2 = !registration ? "\t" : "\t\t";
|
|
332
|
-
// eslint-disable-next-line max-len
|
|
333
|
-
debugEvents(`[${this.remoteAddress}] ${registration ? "Registered" : "Unregistered"} event '${String(event).toUpperCase()}' ${tabs1}(total: ${eventCount}${!registration ? " Before: " + beforeCount : ""}) ${tabs2}${stackTrace}`);
|
|
334
|
-
}
|
|
335
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
336
|
-
on(event, listener) {
|
|
337
|
-
const result = super.on(event, listener);
|
|
338
|
-
this.debugListenerRegistration(event);
|
|
339
|
-
return result;
|
|
340
|
-
}
|
|
341
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
342
|
-
addListener(event, listener) {
|
|
343
|
-
const result = super.addListener(event, listener);
|
|
344
|
-
this.debugListenerRegistration(event);
|
|
345
|
-
return result;
|
|
346
|
-
}
|
|
347
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
348
|
-
removeListener(event, listener) {
|
|
349
|
-
const beforeCount = this.listeners(event).length;
|
|
350
|
-
const result = super.removeListener(event, listener);
|
|
351
|
-
this.debugListenerRegistration(event, false, beforeCount);
|
|
352
|
-
return result;
|
|
353
|
-
}
|
|
354
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
355
|
-
off(event, listener) {
|
|
356
|
-
const result = super.off(event, listener);
|
|
357
|
-
const beforeCount = this.listeners(event).length;
|
|
358
|
-
this.debugListenerRegistration(event, false, beforeCount);
|
|
359
|
-
return result;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* This method is called once the connection has gone through pair-verify.
|
|
363
|
-
* As any HomeKit controller will initiate a pair-verify after the pair-setup procedure, this method gets
|
|
364
|
-
* not called on the initial pair-setup.
|
|
365
|
-
*
|
|
366
|
-
* Once this method has been called, the connection is authenticated and encryption is turned on.
|
|
367
|
-
*/
|
|
368
|
-
connectionAuthenticated(username) {
|
|
369
|
-
this.state = 2 /* HAPConnectionState.AUTHENTICATED */;
|
|
370
|
-
this.username = username;
|
|
371
|
-
this.emit("authenticated" /* HAPConnectionEvent.AUTHENTICATED */, username);
|
|
372
|
-
}
|
|
373
|
-
isAuthenticated() {
|
|
374
|
-
return this.state === 2 /* HAPConnectionState.AUTHENTICATED */;
|
|
375
|
-
}
|
|
376
|
-
close() {
|
|
377
|
-
if (this.state >= 4 /* HAPConnectionState.CLOSING */) {
|
|
378
|
-
return; // already closed/closing
|
|
379
|
-
}
|
|
380
|
-
this.state = 4 /* HAPConnectionState.CLOSING */;
|
|
381
|
-
this.tcpSocket.destroy();
|
|
382
|
-
}
|
|
383
|
-
closeConnectionAsOfUnpair(initiator) {
|
|
384
|
-
if (this === initiator) {
|
|
385
|
-
// the initiator of the unpair request is this connection, meaning it unpaired itself.
|
|
386
|
-
// we still need to send the response packet to the unpair request.
|
|
387
|
-
this.state = 3 /* HAPConnectionState.TO_BE_TEARED_DOWN */;
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
// as HomeKit requires it, destroy any active session which got unpaired
|
|
391
|
-
this.close();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
sendEvent(aid, iid, value, immediateDelivery) {
|
|
395
|
-
(0, assert_1.default)(aid != null, "HAPConnection.sendEvent: aid must be defined!");
|
|
396
|
-
(0, assert_1.default)(iid != null, "HAPConnection.sendEvent: iid must be defined!");
|
|
397
|
-
const eventName = aid + "." + iid;
|
|
398
|
-
if (!this.registeredEvents.has(eventName)) {
|
|
399
|
-
// non verified connections can't register events, so this case is covered!
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
const event = {
|
|
403
|
-
aid: aid,
|
|
404
|
-
iid: iid,
|
|
405
|
-
value: value,
|
|
406
|
-
};
|
|
407
|
-
if (immediateDelivery) {
|
|
408
|
-
// some characteristics are required to deliver notifications immediately
|
|
409
|
-
// we will flush all other events too, on that occasion.
|
|
410
|
-
this.queuedEvents.push(event);
|
|
411
|
-
this.eventsQueuedForImmediateDelivery = true;
|
|
412
|
-
if (this.eventsTimer) {
|
|
413
|
-
clearTimeout(this.eventsTimer);
|
|
414
|
-
this.eventsTimer = undefined;
|
|
415
|
-
}
|
|
416
|
-
this.handleEventsTimeout();
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
// we search the list of queued events in reverse order.
|
|
420
|
-
// if the last element with the same aid and iid has the same value we don't want to send the event notification twice.
|
|
421
|
-
// BUT, we do not want to override previous event notifications which have a different value. Automations must be executed!
|
|
422
|
-
for (let i = this.queuedEvents.length - 1; i >= 0; i--) {
|
|
423
|
-
const queuedEvent = this.queuedEvents[i];
|
|
424
|
-
if (queuedEvent.aid === aid && queuedEvent.iid === iid) {
|
|
425
|
-
if (queuedEvent.value === value) {
|
|
426
|
-
return; // the same event was already queued. do not add it again!
|
|
427
|
-
}
|
|
428
|
-
break; // we break in any case
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
this.queuedEvents.push(event);
|
|
432
|
-
// if there is already a timer running we just add it in the queue.
|
|
433
|
-
if (!this.eventsTimer) {
|
|
434
|
-
this.eventsTimer = setTimeout(this.handleEventsTimeout.bind(this), HAPConnection.EVENT_COALESCING_DELAY);
|
|
435
|
-
this.eventsTimer.unref();
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
handleEventsTimeout() {
|
|
439
|
-
this.eventsTimer = undefined;
|
|
440
|
-
if (this.state > 2 /* HAPConnectionState.AUTHENTICATED */) {
|
|
441
|
-
// connection is closed or about to be closed. no need to send any further events
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
this.writeQueuedEventNotifications();
|
|
445
|
-
}
|
|
446
|
-
writeQueuedEventNotifications() {
|
|
447
|
-
if (this.queuedEvents.length === 0 || this.handlingRequest) {
|
|
448
|
-
return; // don't send empty event notifications or if we are currently handling a request
|
|
449
|
-
}
|
|
450
|
-
if (this.eventsTimer) {
|
|
451
|
-
// this method might be called when we have enqueued data AND data that is queued for immediate delivery!
|
|
452
|
-
clearTimeout(this.eventsTimer);
|
|
453
|
-
this.eventsTimer = undefined;
|
|
454
|
-
}
|
|
455
|
-
const eventData = {
|
|
456
|
-
characteristics: [],
|
|
457
|
-
};
|
|
458
|
-
for (const queuedEvent of this.queuedEvents) {
|
|
459
|
-
if (!this.registeredEvents.has(queuedEvent.aid + "." + queuedEvent.iid)) {
|
|
460
|
-
continue; // client unregistered that event in the meantime
|
|
461
|
-
}
|
|
462
|
-
eventData.characteristics.push(queuedEvent);
|
|
463
|
-
}
|
|
464
|
-
this.queuedEvents.splice(0, this.queuedEvents.length);
|
|
465
|
-
this.eventsQueuedForImmediateDelivery = false;
|
|
466
|
-
this.writeEventNotification(eventData);
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* This will create an EVENT/1.0 notification header with the provided event notification.
|
|
470
|
-
* If currently an HTTP request is in progress the assembled packet will be
|
|
471
|
-
* added to the pending events list.
|
|
472
|
-
*
|
|
473
|
-
* @param notification - The event which should be sent out
|
|
474
|
-
*/
|
|
475
|
-
writeEventNotification(notification) {
|
|
476
|
-
debugCon("[%s] Sending HAP event notifications %o", this.remoteAddress, notification.characteristics);
|
|
477
|
-
(0, assert_1.default)(!this.handlingRequest, "Can't write event notifications while handling a request!");
|
|
478
|
-
// Apple backend processes events in reverse order, so we need to reverse the array
|
|
479
|
-
// so that events are processed in chronological order.
|
|
480
|
-
notification.characteristics.reverse();
|
|
481
|
-
const dataBuffer = Buffer.from(JSON.stringify(notification), "utf8");
|
|
482
|
-
const header = Buffer.from("EVENT/1.0 200 OK\r\n" +
|
|
483
|
-
"Content-Type: application/hap+json\r\n" +
|
|
484
|
-
"Content-Length: " + dataBuffer.length + "\r\n" +
|
|
485
|
-
"\r\n", "utf8");
|
|
486
|
-
const buffer = Buffer.concat([header, dataBuffer]);
|
|
487
|
-
this.tcpSocket.write(this.encrypt(buffer), this.handleTCPSocketWriteFulfilled.bind(this));
|
|
488
|
-
}
|
|
489
|
-
enableEventNotifications(aid, iid) {
|
|
490
|
-
this.registeredEvents.add(aid + "." + iid);
|
|
491
|
-
}
|
|
492
|
-
disableEventNotifications(aid, iid) {
|
|
493
|
-
this.registeredEvents.delete(aid + "." + iid);
|
|
494
|
-
}
|
|
495
|
-
hasEventNotifications(aid, iid) {
|
|
496
|
-
return this.registeredEvents.has(aid + "." + iid);
|
|
497
|
-
}
|
|
498
|
-
getRegisteredEvents() {
|
|
499
|
-
return this.registeredEvents;
|
|
500
|
-
}
|
|
501
|
-
clearRegisteredEvents() {
|
|
502
|
-
this.registeredEvents.clear();
|
|
503
|
-
}
|
|
504
|
-
encrypt(data) {
|
|
505
|
-
// if accessoryToControllerKey is not empty, then encryption is enabled for this connection. However, we'll
|
|
506
|
-
// need to be careful to ensure that we don't encrypt the last few bytes of the response from handlePairVerifyStepTwo.
|
|
507
|
-
// Since all communication calls are asynchronous, we could easily receive this 'encrypt' event for those bytes.
|
|
508
|
-
// So we want to make sure that we aren't encrypting data until we have *received* some encrypted data from the client first.
|
|
509
|
-
if (this.encryption && this.encryption.accessoryToControllerKey.length > 0 && this.encryption.controllerToAccessoryCount > 0) {
|
|
510
|
-
return hapCrypto.layerEncrypt(data, this.encryption);
|
|
511
|
-
}
|
|
512
|
-
return data; // otherwise, we don't encrypt and return plaintext
|
|
513
|
-
}
|
|
514
|
-
decrypt(data) {
|
|
515
|
-
if (this.encryption && this.encryption.controllerToAccessoryKey.length > 0) {
|
|
516
|
-
// below call may throw an error if decryption failed
|
|
517
|
-
return hapCrypto.layerDecrypt(data, this.encryption);
|
|
518
|
-
}
|
|
519
|
-
return data; // otherwise, we don't decrypt and return plaintext
|
|
520
|
-
}
|
|
521
|
-
onHttpServerListening() {
|
|
522
|
-
const addressInfo = this.internalHttpServer.address(); // address() is only a string when listening to unix domain sockets
|
|
523
|
-
const addressString = addressInfo.family === "IPv6" ? `[${addressInfo.address}]` : addressInfo.address;
|
|
524
|
-
this.internalHttpServerPort = addressInfo.port;
|
|
525
|
-
debugCon("[%s] Internal HTTP server listening on %s:%s", this.remoteAddress, addressString, addressInfo.port);
|
|
526
|
-
this.internalHttpServer.on("close", this.onHttpServerClose.bind(this));
|
|
527
|
-
// now we can establish a connection to this running HTTP server for proxying data
|
|
528
|
-
this.httpSocket = net_1.default.createConnection(this.internalHttpServerPort, this.internalHttpServerAddress); // previously we used addressInfo.address
|
|
529
|
-
this.httpSocket.setNoDelay(true); // disable Nagle algorithm
|
|
530
|
-
this.httpSocket.on("data", this.handleHttpServerResponse.bind(this));
|
|
531
|
-
// we MUST register for this event, otherwise the error will bubble up to the top and crash the node process entirely.
|
|
532
|
-
this.httpSocket.on("error", this.onHttpSocketError.bind(this));
|
|
533
|
-
this.httpSocket.on("close", this.onHttpSocketClose.bind(this));
|
|
534
|
-
this.httpSocket.on("connect", () => {
|
|
535
|
-
// we are now fully set up:
|
|
536
|
-
// - clientSocket is connected to the iOS device
|
|
537
|
-
// - serverSocket is connected to the httpServer
|
|
538
|
-
// - ready to proxy data!
|
|
539
|
-
this.state = 1 /* HAPConnectionState.FULLY_SET_UP */;
|
|
540
|
-
debugCon("[%s] Internal HTTP socket connected. HAPConnection now fully set up!", this.remoteAddress);
|
|
541
|
-
// start by flushing any pending buffered data received from the client while we were setting up
|
|
542
|
-
if (this.pendingClientSocketData && this.pendingClientSocketData.length > 0) {
|
|
543
|
-
this.httpSocket.write(this.pendingClientSocketData);
|
|
544
|
-
}
|
|
545
|
-
this.pendingClientSocketData = undefined;
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* This event handler is called when we receive data from a HomeKit controller on our tcp socket.
|
|
550
|
-
* We store the data if the internal http server is not read yet, or forward it to the http server.
|
|
551
|
-
*/
|
|
552
|
-
onTCPSocketData(data) {
|
|
553
|
-
if (this.state > 2 /* HAPConnectionState.AUTHENTICATED */) {
|
|
554
|
-
// don't accept data of a connection which is about to be closed or already closed
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
this.handlingRequest = true; // reverted to false once response was sent out
|
|
558
|
-
this.lastSocketOperation = new Date().getTime();
|
|
559
|
-
console.info("[HK4K-HAP-DIAG] inbound", JSON.stringify({ remote: this.remoteAddress, bytes: data.length, encrypted: !!(this.encryption && this.encryption.controllerToAccessoryKey.length > 0), authenticated: this.isAuthenticated() }));
|
|
560
|
-
try {
|
|
561
|
-
data = this.decrypt(data);
|
|
562
|
-
}
|
|
563
|
-
catch (error) { // decryption and/or verification failed, disconnect the client
|
|
564
|
-
console.info("[HK4K-HAP-DIAG] decrypt-failed", JSON.stringify({ remote: this.remoteAddress, error: error instanceof Error ? error.message : String(error) }));
|
|
565
|
-
debugCon("[%s] Error occurred trying to decrypt incoming packet: %s", this.remoteAddress, error.message);
|
|
566
|
-
this.close();
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
if (this.state < 1 /* HAPConnectionState.FULLY_SET_UP */) { // we're not setup yet, so add this data to our intermediate buffer
|
|
570
|
-
this.pendingClientSocketData = Buffer.concat([this.pendingClientSocketData, data]);
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
this.httpSocket.write(data); // proxy it along to the HTTP server
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* This event handler is called when the internal http server receives a request.
|
|
578
|
-
* Meaning we received data from the HomeKit controller in {@link onTCPSocketData}, which then send the
|
|
579
|
-
* data unencrypted to the internal http server. And now it landed here, fully parsed as a http request.
|
|
580
|
-
*/
|
|
581
|
-
handleHttpServerRequest(request, response) {
|
|
582
|
-
if (this.state > 2 /* HAPConnectionState.AUTHENTICATED */) {
|
|
583
|
-
// don't accept data of a connection which is about to be closed or already closed
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
debugCon("[%s] HTTP request: %s", this.remoteAddress, request.url);
|
|
587
|
-
request.socket.setNoDelay(true);
|
|
588
|
-
this.emit("request" /* HAPConnectionEvent.REQUEST */, request, response);
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* This event handler is called by the socket which is connected to our internal http server.
|
|
592
|
-
* It is called with the response returned from the http server.
|
|
593
|
-
* In this method we have to encrypt and forward the message back to the HomeKit controller.
|
|
594
|
-
*/
|
|
595
|
-
handleHttpServerResponse(data) {
|
|
596
|
-
data = this.encrypt(data);
|
|
597
|
-
this.tcpSocket.write(data, this.handleTCPSocketWriteFulfilled.bind(this));
|
|
598
|
-
debugCon("[%s] HTTP Response is finished", this.remoteAddress);
|
|
599
|
-
this.handlingRequest = false;
|
|
600
|
-
if (this.state === 3 /* HAPConnectionState.TO_BE_TEARED_DOWN */) {
|
|
601
|
-
setTimeout(() => this.close(), 10);
|
|
602
|
-
}
|
|
603
|
-
else if (this.state < 3 /* HAPConnectionState.TO_BE_TEARED_DOWN */) {
|
|
604
|
-
if (!this.eventsTimer || this.eventsQueuedForImmediateDelivery) {
|
|
605
|
-
// we deliver events if there is no eventsTimer (meaning it ran out in the meantime)
|
|
606
|
-
// or when the queue contains events set to be delivered immediately
|
|
607
|
-
this.writeQueuedEventNotifications();
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
handleTCPSocketWriteFulfilled() {
|
|
612
|
-
this.lastSocketOperation = new Date().getTime();
|
|
613
|
-
}
|
|
614
|
-
onTCPSocketError(err) {
|
|
615
|
-
debugCon("[%s] Client connection error: %s", this.remoteAddress, err.message);
|
|
616
|
-
// onTCPSocketClose will be called next
|
|
617
|
-
}
|
|
618
|
-
onTCPSocketClose() {
|
|
619
|
-
this.state = 5 /* HAPConnectionState.CLOSED */;
|
|
620
|
-
debugCon("[%s] Client connection closed", this.remoteAddress);
|
|
621
|
-
if (this.httpSocket) {
|
|
622
|
-
this.httpSocket.destroy();
|
|
623
|
-
}
|
|
624
|
-
this.internalHttpServer.close();
|
|
625
|
-
this.emit("closed" /* HAPConnectionEvent.CLOSED */); // sending final closed event
|
|
626
|
-
this.removeAllListeners(); // cleanup listeners, we are officially dead now
|
|
627
|
-
}
|
|
628
|
-
onHttpServerError(err) {
|
|
629
|
-
debugCon("[%s] HTTP server error: %s", this.remoteAddress, err.message);
|
|
630
|
-
if (err.code === "EADDRINUSE") {
|
|
631
|
-
this.internalHttpServerPort = undefined;
|
|
632
|
-
this.internalHttpServer.close();
|
|
633
|
-
this.internalHttpServer.listen(0, this.internalHttpServerAddress = (0, net_utils_1.getOSLoopbackAddressIfAvailable)());
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
onHttpServerClose() {
|
|
637
|
-
debugCon("[%s] HTTP server was closed", this.remoteAddress);
|
|
638
|
-
// make sure the iOS side is closed as well
|
|
639
|
-
this.close();
|
|
640
|
-
}
|
|
641
|
-
onHttpSocketError(err) {
|
|
642
|
-
debugCon("[%s] HTTP connection error: ", this.remoteAddress, err.message);
|
|
643
|
-
// onHttpSocketClose will be called next
|
|
644
|
-
}
|
|
645
|
-
onHttpSocketClose() {
|
|
646
|
-
debugCon("[%s] HTTP connection was closed", this.remoteAddress);
|
|
647
|
-
// we only support a single long-lived connection to our internal HTTP server. Since it's closed,
|
|
648
|
-
// we'll need to shut it down entirely.
|
|
649
|
-
this.internalHttpServer.close();
|
|
650
|
-
}
|
|
651
|
-
getLocalAddress(ipVersion) {
|
|
652
|
-
const interfaceDetails = os_1.default.networkInterfaces()[this.networkInterface];
|
|
653
|
-
if (!interfaceDetails) {
|
|
654
|
-
throw new Error("Could not find " + ipVersion + " address for interface " + this.networkInterface);
|
|
655
|
-
}
|
|
656
|
-
// Find our first local IPv4 address.
|
|
657
|
-
if (ipVersion === "ipv4") {
|
|
658
|
-
const ipv4Info = interfaceDetails.find(info => info.family === "IPv4");
|
|
659
|
-
if (ipv4Info) {
|
|
660
|
-
return ipv4Info.address;
|
|
661
|
-
}
|
|
662
|
-
throw new Error("Could not find " + ipVersion + " address for interface " + this.networkInterface + ".");
|
|
663
|
-
}
|
|
664
|
-
let localUniqueAddress;
|
|
665
|
-
for (const v6entry of interfaceDetails.filter(entry => entry.family === "IPv6")) {
|
|
666
|
-
if (!v6entry.scopeid) {
|
|
667
|
-
return v6entry.address;
|
|
668
|
-
}
|
|
669
|
-
localUniqueAddress ??= v6entry.address;
|
|
670
|
-
}
|
|
671
|
-
if (localUniqueAddress) {
|
|
672
|
-
return localUniqueAddress;
|
|
673
|
-
}
|
|
674
|
-
throw new Error("Could not find " + ipVersion + " address for interface " + this.networkInterface);
|
|
675
|
-
}
|
|
676
|
-
static getLocalNetworkInterface(socket) {
|
|
677
|
-
let localAddress = socket.localAddress;
|
|
678
|
-
// Grab the list of network interfaces.
|
|
679
|
-
const interfaces = os_1.default.networkInterfaces();
|
|
680
|
-
// Default to the first non-loopback interface we see.
|
|
681
|
-
const defaultInterface = () => Object.entries(interfaces).find(([, addresses]) => addresses?.some(address => !address.internal))?.[0] ?? "unknown";
|
|
682
|
-
// No local address return our default.
|
|
683
|
-
if (!localAddress) {
|
|
684
|
-
return defaultInterface();
|
|
685
|
-
}
|
|
686
|
-
// Handle IPv4-mapped IPv6 addresses.
|
|
687
|
-
localAddress = localAddress.replace(/^::ffff:/i, "");
|
|
688
|
-
// Handle edge cases where we have an IPv4-mapped IPv6 address without the requisite prefix.
|
|
689
|
-
if (/^::(?:\d{1,3}\.){3}\d{1,3}$/.test(localAddress)) {
|
|
690
|
-
localAddress = localAddress.replace(/^::/, "");
|
|
691
|
-
}
|
|
692
|
-
// Handle link-local IPv6 addresses.
|
|
693
|
-
localAddress = localAddress.split("%")[0];
|
|
694
|
-
// Let's find an exact match using the IP.
|
|
695
|
-
for (const [name, addresses] of Object.entries(interfaces)) {
|
|
696
|
-
if (addresses?.some(({ address }) => address === localAddress)) {
|
|
697
|
-
return name;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
// We couldn't find an interface to match the address from above, so we attempt to match subnets (see https://github.com/homebridge/HAP-NodeJS/issues/847).
|
|
701
|
-
const family = net_1.default.isIPv4(localAddress) ? "IPv4" : "IPv6";
|
|
702
|
-
// Let's find a match based on the subnet.
|
|
703
|
-
for (const [name, addresses] of Object.entries(interfaces)) {
|
|
704
|
-
if (addresses?.some(entry => entry.family === family && (0, domain_formatter_1.getNetAddress)(localAddress, entry.netmask) === (0, domain_formatter_1.getNetAddress)(entry.address, entry.netmask))) {
|
|
705
|
-
return name;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
console.log("WARNING: unable to determine which interface to use for socket coming from " + socket.remoteAddress + ":" + socket.remotePort + " to " +
|
|
709
|
-
socket.localAddress + ".");
|
|
710
|
-
return defaultInterface();
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
exports.HAPConnection = HAPConnection;
|
|
714
|
-
//# sourceMappingURL=eventedhttp.js.map
|