Namespace: diffusion

diffusion

The top-level Diffusion API.

Provides access to Session connections and global namespaces.

Properties:
Name Type Description
version String

The version of this client library in the form major.minor.patch

topics diffusion.topics

Access to the topics namespace.

topicUpdate diffusion.topicUpdate

Access to the topicUpdate namespace.

clients diffusion.clients

Access to PropertyKeys.

selectors diffusion.selectors

Access to the selectors namespace.

datatypes diffusion.datatypes

Access to the datatypes namespace.

locks diffusion.locks

Access to the locks namespace.

errorReport ErrorReport

Access to the ErrorReport class.

Namespaces

clients
datatypes
locks
selectors
topics
topicUpdate

Members


<static, readonly> errors

Enum containing reason codes used to report error conditions.

Some common ErrorReason values are defined as global constants. More specific reasons may be defined by individual features.

Properties:
Name Type Default Description
COMMUNICATION_FAILURE

Communication with the server failed.

SESSION_CLOSED

Communication with the server failed because the session is closed.

REQUEST_TIME_OUT

Communication with the server failed because a service request timed out.

ACCESS_DENIED

The request was rejected because the caller has insufficient permissions.

UNSUPPORTED

The request was rejected because the requested operation is unsupported for this caller.

CALLBACK_EXCEPTION

An application callback threw an exception. Check logs for more information.

INVALID_DATA

An operation failed because invalid data was received.

NO_SUCH_SESSION

An operation failed because an addressed session could not be found.

INCOMPATIBLE_DATATYPE

An operation failed due to using an incompatible data type.

UNHANDLED_MESSAGE

A sent message was not handled by the specified recipient.

TOPIC_TREE_REGISTRATION_CONFLICT

A conflicting registration exists on the same branch of the topic tree.

HANDLER_CONFLICT

A conflicting registration exists on the server.

INVALID_PATH

An invalid path was supplied.

REJECTED_REQUEST

A recipient session has rejected a received message request.

Example
// Handle an error from the server
session.subscribe('foo').on('error', function(e) {
    if (e == diffusion.errors.ACCESS_DENIED) {
        // Handle authorisation error
    } else {
        // Log the problem
        console.log(e);
    }
});

Methods


<static> escape(string)

Escapes special characters in a string that is to be used within a topic property or a session filter.

This is a convenience method which inserts an escape character '\' before any of the special characters ' " or \.

Parameters:
Name Type Description
string String

the string to be escaped

Since:
  • 6.1
Returns:

the string value with escape characters inserted as appropriate

Type
String

<static> rolesToString(roles)

Utility method which converts a set of authorisation roles to the string format required by the $Roles session property.

Parameters:
Name Type Description
roles Set.<String> | Array.<String>

a set of roles

Since:
  • 6.2
Returns:

a string representing the supplied roles, formatted as required by the $Roles session property

Type
String

<static> stringToRoles(string)

Utility method which converts a string of the format required by the $Roles session property into a mutable set of strings.

Parameters:
Name Type Description
string String

the string with quoted roles separated by whitespace or commas

Since:
  • 6.2
Returns:

set of roles

Type
Set.<String>

connect( [options])

Connect to a specified Diffusion server. This will return a Result that will complete succesfully if a session can be connected, or fail if an error was encountered.

If the result is succesful, the fulfilled handler will be called with a Session instance. This session will be in a connected state and may be used for subsequent API calls.

If the result fails, the rejected handler will be called with an error reason.

Parameters:
Name Type Argument Description
options Session.Options | String <optional>

The options to construct the session with.

Returns:

A Result.<Session> for this operation

Type
Result.<Session>
Example
diffusion.connect('example.server.com').then(function(session) {
    // Connected with a session
    console.log('Connected!', session);
}, function(error) {
    // Connection failed
    console.log('Failed to connect', error);
});

log(level)

Set the level of logging used by Diffusion. This will default to silent. Log levels are strings that represent different degrees of information to be logged. Available options are:

  • silent
  • error
  • warn
  • info
  • debug
Parameters:
Name Type Description
level String

The log level to use.


updateConstraints()

Returns an update constraint factory.

Since:
  • 6.2
Returns:

update constraint factory

Type
diffusion.topicUpdate.UpdateConstraintFactory