The Connector uses WebSocket to enable transmission of data over an open connection with the CloudVision API server. It supports subscriptions, which allows clients to receive streaming updates as data changes in real-time.

Hierarchy

  • default
    • default

Constructors

  • new default(options?: ConnectorOptions, websocketClass?: {}, parser?: typeof Parser): default
  • Parameters

    • options: ConnectorOptions = ...
    • websocketClass: {} = WebSocket
      • parser: typeof Parser = Parser

      Returns default

    Properties

    isRunning: boolean
    CLOSE: "close" = CLOSE
    CONNECTED: "connected" = CONNECTED
    DEVICES_DATASET_ID: "DEVICES_DATASET_ID" = DEVICES_DATASET_ID
    DISCONNECTED: "disconnected" = DISCONNECTED
    GET: "get" = GET
    GET_AND_SUBSCRIBE: "getAndSubscribe" = GET_AND_SUBSCRIBE
    GET_DATASETS: "getDatasets" = GET_DATASETS
    ID: "cloudvision-connector" = ID
    PUBLISH: "publish" = PUBLISH
    SEARCH: "alpha/search" = SEARCH
    SEARCH_SUBSCRIBE: "alpha/searchSubscribe" = SEARCH_SUBSCRIBE
    SERVICE_REQUEST: "serviceRequest" = SERVICE_REQUEST
    SUBSCRIBE: "subscribe" = SUBSCRIBE

    Accessors

    • get connectionEmitter(): Emitter
    • Returns Emitter

    • get eventsEmitter(): Emitter
    • Returns Emitter

    • get websocket(): WebSocket
    • Returns WebSocket

    Methods

    • cleanUpConnections(): void
    • Cleans up all event emitters. All bound callbacks will be unbound.

      Returns void

    • close(): void
    • Closes connection to the server and cleans up all event emitters. All bound callbacks will be unbound.

      Returns void

    • closeStream(stream: SubscriptionIdentifier, callback: NotifCallback): null | string
    • Closes one single stream.

      Parameters

      • stream: SubscriptionIdentifier
      • callback: NotifCallback

      Returns null | string

    • closeStreams(streams: SubscriptionIdentifier[], callback: NotifCallback): null | string
    • Closes multiple streams in one close call.

      Parameters

      • streams: SubscriptionIdentifier[]
      • callback: NotifCallback

      Returns null | string

    • closeSubscriptions(subscriptions: SubscriptionIdentifier[], callback: NotifCallback): null | string
    • Close multiple subscriptions in one close call. The subscription identifier return in the subscribe call along with the close function can be passed in here to close the subscription together with others.

      Example


      const query = [{
      dataset: {
      type: 'app',
      name: 'analytics'
      },
      paths: [{
      path_elements: ['events', 'activeEvents'],
      }],
      }];
      const handleResponse = (err, res) => {...};

      // Send the request
      const subscriptionCloseFn = connector.subscribe(query, handleResponse);

      // Close the subscription via `closeSubscriptions`
      const closeSubscriptions([subscriptionCloseFn.identifier]);

      Parameters

      • subscriptions: SubscriptionIdentifier[]
      • callback: NotifCallback

      Returns null | string

    • connection(callback: ConnectionCallback): (() => void)
    • Subscribes a callback to connection events. The callback can receive either Wrpc.CONNECTED or Wrpc.DISCONNECTED`.

      Parameters

      • callback: ConnectionCallback

      Returns (() => void)

        • (): void
        • Subscribes a callback to connection events. The callback can receive either Wrpc.CONNECTED or Wrpc.DISCONNECTED`.

          Returns void

    • get(command: GetCommand, params: CloudVisionParams, callback: NotifCallback): null | string
    • Sends the command along with the params to the API, if the WebSocket is connected. The response is received via the provided callback function.

      Parameters

      • command: GetCommand
      • params: CloudVisionParams
      • callback: NotifCallback

      Returns null | string

    • getAndSubscribe(query: Query, callback: NotifCallback, options: Options): null | SubscriptionIdentifier
    • Returns all notifications that match the given Query and Options, in addition to subscribing to updates. This will return notifications as new updates to the data requested come in.

      A getAndSubscribe is done in such a way that no notifications are lost. Before doing a get, a subscribe is initiated and we wait for an active status message to be returned before initiating a get. This means no notifications are missed, but there is a chance of duplicate notifications.

      Example


      const query = [{
      dataset: {
      type: 'app',
      name: 'analytics'
      },
      paths: [{
      path_elements: ['events', 'activeEvents'],
      }],
      }];
      const options = {
      start: 1504113817725,
      end: 1504113917725,
      };
      const handleResponse = (err, res) => {...};

      // open the stream
      const closeSubscription = connector.getAndSubscribe(
      query, handleResponse, options);

      closeSubscription(); // close the stream when finished

      Parameters

      • query: Query
      • callback: NotifCallback
      • options: Options

      Returns null | SubscriptionIdentifier

    • getApps(callback: NotifCallback): null | string
    • Returns a list of apps (datasets with type == 'app').

      Parameters

      • callback: NotifCallback

      Returns null | string

    • getConfigs(callback: NotifCallback): null | string
    • Returns a list of configs (datasets with type == 'config').

      Parameters

      • callback: NotifCallback

      Returns null | string

    • getDatasets(callback: NotifCallback): null | string
    • Returns a list of datasets (datasets with type 'app', 'config' or 'device').

      Parameters

      • callback: NotifCallback

      Returns null | string

    • getDevices(callback: NotifCallback): null | string
    • Returns a list of devices (datasets with type == 'device').

      Parameters

      • callback: NotifCallback

      Returns null | string

    • getRegionsAndClusters(callback: NotifCallback): null | string
    • Returns a list of regions and associated clusters.

      Parameters

      • callback: NotifCallback

      Returns null | string

    • getWithOptions(query: "DEVICES_DATASET_ID" | Query, callback: NotifCallback, options: Options): null | string
    • Returns all notifications that match the given query and options.

      Example


      const query = [{
      dataset: {
      type: 'app',
      name: 'analytics'
      },
      paths: [{
      path_elements: ['events', 'activeEvents'],
      }],
      }];
      const options = {
      start: 1504113817725,
      end: 1504113917725,
      };
      const handleResponse = (err, res) => {...};

      // Send the request
      connector.getWithOptions(query, handleResponse, options);

      Parameters

      • query: "DEVICES_DATASET_ID" | Query
      • callback: NotifCallback
      • options: Options

      Returns null | string

    • publish(params: CloudVisionPublishRequest, callback: NotifCallback): null | string
    • Writes data in params to the CloudVision API. It receives one message via the provided callback, to indicate whether the write is successful or not.

      Parameters

      • params: CloudVisionPublishRequest
      • callback: NotifCallback

      Returns null | string

    • requestService(request: ServiceRequest, callback: NotifCallback): null | string
    • Send a service request command to the CloudVision API

      Parameters

      • request: ServiceRequest
      • callback: NotifCallback

      Returns null | string

    • run(url: string): void
    • Run connects connector to the specified url

      Parameters

      • url: string

      Returns void

    • runService(request: ServiceRequest, callback: NotifCallback): void
    • Parameters

      • request: ServiceRequest
      • callback: NotifCallback

      Returns void

    • runStreamingService(request: ServiceRequest, callback: NotifCallback): null | SubscriptionIdentifier
    • Parameters

      • request: ServiceRequest
      • callback: NotifCallback

      Returns null | SubscriptionIdentifier

    • search(params: CloudVisionParams, callback: NotifCallback): null | string
    • Parameters

      • params: CloudVisionParams
      • callback: NotifCallback

      Returns null | string

    • searchSubscribe(query: Query, callback: NotifCallback, options?: SearchOptions): null | SubscriptionIdentifier
    • Parameters

      • query: Query
      • callback: NotifCallback
      • options: SearchOptions = ...

      Returns null | SubscriptionIdentifier

    • searchWithOptions(query: Query, callback: NotifCallback, options: Options & SearchOptions): null | string
    • Parameters

      • query: Query
      • callback: NotifCallback
      • options: Options & SearchOptions

      Returns null | string

    • stream(command: StreamCommand, params: CloudVisionParams | ServiceRequest, callback: NotifCallback): null | SubscriptionIdentifier
    • Sends the command along with the params to the API, which creates a subscriptions on the server. It receives a stream of messages via the provided callback, as these messages get produced. The client can close the stream with returned close function, or use the attached identifier (closeFunction.identifier) to close multiple streams at once via closeStream.

      Parameters

      • command: StreamCommand
      • params: CloudVisionParams | ServiceRequest
      • callback: NotifCallback

      Returns null | SubscriptionIdentifier

    • subscribe(query: Query, callback: NotifCallback): null | SubscriptionIdentifier
    • Creates a subscription to the given query, which will return notifications as they happen. Note that this will not return any historical data. The first update that is sent will be when the state of the data in the query changes.

      Example


      const query = [{
      dataset: {
      type: 'app',
      name: 'analytics'
      },
      paths: [{
      path_elements: ['events', 'activeEvents'],
      }],
      }];
      const handleResponse = (err, res) => {...};

      // Send the request
      const subscriptionCloseFn = connector.subscribe(query, handleResponse);

      Parameters

      • query: Query
      • callback: NotifCallback

      Returns null | SubscriptionIdentifier

    • writeSync(publishRequest: PublishRequest, callback: PublishCallback): void
    • Write data to the CloudVision API server, where the update is a series of notifications of a certain dataset.

      The writeSync operation is synchronous.

      Parameters

      • publishRequest: PublishRequest
      • callback: PublishCallback

      Returns void