Realtime Cloud Storage

Connection

class Connection

Represents a connection to the Realtime server.

Methods

Boolean active([Boolean value])

Changes or returns the active state of the connection.

Parameters

Boolean value optional

The new active state.

void connect(Object credentials)

Establishes the connection to the ORTC server.

Parameters

Object credentials

structure with the credentials' attributes.

Properties

String appKey

ORTC's application key

String authToken

ORTC's authentication key. Identifies a user using the application.

Channel createChannel(Channel c)

Adds, but doesn't subscribe, a channel to the connection.

Parameters

Channel c

The channel to be added.

void disconnect()

Closes the connection to the ORTC server.

void dispose()

Disconnects and removes references to this Connection.

String getAnnouncementSubChannel()

Gets the client announcement subchannel.

Boolean getMetadata()

Gets the information related to the connection.

Boolean isConnected()

Checks if the connection to the ORTC server is established.

Boolean isCreated()

Checks if the connection is initialized.

Boolean isSubscribed(String channel)

Checks if the connection has subscribed the channel.

Parameters

String channel

Name of the channel.

void send(Object args)

Transmits a message through a channel.

Parameters

Object args

structure with the message attributes.

Properties

String channel

Name of the channel through which we're sending the message.

Object content

The message to be sent through the channel.

Boolean sendOnly

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

void setMetadata(String metadata)

Associates information about the connection. The metadata is only set before the connection is established and updated after a reconnect.

Parameters

String metadata

Information to store.

void subscribe(Channel channel)

Adds and subscribes a channel to the connection.

Parameters

Channel channel

Channel the connection is going to subscribe.

void unsubscribe(String name)

Unsubscribes a channel from the connection.

Parameters

String name

Name of the channel.

Properties

String announcementSubChannel

The name of the announcement subchannel. Defining and subscribing to an announcement sub channel allows monitoring a single or set of users' ORTCs related activities.

String appKey

Identifies the application using the Realtime API.

String authToken

Identifies a user belonging to the application using the Realtime API.

Boolean autoConnect

Indicates if a connection should be established implicitly after it's created. {@default true}

Object channels

Contains all the existing channels in the connection.

Number connectAttempts

Number of tries a connection should attempt to be established. {@default 5}

Number connectionAttemptsCounter

Number of connection attempts that have been made. Connection attemps stop after it reaches the value specified in connectionAttempts. {@default 0}

String id

Identification of the connection assigned by the user.

String internalId

Identification of the connection, generated automatically.

Boolean isCluster

Indicates if connection should be made to a cluster server. {@default true}

Function messageAdapter

Function that allows changes to be made to a message prior to it being processed by a tag. Called when a message arrives through any channel subscribed to this connection.

Object metadata

Provides information related with the connection itself.

Function onChannelCreate

Event handler raised when a channel is added to the connection.

Function onConnect

Event handler raised when the connection is established.

Function onCreate

Event handler raised when the connection is created.

Function onDisconnect

Event handler raised when there's a disconnection from the Realtime server.

Function onDispose

Event handler raised when a connection is disposed.

Function onException

Event handler raised when an Realtime related exception has occurred.

Function onMessage

Event handler raised when a connection receives a message through a subscribed channel.

Function onReconnect

Event handler raised when a connection to an Realtime server is reestablished.

Function onReconnecting

Event handler raised when a connection to an Realtime server is in the process of being reestablished.

Function onSubscribe

Event handler raised when the connection subscribes a channel.

Function onUnsubscribe

Event handler raised when the connection unsubscribes a channel.

Number sendInterval

Period of time, in miliseconds, between message send retries made by the connection. {@default 1000 ms}

Number sendRetries

Number of times a connection should try to send a message in case the first attempt fails. {@default 5}

Number timeout

Period of time in miliseconds between connection attempts. {@default 10000ms}

String url

Path to the location of the real-time comunication server is located.

Events

void channelCreate(Realtime.Messaging.Channel channel)

Fired when a channel is added to the connection.

Parameters

Realtime.Messaging.Channel channel

structure with the channel's definition.

void connect(Object e)

Fired when the connection is established.

Parameters

Object e

structure with the definition of the event's parameters.

void create(Object e)

Fired when the connection is created.

Parameters

Object e

structure with the definition of the event's parameters.

void disconnect(Object e)

Fired when there's a disconnection from the Realtime server.

Parameters

Object e

structure with the definition of the event's parameters.

void dispose(Object e)

Fired when a connection is disposed.

Parameters

Object e

structure with the definition of the event's parameters.

void exception(Object e)

Fired when an Realtime related exception has occurred.

Parameters

Object e

structure with the definition of the event's parameters.

Properties

String message

description of the raised exception.

void message(Object e)

Fired when a connection receives a message through a subscribed channel.

Parameters

Object e

structure with the definition of the event's parameters.

Properties

String channel

name of the subscribed channel from where the message was received.

String message

message that was received.

void reconnect(Object e)

Fired when a connection to an Realtime server is reestablished.

Parameters

Object e

structure with the definition of the event's parameters.

void reconnecting(Object e)

Fired when a connection to an Realtime server is in the process of being reestablished.

Parameters

Object e

structure with the definition of the event's parameters.

void subscribe(Object e)

Fired when the connection has subscribed to a channel.

Parameters

Object e

structure with the definition of the event's parameters.

Properties

String channel

name of the subscribed channel.

void unsubscribe(Object e)

Fired when the connection has unsubscribed a channel.

Parameters

Object e

structure with the definition of the event's parameters.

Properties

String channel

name of the unsubscribed channel.