Skip to content

Latest commit

 

History

History
137 lines (95 loc) · 5.33 KB

SERVER.md

File metadata and controls

137 lines (95 loc) · 5.33 KB

CustomProtocol : CustomProtocol

Custom protocol server 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.send(messageId, payload, sessionIds, deferred)

Encodes and sends the message to specified session ids.

Kind: instance method of CustomProtocol

Param Type Default Description
messageId number Id of the message.
payload Array Array of data that the message should carry.
sessionIds Array | string Session id or an array of it.
deferred boolean false Specifies whether to defer the sending in the loop.

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.