import { Observable } from "rxjs" ; import { filter , map } from "rxjs/operators" ; import { Controller , DiscoverEvent , filterOp , ObjectFilter , QueryEvent , Uuid } from ".." ; import { Observation , Sensor } from "./objects" ; import { SensorThingsTypes } from "./types" ; /**
 * Observes Sensors and Sensor-related objects. This controller is designed to
 * be used by a client as a counterpart to a SensorSourceController which should
 * answer its requests.
 */ export class SensorObserverController extends Controller { param sensorId param channelId observeChanneledObservations ( sensorId , channelId ? ) { return this . communicationManager . observeChannel ( channelId || sensorId ) . pipe ( filter ( event => ! ! event . data . object && event . data . object . objectType === SensorThingsTypes . OBJECT_TYPE_OBSERVATION && event . data . object . parentObjectId === sensorId ) , map ( event => event . data . object as Observation ) ) ; } param sensorId observeAdvertisedObservations ( sensorId ) { return this . communicationManager . observeAdvertiseWithObjectType ( SensorThingsTypes . OBJECT_TYPE_OBSERVATION ) . pipe ( filter ( event => ! ! event . data . object && event . data . object . parentObjectId === sensorId ) , map ( event => event . data . object as Observation ) ) ; } /**
     * Returns an observable emitting advertised Sensors.
     *
     * This method does not perform any kind of caching and it should
     * be performed on the application-side.
     */ observeAdvertisedSensors ( ) { return this . communicationManager . observeAdvertiseWithObjectType ( SensorThingsTypes . OBJECT_TYPE_SENSOR ) . pipe ( map ( event => event . data . object as Sensor ) , filter ( sensor => ! ! sensor ) ) ; } /**
     * Returns an observable of the Sensors in the system.
     *
     * This is performed by sending a Discovery event with the object type of
     * Sensor.
     *
     * This method does not perform any kind of caching and it should be
     * performed on the application-side.
     */ discoverSensors ( ) { return this . communicationManager . publishDiscover ( DiscoverEvent . withObjectTypes ( [ SensorThingsTypes . OBJECT_TYPE_SENSOR ] ) ) . pipe ( filter ( event => ! ! event . data . object ) , map ( event => event . data . object as Sensor ) ) ; } /**
     * Returns an observable of the Sensors that are associated with this Thing.
     *
     * This is performed by sending a Query event for Sensor objects with the
     * parentObjectId matching the objectId of the Thing.
     *
     * This method does not perform any kind of caching and it should be
     * performed on the application-side.
     */ querySensorsOfThing ( thingId ) { const objectFilter = { conditions : [ "parentObjectId" , filterOp . equals ( thingId ) ] , } ; return this . communicationManager . publishQuery ( QueryEvent . withObjectTypes ( [ SensorThingsTypes . OBJECT_TYPE_SENSOR ] , objectFilter ) ) . pipe ( map ( event => event . data . objects as Sensor [ ] ) ) ; } }