ActionHero. Connection

new Connection(data)

Name Type Description
id string

A unique string identifer for this connection.

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.

type string

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

rooms Array

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

canChat Boolean

Can this connection use the chat system?

params Object

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.

totalActions Number

How many actions has this connection run since it connected.

messageId Number

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

connectedAt Number

The timestamp of when this connection was created.

remoteIP string

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

remotePort Number

The remote connection's port.

rawConnection Object

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

The generic represenation 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 Actons and Action Middleware. All Connections share common properties:

Name Type Description
data Object

The specifics of this connection


(static) destroy()


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.

(static) localize(message) → {String}


Localize a key for this connection's locale. Keys usually look like messages.errors.notFound, and are defined in your locales directory. Strings can be interploated as well, connection.localize('the count was {{count}}', {count: 4})

Name Type Description
message String

The mesage key to be translated.


The translated message. If an appropraite translation cannot be found, the key will be returned.


(static) sendFile(path)


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

Name Type Description
path String

The path of the file to send, within one of your api.config.general.paths.public directories.

(static) sendMessage(message)


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

Name Type Description
message String

The message to send. Can be an Object or String... but it depends on the server in use.