Realtime Cloud Storage

ConnectionManager

class ConnectionManager

Provides access to a data layer that manages the creation and dispose of connections, transmission and retrieval of information between the connections and the Realtime Framework servers.

Methods

Realtime.Messaging.Connection add(Realtime.Messaging.Connection connection)

Adds a unique Realtime Connection to the Realtime Messaging platform.

Parameters

Realtime.Messaging.Connection connection

Realtime Connection object.

void addChannel(Object channel)

Adds a channel to a connection.

Parameters

Object channel

structure with the channel definition.

Properties

String name

The name of the channel.

Boolean subscribeOnReconnect optional

Defines if the channel is to be subscribed after a reconnect.

Boolean subscribe optional

Defines if the channel is to be subscribed as soon as the connection is established.

Function messageAdapter optional

Callback method that allow changes to be made to the message. Called when a message arrives through any channel subscribed in this connection.

Function onMessage optional

Event handler raised when a message arrives through the channel.

Function onSubscribe optional

Event handler raised when the channel is subscribed.

Function onUnsubscribe optional

Event handler raised when the channel is unsubscribed.

Connection create(Object connection)

Creates a new connection.

Parameters

Object connection

structure with the connection attributes.

Properties

String id optional

Connection's identification.

String appKey optional

Identifies the application using the Realtime API. Optional only if attribute 'autoConnect' is set to false.

String authToken optional

Identifies a user belonging to the application using the Realtime API. Optional only if attribute 'autoConnect' is set to false.

Number sendRetries optional

Number of times a connection should try to send a message in case the first attempt fails.

Number sendInterval optional

Period of time in miliseconds between message send retries by the connection.

Number timeout optional

Maximum amount of time (miliseconds) a connection tag should take to perform a connect.

Number connectAttempts optional

Number of times a connection should try to issue a connect.

Boolean autoConnect optional

Indicates if a connection should be established implicitly after it's created. Defaults to true.

String metadata optional

Provides information about one or more aspects of the data associated with the connection.

String serverType optional

Tells which library to be used by the Realtime Messaging client. Defaults to 'IbtRealTimeSJ'.

String url optional

Path to the location of the real-time comunication server is located. Optional if attribute 'autoConnect' is set to false.

Boolean isCluster optional

Indicates if connection should be made to a cluster server. Default is true.

Channel channels optional

[ARRAY]Array of channels to be added to the connection.

Function onCreate optional

Event handler raised when the connection is created.

Function onConnect optional

Event handler raised when a connection is successfully established.

Function onDisconnect optional

Event handler raised when the connection has lost comunication with the Online Realtime Communication (Realtime) server.

Function onSubscribe optional

Event handler raised when a channel is subscribed.

Function onUnsubscribe optional

Event handler raised when a channel is unsubscribed.

Function onException optional

Event handler raised when there's an error performing Realtime Messaging Connection related operations.

Function onReconnect optional

Event handler raised when there's a reconnection to the Realtime servers.

Function onReconnecting optional

Event handler raised when a reconnection to the Realtime servers is under way.

Function onMessage optional

Event handler raised when a message arrives through any channel subscribed in this connection.

Function messageAdapter optional

Callback method that allow changes to be made to the message. Called when a message arrives through any channel subscribed in this connection.

Sample

Realtime.Messaging.ConnectionManager.create({
    url: "http://ortc-developers.realtime.co/server/2.1",
    id: "connectionExample",
    appKey: 'your_application_key_here',
    authToken: 'your_authentication_token_here',
    channels: [{ name: 'connectionExample_channel'}]
});

void dispose(String id)

Removes all references of the specified Connection.

Parameters

String id

The id of the intended connection.

Realtime.Messaging.Connection getById(String id)

Gets a connection by its internal or user given id.

Parameters

String id

The id of the intended connection.

void postMessage(Object args)

Sends a message through the specified connections and channel using a RESTful web service.

Parameters

Object args

structure with the arguments to send a message.

Properties

String host

The url of the server.

Boolean isCluster

Flag that indicates if the server is cluster.

String appKey

The application key.

String authToken

The authentication token.

String privateKey

The private key.

String channel

The channel name to send the message.

String message

The message to send.

Function callback optional

The callback to execute after the post of the message. The callback will execute with an object as argument containing the properties error and response.

void saveAuthentication(Object args)

Saves authentication for the specified token with the specified authentication key.

Parameters

Object args

structure with the arguments to perform the authentication.

Properties

String url

The url of the server.

Boolean isCluster

Flag that indicates if the server is cluster. {@default true}

String appKey

The application key.

String authToken

The authentication token.

String privateKey

The private key

Number timeToLive

The time to live in seconds.

Object permissions

The permissions for the channels. The channel name should be the property name and the permission ('r', 'W' and 'p') should be the property value. 'r' stands for read, 'w' for write and 'p' for presence service access.

Boolean isPrivateToken

Flag that indicates if the authentication token is private. If its private, only one connection can use the token (first connection that tries to connect).

Function callback

The callback to execute after the authentication. The callback will execute with two arguments: error and success. If the authentication succeeds the error is null.

void sendMessage(Object message)

Sends a message through the specified connections and channel.

Parameters

Object message

structure with the definition of the message.

Properties

String connections

[ARRAY]Ids of the connections.

String channel

Name of the channel.

Object content

Message to be sent.

Boolean sendOnly optional

Identifies if the message should be sent and discarded by the connection that sends it.

Sample

// send a string message
Realtime.Messaging.ConnectionManager.sendMessage({
    connections: ["myConnection"],
    channel: 'myChannel',
    content: "this is a message." 
});

Properties

Connection[] Connections

The array where the connections ids are stored.