UNPKG

@obelisk/client

Version:

Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.

57 lines (56 loc) 2.09 kB
import { Observable } from 'rxjs'; import { ApiVersion } from '../interfaces'; import { ObeliskClient } from '../obelisk-client'; /** * Endpoint class represents an IoT-stack API Endpoint. * For now just get(), but will support all http methods. */ export declare class StreamEndpoint { private client; private _url; private apiVersion; /** * Absolute url to use in requests */ get url(): string; /** * Creates an Endpoint instance * @param client The client is used to add auth tokens to the request * @param uri The uri is a relative path starting after /api/<version>. Examples are: <code>/things/my_thing/metrics/my_metric/events?from=1530089953000</code> or <code>/locations/my_loc/metrics/my_metric/stats/unit</code> */ static create(client: ObeliskClient, uri: string, apiVersion?: ApiVersion): StreamEndpoint; private constructor(); /** * Connects with this endpoint as an eventsource. * @param options StreamOptions to filter the stream. * @return Observable of TPage objects. Unsubscribe to manually close the stream. */ connect(options?: StreamOptions): Observable<any>; /** * Wraps the EventSourcePolyfill in an Observable. * @param options */ private observablePolyEventSource; /** * Adds the StreamOptions to the url as a querystring. * @param url The url to add querystring to * @param options The StreamOptions to limit the stream */ private addOptionsToUrl; } /** * Options to limit the SSE output. */ export interface StreamOptions { /** String or array of string with Thing ids */ things?: string | string[]; /** String or array of string with Metric ids */ metrics?: string | string[]; /** String or array of string with Location geohashes */ area?: string | string[]; /** * By default: reconnect on 504 timeout when not receiving data for a while. * **Set to false to stop on first 504** * */ stopOn504?: boolean; }