()
| 189 | } |
| 190 | |
| 191 | public async start(): Promise<void> { |
| 192 | if (this.config.bridge.disableIpc !== true) { |
| 193 | this.initializeIpcEventHandlers() |
| 194 | } |
| 195 | |
| 196 | const promises: Promise<void>[] = [] |
| 197 | |
| 198 | // load the cached accessories |
| 199 | await this.bridgeService.loadCachedPlatformAccessoriesFromDisk() |
| 200 | |
| 201 | // Validate Matter configuration up front so we know whether to expose |
| 202 | // api.matter to plugins. Validator may strip invalid entries, so re-check |
| 203 | // after. Caching the result avoids two more hasMatterConfig calls below. |
| 204 | let matterIsConfigured = MatterConfigCollector.hasMatterConfig(this.config) |
| 205 | if (matterIsConfigured) { |
| 206 | await MatterConfigCollector.validateMatterConfig(this.config) |
| 207 | matterIsConfigured = MatterConfigCollector.hasMatterConfig(this.config) |
| 208 | } |
| 209 | |
| 210 | // Eagerly load the MatterAPI facade before plugins initialize, so api.matter |
| 211 | // is defined when plugin code runs on Matter-enabled bridges. The heavy |
| 212 | // MatterBridgeManager init still happens after plugins load (below) — only |
| 213 | // the API surface needs to be ready early. |
| 214 | if (matterIsConfigured) { |
| 215 | await this.api.loadMatterAPI() |
| 216 | } |
| 217 | |
| 218 | // initialize plugins |
| 219 | await this.pluginManager.initializeInstalledPlugins() |
| 220 | |
| 221 | // Initialize Matter manager only if configured. Heavy Matter.js libraries |
| 222 | // are loaded here (async), avoiding sync blocking during construction. |
| 223 | if (matterIsConfigured) { |
| 224 | // Dynamically import MatterBridgeManager only when needed |
| 225 | // This prevents loading heavy Matter.js libraries when Matter is not configured |
| 226 | const { MatterBridgeManager } = await import('./matter/MatterBridgeManager.js') |
| 227 | |
| 228 | // Create the manager |
| 229 | this.matterManager = new MatterBridgeManager( |
| 230 | this.config, |
| 231 | this.api, |
| 232 | this.externalPortService, |
| 233 | this.pluginManager, |
| 234 | this.options, |
| 235 | this, // Pass server instance for registry access |
| 236 | ) |
| 237 | |
| 238 | // Set manager reference on API for getAccessoryState |
| 239 | this.api._setMatterManager(this.matterManager) |
| 240 | |
| 241 | // Initialize Matter server for main bridge if enabled |
| 242 | await this.matterManager.initialize() |
| 243 | } |
| 244 | |
| 245 | if (this.config.platforms.length > 0) { |
| 246 | promises.push(...this.loadPlatforms()) |
| 247 | } |
| 248 | if (this.config.accessories.length > 0) { |
no test coverage detected