2014-12-29 13:57:20 -08:00
|
|
|
/*global define*/
|
|
|
|
|
|
|
|
define(
|
2014-12-30 13:27:28 -08:00
|
|
|
["./TelemetrySubscription"],
|
|
|
|
function (TelemetrySubscription) {
|
2014-12-29 13:57:20 -08:00
|
|
|
"use strict";
|
|
|
|
|
2014-12-30 17:54:54 -08:00
|
|
|
/**
|
|
|
|
* The TelemetrySubscriber is a service which allows
|
|
|
|
* subscriptions to be made for new data associated with
|
|
|
|
* domain objects. It is exposed as a service named
|
|
|
|
* `telemetrySubscriber`.
|
|
|
|
*
|
|
|
|
* Subscriptions may also be made directly using the
|
|
|
|
* `telemetry` capability of a domain objcet; the subscriber
|
|
|
|
* uses this as well, but additionally handles delegation
|
|
|
|
* (e.g. for telemetry panels) as well as latest-value
|
|
|
|
* extraction.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param $q Angular's $q
|
|
|
|
* @param $timeout Angular's $timeout
|
|
|
|
*/
|
2014-12-30 13:27:28 -08:00
|
|
|
function TelemetrySubscriber($q, $timeout) {
|
2014-12-29 13:57:20 -08:00
|
|
|
return {
|
2014-12-30 17:54:54 -08:00
|
|
|
/**
|
|
|
|
* Subscribe to streaming telemetry updates
|
|
|
|
* associated with this domain object (either
|
|
|
|
* directly or via capability delegation.)
|
|
|
|
*
|
|
|
|
* @param {DomainObject} domainObject the object whose
|
|
|
|
* associated telemetry data is of interest
|
|
|
|
* @param {Function} callback a function to invoke
|
|
|
|
* when new data has become available.
|
2015-01-30 15:34:18 -08:00
|
|
|
* @param {boolean} lossless flag to indicate whether the
|
|
|
|
* callback should be notified for all values
|
|
|
|
* (otherwise, multiple values in quick succession
|
|
|
|
* will call back with only the latest value.)
|
2014-12-30 17:54:54 -08:00
|
|
|
* @returns {TelemetrySubscription} the subscription,
|
|
|
|
* which will provide access to latest values.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @memberof TelemetrySubscriber
|
|
|
|
*/
|
2015-01-30 15:34:18 -08:00
|
|
|
subscribe: function (domainObject, callback, lossless) {
|
2014-12-30 13:27:28 -08:00
|
|
|
return new TelemetrySubscription(
|
|
|
|
$q,
|
|
|
|
$timeout,
|
|
|
|
domainObject,
|
2015-01-30 15:34:18 -08:00
|
|
|
callback,
|
|
|
|
lossless
|
2014-12-30 13:27:28 -08:00
|
|
|
);
|
2014-12-29 13:57:20 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return TelemetrySubscriber;
|
|
|
|
}
|
|
|
|
);
|