Properties
type
This field exists on all
AGAction instances. It represents the type of the action as a string. It can be used by a middleware function to decide whether to allow or block an action.
request
This field only exists on actions of type
HANDSHAKE_WS and HANDSHAKE_SC. It holds a Node.js http.IncomingMessage object.
socket
This field exists on all action types except for the
HANDSHAKE_WS action. It holds the AGServerSocket whose corresponding client initiated the action.
data
This field exists on all action types except for
HANDSHAKE_WS, HANDSHAKE_SC and AUTHENTICATE actions. It holds the payload associated with the action.
receiver
This field exists only on the
TRANSMIT action. It represents the name of the receiver which this action would trigger if it is allowed through by the middleware.
procedure
This field exists only on the
INVOKE action. It represents the name of the procedure which this action will invoke if it is allowed through by the middleware.
channel
This field exists only on the
SUBSCRIBE, PUBLISH_IN and PUBLISH_OUT actions. It represents the name of the channel which this action would affect if it is allowed through by the middleware.
signedAuthToken
This field exists only on the
AUTHENTICATE action. It represents the signed auth token which was used by the client for authentication. This value can be null.
authToken
This field exists only on the
AUTHENTICATE action. It represents the raw auth token data which was used by the client for authentication. This value can be null.
outcome
The outcome of the action. Can be
null, 'allowed' or 'blocked' depending on which method was called on the action.
promise
A
Promise which will resolve or reject depending on whether the action was allowed or blocked. This property is mostly meant for internal use by SocketCluster middleware.
HANDSHAKE_WS
A string constant which is used to indicate that an action is a low level WebSocket handshake action. See the
type property above.
HANDSHAKE_SC
A string constant which is used to indicate that an action is a SocketCluster handshake action. See the
type property above.
MESSAGE
A string constant which is used to indicate that an action is a message action. See the
type property above.
TRANSMIT
A string constant which is used to indicate that an action is a transmit action. See the
type property above.
INVOKE
A string constant which is used to indicate that an action is an invoke action. See the
type property above.
SUBSCRIBE
A string constant which is used to indicate that an action is a subscribe action. See the
type property above.
PUBLISH_IN
A string constant which is used to indicate that an action is an inbound publish action. See the
type property above.
PUBLISH_OUT
A string constant which is used to indicate that an action is an outbout publish action. See the
type property above.
AUTHENTICATE
A string constant which is used to indicate that an action is an authenticate action. See the
type property above.
Methods
allow([packet])
Allow an action to be processed by the back end server/socket logic. This method accepts an optional
packet argument; if provided, the packet will be used as the action payload instead of action.data. This allows middleware to transform data from clients before it is handled by the back end logic.
block(error)
Prevent an action from reaching the back end server/socket logic. This method accepts an
Error as argument. This error will be sent to the client which initiated the action.