homebridge 2.0.0-beta.5 → 2.0.0-beta.51

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.
Files changed (286) hide show
  1. package/README.md +16 -17
  2. package/bin/homebridge.js +22 -0
  3. package/config-sample.json +3 -3
  4. package/dist/api.d.ts +137 -0
  5. package/dist/api.d.ts.map +1 -0
  6. package/dist/api.js +151 -0
  7. package/dist/api.js.map +1 -0
  8. package/{lib → dist}/bridgeService.d.ts +16 -32
  9. package/dist/bridgeService.d.ts.map +1 -0
  10. package/dist/bridgeService.js +341 -0
  11. package/dist/bridgeService.js.map +1 -0
  12. package/dist/childBridgeFork.d.ts +40 -0
  13. package/dist/childBridgeFork.d.ts.map +1 -0
  14. package/dist/childBridgeFork.js +362 -0
  15. package/dist/childBridgeFork.js.map +1 -0
  16. package/dist/childBridgeService.d.ts +146 -0
  17. package/dist/childBridgeService.d.ts.map +1 -0
  18. package/dist/childBridgeService.js +416 -0
  19. package/dist/childBridgeService.js.map +1 -0
  20. package/dist/cli.d.ts +3 -0
  21. package/dist/cli.d.ts.map +1 -0
  22. package/dist/cli.js +88 -0
  23. package/dist/cli.js.map +1 -0
  24. package/dist/externalPortService.d.ts +26 -0
  25. package/dist/externalPortService.d.ts.map +1 -0
  26. package/dist/externalPortService.js +77 -0
  27. package/dist/externalPortService.js.map +1 -0
  28. package/dist/index.d.ts +29 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +9 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/ipcService.d.ts +58 -0
  33. package/dist/ipcService.d.ts.map +1 -0
  34. package/dist/ipcService.js +43 -0
  35. package/dist/ipcService.js.map +1 -0
  36. package/dist/logger.d.ts +38 -0
  37. package/dist/logger.d.ts.map +1 -0
  38. package/dist/logger.js +102 -0
  39. package/dist/logger.js.map +1 -0
  40. package/dist/matter/BaseMatterManager.d.ts +20 -0
  41. package/dist/matter/BaseMatterManager.d.ts.map +1 -0
  42. package/dist/matter/BaseMatterManager.js +183 -0
  43. package/dist/matter/BaseMatterManager.js.map +1 -0
  44. package/dist/matter/ChildBridgeMatterManager.d.ts +35 -0
  45. package/dist/matter/ChildBridgeMatterManager.d.ts.map +1 -0
  46. package/dist/matter/ChildBridgeMatterManager.js +222 -0
  47. package/dist/matter/ChildBridgeMatterManager.js.map +1 -0
  48. package/dist/matter/ClusterCommandMapper.d.ts +5 -0
  49. package/dist/matter/ClusterCommandMapper.d.ts.map +1 -0
  50. package/dist/matter/ClusterCommandMapper.js +222 -0
  51. package/dist/matter/ClusterCommandMapper.js.map +1 -0
  52. package/dist/matter/ExternalMatterAccessoryPublisher.d.ts +22 -0
  53. package/dist/matter/ExternalMatterAccessoryPublisher.d.ts.map +1 -0
  54. package/dist/matter/ExternalMatterAccessoryPublisher.js +49 -0
  55. package/dist/matter/ExternalMatterAccessoryPublisher.js.map +1 -0
  56. package/dist/matter/MatterAPIImpl.d.ts +443 -0
  57. package/dist/matter/MatterAPIImpl.d.ts.map +1 -0
  58. package/dist/matter/MatterAPIImpl.js +210 -0
  59. package/dist/matter/MatterAPIImpl.js.map +1 -0
  60. package/dist/matter/MatterBridgeManager.d.ts +40 -0
  61. package/dist/matter/MatterBridgeManager.d.ts.map +1 -0
  62. package/dist/matter/MatterBridgeManager.js +340 -0
  63. package/dist/matter/MatterBridgeManager.js.map +1 -0
  64. package/dist/matter/MatterConfigCollector.d.ts +7 -0
  65. package/dist/matter/MatterConfigCollector.d.ts.map +1 -0
  66. package/dist/matter/MatterConfigCollector.js +65 -0
  67. package/dist/matter/MatterConfigCollector.js.map +1 -0
  68. package/dist/matter/accessoryCache.d.ts +57 -0
  69. package/dist/matter/accessoryCache.d.ts.map +1 -0
  70. package/dist/matter/accessoryCache.js +155 -0
  71. package/dist/matter/accessoryCache.js.map +1 -0
  72. package/dist/matter/behaviors/AirQualityBehavior.d.ts +8 -0
  73. package/dist/matter/behaviors/AirQualityBehavior.d.ts.map +1 -0
  74. package/dist/matter/behaviors/AirQualityBehavior.js +11 -0
  75. package/dist/matter/behaviors/AirQualityBehavior.js.map +1 -0
  76. package/dist/matter/behaviors/BehaviorRegistry.d.ts +27 -0
  77. package/dist/matter/behaviors/BehaviorRegistry.d.ts.map +1 -0
  78. package/dist/matter/behaviors/BehaviorRegistry.js +110 -0
  79. package/dist/matter/behaviors/BehaviorRegistry.js.map +1 -0
  80. package/dist/matter/behaviors/ColorControlBehavior.d.ts +12 -0
  81. package/dist/matter/behaviors/ColorControlBehavior.d.ts.map +1 -0
  82. package/dist/matter/behaviors/ColorControlBehavior.js +139 -0
  83. package/dist/matter/behaviors/ColorControlBehavior.js.map +1 -0
  84. package/dist/matter/behaviors/ConcentrationMeasurementBehavior.d.ts +32 -0
  85. package/dist/matter/behaviors/ConcentrationMeasurementBehavior.d.ts.map +1 -0
  86. package/dist/matter/behaviors/ConcentrationMeasurementBehavior.js +51 -0
  87. package/dist/matter/behaviors/ConcentrationMeasurementBehavior.js.map +1 -0
  88. package/dist/matter/behaviors/DoorLockBehavior.d.ts +7 -0
  89. package/dist/matter/behaviors/DoorLockBehavior.d.ts.map +1 -0
  90. package/dist/matter/behaviors/DoorLockBehavior.js +48 -0
  91. package/dist/matter/behaviors/DoorLockBehavior.js.map +1 -0
  92. package/dist/matter/behaviors/FanControlBehavior.d.ts +7 -0
  93. package/dist/matter/behaviors/FanControlBehavior.d.ts.map +1 -0
  94. package/dist/matter/behaviors/FanControlBehavior.js +57 -0
  95. package/dist/matter/behaviors/FanControlBehavior.js.map +1 -0
  96. package/dist/matter/behaviors/IdentifyBehavior.d.ts +7 -0
  97. package/dist/matter/behaviors/IdentifyBehavior.d.ts.map +1 -0
  98. package/dist/matter/behaviors/IdentifyBehavior.js +25 -0
  99. package/dist/matter/behaviors/IdentifyBehavior.js.map +1 -0
  100. package/dist/matter/behaviors/LevelControlBehavior.d.ts +11 -0
  101. package/dist/matter/behaviors/LevelControlBehavior.d.ts.map +1 -0
  102. package/dist/matter/behaviors/LevelControlBehavior.js +100 -0
  103. package/dist/matter/behaviors/LevelControlBehavior.js.map +1 -0
  104. package/dist/matter/behaviors/OnOffBehavior.d.ts +8 -0
  105. package/dist/matter/behaviors/OnOffBehavior.d.ts.map +1 -0
  106. package/dist/matter/behaviors/OnOffBehavior.js +60 -0
  107. package/dist/matter/behaviors/OnOffBehavior.js.map +1 -0
  108. package/dist/matter/behaviors/RegistryManager.d.ts +15 -0
  109. package/dist/matter/behaviors/RegistryManager.d.ts.map +1 -0
  110. package/dist/matter/behaviors/RegistryManager.js +31 -0
  111. package/dist/matter/behaviors/RegistryManager.js.map +1 -0
  112. package/dist/matter/behaviors/RvcCleanModeBehavior.d.ts +14 -0
  113. package/dist/matter/behaviors/RvcCleanModeBehavior.d.ts.map +1 -0
  114. package/dist/matter/behaviors/RvcCleanModeBehavior.js +29 -0
  115. package/dist/matter/behaviors/RvcCleanModeBehavior.js.map +1 -0
  116. package/dist/matter/behaviors/RvcOperationalStateBehavior.d.ts +10 -0
  117. package/dist/matter/behaviors/RvcOperationalStateBehavior.d.ts.map +1 -0
  118. package/dist/matter/behaviors/RvcOperationalStateBehavior.js +81 -0
  119. package/dist/matter/behaviors/RvcOperationalStateBehavior.js.map +1 -0
  120. package/dist/matter/behaviors/RvcRunModeBehavior.d.ts +14 -0
  121. package/dist/matter/behaviors/RvcRunModeBehavior.d.ts.map +1 -0
  122. package/dist/matter/behaviors/RvcRunModeBehavior.js +29 -0
  123. package/dist/matter/behaviors/RvcRunModeBehavior.js.map +1 -0
  124. package/dist/matter/behaviors/ServiceAreaBehavior.d.ts +9 -0
  125. package/dist/matter/behaviors/ServiceAreaBehavior.d.ts.map +1 -0
  126. package/dist/matter/behaviors/ServiceAreaBehavior.js +62 -0
  127. package/dist/matter/behaviors/ServiceAreaBehavior.js.map +1 -0
  128. package/dist/matter/behaviors/ThermostatBehavior.d.ts +9 -0
  129. package/dist/matter/behaviors/ThermostatBehavior.d.ts.map +1 -0
  130. package/dist/matter/behaviors/ThermostatBehavior.js +92 -0
  131. package/dist/matter/behaviors/ThermostatBehavior.js.map +1 -0
  132. package/dist/matter/behaviors/WindowCoveringBehavior.d.ts +12 -0
  133. package/dist/matter/behaviors/WindowCoveringBehavior.d.ts.map +1 -0
  134. package/dist/matter/behaviors/WindowCoveringBehavior.js +108 -0
  135. package/dist/matter/behaviors/WindowCoveringBehavior.js.map +1 -0
  136. package/dist/matter/behaviors/index.d.ts +18 -0
  137. package/dist/matter/behaviors/index.d.ts.map +1 -0
  138. package/dist/matter/behaviors/index.js +17 -0
  139. package/dist/matter/behaviors/index.js.map +1 -0
  140. package/dist/matter/clusterTypes.d.ts +178 -0
  141. package/dist/matter/clusterTypes.d.ts.map +1 -0
  142. package/dist/matter/clusterTypes.js +2 -0
  143. package/dist/matter/clusterTypes.js.map +1 -0
  144. package/dist/matter/configValidator.d.ts +26 -0
  145. package/dist/matter/configValidator.d.ts.map +1 -0
  146. package/dist/matter/configValidator.js +173 -0
  147. package/dist/matter/configValidator.js.map +1 -0
  148. package/dist/matter/errorHandler.d.ts +11 -0
  149. package/dist/matter/errorHandler.d.ts.map +1 -0
  150. package/dist/matter/errorHandler.js +81 -0
  151. package/dist/matter/errorHandler.js.map +1 -0
  152. package/dist/matter/errors.d.ts +46 -0
  153. package/dist/matter/errors.d.ts.map +1 -0
  154. package/dist/matter/errors.js +68 -0
  155. package/dist/matter/errors.js.map +1 -0
  156. package/dist/matter/index.d.ts +97 -0
  157. package/dist/matter/index.d.ts.map +1 -0
  158. package/dist/matter/index.js +10 -0
  159. package/dist/matter/index.js.map +1 -0
  160. package/dist/matter/logFormatter.d.ts +2 -0
  161. package/dist/matter/logFormatter.d.ts.map +1 -0
  162. package/dist/matter/logFormatter.js +100 -0
  163. package/dist/matter/logFormatter.js.map +1 -0
  164. package/dist/matter/managerTypes.d.ts +57 -0
  165. package/dist/matter/managerTypes.d.ts.map +1 -0
  166. package/dist/matter/managerTypes.js +2 -0
  167. package/dist/matter/managerTypes.js.map +1 -0
  168. package/dist/matter/server.d.ts +112 -0
  169. package/dist/matter/server.d.ts.map +1 -0
  170. package/dist/matter/server.js +1508 -0
  171. package/dist/matter/server.js.map +1 -0
  172. package/dist/matter/serverHelpers.d.ts +31 -0
  173. package/dist/matter/serverHelpers.d.ts.map +1 -0
  174. package/dist/matter/serverHelpers.js +273 -0
  175. package/dist/matter/serverHelpers.js.map +1 -0
  176. package/dist/matter/sharedTypes.d.ts +93 -0
  177. package/dist/matter/sharedTypes.d.ts.map +1 -0
  178. package/dist/matter/sharedTypes.js +20 -0
  179. package/dist/matter/sharedTypes.js.map +1 -0
  180. package/dist/matter/storage.d.ts +45 -0
  181. package/dist/matter/storage.d.ts.map +1 -0
  182. package/dist/matter/storage.js +325 -0
  183. package/dist/matter/storage.js.map +1 -0
  184. package/dist/matter/typeHelpers.d.ts +15 -0
  185. package/dist/matter/typeHelpers.d.ts.map +1 -0
  186. package/dist/matter/typeHelpers.js +33 -0
  187. package/dist/matter/typeHelpers.js.map +1 -0
  188. package/dist/matter/types.d.ts +565 -0
  189. package/dist/matter/types.d.ts.map +1 -0
  190. package/dist/matter/types.js +132 -0
  191. package/dist/matter/types.js.map +1 -0
  192. package/dist/matter/utils.d.ts +13 -0
  193. package/dist/matter/utils.d.ts.map +1 -0
  194. package/dist/matter/utils.js +21 -0
  195. package/dist/matter/utils.js.map +1 -0
  196. package/{lib → dist}/platformAccessory.d.ts +8 -21
  197. package/dist/platformAccessory.d.ts.map +1 -0
  198. package/dist/platformAccessory.js +79 -0
  199. package/dist/platformAccessory.js.map +1 -0
  200. package/{lib → dist}/plugin.d.ts +2 -6
  201. package/dist/plugin.d.ts.map +1 -0
  202. package/dist/plugin.js +159 -0
  203. package/dist/plugin.js.map +1 -0
  204. package/{lib → dist}/pluginManager.d.ts +3 -25
  205. package/dist/pluginManager.d.ts.map +1 -0
  206. package/{lib → dist}/pluginManager.js +87 -115
  207. package/dist/pluginManager.js.map +1 -0
  208. package/{lib → dist}/server.d.ts +15 -20
  209. package/dist/server.d.ts.map +1 -0
  210. package/dist/server.js +732 -0
  211. package/dist/server.js.map +1 -0
  212. package/{lib → dist}/storageService.d.ts.map +1 -1
  213. package/dist/storageService.js +41 -0
  214. package/dist/storageService.js.map +1 -0
  215. package/{lib → dist}/user.d.ts +1 -3
  216. package/dist/user.d.ts.map +1 -0
  217. package/dist/user.js +29 -0
  218. package/dist/user.js.map +1 -0
  219. package/{lib → dist}/util/mac.d.ts +1 -0
  220. package/dist/util/mac.d.ts.map +1 -0
  221. package/dist/util/mac.js +13 -0
  222. package/dist/util/mac.js.map +1 -0
  223. package/dist/version.d.ts.map +1 -0
  224. package/dist/version.js +16 -0
  225. package/dist/version.js.map +1 -0
  226. package/package.json +49 -50
  227. package/bin/homebridge +0 -17
  228. package/lib/api.d.ts +0 -210
  229. package/lib/api.d.ts.map +0 -1
  230. package/lib/api.js +0 -155
  231. package/lib/api.js.map +0 -1
  232. package/lib/bridgeService.d.ts.map +0 -1
  233. package/lib/bridgeService.js +0 -426
  234. package/lib/bridgeService.js.map +0 -1
  235. package/lib/childBridgeFork.d.ts +0 -37
  236. package/lib/childBridgeFork.d.ts.map +0 -1
  237. package/lib/childBridgeFork.js +0 -244
  238. package/lib/childBridgeFork.js.map +0 -1
  239. package/lib/childBridgeService.d.ts +0 -199
  240. package/lib/childBridgeService.d.ts.map +0 -1
  241. package/lib/childBridgeService.js +0 -428
  242. package/lib/childBridgeService.js.map +0 -1
  243. package/lib/cli.d.ts +0 -4
  244. package/lib/cli.d.ts.map +0 -1
  245. package/lib/cli.js +0 -111
  246. package/lib/cli.js.map +0 -1
  247. package/lib/externalPortService.d.ts +0 -33
  248. package/lib/externalPortService.d.ts.map +0 -1
  249. package/lib/externalPortService.js +0 -64
  250. package/lib/externalPortService.js.map +0 -1
  251. package/lib/index.d.ts +0 -76
  252. package/lib/index.d.ts.map +0 -1
  253. package/lib/index.js +0 -72
  254. package/lib/index.js.map +0 -1
  255. package/lib/ipcService.d.ts +0 -33
  256. package/lib/ipcService.d.ts.map +0 -1
  257. package/lib/ipcService.js +0 -49
  258. package/lib/ipcService.js.map +0 -1
  259. package/lib/logger.d.ts +0 -78
  260. package/lib/logger.d.ts.map +0 -1
  261. package/lib/logger.js +0 -147
  262. package/lib/logger.js.map +0 -1
  263. package/lib/platformAccessory.d.ts.map +0 -1
  264. package/lib/platformAccessory.js +0 -102
  265. package/lib/platformAccessory.js.map +0 -1
  266. package/lib/plugin.d.ts.map +0 -1
  267. package/lib/plugin.js +0 -194
  268. package/lib/plugin.js.map +0 -1
  269. package/lib/pluginManager.d.ts.map +0 -1
  270. package/lib/pluginManager.js.map +0 -1
  271. package/lib/server.d.ts.map +0 -1
  272. package/lib/server.js +0 -457
  273. package/lib/server.js.map +0 -1
  274. package/lib/storageService.js +0 -70
  275. package/lib/storageService.js.map +0 -1
  276. package/lib/user.d.ts.map +0 -1
  277. package/lib/user.js +0 -36
  278. package/lib/user.js.map +0 -1
  279. package/lib/util/mac.d.ts.map +0 -1
  280. package/lib/util/mac.js +0 -20
  281. package/lib/util/mac.js.map +0 -1
  282. package/lib/version.d.ts.map +0 -1
  283. package/lib/version.js +0 -21
  284. package/lib/version.js.map +0 -1
  285. /package/{lib → dist}/storageService.d.ts +0 -0
  286. /package/{lib → dist}/version.d.ts +0 -0
