MCPcopy
hub / github.com/homebridge/homebridge / startBridge

Method startBridge

src/childBridgeFork.ts:147–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145 }
146
147 async startBridge(): Promise<void> {
148 // Conditionally load Matter support only if this child bridge has Matter active
149 // (configured + enabled OR externalsOnly). Prevents loading heavy Matter.js
150 // libraries for child bridges that don't use it.
151 if (isMatterActive(this.bridgeConfig.matter) && this.type === PluginType.ACCESSORY) {
152 matterLogger.warn('Matter is not supported on accessory child bridges. Ignoring matter configuration.')
153 }
154
155 if (isMatterActive(this.bridgeConfig.matter) && this.type !== PluginType.ACCESSORY) {
156 matterLogger.info('Loading Matter support for child bridge...')
157
158 // Note: api.loadMatterAPI() was already called at the start of loadPlugin()
159 // so api.matter is already defined by the time the plugin's initializer ran.
160
161 // Dynamically import Matter manager only when needed
162 const { ChildBridgeMatterManager } = await import('./matter/index.js')
163
164 // Create Matter bridge manager
165 this.matterManager = new ChildBridgeMatterManager(
166 this.bridgeConfig,
167 this.bridgeOptions,
168 this.api,
169 this.externalPortService,
170 this.pluginManager,
171 )
172
173 // Set manager reference on API for getAccessoryState
174 this.api._setMatterManager(this.matterManager)
175
176 // Initialize Matter server if configured
177 // Pass callback to send status updates when commissioning changes
178 await this.matterManager.initialize(() => {
179 this.sendPairedStatusEvent()
180 })
181
182 // Create Matter message handler to delegate IPC handling
183 matterLogger.debug('Creating ChildBridgeMatterMessageHandler...')
184 this.matterMessageHandler = new ChildBridgeMatterMessageHandler(
185 this.matterManager,
186 this.bridgeConfig.username,
187 (type, data) => this.sendMessage(type as ChildProcessMessageEventType, data),
188 )
189 matterLogger.debug(`Matter message handler created for child bridge ${this.bridgeConfig.username}`)
190 } else {
191 matterLogger.debug('Matter not configured for this child bridge, skipping Matter setup')
192 }
193
194 this.bridgeService = new BridgeService(
195 this.api,
196 this.pluginManager,
197 this.externalPortService,
198 this.bridgeOptions,
199 this.bridgeConfig,
200 )
201
202 // watch bridge events to check when server is online
203 this.bridgeService.bridge.on(AccessoryEventTypes.ADVERTISED, () => {
204 this.sendPairedStatusEvent()

Callers 1

childBridgeFork.tsFile · 0.45

Calls 15

sendPairedStatusEventMethod · 0.95
sendMessageMethod · 0.95
publishHapIfEnabledMethod · 0.95
isMatterActiveFunction · 0.85
warnMethod · 0.80
infoMethod · 0.80
_setMatterManagerMethod · 0.80
debugMethod · 0.80
onMethod · 0.80
getPluginForPlatformMethod · 0.80
withPrefixMethod · 0.80

Tested by

no test coverage detected