Android पर Hub Activation API

HubManagementTrait

हब ऐक्टिवेशन एपीआई का इस्तेमाल करके, ऐसा ऐप्लिकेशन बनाया जा सकता है जो हब ढूंढ सके और उन्हें चालू कर सके. ऐसा करने के लिए:

  1. स्ट्रक्चर में HubManagementTrait का रेफ़रंस पाएं:

    val hubManagementTrait =
      hubManagementTraitFlow.firstOrNull {
        it.metadata.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE
      }
    if (hubManagementTrait == null) {
      errorsEmitter.emit(HomeException.notFound("HubManagement trait isn't online"))
    }
    
  2. वाई-फ़ाई नेटवर्क पर, हब के तौर पर काम करने वाले डिवाइसों की पहचान करें:

    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(),
        )
    
  3. हब के तौर पर काम करने वाले डिवाइस को चालू करें:

    try {
      val unused = hubManagementTrait.activateHub(hub)
    } catch (e: Exception) {
      Log.d("Hub Activation", "Error activating hub $e")
    }