CustomProtocol : CustomProtocol
Custom protocol server side API.
Kind: global class
Extends: CustomProtocolCommon
Category: CLIENT
- CustomProtocol :
CustomProtocol
- .protocolTypes :
enum
- .send(messageId, payload, sessionIds, deferred)
- .setTypeFieldName(name)
- .registerProtocol(name, options)
- .registerMessages()
- .registerMessage(messageId, definition)
- .on(messageId, callback)
- .removeCallback(messageId, callback)
- .removeAllCallbacks(messageId)
- .getEncodedMessage(messageId, payload) ⇒
string
- .protocolTypes :
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 |
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. |
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. |
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. |
Registers all the declared messages and their definitions in core class.
Kind: instance method of CustomProtocol
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. |
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. |
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. |
Removes all callbacks for a specified message.
Kind: instance method of CustomProtocol
Param | Type | Description |
---|---|---|
messageId | number |
Id of the message. |
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. |