ClientServerTransaction

flitter-socket/ClientServerTransaction~ ClientServerTransaction

Specific type of transaction where a request from the client comes in to the server.


Constructor

new ClientServerTransaction(data, cm)

Initialize the transaction from the message data.

Parameters:
Name Type Description
data
cm

Extends

Members

(private) _message :string

Message to be included in the response. User this.message() to get/set.

Type:
  • string

(private) _status :number

HTTP-equivalent status code for this transaction. Use this.status() to get/set.

Type:
  • number

cm :module:flitter-socket/ConnectionManager~ConnectionManager

The connection manager that spawned this transaction.

connection_id :string

Unique ID of the websocket client's connection in the connection manager.

Type:
  • string

endpoint :string

The socket handler's requested endpoing.

Type:
  • string

id :string

Universally-unique id of this transaction. Used by both parties to match up requests and responses.

Type:
  • string

incoming :Object

Contains the incoming data for the transaction. That is, the data from the sender.

Type:
  • Object

outgoing :Object

Contains the outgoing data for the transaction. That is, the data sent/to be sent back to the sender.

Type:
  • Object

received :boolean

Set to true if 1. the transaction was awaiting data and 2. the data has been received

Type:
  • boolean

resolved :boolean

Whether the transaction has completed. That is, has the recipient sent a response.

Type:
  • boolean

sent :boolean

Set to true if 1. this transaction is a response and 2. the response has been sent

Type:
  • boolean

socket :Socket

The open websocket used for communication

Type:
  • Socket

type :"request"|"response"

Is this a request or a response-type transaction?

Type:
  • "request" | "response"

Methods

message(msgopt) → {Transaction|string}

Get or set the message. If a new message is provided, set the message and return this for chaining. Otherwise get the current message.

Parameters:
Name Type Attributes Default Description
msg string <optional>
null
Returns:
  • if message is provided, set the message and return this; otherwise return the current message
Type
Transaction | string

resolve()

Mark the transaction as resolved.

send(data) → {*|boolean|void}

Send data to the recipient of this transaction as stringified JSON, and resolve the transaction.

Parameters:
Name Type Description
data
Returns:
Type
* | boolean | void

set(key, value) → {ClientServerTransaction}

Set values in the outgoing data.

Parameters:
Name Type Default Description
key
value null
Returns:
  • for chaining
Type
ClientServerTransaction

status(codeopt) → {Transaction|number}

Get or set the status code. If a new code is provided, set the status code and return this for chaining. Otherwise, get the current status code.

Parameters:
Name Type Attributes Default Description
code number <optional>
null
Returns:
  • if code is provided, set the code and return this; otherwise return the current code
Type
Transaction | number