HubManagementTrait
Hub Activation API का इस्तेमाल करके, ऐसा ऐप्लिकेशन बनाया जा सकता है जो हब ढूंढ सके और उन्हें चालू कर सके. ऐसा करने के लिए:
स्ट्रक्चर में
HubManagementTraitका रेफ़रंस पाएं:val hubManagementTrait = hubManagementTraitFlow.firstOrNull { it.metadata.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE } if (hubManagementTrait == null) { errorsEmitter.emit(HomeException.notFound("HubManagement trait isn't online")) }वाई-फ़ाई नेटवर्क पर, हब के तौर पर काम करने वाले डिवाइसों की पहचान करें:
try { val unused = hubManagementTrait.discoverAvailableHubs() } catch (e: Exception) { Log.d(TAG_HUB_DISCOVERY, "Error discovering hubs $e") errorsEmitter.emit(e) } val hubManagementTraitFlow = structureFlow.flatMapLatest { it.trait(HubManagement) } val discoveredHubs = hubManagementTraitFlow .map { it.discoveredHubsList } .handleErrors() .flowOn(ioDispatcher) .stateIn( scope = CoroutineScope(viewModelScope.coroutineContext + ioDispatcher), started = SharingStarted.WhileSubscribed(), listOf(), )हब के तौर पर काम करने वाले डिवाइस को चालू करें:
try { val unused = hubManagementTrait.activateHub(hub) } catch (e: Exception) { Log.d("Hub Activation", "Error activating hub $e") }