Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ValueStream

Provides a stream of topic events, specific to the topic selector that this ValueStream was created for, with topic values provided as instances of the associated DataType.

ValueStream inherits all functions defined on Stream.

Example:

// Create a value stream for topic 'foo'
session.addStream('foo', datatype).on('value', function(topic, specification, newValue, oldValue) {
    // Receive updates for the topic 'foo'
});

// Then subscribe to topic 'foo'
session.select('foo');

Example:

// Attach multiple listeners for events
session.addStream('foo', datatype).on({
    subscribe : function(topic, specification) {
        // Subscribed to a particular topic
    },
    unsubscribe : function(topic, specification, reason) {
        // Unsubscribed from a particular topic
    },
    value : function(topic, specification, newValue, oldValue) {
        // Value from a topic
    }
});

Events

open

Emitted when the subscription is initially opened, passing a reference to the subscription itself. This will only be fired once.

subscribe

Emitted when a topic that is selected by this ValueStream's topic selector is subscribed to by this session. Once subscribed, value update events may be received for this topic. The specification is a TopicSpecification instance that contains details about the topic.

Parameters:

topic: string - The topic to which the subscription applies

specification: TopicSpecification - Instance that contains details about the topic

unsubscribe

Emitted when a topic that was previously subscribed, has been unsubscribed. No further update events will be received from this topic until subscribed again. Unsubscriptions may occur due to the topic being removed, or through calling Session.unsubscribe - an object containing the reason is provided.

Parameters:

topic: string - The topic to which the unsubscription applies

specification: TopicSpecification - Instance that contains details about the topic

reason: UnsubscribeReason - the reason for the unsubscription

value

Emitted when an update has been received for a topic's value. Values will be provided as instances appropriate for the associated DataType this subscription was created for. Both the previous value and the new value are provided.

Parameters:

topic: string - The topic to which the update applies

specification: TopicSpecification - Instance that contains details about the topic

newValue: any - the new value of the topic

oldValue: any - the old value of the topic

close

Emitted when the subscription has been closed using ValueStream.close.

error

Emitted when the subscription request fails. No further events will be emitted after this.

Parameters:

error: ErrorReason - the error the subscription request failed with

Hierarchy

Index

Properties

Methods

Properties

selector

selector: TopicSelector

A static reference to the selector this Subscription was created for.

Methods

close

  • close(): void
  • Close the stream. No further events will be emitted.

    This does not unsubscribe the topic. Other streams may still receive updates for the same topic selector. To unsubscribe, use Session.unsubscribe

    Returns void

off

  • Remove a listener from a specified event.

    Example:

    // Bind a single listener to the 'foo' event and then deregister it
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo', listener);

    Example:

    // Bind a listener to the 'foo' event and deregister all listeners
    var listener = function() {};
    stream.on('foo', listener);
    stream.off('foo');

    Parameters

    • events: string | CallbackMap
    • Optional listener: StreamCallback

      the listener to remove. All listeners for the event are removed if this is not specified. This argument is ignored if the first argument is a CallbackMap.

    Returns Stream

    this stream.

on

  • Register listeners against events.

    A single listener may be bound to an event by passing the event name and listener function.

    Multiple listeners may be bound by passing in a CallbackMap, mapping event names to listener functions.

    Example:

    // Bind a single listener to the 'foo' event
    stream.on('foo', function(arg1, arg2) {
        console.log("Called for 'foo' event", arg1, arg2);
    });

    Example:

    // Bind multiple listeners
    stream.on({
        foo : function() { ... },
        bar : function() { ... },
        baz : function() { ... }
    });

    Parameters

    • events: string | CallbackMap

      the event name or CallbackMap mapping event names to listeners

    • Optional listener: StreamCallback

      the listener to bind to the event, if passed as string. This argument is ignored if the first argument is a CallbackMap.

    Returns Stream

    this stream.