MCPcopy
hub / github.com/homebridge/homebridge / start

Method start

src/server.ts:191–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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) {

Callers 4

cliFunction · 0.95
server.spec.tsFile · 0.45

Calls 15

loadPlatformsMethod · 0.95
loadAccessoriesMethod · 0.95
publishBridgeMethod · 0.95
setServerStatusMethod · 0.95
isHapExternalsOnlyFunction · 0.85
hasMatterConfigMethod · 0.80
validateMatterConfigMethod · 0.80
loadMatterAPIMethod · 0.80
_setMatterManagerMethod · 0.80

Tested by

no test coverage detected