Class Connection

The generic representation of a connection for all server types is an Actionhero.Connection. You will never be creating these yourself via an action or task, but you will find them in your Actions and Action Middleware.

Constructors

  • Parameters

    • data: ConnectionData

      The specifics of this connection

    • callCreateMethods: boolean = true

      The specifics of this connection will calls create methods in the constructor. This property will exist for backward compatibility. If you want to construct connection and call create methods within async, you can use await Actionhero.Connection.createAsync(details) for construction.

    Returns Connection

Properties

canChat: boolean

Can this connection use the chat system?

connectedAt: number

The timestamp of when this connection was created

destroyed: boolean
error?: ErrnoException

If there's a local error

extension?: string

If there's a local extension to the request

fingerprint: string

A unique string identifer for this connection, but common among subsequent requests. For example, all web requests from the same client have the same fingerprint, but not the same id

id: string

A unique string identifer for this connection.

matchedRoute?: RouteType
messageId: string

The Id of the latest message this connection has sent to the server.

messages?: {
    message: string;
    [key: string]: any;
}[]

for specHelper

params: ConnectionParams

Any params this connection has saved for use in subsequent Actions.

pendingActions: number

How many actions are currently running for this connection? Most server types have a limit

pipe?: Function
rawConnection: any

Any connection-specific properties. For, example, the HTTP res and req objects for web connections are here

remoteIP: string

The remote connection's IP address (as best as we can tell). May be either IPv4 or IPv6.

remotePort: string | number

The remote connection's port. Related to connection.remoteIP

response?: Record<string, unknown>

storage for a response payload

rooms: string[]

Any rooms this connection is a member of, it it can chat

session?: Record<string, any>

storage for session data

setHeader?: ((key: string, value: string) => {})
setStatusCode?: ((code: number) => {})
totalActions: number

How many actions has this connection run since it connected.

type: string

The type of this connection (web, websocket, etc) as defined by the name of the server which created it

Methods

  • Destroys the connection. If the type/sever of the connection has a goodbye message, it will be sent. The connection will be removed from all rooms. The connection's socket will be closed when possible.

    Returns Promise<void>

  • Send a file to a connection (usually in the context of an Action). Be sure to set data.toRender = false in the action! Uses Server#processFile and will set connection.params.file = path

    Parameters

    • path: string

    Returns Promise<void>

  • Send a message to a connection. Uses Server#sendMessage.

    Parameters

    • message: string | object | any[]
    • Optionalverb: string

    Returns Promise<void>

  • Try to run a verb command for a connection

    Parameters

    • verb: string
    • words: string | string[]

    Returns Promise<any>

  • Parameters

    • data: ConnectionData

      The specifics of this connection

    Returns Promise<Connection>