ServerClientTransaction

flitter-socket/ServerClientTransaction~ ServerClientTransaction

Specific transaction that is sent from the server to the client, waiting for data from the client.


Constructor

new ServerClientTransaction(data, cm)

Initialize the transaction. Set the outgoing data and the endpoint.

Parameters:
Name Type Description
data Object

information to load into this transaction

cm module:flitter-socket/ConnectionManager~ConnectionManager

the associated connection manager

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 endpoint of this transaction. Typically, corresponds to the name of a method in a controller somewhere.

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

(private) _handler()

Callback function called when the client sends a valid response. Use this.handler() to get/set.

handler(fnopt) → {ServerClientTransaction|function}

Get or set the callback function. If no function is provided, returns the current callback function. If one is specified, set this._handler and return this for chaining.

Parameters:
Name Type Attributes Description
fn function <optional>
Returns:
  • if fn is specified, this; otherwise, the current callback function
Type
ServerClientTransaction | function

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

receipt(data)

Called when data is received from the client. Sets this.received to true and calls the callback handler.

Parameters:
Name Type Description
data object

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

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