diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a587b536..bf97b099e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `hap-nodejs` will be documented in this file. This project tries to adhere to [Semantic Versioning](http://semver.org/). +## BETA + +### Changed + +- Updated dependencies (`rimraf` and `@types/node`) + ## v0.12.1 (2024-05-11) ### Changed diff --git a/package-lock.json b/package-lock.json index 190674823..285eefdd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@types/debug": "^4.1.12", "@types/escape-html": "^1.0.4", "@types/jest": "^29.5.12", - "@types/node": "^10.17.60", + "@types/node": "^20.12.11", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "axios": "^1.6.8", @@ -33,7 +33,7 @@ "eslint": "^8.57.0", "http-parser-js": "^0.5.8", "jest": "^29.7.0", - "rimraf": "^3.0.2", + "rimraf": "^5.0.6", "semver": "^7.6.2", "simple-plist": "~1.1.1", "ts-jest": "^29.1.2", @@ -795,6 +795,102 @@ "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1269,6 +1365,16 @@ "node": ">= 8" } }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -1429,10 +1535,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "10.17.60", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", - "dev": true + "version": "20.12.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.11.tgz", + "integrity": "sha512-vDg9PZ/zi+Nqp6boSOT7plNuthRugEKixDv5sFTIpkE89MmNtEArAShI4mxuX2+UrLEe9pxC1vm2cjm9YlWbJw==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/semver": { "version": "7.5.8", @@ -2523,6 +2632,12 @@ "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==" }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, "node_modules/electron-to-chromium": { "version": "1.4.763", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.763.tgz", @@ -3003,6 +3118,21 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/flat-cache/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/flatted": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", @@ -3037,6 +3167,34 @@ "is-callable": "^1.1.3" } }, + "node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -3800,6 +3958,24 @@ "node": ">=8" } }, + "node_modules/jackspeak": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", + "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, "node_modules/jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", @@ -4650,6 +4826,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.1.tgz", + "integrity": "sha512-UZ7eQ+h8ywIRAW1hIEl2AqdwzJucU/Kp59+8kkZeSvafXhZjul247BvIJjEVFVeON6d7lM46XX1HXCduKAS8VA==", + "dev": true, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, "node_modules/mkdirp": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", @@ -4928,6 +5113,31 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-scurry": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.0.tgz", + "integrity": "sha512-LNHTaVkzaYaLGlO+0u3rQTz7QrHTFOuKyba9JMTQutkmtNew8dw8wOD7mTU/5fCPZzCWpfW0XnQKzY61P0aTaw==", + "dev": true, + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", + "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "dev": true, + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -5265,15 +5475,64 @@ } }, "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.6.tgz", + "integrity": "sha512-X72SgyOf+1lFnGM6gYcmZ4+jMOwuT4E4SajKQzUIlI7EoR5eFHMhS/wf8Ll0mN+w2bxcIVldrJQ6xT7HFQywjg==", "dev": true, "dependencies": { - "glob": "^7.1.3" + "glob": "^10.3.7" }, "bin": { - "rimraf": "bin.js" + "rimraf": "dist/esm/bin.mjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/rimraf/node_modules/glob": { + "version": "10.3.14", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.14.tgz", + "integrity": "sha512-4fkAqu93xe9Mk7le9v0y3VrPDqLKHarNi2s4Pv7f2yOvfhWfhc7hRPHC/JyqMqb8B/Dt/eGS4n7ykwf3fOsl8g==", + "dev": true, + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^2.3.6", + "minimatch": "^9.0.1", + "minipass": "^7.0.4", + "path-scurry": "^1.11.0" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -5561,6 +5820,21 @@ "node": ">=8" } }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -5573,6 +5847,19 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", @@ -5892,6 +6179,12 @@ "node": ">=4.2.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/update-browserslist-db": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.15.tgz", @@ -6063,6 +6356,24 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 0ba7a2107..6ea52657e 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@types/debug": "^4.1.12", "@types/escape-html": "^1.0.4", "@types/jest": "^29.5.12", - "@types/node": "^10.17.60", + "@types/node": "^20.12.11", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "axios": "^1.6.8", @@ -76,7 +76,7 @@ "eslint": "^8.57.0", "http-parser-js": "^0.5.8", "jest": "^29.7.0", - "rimraf": "^3.0.2", + "rimraf": "^5.0.6", "semver": "^7.6.2", "simple-plist": "~1.1.1", "ts-jest": "^29.1.2", diff --git a/src/accessories/Camera_accessory.ts b/src/accessories/Camera_accessory.ts index 959d81db0..6a44d3e21 100644 --- a/src/accessories/Camera_accessory.ts +++ b/src/accessories/Camera_accessory.ts @@ -519,8 +519,8 @@ class MP4StreamingServer { console.error("ChildProcess is undefined directly after the init!"); } if(this.debugMode) { - this.childProcess.stdout.on("data", data => console.log(data.toString())); - this.childProcess.stderr.on("data", data => console.log(data.toString())); + this.childProcess.stdout?.on("data", data => console.log(data.toString())); + this.childProcess.stderr?.on("data", data => console.log(data.toString())); } } diff --git a/src/accessories/gstreamer-audioProducer.ts b/src/accessories/gstreamer-audioProducer.ts index e75e3e184..fcff80dd0 100644 --- a/src/accessories/gstreamer-audioProducer.ts +++ b/src/accessories/gstreamer-audioProducer.ts @@ -128,7 +128,7 @@ export class GStreamerAudioProducer implements SiriAudioStreamProducer { debug("Failed to kill gstreamer process: " + error.message); } }); - this.process.stdout.on("data", (data: Buffer) => { + this.process.stdout?.on("data", (data: Buffer) => { if (!this.running) { // received data after it was closed return; } @@ -149,7 +149,7 @@ export class GStreamerAudioProducer implements SiriAudioStreamProducer { rms: 0.25, // only way currently to extract rms from gstreamer is by interfacing with the api directly (nodejs c++ submodule could be a solution) }); }); - this.process.stderr.on("data", data => { + this.process.stderr?.on("data", data => { debug("GStreamer process reports the following error: " + String(data)); }); this.process.on("exit", (code, signal) => { diff --git a/src/lib/datastream/DataStreamParser.ts b/src/lib/datastream/DataStreamParser.ts index 5ba01f9d0..3ec48710c 100644 --- a/src/lib/datastream/DataStreamParser.ts +++ b/src/lib/datastream/DataStreamParser.ts @@ -809,7 +809,7 @@ export class DataStreamWriter { const byteLength = Buffer.byteLength(utf8); this.ensureLength(byteLength); - this.data.write(utf8, this.writerIndex, undefined, "utf8"); + this.data.write(utf8, this.writerIndex, byteLength, "utf8"); this.writerIndex += byteLength; } diff --git a/src/lib/util/eventedhttp.ts b/src/lib/util/eventedhttp.ts index 2f819a9d8..771ece8be 100644 --- a/src/lib/util/eventedhttp.ts +++ b/src/lib/util/eventedhttp.ts @@ -384,7 +384,7 @@ export class HAPConnection extends EventEmitter { this.server = server; this.sessionID = uuid.generate(clientSocket.remoteAddress + ":" + clientSocket.remotePort); - this.localAddress = clientSocket.localAddress; + this.localAddress = clientSocket.localAddress as string; this.remoteAddress = clientSocket.remoteAddress!; // cache because it becomes undefined in 'onClientSocketClose' this.remotePort = clientSocket.remotePort!; this.networkInterface = HAPConnection.getLocalNetworkInterface(clientSocket); @@ -806,10 +806,12 @@ export class HAPConnection extends EventEmitter { const infos = os.networkInterfaces()[this.networkInterface]; if (ipVersion === "ipv4") { - for (const info of infos) { - // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" - if (info.family === "IPv4" || info.family === 4) { - return info.address; + if (infos) { + for (const info of infos) { + // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" + if (info.family === "IPv4" || info.family === 4) { + return info.address; + } } } @@ -817,13 +819,15 @@ export class HAPConnection extends EventEmitter { } else { let localUniqueAddress: string | undefined = undefined; - for (const info of infos) { - // @ts-expect-error Nodejs 18+ uses the number 6 instead of the string "IPv6" - if (info.family === "IPv6" || info.family === 6) { - if (!info.scopeid) { - return info.address; - } else if (!localUniqueAddress) { - localUniqueAddress = info.address; + if (infos) { + for (const info of infos) { + // @ts-expect-error Nodejs 18+ uses the number 6 instead of the string "IPv6" + if (info.family === "IPv6" || info.family === 6) { + if (!info.scopeid) { + return info.address; + } else if (!localUniqueAddress) { + localUniqueAddress = info.address; + } } } } @@ -836,7 +840,7 @@ export class HAPConnection extends EventEmitter { } private static getLocalNetworkInterface(socket: Socket): string { - let localAddress = socket.localAddress; + let localAddress = socket.localAddress as string; if (localAddress.startsWith("::ffff:")) { // IPv4-Mapped IPv6 Address https://tools.ietf.org/html/rfc4291#section-2.5.5.2 localAddress = localAddress.substring(7); @@ -849,9 +853,11 @@ export class HAPConnection extends EventEmitter { const interfaces = os.networkInterfaces(); for (const [name, infos] of Object.entries(interfaces)) { - for (const info of infos) { - if (info.address === localAddress) { - return name; + if (infos) { + for (const info of infos) { + if (info.address === localAddress) { + return name; + } } } } @@ -859,14 +865,16 @@ export class HAPConnection extends EventEmitter { // we couldn't map the address from above, we try now to match subnets (see https://github.com/homebridge/HAP-NodeJS/issues/847) const family = net.isIPv4(localAddress)? "IPv4": "IPv6"; for (const [name, infos] of Object.entries(interfaces)) { - for (const info of infos) { - if (info.family !== family) { - continue; - } + if (infos) { + for (const info of infos) { + if (info.family !== family) { + continue; + } - // check if the localAddress is in the same subnet - if (getNetAddress(localAddress, info.netmask) === getNetAddress(info.address, info.netmask)) { - return name; + // check if the localAddress is in the same subnet + if (getNetAddress(localAddress, info.netmask) === getNetAddress(info.address, info.netmask)) { + return name; + } } } } diff --git a/src/lib/util/hapCrypto.ts b/src/lib/util/hapCrypto.ts index e67b05a11..e3b517a2b 100644 --- a/src/lib/util/hapCrypto.ts +++ b/src/lib/util/hapCrypto.ts @@ -68,10 +68,9 @@ export function chacha20_poly1305_decryptAndVerify(key: Buffer, nonce: Buffer, a ]); } - // @ts-expect-error: types for this are really broken const decipher = crypto.createDecipheriv("chacha20-poly1305", key, nonce, { authTagLength: 16 }); if (aad) { - decipher.setAAD(aad); + decipher.setAAD(aad, { plaintextLength: ciphertext.length }); } decipher.setAuthTag(authTag); const plaintext = decipher.update(ciphertext); @@ -99,11 +98,10 @@ export function chacha20_poly1305_encryptAndSeal(key: Buffer, nonce: Buffer, aad ]); } - // @ts-expect-error: types for this are really broken const cipher = crypto.createCipheriv("chacha20-poly1305", key, nonce, { authTagLength: 16 }); if (aad) { - cipher.setAAD(aad); + cipher.setAAD(aad, { plaintextLength: plaintext.length }); } const ciphertext = cipher.update(plaintext); diff --git a/src/lib/util/net-utils.ts b/src/lib/util/net-utils.ts index 30f02ee92..81ba2eb89 100644 --- a/src/lib/util/net-utils.ts +++ b/src/lib/util/net-utils.ts @@ -10,25 +10,27 @@ export function findLoopbackAddress(): string { for (const [name, infos] of Object.entries(os.networkInterfaces())) { let internal = false; - for (const info of infos) { - if (!info.internal) { - continue; - } - - internal = true; - // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" - if (info.family === "IPv4" || info.family === 4) { - if (!ipv4) { - ipv4 = info.address; + if (infos) { + for (const info of infos) { + if (!info.internal) { + continue; } - // @ts-expect-error Nodejs 18+ uses the number 6 the string "IPv6" - } else if (info.family === "IPv6" || info.family === 6) { - if (info.scopeid) { - if (!ipv6LinkLocal) { - ipv6LinkLocal = info.address + "%" + name; // ipv6 link local addresses are only valid with a scope + + internal = true; + // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" + if (info.family === "IPv4" || info.family === 4) { + if (!ipv4) { + ipv4 = info.address; + } + // @ts-expect-error Nodejs 18+ uses the number 6 the string "IPv6" + } else if (info.family === "IPv6" || info.family === 6) { + if (info.scopeid) { + if (!ipv6LinkLocal) { + ipv6LinkLocal = info.address + "%" + name; // ipv6 link local addresses are only valid with a scope + } + } else if (!ipv6) { + ipv6 = info.address; } - } else if (!ipv6) { - ipv6 = info.address; } } }