ChannelStreamConnection

ChannelStreamConnection

Main Channelstream connection class

Constructor

new ChannelStreamConnection()

Source:

Classes

ChannelStreamConnection

Members

channels

Source:

List of channels user should be subscribed to.

connectionId

Source:

Connection identifier.

connectUrl

Source:

URL used in connect().

disconnectUrl

Source:

URL used in disconnect().

heartbeats

Source:

Should send heartbeats.

increaseBounceIv

Source:

How much should every retry interval increase (in milliseconds)

longPollUrl

Source:

Long-polling connection url.

messageDeleteUrl

Source:

URL used in deleteMessage().

messageEditUrl

Source:

URL used in editMessage().

messageUrl

Source:

URL used in message().

mutators

Source:

Mutators hold functions that you can set locally to change the data that the client is sending to all endpoints you can call it like elem.mutators('connect', yourFunc()) mutators will be executed in order they were pushed onto arrays

noWebsocket

Source:

Should use websockets or long-polling by default

shouldReconnect

Source:

Long-polling connection url.

subscribeUrl

Source:

URL used in subscribe().

unsubscribeUrl

Source:

URL used in unsubscribe().

username

Source:

Username of connecting user.

userStateUrl

Source:

URL used in updateUserState().

websocket

Source:

Websocket instance.

websocketUrl

Source:

Websocket connection url.

Methods

addMutator(type, func)

Source:

Add custom function that will manipulate request before its being executed

Parameters:
Name Type Description
type string

type of mutator function to register

func function

a callable to register

beforeListeningCallback(request, data)

Source:

Fired before connection start listening for messages

Parameters:
Name Type Description
request
data

calculateSubscribe(channels)

Source:

calculates list of channels we should add user to based on difference between channels property and passed channel list

Parameters:
Name Type Description
channels Array.<string>

List of channels to subscribe

calculateUnsubscribe(channels)

Source:

calculates list of channels we should remove user from based difference between channels property and passed channel list

Parameters:
Name Type Description
channels Array.<string>

List of channels to un-subscribe

channelsChangedCallback()

Source:

Fired when channels property get mutated

closeConnection()

Source:

Closes currently listening connection.

connect()

Source:

Sends AJAX call that creates user and fetches connection information from the server.

connectCallback(request, data)

Source:

Fired on successful connect() call

Parameters:
Name Type Description
request
data

connectErrorCallback(request, data)

Source:

Fired when client fails connect() call

Parameters:
Name Type Description
request
data

connectionClosedCallback()

Source:

Fired when listening connection is closed

createHeartBeats()

Source:

Starts sending heartbeats to maintain connection and notify server

delete(message)

Source:

Sends a DELETE request to the web application backend.

Parameters:
Name Type Description
message object

Message object sent to DELETE to messageUrl.

disconnect()

Source:

Marks the connection as expired via /disconnect API.

disconnectCallback(request, data)

Source:

Fired after successful disconnect() call

Parameters:
Name Type Description
request
data

edit(message)

Source:

Sends a PATCH request to the web application backend.

Parameters:
Name Type Description
message object

Message object sent via PATCH to messageUrl.

listenCloseCallback(request, data)

Source:

Fired on websocket connection close event

Parameters:
Name Type Description
request
data

listenErrorCallback(request, data)

Source:

Fired on long-pool/websocket connection error event

Parameters:
Name Type Description
request
data

listenMessageCallback(data)

Source:

Fired when messages are received

Parameters:
Name Type Description
data

listenOpenedCallback(request, data)

Source:

Fired when client starts listening for messages

Parameters:
Name Type Description
request
data

message(message)

Source:

Sends a POST to the web application backend.

Parameters:
Name Type Description
message object

Message object sent via POST to messageUrl.

messageCallback(request, data)

Source:

Fired on successful message() call

Parameters:
Name Type Description
request
data

messageDeleteCallback(request, data)

Source:

Fired on successful delete() call

Parameters:
Name Type Description
request
data

messageDeleteErrorCallback(request, data)

Source:

Fired on delete() call error

Parameters:
Name Type Description
request
data

messageEditCallback(request, data)

Source:

Fired on successful edit() call

Parameters:
Name Type Description
request
data

messageEditErrorCallback(request, data)

Source:

Fired on edit() call error

Parameters:
Name Type Description
request
data

messageErrorCallback(request, data)

Source:

Fired on message() call error

Parameters:
Name Type Description
request
data

openLongPoll()

Source:

Opens long-poll connection.

openWebsocket()

Source:

Opens websocket connection.

retryConnection()

Source:

Retries connect() call while incrementing interval between tries up to 1 minute.

setUserStateCallback(request, data)

Source:

Fired on successful updateUserState() call

Parameters:
Name Type Description
request
data

setUserStateErrorCallback(request, data)

Source:

Fired on updateUserState() error

Parameters:
Name Type Description
request
data

startListening(request, data)

Source:

Opens "long lived" (websocket/longpoll) connection to the channelstream server.

Parameters:
Name Type Description
request
data

subscribe(channels)

Source:

Subscribes user to channels.

Parameters:
Name Type Description
channels Array.<string>

List of channels sent via POST to subscribeUrl.

subscribeCallback(request, data)

Source:

Fired on successful subscribe() call

Parameters:
Name Type Description
request
data

subscribeErrorCallback(request, data)

Source:

Fired on subscribe() call error

Parameters:
Name Type Description
request
data

unsubscribe(channels)

Source:

Unsubscribes user from channels.

Parameters:
Name Type Description
channels Array.<string>

List of channels sent via POST to unsubscribeUrl.

unsubscribeCallback(request, data)

Source:

Fired on successful unsubscribe() call

Parameters:
Name Type Description
request
data

unsubscribeErrorCallback(request, data)

Source:

Fired on unsubscribe() call error

Parameters:
Name Type Description
request
data

updateUserState(stateObj)

Source:

Sends AJAX request to update user state.

Parameters:
Name Type Description
stateObj object