Skip to content

Latest commit

 

History

History
149 lines (103 loc) · 5.68 KB

CLIENT.md

File metadata and controls

149 lines (103 loc) · 5.68 KB

CustomProtocol : CustomProtocol

Custom protocol client side API.

Kind: global class
Extends: CustomProtocolCommon
Category: CLIENT

customProtocol.protocolTypes : enum

There are two types of protocols. Those with messages declared explicitly in the class constructor and those which allow to register messages dynamically at any time.

Kind: instance enum property of CustomProtocol
Properties

Name Type Default
DECLARED_MESSAGES number 1
DYNAMIC_MESSAGES number 2

customProtocol.registerConnection([connection]) ⇒ Symbol

Register a custom connection from DDP.connect.

Kind: instance method of CustomProtocol
Returns: Symbol - Id of the additional DDP connection.

Param Type Description
[connection] Object Reference to DDP connection object.

customProtocol.send(messageId, payload, connection)

Encodes and send the message to the server.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Id of the message.
payload Array Array of data that the message should carry.
connection Object DDP connection instance.

customProtocol.setTypeFieldName(name)

For protocols with dynamic messages sets the field name that holds the message type.

Kind: instance method of CustomProtocol

Param Type Description
name string Name of the field in the message object.

customProtocol.registerProtocol(name, options)

Registers the protocol in core class.

Kind: instance method of CustomProtocol

Param Type Description
name string Class name of the protocol.
options Object An object with the protocol config.

customProtocol.registerMessages()

Registers all the declared messages and their definitions in core class.

Kind: instance method of CustomProtocol

customProtocol.registerMessage(messageId, definition)

Registers a single message.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Unique id of the message.
definition Object Object with the message definition.

customProtocol.on(messageId, callback)

Registers a callback for a specified message.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Id of the message.
callback callback Function that will receive the message payload.

customProtocol.removeCallback(messageId, callback)

Removes a callback for a specified message.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Id of the message.
callback function Reference of the function to call when a message arrives.

customProtocol.removeAllCallbacks(messageId)

Removes all callbacks for a specified message.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Id of the message.

customProtocol.getEncodedMessage(messageId, payload) ⇒ string

Computes the message string by concatenating header and encoded message payload.

Kind: instance method of CustomProtocol

Param Type Description
messageId number Id of the message.
payload Array An array with message payload.