@@ -0,0 +1,416 @@
1
+ import { fork } from 'node:child_process';
2
+ import { dirname, resolve } from 'node:path';
3
+ import process from 'node:process';
4
+ import { fileURLToPath } from 'node:url';
5
+ import fs from 'fs-extra';
6
+ import { Logger } from './logger.js';
7
+ import { User } from './user.js';
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ export var ChildProcessMessageEventType;
11
+ (function (ChildProcessMessageEventType) {
12
+ ChildProcessMessageEventType["READY"] = "ready";
13
+ ChildProcessMessageEventType["LOAD"] = "load";
14
+ ChildProcessMessageEventType["LOADED"] = "loaded";
15
+ ChildProcessMessageEventType["START"] = "start";
16
+ ChildProcessMessageEventType["ONLINE"] = "online";
17
+ ChildProcessMessageEventType["PORT_REQUEST"] = "portRequest";
18
+ ChildProcessMessageEventType["PORT_ALLOCATED"] = "portAllocated";
19
+ ChildProcessMessageEventType["STATUS_UPDATE"] = "status";
20
+ ChildProcessMessageEventType["START_MATTER_MONITORING"] = "startMatterMonitoring";
21
+ ChildProcessMessageEventType["STOP_MATTER_MONITORING"] = "stopMatterMonitoring";
22
+ ChildProcessMessageEventType["GET_MATTER_ACCESSORIES"] = "getMatterAccessories";
23
+ ChildProcessMessageEventType["GET_MATTER_ACCESSORY_INFO"] = "getMatterAccessoryInfo";
24
+ ChildProcessMessageEventType["MATTER_ACCESSORY_CONTROL"] = "matterAccessoryControl";
25
+ ChildProcessMessageEventType["MATTER_EVENT"] = "matterEvent";
26
+ })(ChildProcessMessageEventType || (ChildProcessMessageEventType = {}));
27
+ export var ChildBridgeStatus;
28
+ (function (ChildBridgeStatus) {
29
+ ChildBridgeStatus["PENDING"] = "pending";
30
+ ChildBridgeStatus["OK"] = "ok";
31
+ ChildBridgeStatus["DOWN"] = "down";
32
+ })(ChildBridgeStatus || (ChildBridgeStatus = {}));
33
+ export class ChildBridgeService {
34
+ type;
35
+ identifier;
36
+ plugin;
37
+ bridgeConfig;
38
+ homebridgeConfig;
39
+ homebridgeOptions;
40
+ api;
41
+ ipcService;
42
+ externalPortService;
43
+ child;
44
+ args = [];
45
+ processEnv = {};
46
+ shuttingDown = false;
47
+ lastBridgeStatus = "pending";
48
+ pairedStatus = null;
49
+ manuallyStopped = false;
50
+ setupUri = null;
51
+ matterCommissioningInfo;
52
+ pluginConfig = [];
53
+ log;
54
+ displayName;
55
+ restartCount = 0;
56
+ maxRestarts = 4;
57
+ lastMatterAccessoriesResponse;
58
+ onExternalBridgeRegistered;
59
+ constructor(type, identifier, plugin, bridgeConfig, homebridgeConfig, homebridgeOptions, api, ipcService, externalPortService) {
60
+ this.type = type;
61
+ this.identifier = identifier;
62
+ this.plugin = plugin;
63
+ this.bridgeConfig = bridgeConfig;
64
+ this.homebridgeConfig = homebridgeConfig;
65
+ this.homebridgeOptions = homebridgeOptions;
66
+ this.api = api;
67
+ this.ipcService = ipcService;
68
+ this.externalPortService = externalPortService;
69
+ this.log = Logger.withPrefix(this.plugin.getPluginIdentifier());
70
+ this.api.on('shutdown', () => {
71
+ this.shuttingDown = true;
72
+ this.teardown();
73
+ });
74
+ this.api.setMaxListeners(this.api.getMaxListeners() + 1);
75
+ }
76
+ start() {
77
+ this.setProcessFlags();
78
+ this.setProcessEnv();
79
+ this.startChildProcess();
80
+ if (this.pluginConfig.length > 1 || this.pluginConfig.length === 0) {
81
+ this.displayName = this.plugin.getPluginIdentifier();
82
+ }
83
+ else {
84
+ this.displayName = this.pluginConfig[0]?.name || this.plugin.getPluginIdentifier();
85
+ }
86
+ this.log = Logger.withPrefix(this.displayName);
87
+ }
88
+ addConfig(config) {
89
+ this.pluginConfig.push(config);
90
+ }
91
+ startMatterMonitoring() {
92
+ this.sendMessage("startMatterMonitoring");
93
+ }
94
+ stopMatterMonitoring() {
95
+ this.sendMessage("stopMatterMonitoring");
96
+ }
97
+ getMatterAccessories() {
98
+ this.sendMessage("getMatterAccessories");
99
+ }
100
+ getMatterAccessoryInfo(uuid) {
101
+ this.sendMessage("getMatterAccessoryInfo", { uuid });
102
+ }
103
+ controlMatterAccessory(data) {
104
+ this.sendMessage("matterAccessoryControl", data);
105
+ }
106
+ get bridgeStatus() {
107
+ return this.lastBridgeStatus;
108
+ }
109
+ set bridgeStatus(value) {
110
+ this.lastBridgeStatus = value;
111
+ this.sendStatusUpdate();
112
+ }
113
+ startChildProcess() {
114
+ this.bridgeStatus = "pending";
115
+ this.child = fork(resolve(__dirname, 'childBridgeFork.js'), this.args, this.processEnv);
116
+ this.child.stdout?.on('data', (data) => {
117
+ process.stdout.write(data);
118
+ });
119
+ this.child.stderr?.on('data', (data) => {
120
+ process.stderr.write(data);
121
+ });
122
+ this.child.on('error', (e) => {
123
+ this.bridgeStatus = "down";
124
+ this.log.error('Child bridge process error', e);
125
+ });
126
+ this.child.once('close', (code, signal) => {
127
+ this.handleProcessClose(code, signal);
128
+ });
129
+ this.child.on('message', (message) => {
130
+ if (typeof message !== 'object' || !message.id) {
131
+ return;
132
+ }
133
+ switch (message.id) {
134
+ case "ready": {
135
+ this.log(`Child bridge starting${this.child?.pid ? ` (pid ${this.child.pid})` : ''}...`);
136
+ this.loadPlugin();
137
+ break;
138
+ }
139
+ case "loaded": {
140
+ const version = message.data.version;
141
+ if (this.pluginConfig.length > 1) {
142
+ this.log.success(`Child bridge started successfully with ${this.pluginConfig.length} accessories (plugin v${version}).`);
143
+ }
144
+ else {
145
+ this.log.success(`Child bridge started successfully (plugin v${version}).`);
146
+ }
147
+ this.startBridge();
148
+ break;
149
+ }
150
+ case "online": {
151
+ this.bridgeStatus = "ok";
152
+ break;
153
+ }
154
+ case "portRequest": {
155
+ this.handlePortRequest(message.data);
156
+ break;
157
+ }
158
+ case "status": {
159
+ const statusData = message.data;
160
+ this.pairedStatus = statusData.paired;
161
+ this.setupUri = statusData.setupUri;
162
+ if (statusData.matter) {
163
+ this.matterCommissioningInfo = {
164
+ qrCode: statusData.matter.qrCode,
165
+ manualPairingCode: statusData.matter.manualPairingCode,
166
+ serialNumber: statusData.matter.serialNumber,
167
+ commissioned: statusData.matter.commissioned || false,
168
+ deviceCount: statusData.matter.deviceCount,
169
+ };
170
+ }
171
+ this.sendStatusUpdate();
172
+ break;
173
+ }
174
+ case "matterEvent": {
175
+ const matterEvent = message.data;
176
+ if (matterEvent.type === 'accessoriesData') {
177
+ this.lastMatterAccessoriesResponse = matterEvent.data;
178
+ }
179
+ else if (matterEvent.type === 'externalBridgeRegistration') {
180
+ const data = matterEvent.data;
181
+ if (this.onExternalBridgeRegistered) {
182
+ this.onExternalBridgeRegistered(data.externalBridgeUsername, this.bridgeConfig.username);
183
+ }
184
+ }
185
+ else {
186
+ this.ipcService.sendMessage("matterEvent", matterEvent);
187
+ }
188
+ break;
189
+ }
190
+ }
191
+ });
192
+ }
193
+ handleProcessClose(code, signal) {
194
+ const isLikelyPluginCrash = code === 1 && signal === null;
195
+ this.log.warn(`Child bridge ended (code ${code}, signal ${signal}).${isLikelyPluginCrash
196
+ ? ' The child bridge ended unexpectedly, which is normally due to the plugin not catching its errors properly. Please report this to the plugin developer by clicking on the'
197
+ + ' \'Report An Issue\' option in the plugin menu dropdown from the Homebridge UI. If there are related logs shown above, please include them in your report.'
198
+ : ''}`);
199
+ if (isLikelyPluginCrash) {
200
+ if (this.restartCount < this.maxRestarts) {
201
+ this.bridgeStatus = "pending";
202
+ this.restartCount += 1;
203
+ const delay = this.restartCount * 10;
204
+ this.log(`Child bridge will automatically restart in ${delay} seconds (restart attempt ${this.restartCount} of ${this.maxRestarts}).`);
205
+ setTimeout(() => {
206
+ if (!this.shuttingDown) {
207
+ this.startChildProcess();
208
+ }
209
+ }, delay * 1000);
210
+ }
211
+ else {
212
+ this.bridgeStatus = "down";
213
+ this.manuallyStopped = true;
214
+ this.log.error(`Child bridge will no longer restart after failing ${this.maxRestarts + 1} times, you will need to manually start this child bridge from the Homebridge UI.`);
215
+ }
216
+ return;
217
+ }
218
+ if (!this.shuttingDown) {
219
+ this.bridgeStatus = "down";
220
+ this.restartCount = 0;
221
+ this.startChildProcess();
222
+ }
223
+ }
224
+ sendMessage(type, data) {
225
+ if (this.child && this.child.connected) {
226
+ this.child.send({
227
+ id: type,
228
+ data,
229
+ });
230
+ }
231
+ }
232
+ setProcessFlags() {
233
+ if (this.bridgeConfig.debugModeEnabled) {
234
+ this.args.push('-D');
235
+ }
236
+ if (this.homebridgeOptions.forceColourLogging) {
237
+ this.args.push('-C');
238
+ }
239
+ if (this.homebridgeOptions.insecureAccess) {
240
+ this.args.push('-I');
241
+ }
242
+ if (this.homebridgeOptions.noLogTimestamps) {
243
+ this.args.push('-T');
244
+ }
245
+ if (this.homebridgeOptions.keepOrphanedCachedAccessories) {
246
+ this.args.push('-K');
247
+ }
248
+ if (this.homebridgeOptions.customStoragePath) {
249
+ this.args.push('-U', this.homebridgeOptions.customStoragePath);
250
+ }
251
+ if (this.homebridgeOptions.customPluginPath) {
252
+ this.args.push('-P', this.homebridgeOptions.customPluginPath);
253
+ }
254
+ }
255
+ setProcessEnv() {
256
+ this.processEnv = {
257
+ env: {
258
+ ...process.env,
259
+ DEBUG: `${process.env.DEBUG || ''} ${this.bridgeConfig.env?.DEBUG || ''}`.trim(),
260
+ NODE_OPTIONS: `${process.env.NODE_OPTIONS || ''} ${this.bridgeConfig.env?.NODE_OPTIONS || ''}`.trim(),
261
+ },
262
+ silent: true,
263
+ };
264
+ }
265
+ loadPlugin() {
266
+ const bridgeConfig = {
267
+ name: this.bridgeConfig.name || this.displayName || this.plugin.getPluginIdentifier(),
268
+ port: this.bridgeConfig.port,
269
+ username: this.bridgeConfig.username,
270
+ advertiser: this.homebridgeConfig.bridge.advertiser,
271
+ pin: this.bridgeConfig.pin || this.homebridgeConfig.bridge.pin,
272
+ bind: this.homebridgeConfig.bridge.bind,
273
+ setupID: this.bridgeConfig.setupID,
274
+ manufacturer: this.bridgeConfig.manufacturer || this.homebridgeConfig.bridge.manufacturer,
275
+ model: this.bridgeConfig.model || this.homebridgeConfig.bridge.model,
276
+ firmwareRevision: this.bridgeConfig.firmwareRevision || this.homebridgeConfig.bridge.firmwareRevision,
277
+ serialNumber: this.bridgeConfig.serialNumber || this.bridgeConfig.username,
278
+ matter: this.bridgeConfig.matter,
279
+ };
280
+ const bridgeOptions = {
281
+ cachedAccessoriesDir: User.cachedAccessoryPath(),
282
+ cachedAccessoriesItemName: `cachedAccessories.${this.bridgeConfig.username.replace(/:/g, '').toUpperCase()}`,
283
+ };
284
+ Object.assign(bridgeOptions, this.homebridgeOptions);
285
+ if (this.bridgeConfig.debugModeEnabled !== undefined) {
286
+ bridgeOptions.debugModeEnabled = this.bridgeConfig.debugModeEnabled;
287
+ }
288
+ this.sendMessage("load", {
289
+ type: this.type,
290
+ identifier: this.identifier,
291
+ pluginPath: this.plugin.getPluginPath(),
292
+ pluginConfig: this.pluginConfig,
293
+ bridgeConfig,
294
+ bridgeOptions,
295
+ homebridgeConfig: {
296
+ bridge: this.homebridgeConfig.bridge,
297
+ ports: this.homebridgeConfig.ports,
298
+ disabledPlugins: [],
299
+ accessories: [],
300
+ platforms: [],
301
+ },
302
+ });
303
+ }
304
+ startBridge() {
305
+ this.sendMessage("start");
306
+ }
307
+ async handlePortRequest(request) {
308
+ let port;
309
+ if (request.portType === 'matter') {
310
+ port = await this.externalPortService.requestMatterPort(request.username);
311
+ }
312
+ else {
313
+ port = await this.externalPortService.requestPort(request.username);
314
+ }
315
+ this.sendMessage("portAllocated", {
316
+ username: request.username,
317
+ port,
318
+ });
319
+ }
320
+ teardown() {
321
+ if (this.child && this.child.connected) {
322
+ this.bridgeStatus = "down";
323
+ this.child.kill('SIGTERM');
324
+ }
325
+ }
326
+ sendStatusUpdate() {
327
+ this.ipcService.sendMessage("childBridgeStatusUpdate", this.getMetadata());
328
+ }
329
+ restartChildBridge() {
330
+ if (this.manuallyStopped) {
331
+ this.restartCount = 0;
332
+ this.startChildBridge();
333
+ }
334
+ else {
335
+ this.log.warn('Child bridge restarting...');
336
+ this.refreshConfig();
337
+ this.teardown();
338
+ }
339
+ }
340
+ stopChildBridge() {
341
+ if (!this.shuttingDown) {
342
+ this.log.warn('Child bridge stopping, will not restart.');
343
+ this.shuttingDown = true;
344
+ this.manuallyStopped = true;
345
+ this.restartCount = 0;
346
+ this.bridgeStatus = "down";
347
+ this.child?.removeAllListeners('close');
348
+ this.teardown();
349
+ }
350
+ else {
351
+ this.log.warn('Child bridge already shutting down or stopped.');
352
+ }
353
+ }
354
+ startChildBridge() {
355
+ if (this.manuallyStopped && this.bridgeStatus === "down" && (!this.child || !this.child.connected)) {
356
+ this.refreshConfig();
357
+ this.startChildProcess();
358
+ this.shuttingDown = false;
359
+ this.manuallyStopped = false;
360
+ }
361
+ else {
362
+ this.log.warn('Child bridge cannot be started, it is still running or was not manually stopped.');
363
+ }
364
+ }
365
+ async refreshConfig() {
366
+ try {
367
+ const homebridgeConfig = await fs.readJson(User.configPath());
368
+ if (this.type === "platform") {
369
+ const config = homebridgeConfig.platforms?.filter(x => x.platform === this.identifier && x._bridge?.username === this.bridgeConfig.username);
370
+ if (config.length) {
371
+ this.pluginConfig = config;
372
+ this.bridgeConfig = this.pluginConfig[0]._bridge || this.bridgeConfig;
373
+ }
374
+ else {
375
+ this.log.warn('Platform config could not be found, using existing config.');
376
+ }
377
+ }
378
+ else if (this.type === "accessory") {
379
+ const config = homebridgeConfig.accessories?.filter(x => x.accessory === this.identifier && x._bridge?.username === this.bridgeConfig.username);
380
+ if (config.length) {
381
+ this.pluginConfig = config;
382
+ this.bridgeConfig = this.pluginConfig[0]._bridge || this.bridgeConfig;
383
+ }
384
+ else {
385
+ this.log.warn('Accessory config could not be found, using existing config.');
386
+ }
387
+ }
388
+ }
389
+ catch (error) {
390
+ this.log.error('Failed to refresh plugin config:', error.message);
391
+ }
392
+ }
393
+ getMetadata() {
394
+ return {
395
+ status: this.bridgeStatus,
396
+ paired: this.pairedStatus,
397
+ setupUri: this.setupUri,
398
+ username: this.bridgeConfig.username,
399
+ port: this.bridgeConfig.port,
400
+ pin: this.bridgeConfig.pin || this.homebridgeConfig.bridge.pin,
401
+ name: this.bridgeConfig.name || this.displayName || this.plugin.getPluginIdentifier(),
402
+ plugin: this.plugin.getPluginIdentifier(),
403
+ identifier: this.identifier,
404
+ pid: this.child?.pid,
405
+ manuallyStopped: this.manuallyStopped,
406
+ matterConfig: this.bridgeConfig.matter,
407
+ matterIdentifier: this.bridgeConfig.matter ? this.bridgeConfig.username : undefined,
408
+ matterSetupUri: this.matterCommissioningInfo?.qrCode,
409
+ matterPin: this.matterCommissioningInfo?.manualPairingCode,
410
+ matterSerialNumber: this.matterCommissioningInfo?.serialNumber,
411
+ matterCommissioned: this.matterCommissioningInfo?.commissioned,
412
+ matterDeviceCount: this.matterCommissioningInfo?.deviceCount,
413
+ };
414
+ }
415
+ }
416
+ //# sourceMappingURL=childBridgeService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"childBridgeService.js","sourceRoot":"","sources":["../src/childBridgeService.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,MAAM,UAAU,CAAA;AAIzB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAGrC,MAAM,CAAN,IAAkB,4BAwEjB;AAxED,WAAkB,4BAA4B;IAI5C,+CAAe,CAAA;IAKf,6CAAa,CAAA;IAKb,iDAAiB,CAAA;IAKjB,+CAAe,CAAA;IAKf,iDAAiB,CAAA;IAKjB,4DAA4B,CAAA;IAK5B,gEAAgC,CAAA;IAKhC,wDAAwB,CAAA;IAKxB,iFAAiD,CAAA;IAKjD,+EAA+C,CAAA;IAK/C,+EAA+C,CAAA;IAK/C,oFAAoD,CAAA;IAKpD,mFAAmD,CAAA;IAOnD,4DAA4B,CAAA;AAC9B,CAAC,EAxEiB,4BAA4B,KAA5B,4BAA4B,QAwE7C;AAGD,MAAM,CAAN,IAAkB,iBAejB;AAfD,WAAkB,iBAAiB;IAIjC,wCAAmB,CAAA;IAKnB,8BAAS,CAAA;IAKT,kCAAa,CAAA;AACf,CAAC,EAfiB,iBAAiB,KAAjB,iBAAiB,QAelC;AA6ED,MAAM,OAAO,kBAAkB;IA8BpB;IACA;IACC;IACA;IACA;IACA;IACA;IACA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UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG;YACpB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM;YACtC,gBAAgB,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACnF,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM;YACpD,SAAS,EAAE,IAAI,CAAC,uBAAuB,EAAE,iBAAiB;YAC1D,kBAAkB,EAAE,IAAI,CAAC,uBAAuB,EAAE,YAAY;YAC9D,kBAAkB,EAAE,IAAI,CAAC,uBAAuB,EAAE,YAAY;YAC9D,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,EAAE,WAAW;SAC7D,CAAA;IACH,CAAC;CACF"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import 'source-map-support/register.js';
2
+ export default function cli(): void;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAeA,OAAO,gCAAgC,CAAA;AAYvC,MAAM,CAAC,OAAO,UAAU,GAAG,IAAI,IAAI,CAsFlC"}
package/dist/cli.js ADDED
@@ -0,0 +1,88 @@
1
+ import process from 'node:process';
2
+ import { Command } from 'commander';
3
+ import { HAPStorage } from 'hap-nodejs';
4
+ import { satisfies } from 'semver';
5
+ import { Logger } from './logger.js';
6
+ import { Server } from './server.js';
7
+ import { User } from './user.js';
8
+ import getVersion, { getRequiredNodeVersion } from './version.js';
9
+ import 'source-map-support/register.js';
10
+ const log = Logger.internal;
11
+ const requiredNodeVersion = getRequiredNodeVersion();
12
+ if (requiredNodeVersion && !satisfies(process.version, requiredNodeVersion)) {
13
+ log.warn(`Homebridge requires a Node.js version of ${requiredNodeVersion} which does \
14
+ not satisfy the current Node.js version of ${process.version}. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF`);
15
+ }
16
+ export default function cli() {
17
+ let insecureAccess = false;
18
+ let hideQRCode = false;
19
+ let keepOrphans = false;
20
+ let customPluginPath;
21
+ let strictPluginResolution = false;
22
+ let noLogTimestamps = false;
23
+ let debugModeEnabled = false;
24
+ let forceColourLogging = false;
25
+ let customStoragePath;
26
+ let shuttingDown = false;
27
+ const program = new Command();
28
+ program
29
+ .version(getVersion())
30
+ .allowExcessArguments()
31
+ .option('-C, --color', 'force color in logging', () => forceColourLogging = true)
32
+ .option('-D, --debug', 'turn on debug level logging', () => debugModeEnabled = true)
33
+ .option('-I, --insecure', 'allow unauthenticated requests (for easier hacking)', () => insecureAccess = true)
34
+ .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', path => customPluginPath = path)
35
+ .option('-Q, --no-qrcode', 'do not issue QRcode in logging', () => hideQRCode = true)
36
+ .option('-K, --keep-orphans', 'keep cached accessories for which the associated plugin is not loaded', () => keepOrphans = true)
37
+ .option('-T, --no-timestamp', 'do not issue timestamps in logging', () => noLogTimestamps = true)
38
+ .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', path => customStoragePath = path)
39
+ .option('--strict-plugin-resolution', 'only load plugins from the --plugin-path if set, otherwise from the primary global node_modules', () => strictPluginResolution = true)
40
+ .parse(process.argv);
41
+ if (noLogTimestamps) {
42
+ Logger.setTimestampEnabled(false);
43
+ }
44
+ if (debugModeEnabled) {
45
+ Logger.setDebugEnabled(true);
46
+ }
47
+ if (forceColourLogging) {
48
+ Logger.forceColor();
49
+ }
50
+ if (customStoragePath) {
51
+ User.setStoragePath(customStoragePath);
52
+ }
53
+ HAPStorage.setCustomStoragePath(User.persistPath());
54
+ const options = {
55
+ keepOrphanedCachedAccessories: keepOrphans,
56
+ insecureAccess,
57
+ hideQRCode,
58
+ customPluginPath,
59
+ noLogTimestamps,
60
+ debugModeEnabled,
61
+ forceColourLogging,
62
+ customStoragePath,
63
+ strictPluginResolution,
64
+ };
65
+ const server = new Server(options);
66
+ const signalHandler = (signal, signalNum) => {
67
+ if (shuttingDown) {
68
+ return;
69
+ }
70
+ shuttingDown = true;
71
+ log.info('Got %s, shutting down Homebridge...', signal);
72
+ setTimeout(() => process.exit(128 + signalNum), 5000);
73
+ server.teardown();
74
+ };
75
+ process.on('SIGINT', signalHandler.bind(undefined, 'SIGINT', 2));
76
+ process.on('SIGTERM', signalHandler.bind(undefined, 'SIGTERM', 15));
77
+ const errorHandler = (error) => {
78
+ if (error.stack) {
79
+ log.error(error.stack);
80
+ }
81
+ if (!shuttingDown) {
82
+ process.kill(process.pid, 'SIGTERM');
83
+ }
84
+ };
85
+ process.on('uncaughtException', errorHandler);
86
+ server.start().catch(errorHandler);
87
+ }
88
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAIA,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,UAAU,EAAE,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAEjE,OAAO,gCAAgC,CAAA;AAIvC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAA;AAE3B,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAA;AACpD,IAAI,mBAAmB,IAAI,CAAC,SAAS,CAAC,OAAO,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,GAAG,SAAS,CAAC,EAAE,IAAI,CAAC,CAAA;QAErD,MAAM,CAAC,QAAQ,EAAE,CAAA;IACnB,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAA;IAChE,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAA;IAEnE,MAAM,YAAY,GAAG,CAAC,KAAY,EAAQ,EAAE;QAC1C,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACxB,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QACtC,CAAC;IACH,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { MacAddress } from 'hap-nodejs';
2
+ import type { ChildBridgeFork } from './childBridgeFork.js';
3
+ export interface ExternalPortsConfiguration {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ export declare class ExternalPortService {
8
+ private externalPorts?;
9
+ private matterPorts?;
10
+ private nextExternalPort?;
11
+ private allocatedPorts;
12
+ private allocatedMatterPorts;
13
+ private readonly configuredMatterPorts;
14
+ constructor(externalPorts?: ExternalPortsConfiguration | undefined, matterPorts?: ExternalPortsConfiguration | undefined, configuredMatterPorts?: number[]);
15
+ requestPort(username: MacAddress): Promise<number | undefined>;
16
+ requestMatterPort(uuid: string): Promise<number | undefined>;
17
+ private getNextFreePort;
18
+ private getNextFreeMatterPort;
19
+ }
20
+ export declare class ChildBridgeExternalPortService extends ExternalPortService {
21
+ private childBridge;
22
+ constructor(childBridge: ChildBridgeFork);
23
+ requestPort(username: MacAddress): Promise<number | undefined>;
24
+ requestMatterPort(uniqueId: string): Promise<number | undefined>;
25
+ }
26
+ //# sourceMappingURL=externalPortService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalPortService.d.ts","sourceRoot":"","sources":["../src/externalPortService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAI3D,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ;AAOD,qBAAa,mBAAmB;IAO5B,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,WAAW,CAAC;IAPtB,OAAO,CAAC,gBAAgB,CAAC,CAAQ;IACjC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,oBAAoB,CAA6C;IACzE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAyB;gBAGrD,aAAa,CAAC,EAAE,0BAA0B,YAAA,EAC1C,WAAW,CAAC,EAAE,0BAA0B,YAAA,EAChD,qBAAqB,CAAC,EAAE,MAAM,EAAE;IAYrB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAoB9D,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAazE,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,qBAAqB;CAkB9B;AAMD,qBAAa,8BAA+B,SAAQ,mBAAmB;IAEnE,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,eAAe;IAKzB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI9D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAI9E"}
@@ -0,0 +1,77 @@
1
+ import { Logger } from './logger.js';
2
+ export class ExternalPortService {
3
+ externalPorts;
4
+ matterPorts;
5
+ nextExternalPort;
6
+ allocatedPorts = new Map();
7
+ allocatedMatterPorts = new Map();
8
+ configuredMatterPorts = new Set();
9
+ constructor(externalPorts, matterPorts, configuredMatterPorts) {
10
+ this.externalPorts = externalPorts;
11
+ this.matterPorts = matterPorts;
12
+ if (configuredMatterPorts) {
13
+ this.configuredMatterPorts = new Set(configuredMatterPorts);
14
+ }
15
+ }
16
+ async requestPort(username) {
17
+ const existingPortAllocation = this.allocatedPorts.get(username);
18
+ if (existingPortAllocation) {
19
+ return existingPortAllocation;
20
+ }
21
+ const port = this.getNextFreePort();
22
+ this.allocatedPorts.set(username, port);
23
+ return port;
24
+ }
25
+ async requestMatterPort(uuid) {
26
+ const existingPortAllocation = this.allocatedMatterPorts.get(uuid);
27
+ if (existingPortAllocation) {
28
+ return existingPortAllocation;
29
+ }
30
+ const port = this.getNextFreeMatterPort();
31
+ this.allocatedMatterPorts.set(uuid, port);
32
+ return port;
33
+ }
34
+ getNextFreePort() {
35
+ if (!this.externalPorts) {
36
+ return undefined;
37
+ }
38
+ if (this.nextExternalPort === undefined) {
39
+ this.nextExternalPort = this.externalPorts.start;
40
+ return this.nextExternalPort;
41
+ }
42
+ this.nextExternalPort++;
43
+ if (this.nextExternalPort <= this.externalPorts.end) {
44
+ return this.nextExternalPort;
45
+ }
46
+ Logger.internal.warn('External HAP port pool ran out of ports. Falling back to random port assignment.');
47
+ return undefined;
48
+ }
49
+ getNextFreeMatterPort() {
50
+ const rangeStart = this.matterPorts?.start || 5530;
51
+ const rangeEnd = this.matterPorts?.end || 5541;
52
+ const allocatedPortValues = new Set([
53
+ ...this.configuredMatterPorts,
54
+ ...Array.from(this.allocatedMatterPorts.values()).filter((p) => p !== undefined),
55
+ ]);
56
+ for (let port = rangeStart; port <= rangeEnd; port += 1) {
57
+ if (!allocatedPortValues.has(port)) {
58
+ return port;
59
+ }
60
+ }
61
+ throw new Error(`No available Matter ports in range ${rangeStart}-${rangeEnd}. All ports are already allocated.`);
62
+ }
63
+ }
64
+ export class ChildBridgeExternalPortService extends ExternalPortService {
65
+ childBridge;
66
+ constructor(childBridge) {
67
+ super();
68
+ this.childBridge = childBridge;
69
+ }
70
+ async requestPort(username) {
71
+ return await this.childBridge.requestExternalPort(username);
72
+ }
73
+ async requestMatterPort(uniqueId) {
74
+ return await this.childBridge.requestMatterPort(uniqueId);
75
+ }
76
+ }
77
+ //# sourceMappingURL=externalPortService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalPortService.js","sourceRoot":"","sources":["../src/externalPortService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAYpC,MAAM,OAAO,mBAAmB;IAOpB;IACA;IAPF,gBAAgB,CAAS;IACzB,cAAc,GAAwC,IAAI,GAAG,EAAE,CAAA;IAC/D,oBAAoB,GAAoC,IAAI,GAAG,EAAE,CAAA;IACxD,qBAAqB,GAAgB,IAAI,GAAG,EAAE,CAAA;IAE/D,YACU,aAA0C,EAC1C,WAAwC,EAChD,qBAAgC;QAFxB,kBAAa,GAAb,aAAa,CAA6B;QAC1C,gBAAW,GAAX,WAAW,CAA6B;QAGhD,IAAI,qBAAqB,EAAE,CAAC;YAC1B,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAA;QAC7D,CAAC;IACH,CAAC;IAOM,KAAK,CAAC,WAAW,CAAC,QAAoB;QAE3C,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAChE,IAAI,sBAAsB,EAAE,CAAC;YAC3B,OAAO,sBAAsB,CAAA;QAC/B,CAAC;QA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