import { Observable } from "rxjs" ; import { filter , map } from "rxjs/operators" ; import { Controller , DiscoverEvent , filterOp , ObjectFilter , QueryEvent , Uuid } from ".." ; import { Thing } from "./objects" ; import { SensorThingsTypes } from "./types" ; /**
 * Observes Things and Thing-related objects.
 *
 * This controller is designed to be used by a client with a corresponding
 * controller (e.g. ThingSourceController) that answers to its events.
 */ export class ThingObserverController extends Controller { /**
     * Returns an observable of the Things in the system.
     *
     * This is performed by sending a Discovery event with the object type of
     * Thing.
     *
     * This method does not perform any kind of caching and it should be
     * performed on the application-side.
     */ public discoverThings ( ) { return this . communicationManager . publishDiscover ( DiscoverEvent . withObjectTypes ( [ SensorThingsTypes . OBJECT_TYPE_THING ] ) ) . pipe ( filter ( event => ! ! event . data . object ) , map ( event => event . data . object as Thing ) ) ; } /**
     * Returns an observable emitting advertised Things.
     *
     * This method does not perform any kind of caching and it should be
     * performed on the application-side.
     */ public observeAdvertisedThings ( ) { return this . communicationManager . observeAdvertiseWithObjectType ( SensorThingsTypes . OBJECT_TYPE_THING ) . pipe ( map ( event => event . data . object as Thing ) , filter ( thing => ! ! thing ) ) ; } /**
     * Returns an observable of the Things that are located at the given
     * Location.
     *
     * This is performed by sending a Query event for Thing objects with the
     * locationId matching the objectId of the Location.
     *
     * This method does not perform any kind of caching and it should be
     * performed on the application-side.
     */ public queryThingsAtLocation ( locationId ) { const objectFilter = { conditions : [ "locationId" , filterOp . equals ( locationId ) ] , } ; return this . communicationManager . publishQuery ( QueryEvent . withObjectTypes ( [ SensorThingsTypes . OBJECT_TYPE_THING ] , objectFilter ) ) . pipe ( map ( event => event . data . objects as Thing [ ] ) ) ; } }